Repository navigation
Fix/x11 search input #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix/x11 search input #859
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #include "x11keymaskfixer.h" | ||
|
|
||
| #include <QCoreApplication> | ||
| #include <QGuiApplication> | ||
| #include <QWindow> | ||
| #include <qpa/qplatformnativeinterface.h> | ||
| #include <xcb/xcb.h> | ||
|
|
||
| void X11KeyMaskFixer::install() | ||
| { | ||
| static X11KeyMaskFixer *self = nullptr; | ||
| if (!self) { | ||
| self = new X11KeyMaskFixer; | ||
| QCoreApplication::instance()->installNativeEventFilter(self); | ||
| } | ||
| } | ||
|
|
||
| void X11KeyMaskFixer::fixWindow(QWindow *window) | ||
| { | ||
| const QString platform = QGuiApplication::platformName(); | ||
| if (platform != QLatin1String("dxcb") && platform != QLatin1String("xcb")) | ||
| return; | ||
|
|
||
| auto *nativeInterface = QGuiApplication::platformNativeInterface(); | ||
| if (!nativeInterface) | ||
| return; | ||
| auto *connection = static_cast<xcb_connection_t *>( | ||
| nativeInterface->nativeResourceForIntegration("connection")); | ||
| if (!connection || !window) | ||
| return; | ||
|
|
||
| const xcb_window_t winId = window->winId(); | ||
| xcb_get_window_attributes_cookie_t cookie = xcb_get_window_attributes_unchecked(connection, winId); | ||
| xcb_get_window_attributes_reply_t *reply = xcb_get_window_attributes_reply(connection, cookie, nullptr); | ||
| if (!reply) | ||
| return; | ||
| const unsigned mask = reply->your_event_mask; | ||
| free(reply); | ||
|
|
||
| const unsigned keyboardMask = XCB_EVENT_MASK_KEY_PRESS | ||
| | XCB_EVENT_MASK_KEY_RELEASE | ||
| | XCB_EVENT_MASK_FOCUS_CHANGE; | ||
| if ((mask & keyboardMask) == keyboardMask) | ||
| return; | ||
|
|
||
| // OR in the missing masks, keeping whatever this client already selected. | ||
| const uint32_t newMask = mask | keyboardMask | ||
| | XCB_EVENT_MASK_BUTTON_PRESS | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Keyboard masks remain unset When another X11 client has already selected button-press events on the popup window, Do not request the exclusive Prompt for AI agentsIn `x11keymaskfixer.cpp` at line 51:
**Keyboard masks remain unset**
When another X11 client has already selected button-press events on the popup window, `xcb_change_window_attributes` requests the exclusive `ButtonPress` mask with the keyboard masks, so the server rejects the whole request with `BadAccess` and text input remains broken.
Do not request the exclusive `ButtonPress` mask in the same change as the keyboard masks. |
||
| | XCB_EVENT_MASK_BUTTON_RELEASE | ||
| | XCB_EVENT_MASK_BUTTON_MOTION | ||
| | XCB_EVENT_MASK_ENTER_WINDOW | ||
| | XCB_EVENT_MASK_LEAVE_WINDOW | ||
| | XCB_EVENT_MASK_POINTER_MOTION | ||
| | XCB_EVENT_MASK_PROPERTY_CHANGE; | ||
| xcb_change_window_attributes(connection, winId, XCB_CW_EVENT_MASK, &newMask); | ||
| xcb_flush(connection); | ||
| } | ||
|
|
||
| bool X11KeyMaskFixer::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) | ||
| { | ||
| if (eventType != QByteArrayLiteral("xcb_generic_event_t") || !message) | ||
| return false; | ||
|
|
||
| auto *event = static_cast<xcb_generic_event_t *>(message); | ||
| xcb_window_t windowId = 0; | ||
| switch (event->response_type & 0x7f) { | ||
| case XCB_MAP_NOTIFY: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · First keystroke can be lost When the user types before the server processes the mask update after mapping the popup, Apply the keyboard masks before mapping or activating the window, or otherwise preserve input received before the repair completes. Prompt for AI agentsIn `x11keymaskfixer.cpp` at line 70:
**First keystroke can be lost**
When the user types before the server processes the mask update after mapping the popup, `nativeEventFilter` repairs the window only after receiving `MapNotify`; until `fixWindow` sends and flushes the mask change, the X server still drops keyboard events for that window. A key pressed in that interval is lost, so the first character typed into the search box disappears.
Apply the keyboard masks before mapping or activating the window, or otherwise preserve input received before the repair completes. |
||
| windowId = reinterpret_cast<xcb_map_notify_event_t *>(event)->window; | ||
| break; | ||
| case XCB_CONFIGURE_NOTIFY: | ||
| windowId = reinterpret_cast<xcb_configure_notify_event_t *>(event)->window; | ||
| break; | ||
| case XCB_FOCUS_IN: | ||
| case XCB_FOCUS_OUT: | ||
| windowId = reinterpret_cast<xcb_focus_in_event_t *>(event)->event; | ||
| break; | ||
| default: | ||
| return false; | ||
| } | ||
|
Comment on lines
+69
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Repair can never be triggered When a popup's parent has not selected Ensure the fixer is called from a window lifecycle hook, or otherwise subscribe to a notification that is guaranteed to arrive before relying on these events to repair the mask. Also at Prompt for AI agentsIn `x11keymaskfixer.cpp` at lines 69-82:
**Repair can never be triggered**
When a popup's parent has not selected `SubstructureNotify` for it and the popup itself lacks `StructureNotify`, the filter relies on `MapNotify` or `ConfigureNotify` to discover the window, but those events require `StructureNotify` on that window or `SubstructureNotify` on its parent. The repair adds neither guarantee; if the parent is not subscribed, no callback reaches `fixWindow` and keyboard input remains broken.
Ensure the fixer is called from a window lifecycle hook, or otherwise subscribe to a notification that is guaranteed to arrive before relying on these events to repair the mask.
Also at `x11keymaskfixer.cpp:50-58`. |
||
|
|
||
| const auto windows = QGuiApplication::topLevelWindows(); | ||
| for (QWindow *window : windows) { | ||
| if (window->isVisible() && window->winId() == windowId) { | ||
| fixWindow(window); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Window resizing blocks on X server When a visible top-level window generates repeated configure events, such as during interactive resizing, Avoid a synchronous attributes round trip for every configure event, for example by tracking repaired windows or using an asynchronous query. Prompt for AI agentsIn `x11keymaskfixer.cpp` at line 87:
**Window resizing blocks on X server**
When a visible top-level window generates repeated configure events, such as during interactive resizing, `nativeEventFilter` calls `fixWindow` for every matching configure event, and `fixWindow` synchronously waits for `xcb_get_window_attributes_reply` even after the keyboard masks have already been repaired. Repeated resize or move events therefore block the GUI thread on X-server round trips, making the window stutter.
Avoid a synchronous attributes round trip for every configure event, for example by tracking repaired windows or using an asynchronous query. |
||
| break; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static void installX11KeyMaskFixer() | ||
| { | ||
| X11KeyMaskFixer::install(); | ||
| } | ||
|
|
||
| Q_COREAPP_STARTUP_FUNCTION(installX11KeyMaskFixer) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Launcher input stays broken When the shell loads the launcher applet after constructing its Install the filter when the applet loads, including when the application object already exists. Prompt for AI agentsIn `x11keymaskfixer.cpp` at line 99:
**Launcher input stays broken**
When the shell loads the launcher applet after constructing its `QCoreApplication`, `Q_COREAPP_STARTUP_FUNCTION` has already run, so `X11KeyMaskFixer::install()` is never called and no native event filter repairs the popup masks; launcher search input remains broken.
Install the filter when the applet loads, including when the application object already exists. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #pragma once | ||
|
|
||
| #include <QAbstractNativeEventFilter> | ||
| #include <QObject> | ||
|
|
||
| class QWindow; | ||
|
|
||
| // On X11 the dxcb platform plugin creates override-redirect popup windows | ||
| // with an event mask that lacks KeyPressMask/KeyReleaseMask/FocusChangeMask. | ||
| // X11 delivers keyboard events per-client based on the event mask each client | ||
| // selected, so without those masks no key event ever reaches Qt, while mouse | ||
| // events (delivered through XInput2) keep working. This silently breaks text | ||
| // input in any popup window of the process, e.g. the launcher search box. | ||
| // | ||
| // This helper installs a native event filter on QCoreApplication startup and | ||
| // restores the keyboard/focus event masks through Qt's own xcb connection | ||
| // whenever one of our top-level windows gets mapped or focused. The masks are | ||
| // per-client, so only Qt's own event delivery is affected. | ||
| class X11KeyMaskFixer : public QAbstractNativeEventFilter | ||
| { | ||
| public: | ||
| static void install(); | ||
|
|
||
| // Read the window's current event mask and OR in the keyboard, focus and | ||
| // pointer masks if they are missing. Idempotent, safe to call repeatedly. | ||
| static void fixWindow(QWindow *window); | ||
|
|
||
| private: | ||
| bool nativeEventFilter(const QByteArray &eventType, void *message, | ||
| qintptr *result) override; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High · Launcher fails to load
When the build or runtime does not supply libxcb transitively,
launchpadcommonuses XCB symbols without linking XCB, so strict undefined-symbol checks fail or the loader cannot resolve the symbols and the launcher applet fails to load.Declare and link the XCB dependency for
launchpadcommon.Also at
x11keymaskfixer.cpp:10,x11keymaskfixer.cpp:36,x11keymaskfixer.cpp:59.Prompt for AI agents