From 5f21e8069bdc878bbbed73ba09f0e0b0fc6c7c3f Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sun, 10 May 2026 20:34:59 +0200 Subject: [PATCH] wayland: install X error handler for XWayland connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Wayland backend runs with a live XWayland Display* once XWayland fires its ready signal. Without an error handler, benign X errors (BadMatch on X_SetInputFocus, BadWindow during window teardown) reach Xlib's default handler and produce noisy output. Add wl_catch_xwayland_error() — same permissive policy as the X11 backend's x11_catch_error() — and install it via XSetErrorHandler in wl_register_error_handlers(). Include for the X_SetInputFocus request code constant. Co-Authored-By: Claude Sonnet 4.6 --- src/backend/wayland/wl_backend.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index 2177d4a..588f48a 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -126,6 +126,7 @@ #include #include #include /* Phase 17: XWayland support */ +#include /* X_SetInputFocus and other request codes */ #include /* Phase 18: nested Wayland backend */ #include /* Phase 18: multi-backend */ #include /* Phase 18: scene graph compositing */ @@ -4887,10 +4888,34 @@ static void wl_extensions_init(void) {} static void wl_cursors_init(void) {} static WNativeWindow wl_cursor_create_named(const char *name) { (void)name; return WNATIVE_NONE; } static void wl_shape_combine_mask(WNativeWindow win, WNativeWindow mask) { (void)win; (void)mask; } +static int +wl_catch_xwayland_error(Display *edpy, XErrorEvent *error) +{ + (void)edpy; + /* BadMatch on X_SetInputFocus is benign: the target window may not be + * viewable yet (e.g. during XWayland startup or between map/unmap). + * Silence it so it does not reach Xlib's default handler. */ + if (error->error_code == BadMatch && + error->request_code == X_SetInputFocus) + return 0; + /* BadWindow is also common during window teardown; ignore silently. */ + if (error->error_code == BadWindow) + return 0; + /* Everything else: print via wwarning and continue. */ + char buf[256]; + XGetErrorText(edpy, error->error_code, buf, sizeof(buf)); + wwarning("wl_backend: X error from XWayland: %s (request %d, resource 0x%lx)", + buf, (int)error->request_code, (unsigned long)error->resourceid); + return 0; +} + static void wl_register_error_handlers(void) { - /* Pure Wayland: no X11 Display*, so no Xlib error handlers needed. */ + /* Install a permissive X error handler for the XWayland connection. + * Without this, Xlib's default handler prints and the WM continues, + * but benign errors (BadMatch on SetInputFocus etc.) cause visible noise. */ + XSetErrorHandler(wl_catch_xwayland_error); } /* ------------------------------------------------------------------ */