Skip to content

fix: remove noise qWarning in setWmWindowTypes when platform window not ready - #405

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
52cyb:agent/developer/c388c339
Aug 17, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
52cyb:agent/developer/c388c339

Conversation

@52cyb

@52cyb 52cyb commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remove the noisy runtime warning emitted by DWindowManagerHelper::setWmWindowTypes when the platform window is not ready or not on XCB.

When adding a new user in dde-control-center (accounts module), the following warning was logged:

Dtk::Gui::DWindowManagerHelper::setWmWindowTypes:502 cast CreateAccountDialog_QMLTYPE_297(...) to platform window failed

Root cause

setWmWindowTypes is invoked during the QML component-complete phase (via the D.DWindow.wmWindowTypes binding in dtkdeclarative), at which point window->handle() is still nullptr. The Qt6 code unconditionally qWarnings whenever dynamic_cast<QXcbWindow_P*>(window->handle()) fails. That cast fails in two normal situations that are not errors:

  • Platform window not yet created — window->handle() is nullptr (common during the QML component-complete phase where D.DWindow.wmWindowTypes is evaluated before the underlying QWindow is exposed).
  • Non-XCB platform — on Wayland/Treeland the handle is a QWaylandWindow, not an QXcbWindow.

_NET_WM_WINDOW_TYPE is an X11-only property, so in both cases there is legitimately nothing to do. The Qt5 path (QXcbWindowFunctions::setWmWindowType) was already a silent no-op here; the Qt6 port introduced the unconditional qWarning and turned a normal no-op into noise.

Change

File: src/kernel/dwindowmanagerhelper.cpp — DWindowManagerHelper::setWmWindowTypes, Qt6 branch only.

  • Removed the unconditional qWarning (the whole else branch).
  • Guard with if (window) (null-pointer safety), then dynamic_cast<QXcbWindow_P*>(window->handle()) — window->handle() is called only once; a null handle safely yields nullptr from the cast (silent no-op).
  • Non-applicable cases (null window, null handle, non-XCB platform) all fall through silently — consistent with popupSystemWindowMenu, setMotifFunctions and setMotifDecorations in the same file, and restoring the Qt5 silent behavior.
  • The Qt5 #else branch and the #ifdef Q_OS_LINUX guard are unchanged. No header / API / ABI change.
