Skip to content

feat: expose KWin split menu platform functions - #345

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:kwin-split-menu
Sep 20, 2026
Merged

18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:kwin-split-menu

Conversation

@18202781743

@18202781743 18202781743 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

为 QWidget 与 QML 标题栏提供统一的平台函数 _d_supportSplitMenu、_d_showSplitMenu、_d_hideSplitMenu,使客户端能够请求 KWin 显示分屏菜单。

X11 通过 _WM_TOGGLE_SPLIT_MENU 发送按钮全局矩形和隐藏请求;Wayland 通过 client-management 协议请求菜单,过滤过期的异步窗口查询响应,并避免其他窗口的隐藏请求干扰当前菜单。窗口关闭或消失后的菜单清理由窗管负责。

验证:实现工作目录中 Qt5 X11/Wayland、Qt6 X11 构建通过,均使用最多 6 个核心;PR 分支基于最新 master,差异检查通过。仓库当前未启用 Qt6 Wayland 构建,真实 KWin 桌面显示效果尚未实测。

关联调用端:

Summary by Sourcery

Expose cross-platform KWin split-menu platform functions for client applications.

New Features:

  • Expose unified platform functions for checking support and showing or hiding the KWin split-menu from QWidget and QML clients.
  • Support split-menu requests on X11 and Wayland through their respective compositor integration mechanisms.

Bug Fixes:

  • Prevent stale asynchronous Wayland window lookups and unrelated hide requests from affecting the current split menu.

Enhancements:

  • Add Wayland client-management protocol integration and generated client bindings for split-menu operations.

Build:

  • Add the Deepin Wayland protocol dependency to Arch Linux packaging and Qt5 platform-plugin CI builds.

@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds unified platform-native split-menu functions for QWidget/QML consumers, using KWin’s X11 client messages or the Deepin Wayland client-management protocol, with capability checks, asynchronous-request filtering, and backend diagnostics.

Sequence diagram for the Wayland split-menu request

sequenceDiagram
    participant Client as QWidget or QML
    participant Hook as DWaylandInterfaceHook
    participant Management as DClientManagement
    participant Compositor as KWin compositor

    Client->>Hook: supportSplitMenu(wid)
    Hook->>Management: isValid()
    Management->>Compositor: bind com_deepin_client_management
    Client->>Hook: showSplitMenu(wid, buttonRect)
    Hook->>Management: showSplitMenu(wid, buttonRect)
    Management->>Compositor: get_window_from_point()
    Compositor-->>Management: windowFromPoint(windowId)
    Management->>Management: handleWindowFromPoint(windowId)
    Management->>Compositor: show_split_menu(buttonRect, windowId)
    Client->>Hook: hideSplitMenu(wid, delay)
    Hook->>Management: hideSplitMenu(wid, delay)
    Management->>Compositor: hide_split_menu(delay)
Loading

Sequence diagram for the X11 split-menu request

sequenceDiagram
    participant Client as QWidget or QML
    participant Utility as X11 Utility
    participant KWin as KWin via X11

    Client->>Utility: supportSplitMenu(wid)
    Utility->>KWin: Check _WM_TOGGLE_SPLIT_MENU and compositing support
    KWin-->>Utility: Capability result
    Client->>Utility: showSplitMenu(wid, buttonRect)
    Utility->>KWin: ClientMessage(_WM_TOGGLE_SPLIT_MENU, show, buttonRect)
    Client->>Utility: hideSplitMenu(wid, delay)
    Utility->>KWin: ClientMessage(_WM_TOGGLE_SPLIT_MENU, hide, delay)
Loading

File-Level Changes

Change Details Files
Expose a unified native-interface API for split-menu capability and control on both window-system backends.
  • Register support, show, and hide function names in the shared platform-function constants.
  • Add matching X11 and Wayland hook implementations and dispatch entries.
  • Validate the target window and backend-specific split-menu support before advertising capability.
