From 7b232d9f65ca9a6d54bd85a9b8923decd12a0f6a Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 15 Nov 2023 00:26:35 +0100 Subject: [PATCH] wayland: Keep track of the "input focus" on MetaWaylandSeat This is the unified focus (key, IM, pads, ...) for the focus window. Just like MetaWaylandPointer and others keep track of the "current" surface, this is the "current" surface for those (not necessarily the focused surface, e.g. in the case of compositor grabs). Since this unified focus will exist regardless of keyboard capabilities (e.g. even if just for "logical" focus like IM/clipboard that does not depend on input devices), it does not make sense to trigger a focus sync on keyboard capability changes, the focus is staying the same, we however need to focus the keyboard interface to the already existing focus when the capability is enabled. Part-of: --- src/wayland/meta-wayland-keyboard.c | 4 ++++ src/wayland/meta-wayland-seat.c | 36 ++++++++++++++++++++++------- src/wayland/meta-wayland-seat.h | 3 +++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c index 706991828..5403f8c04 100644 --- a/src/wayland/meta-wayland-keyboard.c +++ b/src/wayland/meta-wayland-keyboard.c @@ -529,6 +529,8 @@ static const MetaWaylandKeyboardGrabInterface default_keyboard_grab_interface = void meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard) { + MetaWaylandInputDevice *input_device = META_WAYLAND_INPUT_DEVICE (keyboard); + MetaWaylandSeat *seat = meta_wayland_input_device_get_seat (input_device); MetaBackend *backend = backend_from_keyboard (keyboard); ClutterBackend *clutter_backend = clutter_get_default_backend (); @@ -549,6 +551,8 @@ meta_wayland_keyboard_enable (MetaWaylandKeyboard *keyboard) G_CALLBACK (on_kbd_a11y_mask_changed), keyboard); meta_wayland_keyboard_take_keymap (keyboard, meta_backend_get_keymap (backend)); + + meta_wayland_keyboard_set_focus (keyboard, seat->input_focus); } static void diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c index 07439f22b..ee91ef1c3 100644 --- a/src/wayland/meta-wayland-seat.c +++ b/src/wayland/meta-wayland-seat.c @@ -155,14 +155,7 @@ meta_wayland_seat_set_capabilities (MetaWaylandSeat *seat, meta_wayland_pointer_disable (seat->pointer); if (CAPABILITY_ENABLED (prev_flags, flags, WL_SEAT_CAPABILITY_KEYBOARD)) - { - MetaWaylandCompositor *compositor = - meta_wayland_seat_get_compositor (seat); - - meta_wayland_keyboard_enable (seat->keyboard); - - meta_wayland_compositor_sync_focus (compositor); - } + meta_wayland_keyboard_enable (seat->keyboard); else if (CAPABILITY_DISABLED (prev_flags, flags, WL_SEAT_CAPABILITY_KEYBOARD)) meta_wayland_keyboard_disable (seat->keyboard); @@ -409,6 +402,13 @@ meta_wayland_seat_handle_event (MetaWaylandSeat *seat, return FALSE; } +static void +input_focus_destroyed (MetaWaylandSurface *surface, + MetaWaylandSeat *seat) +{ + meta_wayland_seat_set_input_focus (seat, NULL); +} + void meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat, MetaWaylandSurface *surface) @@ -416,6 +416,26 @@ meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat, MetaWaylandCompositor *compositor = meta_wayland_seat_get_compositor (seat); MetaWaylandTabletSeat *tablet_seat; + if (seat->input_focus == surface) + return; + + if (seat->input_focus) + { + g_clear_signal_handler (&seat->input_focus_destroy_id, + seat->input_focus); + seat->input_focus = NULL; + } + + seat->input_focus = surface; + + if (surface) + { + seat->input_focus_destroy_id = + g_signal_connect (surface, "destroy", + G_CALLBACK (input_focus_destroyed), + seat); + } + if (meta_wayland_seat_has_keyboard (seat)) { meta_wayland_keyboard_set_focus (seat->keyboard, surface); diff --git a/src/wayland/meta-wayland-seat.h b/src/wayland/meta-wayland-seat.h index ba2cf5644..df2e92dda 100644 --- a/src/wayland/meta-wayland-seat.h +++ b/src/wayland/meta-wayland-seat.h @@ -48,6 +48,9 @@ struct _MetaWaylandSeat MetaWaylandTextInput *text_input; + MetaWaylandSurface *input_focus; + gulong input_focus_destroy_id; + guint capabilities; };