Skip to content

Conversation

@18202781743
Copy link
Contributor

  1. Added xcb-icccm dependency to CMakeLists.txt for X11 ICCCM support
  2. Modified DLayerShellWindow to have empty default scope instead of
    "window"
  3. Implemented onScopeChanged() method to set WM_CLASS property on X11
    windows
  4. Connected scopeChanged signal to update WM_CLASS when scope changes
  5. WM_CLASS is set using both instance and class name from the scope
    property

Log: Layer shell windows now set WM_CLASS property on X11 for better
window identification

Influence:

  1. Test layer shell windows on X11 display server
  2. Verify WM_CLASS property is correctly set using xprop tool
  3. Test scope changes dynamically update WM_CLASS
  4. Verify empty scope doesn't set WM_CLASS property
  5. Test backward compatibility with existing layer shell windows
  6. Verify window managers can properly identify layer shell windows
    by class

feat: 为层壳窗口添加X11 WM_CLASS支持

  1. 在CMakeLists.txt中添加xcb-icccm依赖以支持X11 ICCCM
  2. 修改DLayerShellWindow的scope默认值为空而不是"window"
  3. 实现onScopeChanged()方法为X11窗口设置WM_CLASS属性
  4. 连接scopeChanged信号以便在scope变化时更新WM_CLASS
  5. WM_CLASS使用scope属性同时作为实例名和类名进行设置

Log: 层壳窗口现在会在X11上设置WM_CLASS属性,便于窗口识别

Influence:

  1. 在X11显示服务器上测试层壳窗口
  2. 使用xprop工具验证WM_CLASS属性是否正确设置
  3. 测试scope变化时WM_CLASS是否动态更新
  4. 验证空scope不会设置WM_CLASS属性
  5. 测试与现有层壳窗口的向后兼容性
  6. 验证窗口管理器能否通过类名正确识别层壳窗口

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@18202781743 18202781743 requested a review from tsic404 February 2, 2026 03:31
BLumia
BLumia previously approved these changes Feb 2, 2026
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

1. Added xcb-icccm dependency to CMakeLists.txt for X11 ICCCM support
2. Modified DLayerShellWindow to have empty default scope instead of
"window"
3. Implemented onScopeChanged() method to set WM_CLASS property on X11
windows
4. Connected scopeChanged signal to update WM_CLASS when scope changes
5. WM_CLASS is set using both instance and class name from the scope
property

Log: Layer shell windows now set WM_CLASS property on X11 for better
window identification

Influence:
1. Test layer shell windows on X11 display server
2. Verify WM_CLASS property is correctly set using xprop tool
3. Test scope changes dynamically update WM_CLASS
4. Verify empty scope doesn't set WM_CLASS property
5. Test backward compatibility with existing layer shell windows
6. Verify window managers can properly identify layer shell windows
by class

feat: 为层壳窗口添加X11 WM_CLASS支持

1. 在CMakeLists.txt中添加xcb-icccm依赖以支持X11 ICCCM
2. 修改DLayerShellWindow的scope默认值为空而不是"window"
3. 实现onScopeChanged()方法为X11窗口设置WM_CLASS属性
4. 连接scopeChanged信号以便在scope变化时更新WM_CLASS
5. WM_CLASS使用scope属性同时作为实例名和类名进行设置

Log: 层壳窗口现在会在X11上设置WM_CLASS属性,便于窗口识别

Influence:
1. 在X11显示服务器上测试层壳窗口
2. 使用xprop工具验证WM_CLASS属性是否正确设置
3. 测试scope变化时WM_CLASS是否动态更新
4. 验证空scope不会设置WM_CLASS属性
5. 测试与现有层壳窗口的向后兼容性
6. 验证窗口管理器能否通过类名正确识别层壳窗口
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码 diff 主要是在 X11 环境下为 DLayerShellWindow 添加了设置 WM_CLASS 属性的功能,以便更好地模拟 Wayland Layer Shell 的行为。以下是对这段代码的审查意见,分为语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • CMakeLists.txt:
    • pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb-ewmh xcb-icccm xtst x11):添加了 xcb-icccm 的依赖。这是正确的,因为代码中引入了 <xcb/xcb_icccm.h> 并使用了 xcb_icccm_set_wm_class。逻辑正确。
  • dlayershellwindow.cpp:
    • QString scope;:将 scope 的默认值从 "window" 移除,改为空字符串。这是为了配合 onScopeChanged 中的逻辑(if (instanceName.isEmpty()) return;),当未显式设置 scope 时,不覆盖 X11 的默认行为。逻辑正确。
  • x11dlayershellemulation.cpp:
    • onScopeChanged() 的实现逻辑清晰:检查 X11 连接和窗口 ID -> 检查 scope 是否为空 -> 构造符合 X11 规范的 WM_CLASS 字符串(instance\0class\0) -> 调用 xcb 函数设置。
    • onScopeChanged() 的调用时机:在构造函数中手动调用一次以确保初始化,并连接信号槽以便后续更新。逻辑正确。