src/global.h
xcb/dplatformnativeinterfacehook.cpp
xcb/utility.h
wayland/dwayland/dwaylandinterfacehook.cpp
wayland/dwayland/dwaylandinterfacehook.h
Implement X11 split-menu requests through KWin’s client-message protocol.
  • Detect the toggle atom, split-window support, and compositing support.
  • Send button global rectangle data for show requests and delay data for hide requests.
  • Add split-menu diagnostic logging and correct split-support property byte handling.
xcb/utility.h
xcb/utility_x11.cpp
Implement Wayland split-menu requests through the Deepin client-management protocol with asynchronous response protection.
  • Discover and bind the compositor global and generate the client protocol during the build.
  • Resolve the compositor window under the button asynchronously before sending the show request.
  • Use request serials and window ownership checks to discard stale responses and unrelated hide requests.
  • Flush protocol requests and log binding, validation, show, and hide operations.
wayland/dwayland/CMakeLists.txt
wayland/dwayland/dclientmanagement.cpp
wayland/dwayland/dclientmanagement.h
wayland/dwayland/dwaylandinterfacehook.cpp
wayland/dwayland/dwaylandinterfacehook.h

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 1 issue

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

## Individual Comments

### Comment 1
<location path="xcb/utility_x11.cpp" line_range="530-538" />
<code_context>
+
+void DClientManagement::showSplitMenu(WId wid, const QRect &buttonRect)
+{
+    if (!wid || !buttonRect.isValid()) {
+        qCDebug(lcWaylandSplitMenu) << "Ignore invalid SplitMenu show request, wid:" << wid
+                                   << "button rect:" << buttonRect;
</code_context>
<issue_to_address>
**nitpick (broader_impact):** The X11 show and hide paths send `_WM_TOGGLE_SPLIT_MENU` messages without checking whether the compositor supports the atom. `internAtom(..., false)` creates the atom on unsupported compositors, then sends a message that cannot be handled instead of gracefully ignoring the request.

**Triggers:** When a client calls showSplitMenu or hideSplitMenu on a compositor that does not advertise `_WM_TOGGLE_SPLIT_MENU`.

**Suggested fix:** Check `supportSplitMenu` or intern the atom with `only_if_exists=true` before sending, and return when the atom is unavailable.
</issue_to_address>

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

Comment thread xcb/utility_x11.cpp
Comment on lines +530 to +538
if (!wid || !buttonRect.isValid()) {
qCDebug(lcDxcbSplitMenu) << "Ignore invalid SplitMenu show request, wid:" << wid
<< "button rect:" << buttonRect;
return;
}

xcb_client_message_event_t event{};
event.response_type = XCB_CLIENT_MESSAGE;
event.type = internAtom("_WM_TOGGLE_SPLIT_MENU", 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.

nitpick (broader_impact): The X11 show and hide paths send _WM_TOGGLE_SPLIT_MENU messages without checking whether the compositor supports the atom. internAtom(..., false) creates the atom on unsupported compositors, then sends a message that cannot be handled instead of gracefully ignoring the request.

Triggers: When a client calls showSplitMenu or hideSplitMenu on a compositor that does not advertise _WM_TOGGLE_SPLIT_MENU.

Suggested fix: Check supportSplitMenu or intern the atom with only_if_exists=true before sending, and return when the atom is unavailable.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 96 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 96 分,大于 70 分通过阈值,代码质量优秀。本次提交实现了 KWin 分屏菜单平台函数的暴露,支持 Wayland 和 XCB 双平台后端,代码结构清晰,输入验证完善,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. wayland/dwayland/dclientmanagement.cpp:28 - 单例对象 new DClientManagement 不释放内存(Qt 插件标准模式,可接受)

建议: 单例模式在 Qt 平台插件中是标准做法,可保持现状。如需改进,可使用 Q_GLOBAL_STATIC 或智能指针管理生命周期。


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. wayland/dwayland/dclientmanagement.h:26 - 公共 API 函数 showSplitMenu()、hideSplitMenu() 缺少文档注释
  2. wayland/dwayland/dclientmanagement.cpp:10 - #define private public 访问 Qt 私有 API 未添加注释说明原因

建议: 为公共 API 函数添加 Doxygen 风格的文档注释,说明参数含义(wid 为窗口 ID,buttonRect 为按钮区域坐标)。在 #define private public 处添加注释说明这是访问 QtWaylandClient 私有 API 的必要手段。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: Wayland 协议调用为异步非阻塞设计,使用 wl_display_flush 确保消息发送。XCB 实现使用单次 xcb_send_event + xcb_flush,性能优良。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 输入验证完善(wid != 0、buttonRect.isValid() 检查)。supportForSplittingWindowByType 从 reinterpret_cast 改为 static_cast 是安全性改进。无安全漏洞。


💡 改进建议代码示例

// 改进建议:为公共 API 添加文档注释

/// 检查窗口是否支持分屏菜单功能
/// \param wid 窗口 ID
/// \return 支持返回 true,不支持返回 false
bool DClientManagement::supportSplitMenu(WId wid);

/// 显示分屏菜单
/// \param wid 目标窗口 ID
/// \param buttonRect 触发按钮的矩形区域坐标
void DClientManagement::showSplitMenu(WId wid, const QRect &buttonRect);

/// 隐藏分屏菜单
/// \param wid 目标窗口 ID
/// \param delay 是否延迟隐藏
void DClientManagement::hideSplitMenu(WId wid, bool delay);

// 改进建议:在 #define private public 处添加注释
// 访问 QtWaylandClient 私有 API 所需,用于获取 Wayland display 的 globals 列表
#define private public
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#undef private

本报告由 AI 代码审查工具自动生成

BLumia
BLumia previously approved these changes Sep 14, 2026
1. Add DClientManagement class for Wayland client management protocol
2. Implement showSplitMenu, hideSplitMenu, and supportSplitMenu
functions
3. Add Wayland protocol binding for com_deepin_client_management
interface
4. Implement XCB split menu via _WM_TOGGLE_SPLIT_MENU client messages
5. Register new function pointers in both Wayland and XCB hooks
6. Fix potential out-of-bounds read in supportForSplittingWindowByType
7. Add logging categories for split menu debugging
8. Update copyright year and CMake configuration for Wayland protocols

Log: Added split menu support for window splitting feature

Influence:
1. Test SplitMenu display when hovering over split button on XCB
platform
2. Test SplitMenu display and hide on Wayland platform
3. Verify supportSplitMenu returns correct values based on window
properties
4. Test menu positioning with different button rectangle coordinates
5. Verify menu hides properly with and without delay parameter
6. Test behavior when compositor does not support the protocol
7. Verify window switching triggers proper menu hide
8. Test edge cases with invalid window IDs and button rectangles

feat: 为 Wayland 和 XCB 添加分屏菜单支持

1. 新增 DClientManagement 类用于 Wayland 客户端管理协议
2. 实现 showSplitMenu、hideSplitMenu 和 supportSplitMenu 函数
3. 添加 com_deepin_client_management 接口的 Wayland 协议绑定
4. 通过 _WM_TOGGLE_SPLIT_MENU 客户端消息实现 XCB 分屏菜单
5. 在 Wayland 和 XCB 钩子中注册新的函数指针
6. 修复 supportForSplittingWindowByType 中潜在的越界读取问题
7. 添加分屏菜单调试日志分类
8. 更新版权年份和 Wayland 协议的 CMake 配置

Log: 新增窗口分屏菜单功能

Influence:
1. 测试 XCB 平台下悬停分屏按钮时菜单的显示
2. 测试 Wayland 平台下分屏菜单的显示和隐藏
3. 验证 supportSplitMenu 根据窗口属性返回正确的值
4. 测试不同按钮矩形坐标下的菜单位置
5. 验证带延迟和不带延迟参数时菜单的正确隐藏
6. 测试合成器不支持该协议时的行为
7. 验证窗口切换时是否正确隐藏菜单
8. 测试无效窗口 ID 和按钮矩形的边界情况

PMS: BUG-370181
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

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

@18202781743
18202781743 merged commit 781e746 into linuxdeepin:master Sep 20, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants