Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ set(SOURCE_FILES
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`.

)

set(QML_FILES
Expand Down
99 changes: 99 additions & 0 deletions x11keymaskfixer.cpp
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>

Check warning on line 6 in x11keymaskfixer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QGuiApplication>

Check warning on line 7 in x11keymaskfixer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGuiApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QWindow>

Check warning on line 8 in x11keymaskfixer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <qpa/qplatformnativeinterface.h>

Check warning on line 9 in x11keymaskfixer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <qpa/qplatformnativeinterface.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <xcb/xcb.h>

Check warning on line 10 in x11keymaskfixer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <xcb/xcb.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

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

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.

| 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:

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.

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

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


const auto windows = QGuiApplication::topLevelWindows();
for (QWindow *window : windows) {
if (window->isVisible() && window->winId() == windowId) {

Check warning on line 86 in x11keymaskfixer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
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.

break;
}
}
return false;
}

static void installX11KeyMaskFixer()
{
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.

34 changes: 34 additions & 0 deletions x11keymaskfixer.h
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>

Check warning on line 6 in x11keymaskfixer.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QAbstractNativeEventFilter> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QObject>

Check warning on line 7 in x11keymaskfixer.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.

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;
};
Loading