From 83a5bdf5d546bafdcff57dadd3372b49a8c38708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 23 May 2025 18:03:57 +0200 Subject: [PATCH] xwayland: Create a dummy no_focus_window to use for non-X window focus --- include/xwayland/xwm.h | 1 + xwayland/xwm.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/xwayland/xwm.h b/include/xwayland/xwm.h index 799cebc47..d38e5cc91 100644 --- a/include/xwayland/xwm.h +++ b/include/xwayland/xwm.h @@ -115,6 +115,7 @@ struct wlr_xwm { xcb_connection_t *xcb_conn; xcb_screen_t *screen; xcb_window_t window; + xcb_window_t no_focus_window; xcb_visualid_t visual_id; xcb_colormap_t colormap; xcb_render_pictformat_t render_format_id; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index d5a57d5e5..953906fa8 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -2204,6 +2204,9 @@ void xwm_destroy(struct wlr_xwm *xwm) { if (xwm->colormap) { xcb_free_colormap(xwm->xcb_conn, xwm->colormap); } + if (xwm->no_focus_window) { + xcb_destroy_window(xwm->xcb_conn, xwm->no_focus_window); + } if (xwm->window) { xcb_destroy_window(xwm->xcb_conn, xwm->window); } @@ -2361,6 +2364,31 @@ static void xwm_create_wm_window(struct wlr_xwm *xwm) { XCB_CURRENT_TIME); } +static void xwm_create_no_focus_window(struct wlr_xwm *xwm) { + xwm->no_focus_window = xcb_generate_id(xwm->xcb_conn); + + uint32_t values[2] = { + 1, + XCB_EVENT_MASK_KEY_PRESS | + XCB_EVENT_MASK_KEY_RELEASE | + XCB_EVENT_MASK_FOCUS_CHANGE + }; + xcb_create_window(xwm->xcb_conn, + XCB_COPY_FROM_PARENT, + xwm->no_focus_window, + xwm->screen->root, + -100, -100, + 1, 1, + 0, + XCB_WINDOW_CLASS_COPY_FROM_PARENT, + XCB_COPY_FROM_PARENT, + XCB_CW_OVERRIDE_REDIRECT | + XCB_CW_EVENT_MASK, + values); + + xcb_map_window(xwm->xcb_conn, xwm->no_focus_window); +} + // TODO use me to support 32 bit color somehow static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) { xcb_depth_iterator_t d_iter; @@ -2587,6 +2615,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *xwayland, int wm_fd) { &xwm->shell_v1_destroy); xwm_create_wm_window(xwm); + xwm_create_no_focus_window(xwm); xcb_flush(xwm->xcb_conn);