From 2164d99d5e4bef1da0b0fa2b40f75dd6770006c7 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 19 Apr 2025 08:48:17 +0200 Subject: [PATCH] xterm.c: Move GTK3-specific variables into narrower scopes Avoid declaring GTK3-specific variables in larger-than-necessary scopes, especially under #ifdefs. Instead, declare them where used. This improves readability and reduces #ifdef clutter without changing behavior. * src/xterm.c: [HAVE_GTK3] (x_update_opaque_region): (XTframe_up_to_date, x_new_focus_frame, handle_one_xevent) (x_ignore_errors_for_next_request, x_stop_ignoring_errors): Clean up variable declarations. (cherry picked from commit 177accc53d7ed2afc5768ae117fc6a19749e8fb6) --- src/xterm.c | 59 ++++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index 18a9231e75a..1884e780e34 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -5209,10 +5209,6 @@ x_update_opaque_region (struct frame *f, XEvent *configure) (configure ? configure->xconfigure.height : FRAME_PIXEL_HEIGHT (f))}; -#ifdef HAVE_GTK3 - GObjectClass *object_class; - GtkWidgetClass *class; -#endif if (!FRAME_DISPLAY_INFO (f)->alpha_bits) return; @@ -5240,8 +5236,9 @@ x_update_opaque_region (struct frame *f, XEvent *configure) unknown reason. (bug#55779) */ if (!FRAME_PARENT_FRAME (f)) { - object_class = G_OBJECT_GET_CLASS (FRAME_GTK_OUTER_WIDGET (f)); - class = GTK_WIDGET_CLASS (object_class); + GObjectClass *object_class + = G_OBJECT_GET_CLASS (FRAME_GTK_OUTER_WIDGET (f)); + GtkWidgetClass *class = GTK_WIDGET_CLASS (object_class); if (class->style_updated) class->style_updated (FRAME_GTK_OUTER_WIDGET (f)); @@ -7635,12 +7632,6 @@ x_update_end (struct frame *f) static void XTframe_up_to_date (struct frame *f) { -#if defined HAVE_XSYNC && defined HAVE_GTK3 - GtkWidget *widget; - GdkWindow *window; - GdkFrameClock *clock; -#endif - eassert (FRAME_X_P (f)); block_input (); FRAME_MOUSE_UPDATE (f); @@ -7667,10 +7658,10 @@ XTframe_up_to_date (struct frame *f) #else if (FRAME_X_OUTPUT (f)->xg_sync_end_pending_p) { - widget = FRAME_GTK_OUTER_WIDGET (f); - window = gtk_widget_get_window (widget); + GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f); + GdkWindow *window = gtk_widget_get_window (widget); eassert (window); - clock = gdk_window_get_frame_clock (window); + GdkFrameClock *clock = gdk_window_get_frame_clock (window); eassert (clock); gdk_frame_clock_request_phase (clock, @@ -11980,12 +11971,10 @@ x_new_focus_frame (struct x_display_info *dpyinfo, struct frame *frame) { struct frame *old_focus = dpyinfo->x_focus_frame; #if defined USE_GTK && !defined HAVE_GTK3 && defined HAVE_XINPUT2 - XIEventMask mask; - ptrdiff_t l; - if (dpyinfo->supports_xi2) { - l = XIMaskLen (XI_LASTEVENT); + ptrdiff_t l = XIMaskLen (XI_LASTEVENT); + XIEventMask mask; mask.mask = alloca (l); mask.mask_len = l; memset (mask.mask, 0, l); @@ -19287,12 +19276,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, struct frame *f = x_top_window_to_frame (dpyinfo, event->xclient.window); -#if defined HAVE_GTK3 - GtkWidget *widget; - GdkWindow *window; - GdkFrameClock *frame_clock; -#endif - if (f) { #ifndef HAVE_GTK3 @@ -19313,8 +19296,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, *finish = X_EVENT_DROP; #else - widget = FRAME_GTK_OUTER_WIDGET (f); - window = gtk_widget_get_window (widget); + GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f); + GdkWindow *window = gtk_widget_get_window (widget); eassert (window); /* This could be a (former) child frame for which @@ -19324,7 +19307,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (widget && !FRAME_X_OUTPUT (f)->xg_sync_end_pending_p) { - frame_clock = gdk_window_get_frame_clock (window); + GdkFrameClock *frame_clock = gdk_window_get_frame_clock (window); eassert (frame_clock); gdk_frame_clock_request_phase (frame_clock, @@ -24641,9 +24624,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, int i, ndevices, n_disabled, *disabled; struct xi_device_t *device; #if !defined USE_X_TOOLKIT && (!defined USE_GTK || defined HAVE_GTK3) - bool any_changed; - - any_changed = false; + bool any_changed = false; #endif /* !USE_X_TOOLKIT && (!USE_GTK || HAVE_GTK3) */ hev = (XIHierarchyEvent *) xi_event; SAFE_NALLOCA (disabled, 1, hev->num_info); @@ -24770,9 +24751,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, { struct xi_device_t *device, *source; bool menu_bar_p = false, tool_bar_p = false; -#ifdef HAVE_GTK3 - GdkRectangle test_rect; -#endif EMACS_INT local_detail; device = xi_device_from_id (dpyinfo, xev->deviceid); source = xi_device_from_id (dpyinfo, xev->sourceid); @@ -24805,6 +24783,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, { int scale = xg_get_scale (f); + GdkRectangle test_rect; test_rect.x = xev->event_x / scale; test_rect.y = xev->event_y / scale; test_rect.width = 1; @@ -26462,9 +26441,6 @@ x_ignore_errors_for_next_request (struct x_display_info *dpyinfo, { struct x_failable_request *request, *max; unsigned long next_request; -#ifdef HAVE_GTK3 - GdkDisplay *gdpy; -#endif /* This code is not reentrant, so be sure nothing calls it recursively in response to input. */ @@ -26475,9 +26451,7 @@ x_ignore_errors_for_next_request (struct x_display_info *dpyinfo, callbacks, which this can be called from. Instead of trying to restore our own, add a trap for the following requests with GDK as well. */ - - gdpy = gdk_x11_lookup_xdisplay (dpyinfo->display); - + GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpyinfo->display); if (gdpy) gdk_x11_display_error_trap_push (gdpy); #endif @@ -26521,9 +26495,6 @@ void x_stop_ignoring_errors (struct x_display_info *dpyinfo) { struct x_failable_request *range; -#ifdef HAVE_GTK3 - GdkDisplay *gdpy; -#endif range = dpyinfo->next_failable_request - 1; range->end = XNextRequest (dpyinfo->display) - 1; @@ -26535,7 +26506,7 @@ x_stop_ignoring_errors (struct x_display_info *dpyinfo) emacs_abort (); #ifdef HAVE_GTK3 - gdpy = gdk_x11_lookup_xdisplay (dpyinfo->display); + GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpyinfo->display); if (gdpy) gdk_x11_display_error_trap_pop_ignored (gdpy); -- 2.39.5