From aaab61a87b625728538c096e71c8f4208229b1b1 Mon Sep 17 00:00:00 2001 From: Jeff Quast Date: Fri, 25 Sep 2026 06:08:21 +0000 Subject: [PATCH] ignore NotifyPointer as focus events Problem: On X11/KDE, with two kitty windows on different virtual desktops, switching desktops with the keyboard while the mouse pointer sits still caused both windows to report as "focused". Keyboard input still went to visible window, but paste and other actions went to the other window. Fixed by ignoring FocusIn/FocusOut when ``detail == NotifyPointer``. Logfile before:: 0x2 focused: 0 0x2 focused: 1 0x1 focused: 1 Logfile after:: 0x2 focused: 0 0x1 focused: 1 Video attached. This same approach is used by Qt and Wine, https://github.com/qt/qtbase/blob/148bc4bc0508d0f7ac95922b80ced24c4aa6de80/src/plugins/platforms/xcb/qxcbwindow.cpp#L2292-L2312 https://github.com/wine-mirror/wine/blob/9d17984f27bfe25cbef162749ed3592b839b246e/dlls/winex11.drv/event.c#L697 --- docs/changelog.rst | 3 +++ glfw/x11_window.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9b8f31c05..c2d1aa7e0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -213,6 +213,9 @@ Detailed list of changes - Vertical tabs: Improve rendering of tabs when using the ``powerline`` :opt:`tab_bar_style` +- X11: Fix copy and paste targeting the wrong OS window when the keyboard focus + is set to PointerRoot or None + 0.49.1 [2026-09-24] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 01ac6c6b2..4e3ed35da 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -2135,6 +2135,11 @@ processEvent(XEvent *event) { // key chords and window dragging return; } + if (event->xfocus.detail == NotifyPointer) { + // Ignore focus events for the window under the pointer when the + // focus is set to PointerRoot or None + return; + } if (window->cursorMode == GLFW_CURSOR_DISABLED) disableCursor(window); @@ -2148,6 +2153,11 @@ processEvent(XEvent *event) { // key chords and window dragging return; } + if (event->xfocus.detail == NotifyPointer) { + // Ignore focus events for the window under the pointer when the + // focus is set to PointerRoot or None + return; + } if (window->cursorMode == GLFW_CURSOR_DISABLED) enableCursor(window);