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); } /* ------------------------------------------------------------------ */