2. 代码质量

  • 头文件包含顺序:
    • x11dlayershellemulation.cpp 中对头文件进行了排序(Qt 头文件与系统头文件分组)。这符合常见的代码规范,提高了可读性。
  • 注释与文档:
    • onScopeChanged() 中添加了关于 WM_CLASS 格式的注释(instance_name\0class_name\0),这对于维护者理解 X11 协议细节非常有帮助。
  • 日志记录:
    • 使用 qCDebug 打印设置的 WM_CLASS 内容,便于调试。
  • 代码组织:
    • 将 X11 特定的属性设置逻辑封装在 onScopeChanged 函数中,保持了 LayerShellEmulation 类内部结构的整洁。

3. 代码性能

  • 字符串拼接:
    • onScopeChanged 中,使用了 QByteArrayappend 来构造 wmClassData。这种方式对于这种短字符串(通常只有几十字节)来说性能足够,且直观易读。性能影响可忽略。
  • 信号连接:
    • 构造函数中增加了 scopeChanged 信号的连接。这只有在 scope 属性实际改变时才会触发,属于按需调用,不会造成不必要的性能开销。

4. 代码安全

  • 空指针检查:
    • onScopeChanged 中检查了 x11Application 是否有效,以及 m_window->winId() 是否有效。这是很好的防御性编程实践,防止在非 X11 平台或窗口未创建时崩溃。
  • 编码处理:
    • 使用 toUtf8()QString 转换为 QByteArray。X11 的 WM_CLASS 属性通常期望 Latin-1 或 ASCII 字符。虽然 toUtf8() 对于 ASCII 字符是兼容的,但如果 instanceNameclassName 包含非 ASCII 字符(如中文),X11 窗口管理器可能无法正确显示或识别。
    • 改进建议:虽然通常应用名和 scope 都是英文,但为了更严格的符合 ICCCM 规范(通常建议使用 Compound Text 或仅 ASCII),可以考虑增加对非 ASCII 字符的检查或转换逻辑,或者至少在代码注释中注明应使用 ASCII 字符。不过,考虑到 Qt 的 QCoreApplication::applicationName() 通常也是 ASCII,目前的实现在常规场景下是安全的。

总结与改进建议

总体来说,这段代码质量很高,逻辑清晰,正确实现了功能。

唯一的改进建议(针对安全性/健壮性):

x11dlayershellemulation.cpponScopeChanged 函数中,建议对 instanceNameclassName 的字符集进行更明确的说明或处理。

// ... 前面的代码 ...

    QString instanceName = m_dlayerShellWindow->scope();
    if (instanceName.isEmpty()) {
        return;
    }

    QString className = QCoreApplication::applicationName();
    
    // 安全性改进建议:检查是否包含非ASCII字符
    // WM_CLASS 应当由 ASCII 字符组成,包含非 ASCII 字符可能导致窗口管理器识别异常
    if (!instanceName.toLatin1().toUtf8().isEmpty() || !className.toLatin1().toUtf8().isEmpty()) {
        qCWarning(layershell) << "WM_CLASS contains non-ASCII characters, which might not work correctly with all Window Managers.";
    }

    QByteArray wmClassData;
    // ... 后面的代码 ...

或者,如果确定只接受 ASCII,可以直接使用 toLatin1() 并在转换失败或丢失信息时给出警告,或者直接截断。但在当前上下文中,保持现状也是可以接受的,因为 dde-shell 相关的命名通常都是标准的英文标识符。

最终评价:代码可以合并,逻辑完善,无明显缺陷。

@18202781743 18202781743 merged commit 726b9be into linuxdeepin:master Feb 2, 2026
10 of 11 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.

4 participants