From 938317195854546ed969841bf1508824c61fbf0b Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 2 Nov 2023 14:23:22 +0100 Subject: [PATCH] wayland: Move Wayland focus synchronization code out of core Handle focus synchronization in MetaWaylandCompositor itself. This is so far plumbed so that MetaDisplay still drives focus synchronization directly. Part-of: --- src/core/display.c | 13 +------------ src/wayland/meta-wayland.c | 34 ++++++++++++++++++++++++++++++++++ src/wayland/meta-wayland.h | 2 ++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/core/display.c b/src/core/display.c index e525ffa89..4d4b72af3 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -1493,19 +1493,8 @@ meta_display_sync_wayland_input_focus (MetaDisplay *display) { #ifdef HAVE_WAYLAND MetaWaylandCompositor *compositor = wayland_compositor_from_display (display); - MetaWindow *focus_window = NULL; - if (!meta_display_windows_are_interactable (display)) - focus_window = NULL; - else if (!display->focus_window) - focus_window = NULL; - else if (display->focus_window && - meta_window_get_wayland_surface (display->focus_window)) - focus_window = display->focus_window; - else - meta_topic (META_DEBUG_FOCUS, "Focus change has no effect, because there is no matching wayland surface"); - - meta_wayland_compositor_set_input_focus (compositor, focus_window); + meta_wayland_compositor_sync_focus (compositor); #endif } diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c index 60c442d21..36ce5aed2 100644 --- a/src/wayland/meta-wayland.c +++ b/src/wayland/meta-wayland.c @@ -1072,3 +1072,37 @@ meta_wayland_compositor_get_text_input (MetaWaylandCompositor *compositor) { return compositor->seat->text_input; } + +static void +meta_wayland_compositor_update_focus (MetaWaylandCompositor *compositor, + MetaWindow *window) +{ + MetaContext *context = meta_wayland_compositor_get_context (compositor); + MetaDisplay *display = meta_context_get_display (context); + MetaWindow *focus_window = NULL; + + /* Compositor not ready yet */ + if (!compositor->seat) + return; + + if (!display || !meta_display_windows_are_interactable (display)) + focus_window = NULL; + else if (!window) + focus_window = NULL; + else if (window && meta_window_get_wayland_surface (window)) + focus_window = window; + else + meta_topic (META_DEBUG_FOCUS, "Focus change has no effect, because there is no matching wayland surface"); + + meta_wayland_compositor_set_input_focus (compositor, focus_window); +} + +void +meta_wayland_compositor_sync_focus (MetaWaylandCompositor *compositor) +{ + MetaContext *context = meta_wayland_compositor_get_context (compositor); + MetaDisplay *display = meta_context_get_display (context); + + meta_wayland_compositor_update_focus (compositor, + display ? display->focus_window : NULL); +} diff --git a/src/wayland/meta-wayland.h b/src/wayland/meta-wayland.h index 0ea3dfa7f..c95e82b42 100644 --- a/src/wayland/meta-wayland.h +++ b/src/wayland/meta-wayland.h @@ -105,3 +105,5 @@ gboolean meta_wayland_compositor_is_grabbed (MetaWaylandCompositor *compositor); META_EXPORT_TEST MetaWaylandFilterManager * meta_wayland_compositor_get_filter_manager (MetaWaylandCompositor *compositor); + +void meta_wayland_compositor_sync_focus (MetaWaylandCompositor *compositor);