Skip to content

Conversation

@18202781743
Copy link
Contributor

  1. Added logic to set a default window title for panel QWindow objects
    if the title is empty
  2. The default title is set to the pluginId() value
  3. This change helps window managers distinguish dde-shell windows by
    setting the _NET_WM_NAME X window property
  4. The title setting occurs when the rootObjectChanged signal is
    emitted, ensuring it applies to newly created panel windows

Log: Fixed panel windows not having identifiable titles for window
managers

Influence:

  1. Verify panel windows now have proper titles in window manager
    listings
  2. Test that existing custom titles are not overwritten
  3. Check that the _NET_WM_NAME property is correctly set for X11 window
    managers
  4. Ensure window switching and identification works correctly with the
    new titles

fix: 为面板窗口设置默认窗口标题

  1. 添加逻辑为面板QWindow对象设置默认窗口标题(当标题为空时)
  2. 默认标题设置为pluginId()的值
  3. 此更改通过设置_NET_WM_NAME X窗口属性,帮助窗口管理器区分dde-shell窗口
  4. 标题设置在rootObjectChanged信号发出时执行,确保应用于新创建的面板窗口

Log: 修复面板窗口缺少可识别标题导致窗口管理器无法区分的问题

Influence:

  1. 验证面板窗口现在在窗口管理器列表中具有正确的标题
  2. 测试现有的自定义标题不会被覆盖
  3. 检查_NET_WM_NAME属性是否正确设置给X11窗口管理器
  4. 确保窗口切换和识别功能在新标题下正常工作

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

@justforlxz
Copy link
Member

LGTM

BLumia
BLumia previously approved these changes Jan 31, 2026
@18202781743
Copy link
Contributor Author

@deepin-ci-robot
Copy link

[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

1. Added logic to set a default window title for panel QWindow objects
if the title is empty
2. The default title is set to the pluginId() value
3. This change helps window managers distinguish dde-shell windows by
setting the _NET_WM_NAME X window property
4. The title setting occurs when the rootObjectChanged signal is
emitted, ensuring it applies to newly created panel windows

Log: Fixed panel windows not having identifiable titles for window
managers

Influence:
1. Verify panel windows now have proper titles in window manager
listings
2. Test that existing custom titles are not overwritten
3. Check that the _NET_WM_NAME property is correctly set for X11 window
managers
4. Ensure window switching and identification works correctly with the
new titles

fix: 为面板窗口设置默认窗口标题

1. 添加逻辑为面板QWindow对象设置默认窗口标题(当标题为空时)
2. 默认标题设置为pluginId()的值
3. 此更改通过设置_NET_WM_NAME X窗口属性,帮助窗口管理器区分dde-shell窗口
4. 标题设置在rootObjectChanged信号发出时执行,确保应用于新创建的面板窗口

Log: 修复面板窗口缺少可识别标题导致窗口管理器无法区分的问题

Influence:
1. 验证面板窗口现在在窗口管理器列表中具有正确的标题
2. 测试现有的自定义标题不会被覆盖
3. 检查_NET_WM_NAME属性是否正确设置给X11窗口管理器
4. 确保窗口切换和识别功能在新标题下正常工作
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改主要是为了在 DPanelrootObject 变化时,如果该对象是一个 QWindow 且标题为空,则将其标题设置为 pluginId()

以下是对这段代码的审查意见,涵盖语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • 基本正确:代码逻辑是合理的。使用了 qobject_cast 进行安全的类型转换,并检查了 title() 是否为空。
  • 潜在风险d->m_rootObject 的类型是什么?如果它原本就是 QWindow 的子类(如 QQuickWindow),逻辑是通的。但如果 m_rootObject 通常是 QQuickItem,那么这里获取到的是 QWindow 可能意味着获取的是该 Item 的 window(即 item->window())。如果 m_rootObject 本身就是 Window,逻辑没问题。如果 m_rootObject 是 Item,而 Item 刚创建时可能还没有 attached 到 Window,这里的 qobject_cast 会返回空指针,逻辑上虽然安全(进入了 if 块但不执行),但可能达不到预期效果。
    • 假设:根据 DPanel 的命名和上下文(ensurePopupWindow 等),推测 m_rootObject 可能是 QML 的根组件。如果是 QQuickWindowqobject_cast 是正确的。如果它是 QQuickItem,这里可能需要先获取 window()

2. 代码质量

  • 可读性:代码清晰,注释解释了意图,这很好。
  • 类型转换:使用 qobject_cast 而非 C 风格转换或 static_cast 是 Qt 中的最佳实践,值得肯定。
  • 命名规范:变量命名 window 符合上下文,没有问题。

3. 代码性能

  • 性能开销极小
    • qobject_cast 内部只是简单的字符串比较(strcmp),开销非常低。
    • window->title()isEmpty() 也是轻量级操作。
    • 这段代码运行在 rootObjectChanged 信号槽中,通常只在初始化或特定切换时触发一次,不是高频热点路径,因此性能完全可接受。

4. 代码安全

  • 空指针检查qobject_cast 失败会返回 nullptr,代码中通过 if (auto window = ...) 完美处理了这种情况,不会导致空指针解引用。
  • 字符串安全pluginId() 返回的 QString 被传递给 setTitle。如果 pluginId() 返回空字符串,setTitle 会将窗口标题设为空,这是符合逻辑的("如果没设置标题,就用 pluginId,如果 pluginId 也是空的,那就设为空")。
  • 线程安全rootObjectChanged 通常在 GUI 线程触发,操作 QWindow 也是 GUI 线程操作,不存在线程安全问题。

改进建议

虽然代码本身没有明显错误,但为了增强健壮性,可以考虑以下几点:

  1. 类型检查的明确性
    如果 m_rootObject 有可能是 QQuickItem,那么 qobject_cast<QWindow*> 会失败。如果意图是设置根 Item 所在 Window 的标题,代码可能需要调整。但基于当前的 diff,假设 m_rootObject 确实就是 Window。

  2. 日志记录(可选)
    在调试模式下,如果设置了标题,打印一条 Log 可能会有帮助,但这通常不是必须的。

  3. 代码微调(风格优化)
    可以将判断逻辑稍微简化,或者保持现状。现状已经足够好。

    // 当前写法
    if (auto window = qobject_cast<QWindow *>(d->m_rootObject)) {
        if (window->title().isEmpty()) {
            window->setTitle(pluginId());
        }
    }
    
    // 或者稍微紧凑一点(取决于团队代码风格偏好)
    if (auto window = qobject_cast<QWindow *>(d->m_rootObject); window && window->title().isEmpty()) {
        window->setTitle(pluginId());
    }

总结

这段代码是安全、正确且高效的。它遵循了 Qt 的编程规范,正确处理了类型转换和空指针检查。除了根据 m_rootObject 的实际类型确认一下是否需要处理 QQuickItem 的情况外,无需强制修改。

@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Jan 31, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 4f3c0b9 into linuxdeepin:master Jan 31, 2026
8 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