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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3511>
This commit is contained in:
Carlos Garnacho 2023-11-15 00:26:35 +01:00 committed by Marge Bot
parent 962eb9e054
commit 7b232d9f65
3 changed files with 35 additions and 8 deletions

View File

@ -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

View File

@ -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);

View File

@ -48,6 +48,9 @@ struct _MetaWaylandSeat
MetaWaylandTextInput *text_input;
MetaWaylandSurface *input_focus;
gulong input_focus_destroy_id;
guint capabilities;
};