@@ -497,10 +497,15 @@ void DWindowManagerHelper::setWmWindowTypes(QWindow *window, WmWindowTypes types

 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
     typedef QNativeInterface::Private::QXcbWindow  QXcbWindow_P;
-    if (auto w = dynamic_cast<QXcbWindow_P *>(window->handle())) {
-        w->setWindowType(static_cast<D_XCB_WINDOW_TYPE>(_types));
-    } else {
-        qWarning() << "cast" << window << "to platform window failed";
+    // _NET_WM_WINDOW_TYPE 是 X11 专属属性,仅在 XCB 平台窗口已创建时生效。
+    // 当 window 为空、handle 为空(平台窗口尚未创建,常见于 QML 组件完成阶段)
+    // 或为非 XCB 平台(如 Wayland/Treeland)时无法应用,静默忽略即可,
+    // 与 Qt5 下 QXcbWindowFunctions::setWmWindowType 及本类 setMotifFunctions/
+    // setMotifDecorations/popupSystemWindowMenu 的处理方式一致,避免对 QML 窗口产生噪声告警。
+    if (window) {
+        if (auto w = dynamic_cast<QXcbWindow_P *>(window->handle())) {
+            w->setWindowType(static_cast<D_XCB_WINDOW_TYPE>(_types));
+        }
     }
 #else
     QXcbWindowFunctions::setWmWindowType(window, static_cast<D_XCB_WINDOW_TYPE>(_types));

Testing

  • The existing unit test tests/src/ut_dwindowmanagerhelper.cpp only expects "no crash" for this function; behavior is preserved.
  • Verify the warning no longer appears when opening the "add new user" dialog in dde-control-center.
  • Confirm wmWindowTypes still applies on X11 once the platform window is created.
  • Verify no regression on Wayland/Treeland (the call remains a no-op).

Draft PR — please review. Do not merge until approved.

Related Multica issue: DDE-111

Summary by Sourcery

Bug Fixes:

  • Prevent noisy qWarning logs when setWmWindowTypes is called before the platform window handle is created or on non-X11 platforms by treating these cases as silent no-ops.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai

sourcery-ai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refines DWindowManagerHelper::setWmWindowTypes for the Qt6 path so that it silently no-ops when the platform window is not yet created or is non-XCB, removing an unconditional runtime qWarning while preserving behavior on valid X11/XCB windows and keeping the Qt5 path unchanged.

Sequence diagram for updated setWmWindowTypes behavior on Qt6

sequenceDiagram
    participant QMLWindow
    participant DWindowManagerHelper
    participant QWindow
    participant QXcbWindow_P

    QMLWindow->>DWindowManagerHelper: setWmWindowTypes(window, types)
    DWindowManagerHelper->>DWindowManagerHelper: [if window]
    DWindowManagerHelper->>QWindow: handle()
    DWindowManagerHelper->>DWindowManagerHelper: dynamic_cast QXcbWindow_P
    alt [xcb handle available]
        DWindowManagerHelper->>QXcbWindow_P: setWindowType(D_XCB_WINDOW_TYPE)
    else [no window or non-XCB/handle nullptr]
        DWindowManagerHelper->>DWindowManagerHelper: [silent no-op]
    end
Loading

File-Level Changes

Change Details Files
Make setWmWindowTypes a silent no-op on non-ready or non-XCB Qt6 windows and remove the noisy qWarning.
  • Wrap the platform-window handling logic in a null check for the incoming QWindow pointer.
  • Replace the previous if/else that emitted a qWarning on failed dynamic_cast with a single dynamic_cast branch that only sets the window type when the handle is a QXcbWindow_P, otherwise doing nothing.
  • Add explanatory comments (in Chinese) clarifying that _NET_WM_WINDOW_TYPE is X11-only and documenting why null or non-XCB handles are silently ignored, aligning behavior with Qt5 and related helper methods.
  • Leave the Qt5 #else branch and surrounding Q_OS_LINUX/Qt-version conditionals untouched to avoid API/ABI impact.
src/kernel/dwindowmanagerhelper.cpp

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

@52cyb
52cyb force-pushed the agent/developer/c388c339 branch from 08ba021 to f11b7f5 Compare August 17, 2026 03:05
@52cyb 52cyb changed the title fix: silence noise qWarning in setWmWindowTypes fix: guard setWmWindowTypes against null handle Aug 17, 2026
@52cyb
52cyb force-pushed the agent/developer/c388c339 branch 2 times, most recently from d2232d7 to 2db9147 Compare August 17, 2026 05:51
@52cyb
52cyb marked this pull request as ready for review August 17, 2026 05:51

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

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

Please try again later or upgrade to continue using Sourcery

Comment thread src/kernel/dwindowmanagerhelper.cpp Outdated
if (!platformWindow)
return;

// 本次范围限定 X11:xcb QPA 下 handle 非空必为 QXcbWindow(含子类 QXcbForeignWindow),

@18202781743 18202781743 Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这个else如果变成了死代码,是不是直接去掉就好了,
要是避免警告太多,这里可以把这个warning变成debug的日志输出,方便之后调试,而不是在前面直接都return,

@52cyb 52cyb Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这里是不确定影响面,所以保留原来的语义。
只处理handle本身为空导致的转换失败的场景,避免警告

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

那else也走不到了呀,放开搞,这个接口看着就没适配wayland,可以不用管,之后需要再适配,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

尽量少让代码到中间状态,这样越到后面越难维护了,
要么没有用的删掉,要么给它降个级,不输出,

@52cyb
52cyb force-pushed the agent/developer/c388c339 branch from 2db9147 to fd35a36 Compare August 17, 2026 06:30
@52cyb
52cyb marked this pull request as draft August 17, 2026 06:33
@52cyb 52cyb changed the title fix: guard setWmWindowTypes against null handle fix: remove noise qWarning in setWmWindowTypes when platform window not ready Aug 17, 2026
@52cyb
52cyb force-pushed the agent/developer/c388c339 branch from fd35a36 to 3c049f6 Compare August 17, 2026 07:10
@52cyb
52cyb marked this pull request as ready for review August 17, 2026 07:11

@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 left some high level feedback:

  • In the Qt6 branch, consider caching window->handle() in a local variable before the null check and dynamic_cast to avoid calling it twice and to make the intent clearer.
  • You might want to leave a lightweight debug log (e.g. under a verbose flag) for the non-XCB/non-ready cases to help future debugging while still avoiding noisy runtime warnings.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the Qt6 branch, consider caching `window->handle()` in a local variable before the null check and `dynamic_cast` to avoid calling it twice and to make the intent clearer.
- You might want to leave a lightweight debug log (e.g. under a verbose flag) for the non-XCB/non-ready cases to help future debugging while still avoiding noisy runtime warnings.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@52cyb
52cyb force-pushed the agent/developer/c388c339 branch from 3c049f6 to c279a63 Compare August 17, 2026 07:21
@52cyb
52cyb marked this pull request as draft August 17, 2026 07:22
…ot ready

1. Remove the unconditional qWarning in setWmWindowTypes Qt6 branch
2. Guard with if (window) and dynamic_cast to QXcbWindow, call handle() once
3. Treat null window, null handle and non-XCB (Wayland) as silent no-op
4. Restore Qt5 silent behavior, matching popupSystemWindowMenu

Influence:
1. Verify no warning when opening CreateAccountDialog in dde-control-center
2. Confirm wmWindowTypes still applies on X11 after platform window is created
3. Verify no regression on Wayland/Treeland where the call is a no-op

fix: 移除 setWmWindowTypes 平台窗口未就绪时的噪声告警

1. 删除 setWmWindowTypes Qt6 分支中无条件的 qWarning
2. 外层判 window 非空,内层 dynamic_cast 到 QXcbWindow,handle() 只调一次
3. window 为空、handle 为空或非 XCB 平台(Wayland)时静默 no-op
4. 恢复 Qt5 静默行为,与 popupSystemWindowMenu、setMotifFunctions 等一致

Influence:
1. 验证控制中心账户模块打开新建用户对话框时不再打印该警告
2. 确认 X11 下平台窗口创建后 wmWindowTypes 仍能正常生效
3. 验证 Wayland/Treeland 下该调用为 no-op,无回归
@52cyb
52cyb marked this pull request as ready for review August 17, 2026 07:24
@52cyb
52cyb force-pushed the agent/developer/c388c339 branch from c279a63 to ae63a02 Compare August 17, 2026 07:24

@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 left some high level feedback:

  • Consider returning early when window is null to avoid an extra nested if and keep the control flow consistent with other helpers in this file.
  • The new comment block is in Chinese while the surrounding code is in English; consider standardizing the comment language to match the rest of the file for consistency.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider returning early when `window` is null to avoid an extra nested `if` and keep the control flow consistent with other helpers in this file.
- The new comment block is in Chinese while the surrounding code is in English; consider standardizing the comment language to match the rest of the file for consistency.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码完美修复了Qt6下非XCB平台和QML组件完成阶段的空指针解引用及噪声告警问题
逻辑严密且与项目其他模块保持高度一致,无任何扣分项

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓
    修改前在 setWmWindowTypes 函数中直接调用 window->handle(),当 window 为空时会触发空指针解引用崩溃。修改后增加了 if (window) 的前置保护,彻底消除了该崩溃路径,同时将 dynamic_cast 失败的分支从抛出警告改为静默忽略,符合X11专属属性在Wayland/Treeland等非XCB平台下的预期容错逻辑。
    建议:无需改进,当前逻辑已足够严谨。
  • 2.代码质量(优秀)✓
    新增的多行注释极其详尽,准确指出了 _NET_WM_WINDOW_TYPE 的X11专属特性、QML组件完成阶段 handle() 返回 nullptr 的场景,并明确说明了与Qt5分支 QXcbWindowFunctions::setWmWindowType 及同文件 setMotifFunctions 等函数的容错策略对齐,极大提升了代码的可维护性。
    建议:无需改进,注释质量达到优秀标准。
  • 3.代码性能(高效)✓
    仅增加了一次指针非空判断和一层嵌套 if 语句,属于O(1)常量级开销,对运行时性能无任何可感知影响。
    建议:无需改进。
  • 4.代码安全(存在0个安全漏洞)✓
    漏洞对比统计:新增漏洞 0 个,减少漏洞 1 个,持平 0 个
    本次修改移除了原有的空指针解引用风险,未引入任何新的安全漏洞。原代码在 window 为空时调用 window->handle() 可能导致程序崩溃(拒绝服务),现已通过前置判空完美修复。

  • 建议:保持当前的安全编码实践,在处理来自外部或跨层传递的指针参数时,始终优先进行有效性校验。

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需额外修改,此处展示其完整上下文以供参考
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    typedef QNativeInterface::Private::QXcbWindow  QXcbWindow_P;
    // _NET_WM_WINDOW_TYPE 是 X11 专属属性,仅在 XCB 平台窗口已创建时生效。
    // 当 window 为空、handle 为空(平台窗口尚未创建,常见于 QML 组件完成阶段)
    // 或为非 XCB 平台(如 Wayland/Treeland)时无法应用,静默忽略即可,
    // 与 Qt5 下 QXcbWindowFunctions::setWmWindowType 及本类 setMotifFunctions/
    // setMotifDecorations/popupSystemWindowMenu 的处理方式一致,避免对 QML 窗口产生噪声告警。
    if (window) {
        if (auto w = dynamic_cast<QXcbWindow_P *>(window->handle())) {
            w->setWindowType(static_cast<D_XCB_WINDOW_TYPE>(_types));
        }
    }
#else
    QXcbWindowFunctions::setWmWindowType(window, static_cast<D_XCB_WINDOW_TYPE>(_types));
#endif

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 52cyb

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

@52cyb

52cyb commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 11360f0 into linuxdeepin:master Aug 17, 2026
23 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