From 792758faa5c089a484ed733d76eee00ddc278177 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Thu, 14 Dec 2023 18:26:33 +0100 Subject: [PATCH] xwayland: Update lost focus on deactivation Use the "activated" state from xdg-shell to call the pointer and keyboard leave events when running rootful. The regular pointer and keyboard leave notifications are now ignored when running rootful. Signed-off-by: Olivier Fourdan Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1604 Part-of: --- hw/xwayland/xwayland-input.c | 6 ++++-- hw/xwayland/xwayland-screen.h | 1 + hw/xwayland/xwayland-window.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c index 00949ba6b..9c14b3ff4 100644 --- a/hw/xwayland/xwayland-input.c +++ b/hw/xwayland/xwayland-input.c @@ -617,7 +617,8 @@ pointer_handle_leave(void *data, struct wl_pointer *pointer, focus_lost = TRUE; } - xwl_seat_leave_ptr(xwl_seat, focus_lost); + if (xwl_screen->rootless) + xwl_seat_leave_ptr(xwl_seat, focus_lost); } static void @@ -1211,7 +1212,8 @@ keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, xwl_screen->serial = serial; - xwl_seat_leave_kbd(xwl_seat); + if (xwl_screen->rootless) + xwl_seat_leave_kbd(xwl_seat); } static void diff --git a/hw/xwayland/xwayland-screen.h b/hw/xwayland/xwayland-screen.h index dae6445c2..2c7a8cef9 100644 --- a/hw/xwayland/xwayland-screen.h +++ b/hw/xwayland/xwayland-screen.h @@ -54,6 +54,7 @@ struct xwl_screen { int expecting_event; enum RootClipMode root_clip_mode; + Bool active; int rootless; xwl_glamor_mode_flags glamor; int present; diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c index 6774ba096..922b45ee9 100644 --- a/hw/xwayland/xwayland-window.c +++ b/hw/xwayland/xwayland-window.c @@ -795,6 +795,8 @@ xdg_toplevel_handle_configure(void *data, { struct xwl_window *xwl_window = data; struct xwl_screen *xwl_screen = xwl_window->xwl_screen; + uint32_t *p; + Bool old_active = xwl_screen->active; /* Maintain our current size if no dimensions are requested */ if (width == 0 && height == 0) @@ -804,6 +806,20 @@ xdg_toplevel_handle_configure(void *data, /* This will be committed by the xdg_surface.configure handler */ xwl_window_maybe_resize(xwl_window, width, height); } + + xwl_screen->active = FALSE; + wl_array_for_each (p, states) { + uint32_t state = *p; + if (state == XDG_TOPLEVEL_STATE_ACTIVATED) { + xwl_screen->active = TRUE; + break; + } + } + + if (old_active != xwl_screen->active) { + if (!xwl_screen->active) + xwl_screen_lost_focus(xwl_screen); + } } static void