From 7fbc0ccc01fe5cbc9991035c436dd1978454c01a Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 5 Sep 2023 14:13:46 +0200 Subject: [PATCH] x11: Hook X11 focus management to MetaDisplay signal This makes the MetaX11Display indirectly react to MetaDisplay changes, rather than having the MetaDisplay also drive the MetaX11Display focus. Part-of: --- src/core/display.c | 8 -------- src/x11/meta-x11-display-private.h | 3 --- src/x11/meta-x11-display.c | 20 +++++++++++++++++++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/core/display.c b/src/core/display.c index b30414d19..694e2cd44 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -1628,14 +1628,6 @@ meta_display_set_input_focus (MetaDisplay *display, g_signal_emit (display, display_signals[FOCUS_WINDOW], 0, window, ms2us (timestamp)); -#ifdef HAVE_X11_CLIENT - if (display->x11_display) - { - meta_x11_display_set_input_focus (display->x11_display, window, - timestamp); - } -#endif - meta_display_update_focus_window (display, window); display->last_focus_time = timestamp; diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h index 24860e8a7..3714b6a9a 100644 --- a/src/x11/meta-x11-display-private.h +++ b/src/x11/meta-x11-display-private.h @@ -245,9 +245,6 @@ void meta_x11_display_update_focus_window (MetaX11Display *x11_display, Window xwindow, gulong serial, gboolean focused_by_us); -void meta_x11_display_set_input_focus (MetaX11Display *x11_display, - MetaWindow *window, - uint32_t timestamp); MetaDisplay * meta_x11_display_get_display (MetaX11Display *x11_display); diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index d4cb92e5e..d019f7ddf 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -105,6 +105,9 @@ static void meta_x11_display_init_frames_client (MetaX11Display *x11_display); static void meta_x11_display_remove_cursor_later (MetaX11Display *x11_display); +static void meta_x11_display_set_input_focus (MetaX11Display *x11_display, + MetaWindow *window, + uint32_t timestamp); static MetaBackend * backend_from_x11_display (MetaX11Display *x11_display) @@ -1168,6 +1171,15 @@ on_stage_key_focus_changed (MetaX11Display *x11_display) } #endif +static void +focus_window_cb (MetaX11Display *x11_display, + MetaWindow *window, + int64_t timestamp_us) +{ + meta_x11_display_set_input_focus (x11_display, window, + us2ms (timestamp_us)); +} + static void meta_x11_display_init_frames_client (MetaX11Display *x11_display) { @@ -1319,6 +1331,12 @@ meta_x11_display_new (MetaDisplay *display, G_CONNECT_SWAPPED); update_cursor_theme (x11_display); + g_signal_connect_object (display, + "focus-window", + G_CALLBACK (focus_window_cb), + x11_display, + G_CONNECT_SWAPPED); + #ifdef HAVE_XWAYLAND if (!meta_is_wayland_compositor ()) #endif @@ -2067,7 +2085,7 @@ meta_x11_display_set_input_focus_internal (MetaX11Display *x11_display, meta_x11_error_trap_pop (x11_display); } -void +static void meta_x11_display_set_input_focus (MetaX11Display *x11_display, MetaWindow *window, uint32_t timestamp)