From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.devel Subject: Re: MPS: scroll-bars Date: Sun, 05 May 2024 09:53:33 +0200 Message-ID: <87a5l4r8xu.fsf@gmail.com> References: <875xvvp3fo.fsf@gmail.com> <87r0eicht1.fsf_-_@gmail.com> <87plu29lcc.fsf@yahoo.com> <87fruyccs8.fsf@gmail.com> <878r0q9dzd.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8374"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Po Lu , Eli Zaretskii , Emacs Devel To: Gerd =?utf-8?Q?M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 05 09:54:08 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s3WhD-00023e-S6 for ged-emacs-devel@m.gmane-mx.org; Sun, 05 May 2024 09:54:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3Wgn-0003Ub-MG; Sun, 05 May 2024 03:53:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3Wgm-0003Ty-CV for emacs-devel@gnu.org; Sun, 05 May 2024 03:53:40 -0400 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s3Wgk-0001U2-6O; Sun, 05 May 2024 03:53:40 -0400 Original-Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a59b81d087aso113740166b.3; Sun, 05 May 2024 00:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714895616; x=1715500416; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=pdk8JeSBvueBfoS/oL3RAdCbWNh3Jmfj8g6Abr4GLw8=; b=ADexVckRdhzV+P4QEjLKmGoTtH9Dppor1BxIGqhBGm82UhYvUMcp7SD84CGgW6iZKp jUHAPh+hN48fIoD5R+9Sf9GEFWwMNqjRtVRWUKcJEXMs4SRPbYK8bHWp5g7mG/STke4d pNDwzrhV2yCiJZzH7T6mTOCmhMXP2l0SLIcMFOpz4FkAkkUyEba+ITyiF9u+JmnvHMcV 9NXu1d2q+/QZw6mbbrr9UMUjC/irntAk+uozVYHRIroOA7ddm2A72eLttq5PMZcSRWj1 pnA9PBDmOwYucvWHQ+yXh9p4dYQ9NmASQIRWn8YNbfO8VpuKOpylX0NtZFmMXfsNzTan DJQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714895616; x=1715500416; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pdk8JeSBvueBfoS/oL3RAdCbWNh3Jmfj8g6Abr4GLw8=; b=jPgF6aOi4Gi9F2Vau4Nw49q4/sXhDj+95cwwSTeBiQlXMIepCLf2fqUneB2lIMrDX7 c1b4gr/irJovIy6uTvE5CIVKGSNc0dI/3d/0xXATR7EZSpcc1OYefMP4eTXx2ER6UGiQ 5fWOvye/chzUvLB4A0kIsLaJgrfm5u/DztkaBH/TLe6ULI3h7BuRiddAxZ/cRnmkxOld bSO4L4P1RDV6PTU5DbCVnMYhfMArqyfHG77E+VfVz5vj8OEcM2/inAtzLQjSynkjlpVR OF8ka8i9l/4nbU0uXwoHMxu/IsjgN4pM1Ny8Fyr1/L081+cdLqK3Z/80W50uu1HcRC9q 6Pww== X-Forwarded-Encrypted: i=1; AJvYcCVZJD4EmL5tJHjE9sBbzsaCWumdiTJU9IB0aN+0llu5vNZWl/zkg+uvGCN7xyGF/YneTlXw9HLX0PwzQBX8A9fU9GOBSyFKWRfnfDywfDpgbGE= X-Gm-Message-State: AOJu0YwFfgTER+Nu/WtgRGn2l0HS60gV0JWJk2u3CUWxa7UXxoMqbnJi w5Mm7xmTA/clbAFT57r0nys2aj92RI3RCUpQXrWcLnRQgz4UzF1x4elrwA== X-Google-Smtp-Source: AGHT+IGHH9BWmvSHHmm/YPkjXbl9gGiUnntgZRfFJ+nvfq4hpsyWbwNtpew3hSf6xyltviO2aiQblA== X-Received: by 2002:aa7:de0c:0:b0:572:df77:a71b with SMTP id h12-20020aa7de0c000000b00572df77a71bmr4220418edv.11.1714895615386; Sun, 05 May 2024 00:53:35 -0700 (PDT) Original-Received: from caladan (dial-184253.pool.broadband44.net. [212.46.184.253]) by smtp.gmail.com with ESMTPSA id n4-20020aa7d044000000b005720e083878sm3710826edo.49.2024.05.05.00.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 00:53:34 -0700 (PDT) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llman?= =?utf-8?Q?n=22's?= message of "Sun, 05 May 2024 06:52:36 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=eller.helmut@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:318783 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, May 05 2024, Gerd M=C3=B6llmann wrote: > I believe the frame::condemned_scroll_bars is okay on NS as it is now. > With all caveats as usual. I have a hunch that those would need weak references to work as intended. But I'm happy to let them leak for now. Below is my patch for the scroll-bars. I went for the indirection layer solution. Though, the mark-and-sweep pool idea might be more broadly usable; with so many different GUI toolkits it's hard to say. I also had a problem with the tool-bar, triggered by this test: (dotimes (i 40) (igc--collect) (message "%S" (make-list i nil)) (redisplay)) The third patch stops allocating glyph matrices as ambiguous roots. Seems to work for me. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-scroll-bars-for-GTK.patch >From 0e0cc32798f6dc8947e411d0e58ae4b8ea2aaced Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 5 May 2024 06:36:24 +0200 Subject: [PATCH] Fix scroll bars for GTK Use a layer of indirection when struct scroll_bar pointers are used in GTK callbacks. * src/gtkutil.c (xg_finish_scroll_bar_creation): Create a cell with a pointer to the scroll_bar and pass it to callbacks. Also Register a "destroy" callback to free it. (xg_gtk_scroll_free_scroll_bar_cell): New. * src/xterm.c (xg_scroll_callback, xg_end_scroll_callback): Load the scroll_bar* out the cell. (syms_of_xterm): Staticpro window_being_scrolled. (x_unprotect_window_for_callback): Clear unused elements in the protected_windows array to allow windows to be collected. (x_cache_xi_devices, xi_disable_devices, x_term_init): Add FIXMEs. --- src/gtkutil.c | 37 +++++++++++++++++++++++++++++++++++-- src/xterm.c | 21 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/gtkutil.c b/src/gtkutil.c index a01b8a41d5d..342dd35da13 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -44,6 +44,9 @@ #define xp pgtk #include "termhooks.h" #include "keyboard.h" #include "coding.h" +#ifdef HAVE_MPS +#include "igc.h" +#endif #include @@ -4523,6 +4526,13 @@ xg_scroll_bar_size_allocate_cb (GtkWidget *widget, } #endif +static void +xg_gtk_scroll_free_scroll_bar_cell (GtkWidget *widget, gpointer data) +{ + struct scroll_bar **bar_cell = data; + igc_xfree (bar_cell); +} + static void xg_finish_scroll_bar_creation (struct frame *f, GtkWidget *wscroll, @@ -4558,14 +4568,37 @@ xg_finish_scroll_bar_creation (struct frame *f, (gpointer) scroll_id); #endif +#ifdef HAVE_MPS + // FIXME: can use exact reference + struct scroll_bar **bar_cell = + igc_xzalloc_ambig (sizeof (struct scroll_bar*)); + bar_cell[0] = bar; +#endif g_signal_connect (G_OBJECT (wscroll), "change-value", scroll_callback, - (gpointer) bar); +#ifdef HAVE_MPS + (gpointer) bar_cell +#else + (gpointer) bar +#endif + ); g_signal_connect (G_OBJECT (wscroll), "button-release-event", end_callback, - (gpointer) bar); +#ifdef HAVE_MPS + (gpointer) bar_cell +#else + (gpointer) bar +#endif + ); + +#ifdef HAVE_MPS + g_signal_connect (G_OBJECT (wscroll), + "destroy", + G_CALLBACK (xg_gtk_scroll_free_scroll_bar_cell), + (gpointer) bar_cell); +#endif /* The scroll bar widget does not draw on a window of its own. Instead it draws on the parent window, in this case the edit widget. So diff --git a/src/xterm.c b/src/xterm.c index c47c7b0534d..7acd7f9c2a5 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -5748,6 +5748,7 @@ x_cache_xi_devices (struct x_display_info *dpyinfo) } #ifdef HAVE_MPS + // FIXME: use exact references dpyinfo->devices = igc_xzalloc_ambig (sizeof *dpyinfo->devices * ndevices); #else dpyinfo->devices = xzalloc (sizeof *dpyinfo->devices * ndevices); @@ -13782,6 +13783,7 @@ xi_disable_devices (struct x_display_info *dpyinfo, ndevices = 0; #ifdef HAVE_MPS + // FIXME: use exact references devices = igc_xzalloc_ambig (sizeof *devices * dpyinfo->num_devices); #else devices = xzalloc (sizeof *devices * dpyinfo->num_devices); @@ -15480,6 +15482,10 @@ x_unprotect_window_for_callback (struct x_display_info *dpyinfo) memmove (dpyinfo->protected_windows, &dpyinfo->protected_windows[1], sizeof (Lisp_Object) * dpyinfo->n_protected_windows); +#ifdef HAVE_MPS + dpyinfo->protected_windows[dpyinfo->n_protected_windows] = Qnil; +#endif + return window; } @@ -15718,7 +15724,12 @@ xg_scroll_callback (GtkRange *range, GtkScrollType scroll, whole = 0; portion = 0; +#ifdef HAVE_MPS + struct scroll_bar** bar_cell = user_data; + bar = *bar_cell; +#else bar = user_data; +#endif part = scroll_bar_nowhere; adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range)); f = g_object_get_data (G_OBJECT (range), XG_FRAME_DATA); @@ -15795,9 +15806,14 @@ xg_end_scroll_callback (GtkWidget *widget, GdkEventButton *event, gpointer user_data) { +#ifdef HAVE_MPS + struct scroll_bar **bar_cell = user_data; + struct scroll_bar *bar = *bar_cell; +#else struct scroll_bar *bar; bar = user_data; +#endif bar->dragging = -1; if (WINDOWP (window_being_scrolled)) @@ -16936,6 +16952,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio Redraw the scroll bar manually. */ x_scroll_bar_redraw (bar); #endif + } else { @@ -30693,6 +30710,7 @@ #define NUM_ARGV 10 /* We have definitely succeeded. Record the new connection. */ #ifdef HAVE_MPS + // FIXME: use exact references dpyinfo = igc_xzalloc_ambig (sizeof *dpyinfo); #else dpyinfo = xzalloc (sizeof *dpyinfo); @@ -32498,6 +32516,9 @@ syms_of_xterm (void) x_dnd_unsupported_drop_data = Qnil; staticpro (&x_dnd_unsupported_drop_data); + window_being_scrolled = Qnil; + staticpro (&window_being_scrolled); + /* Used by x_cr_export_frames. */ DEFSYM (Qconcat, "concat"); -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-xg_frame_tb_info-an-ambiguous-root.patch >From fd98e52e0efdb5e7bbf37919e3e95f8e440313b0 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 5 May 2024 09:01:06 +0200 Subject: [PATCH] Make xg_frame_tb_info an ambiguous root We could use exact references in the future. * src/gtkutil.c (xg_create_tool_bar): Use igc_xzalloc_ambig for allocation. (free_frame_tool_bar): Use igc_xfree to free it. --- src/gtkutil.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gtkutil.c b/src/gtkutil.c index 342dd35da13..31e0b915000 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -5496,7 +5496,12 @@ xg_create_tool_bar (struct frame *f) TB_INFO_KEY); if (! tbinfo) { +#ifdef HAVE_MPS + // FIXME: use exact references + tbinfo = igc_xzalloc_ambig (sizeof (*tbinfo)); +#else tbinfo = xmalloc (sizeof (*tbinfo)); +#endif tbinfo->last_tool_bar = Qnil; tbinfo->style = Qnil; tbinfo->hmargin = tbinfo->vmargin = 0; @@ -6162,7 +6167,11 @@ free_frame_tool_bar (struct frame *f) TB_INFO_KEY); if (tbinfo) { +#ifdef HAVE_MPS + igc_xfree (tbinfo); +#else xfree (tbinfo); +#endif g_object_set_data (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), TB_INFO_KEY, NULL); -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Glyph-matrices-don-t-need-to-be-ambiguous-roots.patch >From 3d3187e5c55a770cd68b1144479a70032b3c3558 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Sun, 5 May 2024 09:38:48 +0200 Subject: [PATCH] Glyph matrices don't need to be ambiguous roots We scan them with fix_glyph_matrix as part of fix_windows. So avoid scanning them twice. save_current_matrix and restore_current_matrix create temporary matrices that aren't seen by fix_glyph_matrix; these are still ambiguous roots. * src/dispnew.c (adjust_glyph_matrix, realloc_glyph_pool) (free_glyph_matrix): Use plain malloc instead of igc_xzalloc_ambig. (restore_current_matrix): Use igc_free where needed. --- src/dispnew.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/dispnew.c b/src/dispnew.c index 7bb78c3b214..4d7586bdc1e 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -304,11 +304,7 @@ free_glyph_matrix (struct glyph_matrix *matrix) /* Free glyph memory if MATRIX owns it. */ if (matrix->pool == NULL) for (i = 0; i < matrix->rows_allocated; ++i) -#ifdef HAVE_MPS - igc_xfree (matrix->rows[i].glyphs[LEFT_MARGIN_AREA]); -#else xfree (matrix->rows[i].glyphs[LEFT_MARGIN_AREA]); -#endif /* Free row structures and the matrix itself. */ xfree (matrix->rows); xfree (matrix); @@ -512,13 +508,8 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y while (row < end) { row->glyphs[LEFT_MARGIN_AREA] = -#ifdef HAVE_MPS - igc_xnrealloc_ambig (row->glyphs[LEFT_MARGIN_AREA], - dim.width, sizeof (struct glyph)); -#else xnrealloc (row->glyphs[LEFT_MARGIN_AREA], dim.width, sizeof (struct glyph)); -#endif /* The mode line, if displayed, never has marginal areas. */ if ((row == matrix->rows + dim.height - 1 && !(w && window_wants_mode_line (w))) @@ -1374,11 +1365,7 @@ free_glyph_pool (struct glyph_pool *pool) --glyph_pool_count; eassert (glyph_pool_count >= 0); #endif -#ifdef HAVE_MPS - igc_xfree (pool->glyphs); -#else xfree (pool->glyphs); -#endif xfree (pool); } } @@ -1409,15 +1396,9 @@ realloc_glyph_pool (struct glyph_pool *pool, struct dim matrix_dim) if (needed > pool->nglyphs) { ptrdiff_t old_nglyphs = pool->nglyphs; -#ifdef HAVE_MPS - pool->glyphs - = igc_xpalloc_ambig (pool->glyphs, &pool->nglyphs, needed - old_nglyphs, - -1, sizeof *pool->glyphs); -#else pool->glyphs = xpalloc (pool->glyphs, &pool->nglyphs, needed - old_nglyphs, -1, sizeof *pool->glyphs); -#endif memclear (pool->glyphs + old_nglyphs, (pool->nglyphs - old_nglyphs) * sizeof *pool->glyphs); @@ -2055,8 +2036,9 @@ restore_current_matrix (struct frame *f, struct glyph_matrix *saved) memcpy (to->glyphs[RIGHT_MARGIN_AREA], from->glyphs[RIGHT_MARGIN_AREA], nbytes); to->used[RIGHT_MARGIN_AREA] = from->used[RIGHT_MARGIN_AREA]; + #ifdef HAVE_MPS - xfree (from->glyphs[RIGHT_MARGIN_AREA]); + igc_xfree (from->glyphs[RIGHT_MARGIN_AREA]); #else xfree (from->glyphs[RIGHT_MARGIN_AREA]); #endif -- 2.39.2 --=-=-=--