From: Po Lu Date: Sun, 13 Mar 2022 01:28:58 +0000 (+0800) Subject: Improve reliaibility of scroll bar dimensions adjustment on GTK 3 X-Git-Tag: emacs-29.0.90~1931^2~1169 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e7ab69e762c10073e6c52b69ff5e83ad2c638803;p=emacs.git Improve reliaibility of scroll bar dimensions adjustment on GTK 3 * src/gtkutil.c (xg_scroll_bar_size_allocate_cb): New function. (xg_finish_scroll_bar_creation): Attach new signal. (xg_update_scrollbar_pos) (xg_update_horizontal_scrollbar_pos): Also set window dimensions for the event box. * src/xterm.c (x_scroll_bar_configure): New function. * src/xterm.h: Update prototypes. --- diff --git a/src/gtkutil.c b/src/gtkutil.c index 7287f6761db..174a1bffeae 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -4476,6 +4476,32 @@ xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data) } #endif +#if defined HAVE_GTK3 && !defined HAVE_PGTK +static void +xg_scroll_bar_size_allocate_cb (GtkWidget *widget, + GdkRectangle *allocation, + gpointer user_data) +{ + GdkEvent *event = gtk_get_current_event (); + GdkEvent dummy; + + if (event && event->any.type == GDK_CONFIGURE) + x_scroll_bar_configure (event); + else + { + /* These are the only fields used by x_scroll_bar_configure. */ + dummy.configure.send_event = FALSE; + dummy.configure.x = allocation->x; + dummy.configure.y = allocation->y; + dummy.configure.width = allocation->width; + dummy.configure.height = allocation->height; + dummy.configure.window = gtk_widget_get_window (widget); + + x_scroll_bar_configure (&dummy); + } +} +#endif + static void xg_finish_scroll_bar_creation (struct frame *f, GtkWidget *wscroll, @@ -4494,7 +4520,13 @@ xg_finish_scroll_bar_creation (struct frame *f, #ifndef HAVE_GTK3 gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS); #endif - g_object_set_data (G_OBJECT (wscroll), XG_FRAME_DATA, (gpointer)f); + g_object_set_data (G_OBJECT (wscroll), XG_FRAME_DATA, (gpointer) f); + +#if defined HAVE_GTK3 && !defined HAVE_PGTK + g_signal_connect (G_OBJECT (webox), "size-allocate", + G_CALLBACK (xg_scroll_bar_size_allocate_cb), + NULL); +#endif #if defined HAVE_PGTK || !defined HAVE_GTK3 ptrdiff_t scroll_id = xg_store_widget_in_map (wscroll); @@ -4534,6 +4566,7 @@ xg_finish_scroll_bar_creation (struct frame *f, gtk_widget_show_all (webox); #elif defined HAVE_GTK3 bar->x_window = GTK_WIDGET_TO_X_WIN (webox); + gtk_widget_show_all (webox); #else GTK_WIDGET_TO_X_WIN (webox); #endif @@ -4553,6 +4586,7 @@ xg_finish_scroll_bar_creation (struct frame *f, #ifndef HAVE_PGTK gtk_widget_add_events (webox, GDK_STRUCTURE_MASK); + gtk_widget_set_double_buffered (wscroll, FALSE); #endif #endif @@ -4662,6 +4696,9 @@ xg_update_scrollbar_pos (struct frame *f, { GtkWidget *wfixed = f->output_data.xp->edit_widget; GtkWidget *wparent = gtk_widget_get_parent (wscroll); +#if !defined HAVE_PGTK && defined HAVE_GTK3 + GdkWindow *wdesc = gtk_widget_get_window (wparent); +#endif gint msl; int scale = xg_get_scale (f); @@ -4694,6 +4731,14 @@ xg_update_scrollbar_pos (struct frame *f, { gtk_widget_show_all (wparent); gtk_widget_set_size_request (wscroll, width, height); + +#if !defined HAVE_PGTK && defined HAVE_GTK3 + if (wdesc) + { + gdk_window_move_resize (wdesc, left, top, width, height); + gtk_widget_queue_allocate (wparent); + } +#endif } if (oldx != -1 && oldw > 0 && oldh > 0) @@ -4757,6 +4802,9 @@ xg_update_horizontal_scrollbar_pos (struct frame *f, { GtkWidget *wfixed = f->output_data.xp->edit_widget; GtkWidget *wparent = gtk_widget_get_parent (wscroll); +#if !defined HAVE_PGTK && defined HAVE_GTK3 + GdkWindow *wdesc = gtk_widget_get_window (wparent); +#endif gint msl; int scale = xg_get_scale (f); @@ -4788,6 +4836,14 @@ xg_update_horizontal_scrollbar_pos (struct frame *f, { gtk_widget_show_all (wparent); gtk_widget_set_size_request (wscroll, width, height); + +#if !defined HAVE_PGTK && defined HAVE_GTK3 + if (wdesc) + { + gdk_window_move_resize (wdesc, left, top, width, height); + gtk_widget_queue_allocate (wparent); + } +#endif } if (oldx != -1 && oldw > 0 && oldh > 0) /* Clear under old scroll bar position. */ diff --git a/src/xterm.c b/src/xterm.c index 46f9364abec..18a8d5b431a 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -9952,6 +9952,34 @@ flush_dirty_back_buffer_on (struct frame *f) unblock_input (); } +#ifdef HAVE_GTK3 +void +x_scroll_bar_configure (GdkEvent *event) +{ + XEvent configure; + GdkDisplay *gdpy; + Display *dpy; + + configure.xconfigure.type = ConfigureNotify; + configure.xconfigure.serial = 0; + configure.xconfigure.send_event = event->configure.send_event; + configure.xconfigure.x = event->configure.x; + configure.xconfigure.y = event->configure.y; + configure.xconfigure.width = event->configure.width; + configure.xconfigure.height = event->configure.height; + configure.xconfigure.border_width = 0; + configure.xconfigure.event = GDK_WINDOW_XID (event->configure.window); + configure.xconfigure.window = GDK_WINDOW_XID (event->configure.window); + configure.xconfigure.above = None; + configure.xconfigure.override_redirect = False; + + gdpy = gdk_window_get_display (event->configure.window); + dpy = gdk_x11_display_get_xdisplay (gdpy); + + x_dispatch_event (&configure, dpy); +} +#endif + /** mouse_or_wdesc_frame: When not dropping and the mouse was grabbed for DPYINFO, return the frame where the mouse was seen last. If @@ -11319,8 +11347,11 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (configureEvent.xconfigure.width != max (bar->width, 1) || configureEvent.xconfigure.height != max (bar->height, 1)) - XResizeWindow (dpyinfo->display, bar->x_window, - max (bar->width, 1), max (bar->height, 1)); + { + XResizeWindow (dpyinfo->display, bar->x_window, + max (bar->width, 1), max (bar->height, 1)); + x_flush (WINDOW_XFRAME (XWINDOW (bar->window))); + } if (f && FRAME_X_DOUBLE_BUFFERED_P (f)) x_drop_xrender_surfaces (f); diff --git a/src/xterm.h b/src/xterm.h index 5b199cab6b6..3638f322e51 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1353,6 +1353,10 @@ extern void x_xr_apply_ext_clip (struct frame *f, GC gc); extern void x_xr_reset_ext_clip (struct frame *f); #endif +#ifdef HAVE_GTK3 +extern void x_scroll_bar_configure (GdkEvent *); +#endif + extern void x_display_set_last_user_time (struct x_display_info *, Time); INLINE int