Skip to content

Fix/x11 search input - #859

Open
wr5537 wants to merge 1 commit into
linuxdeepin:masterfrom
wr5537:fix/x11-search-input
Open

wr5537 wants to merge 1 commit into
linuxdeepin:masterfrom
wr5537:fix/x11-search-input

Conversation

@wr5537

@wr5537 wr5537 commented Nov 24, 2026 •

Copy link
Copy Markdown

修复dde-shell搜索框不能输文子的问题

Summary by Sourcery

Fix text input in X11 popup windows by restoring the event masks required for Qt to receive keyboard events.

Bug Fixes:

  • Restore missing X11 keyboard and focus event masks for popup windows so text input works in the launcher search box.

Build:

  • Include the X11 key mask fixer in the project build sources.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wr5537

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 2.0.52.1
EXISTED: no
DISTRIBUTION: unstable

@deepin-ci-robot

Copy link
Copy Markdown

Hi @wr5537. Thanks for your PR. 😃

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@deepin-ci-robot

Copy link
Copy Markdown

Hi @wr5537. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

The dxcb platform plugin creates override-redirect popup windows with an
event mask that only selects property/visibility/substructure notification.
Keyboard events are delivered per-client based on the event mask each
client selected, so without KeyPressMask/KeyReleaseMask/FocusChangeMask
no key event ever reaches Qt - while mouse events (delivered through
XInput2) keep working. This silently breaks text input in popup windows
of the process, e.g. the launcher search box.

Install a native event filter on QCoreApplication startup which restores
the keyboard/focus masks through Qt's own xcb connection whenever one of
our top-level windows gets mapped, configured or focused. Event masks are
per-client, so only Qt's own event delivery is affected.
@wr5537
wr5537 force-pushed the fix/x11-search-input branch from c1ef458 to f9a417a Compare November 24, 2026 02:45
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Add a native X11 event filter that restores keyboard and focus event masks on Qt top-level windows, fixing text input in popup windows.

  • x11keymaskfixer.cpp L1-99
  • x11keymaskfixer.h L1-34

Configuration

Add the X11 key-mask fixer source and header to the CMake source list so they are built with the application.

  • CMakeLists.txt L77

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 6 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="CMakeLists.txt" line_range="77" />
<code_context>
     launchercontroller.cpp launchercontroller.h
     debughelper.cpp debughelper.h
     inputeventitem.h inputeventitem.cpp
+    x11keymaskfixer.h x11keymaskfixer.cpp
 )

</code_context>
<issue_to_address>
**Launcher fails to load**

When the build or runtime does not supply libxcb transitively, `launchpadcommon` uses 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`.
</issue_to_address>

### Comment 2
<location path="x11keymaskfixer.cpp" line_range="99" />
<code_context>
+    X11KeyMaskFixer::install();
+}
+
+Q_COREAPP_STARTUP_FUNCTION(installX11KeyMaskFixer)
</code_context>
<issue_to_address>
**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.
</issue_to_address>

### Comment 3
<location path="x11keymaskfixer.cpp" line_range="51" />
<code_context>
+
+    // OR in the missing masks, keeping whatever this client already selected.
+    const uint32_t newMask = mask | keyboardMask
+                             | XCB_EVENT_MASK_BUTTON_PRESS
+                             | XCB_EVENT_MASK_BUTTON_RELEASE
+                             | XCB_EVENT_MASK_BUTTON_MOTION
</code_context>
<issue_to_address>
**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.
</issue_to_address>

### Comment 4
<location path="x11keymaskfixer.cpp" line_range="69-82" />
<code_context>
+
+    auto *event = static_cast<xcb_generic_event_t *>(message);
+    xcb_window_t windowId = 0;
+    switch (event->response_type & 0x7f) {
+    case XCB_MAP_NOTIFY:
+        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;
+    }
+
+    const auto windows = QGuiApplication::topLevelWindows();
</code_context>
<issue_to_address>
**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`.
</issue_to_address>

### Comment 5
<location path="x11keymaskfixer.cpp" line_range="70" />
<code_context>
+    auto *event = static_cast<xcb_generic_event_t *>(message);
+    xcb_window_t windowId = 0;
+    switch (event->response_type & 0x7f) {
+    case XCB_MAP_NOTIFY:
+        windowId = reinterpret_cast<xcb_map_notify_event_t *>(event)->window;
+        break;
</code_context>
<issue_to_address>
**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.
</issue_to_address>

### Comment 6
<location path="x11keymaskfixer.cpp" line_range="87" />
<code_context>
+    const auto windows = QGuiApplication::topLevelWindows();
+    for (QWindow *window : windows) {
+        if (window->isVisible() && window->winId() == windowId) {
+            fixWindow(window);
+            break;
+        }
</code_context>
<issue_to_address>
**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.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread CMakeLists.txt
launchercontroller.cpp launchercontroller.h
debughelper.cpp debughelper.h
inputeventitem.h inputeventitem.cpp
x11keymaskfixer.h x11keymaskfixer.cpp

Copy link
Copy Markdown

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, launchpadcommon uses 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
In `CMakeLists.txt` at line 77:

**Launcher fails to load**

When the build or runtime does not supply libxcb transitively, `launchpadcommon` uses 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`.

Comment thread x11keymaskfixer.cpp
X11KeyMaskFixer::install();
}

Q_COREAPP_STARTUP_FUNCTION(installX11KeyMaskFixer)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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.

Comment thread x11keymaskfixer.cpp

// OR in the missing masks, keeping whatever this client already selected.
const uint32_t newMask = mask | keyboardMask
| XCB_EVENT_MASK_BUTTON_PRESS

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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.

Comment thread x11keymaskfixer.cpp
Comment on lines +69 to +82
switch (event->response_type & 0x7f) {
case XCB_MAP_NOTIFY:
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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`.

Comment thread x11keymaskfixer.cpp
auto *event = static_cast<xcb_generic_event_t *>(message);
xcb_window_t windowId = 0;
switch (event->response_type & 0x7f) {
case XCB_MAP_NOTIFY:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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.

Comment thread x11keymaskfixer.cpp
const auto windows = QGuiApplication::topLevelWindows();
for (QWindow *window : windows) {
if (window->isVisible() && window->winId() == windowId) {
fixWindow(window);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants