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; };