From 05519c3eaaae5b506746c315ac77ee3f04b26401 Mon Sep 17 00:00:00 2001 From: Ivy233 Date: Wed, 25 Nov 2026 09:42:23 +0800 Subject: [PATCH] fix(dock): preserve X11 event subscriptions in smart hide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Read the event mask already selected on Qt's X11 connection with xcb_get_window_attributes, then merge the property, structure and visibility events required by smart hide instead of replacing the whole mask. 2. Keep Qt's focus, keyboard, button and exposure subscriptions intact, so the launcher still receives input and popups close when they lose focus. 3. In onWindowClientListChanged, collect the newly tracked windows and queue their event-mask queries before reading any reply, then apply the merged masks in one pass before initializing their metadata. The attribute reads for this update no longer block on one X11 round trip per window. 4. Skip the update when an attribute query fails or the merged mask is unchanged, and consume every queued cookie, so existing subscriptions are not lost. Log: Preserve Qt's X11 event subscriptions and batch event-mask queries for newly tracked windows. Influence: Smart hide keeps working without losing launcher input or focus-out behavior, and window updates avoid one blocking X11 round trip per window. fix(dock): 智能隐藏监听窗口时保留 X11 事件订阅并批量查询 1. 使用 xcb_get_window_attributes 读取 Qt 的 X11 连接上已选择的事件 掩码,将智能隐藏所需的属性变化、结构变化和可见性事件合并进去,而不是 替换整个掩码。 2. 保留 Qt 自身的焦点、键盘、鼠标按键和重绘(Expose)订阅,使启动器 仍能接收输入,弹窗失焦时也能正常关闭。 3. 在 onWindowClientListChanged 中先收集本次新增的窗口,为它们排入 事件掩码查询后统一读取回复,再批量应用合并后的掩码并初始化窗口元数据; 本次更新不再按窗口逐一阻塞等待 X11 往返。 4. 当事件掩码查询失败或合并后的掩码未变化时跳过更新,并读取每个已排入 的 cookie,避免丢失已有订阅。 Log: 监听窗口时保留 Qt 的 X11 事件订阅,并批量查询本次新增窗口的事件掩码,保证智能隐藏正常工作。 Influence: 智能隐藏正常生效,启动器和弹窗保持正常的输入与失焦关闭行为;新增窗口的事件掩码批量处理,不再按窗口逐一阻塞等待 X11 往返。 PMS: BUG-383253 --- panels/dock/x11dockhelper.cpp | 46 ++++++++++++++++++++++++++++++----- panels/dock/x11dockhelper.h | 4 +-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/panels/dock/x11dockhelper.cpp b/panels/dock/x11dockhelper.cpp index 378e0c2bc..897f00513 100644 --- a/panels/dock/x11dockhelper.cpp +++ b/panels/dock/x11dockhelper.cpp @@ -307,10 +307,40 @@ bool XcbEventFilter::shouldSkip(const xcb_window_t &window) return false; } -void XcbEventFilter::monitorWindowChange(const xcb_window_t &window) -{ - uint32_t value_list[] = { XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_VISIBILITY_CHANGE }; - xcb_change_window_attributes(m_connection, window, XCB_CW_EVENT_MASK, value_list); +void XcbEventFilter::monitorWindowChange(const QList &windows) +{ + const uint32_t monitorMask = XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_VISIBILITY_CHANGE; + + // Queue the attribute requests before reading replies to avoid serial round trips. + QList cookies; + cookies.reserve(windows.size()); + for (auto window : windows) + cookies.append(xcb_get_window_attributes(m_connection, window)); + + for (int i = 0; i < windows.size(); ++i) { + xcb_generic_error_t *error = nullptr; + xcb_get_window_attributes_reply_t *attributes = + xcb_get_window_attributes_reply(m_connection, cookies.at(i), &error); + if (!attributes) { + if (error) { + qCWarning(dockX11Log) << "failed to query event mask of window" << windows.at(i) << "error" << error->error_code; + free(error); + } + continue; + } + + const uint32_t currentMask = attributes->your_event_mask; + free(attributes); + + const uint32_t mergedMask = currentMask | monitorMask; + if (mergedMask == currentMask) + continue; + + // This runs on the connection owned by Qt. Merging keeps Qt's own subscriptions + // (focus, keyboard, buttons, exposure) instead of replacing them. + uint32_t value_list[] = { mergedMask }; + xcb_change_window_attributes(m_connection, windows.at(i), XCB_CW_EVENT_MASK, value_list); + } }; void XcbEventFilter::setWindowState(const xcb_window_t& window, uint32_t list_len, xcb_atom_t *state) @@ -389,12 +419,17 @@ void X11DockHelper::onHideModeChanged(HideMode mode) void X11DockHelper::onWindowClientListChanged() { QList windows = m_xcbHelper->getWindowClientList(); + QList addedWindows; for (auto &&window : windows) { if (!m_windows.contains(window) && !m_xcbHelper->shouldSkip(window)) { m_windows.insert(window, new WindowData()); - onWindowAdded(window); + addedWindows.append(window); } } + m_xcbHelper->monitorWindowChange(addedWindows); + for (auto &&window : addedWindows) { + onWindowAdded(window); + } bool mightNeedRecheckDockOverlap = false; for (auto it = m_windows.cbegin(); it != m_windows.cend();) { if (!windows.contains(it.key())) { @@ -412,7 +447,6 @@ void X11DockHelper::onWindowClientListChanged() void X11DockHelper::onWindowAdded(xcb_window_t window) { - m_xcbHelper->monitorWindowChange(window); onWindowPropertyChanged(window, m_xcbHelper->getAtomByName("WM_STATE")); onWindowGeometryChanged(window); onWindowWorkspaceChanged(window); diff --git a/panels/dock/x11dockhelper.h b/panels/dock/x11dockhelper.h index 1e694b685..ec519ab8b 100644 --- a/panels/dock/x11dockhelper.h +++ b/panels/dock/x11dockhelper.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later #pragma once @@ -32,7 +32,7 @@ class XcbEventFilter: public QObject, public QAbstractNativeEventFilter uint32_t getCurrentWorkspace(); void checkCurrentWorkspace(); bool shouldSkip(const xcb_window_t& window); - void monitorWindowChange(const xcb_window_t& window); + void monitorWindowChange(const QList &windows); void setWindowState(const xcb_window_t& window, uint32_t list_len, xcb_atom_t *state); Q_SIGNALS: