Skip to content

Conversation

@yixinshark
Copy link
Contributor

include minisize luancher, tray plugin popup and tray menu

fix: prevent dock screen switch if any popup is showing
Pms: BUG-288701

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 @yixinshark, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@yixinshark yixinshark force-pushed the fix-closeAllpupop branch 2 times, most recently from 38f7150 to 0f7ca3d Compare January 31, 2026 08:02
include minisize luancher, tray plugin popup and tray menu

fix: prevent dock screen switch if any popup is showing
Pms: BUG-288701
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改旨在防止在存在弹窗或瞬时子窗口时切换屏幕,这是一个合理的需求。以下是对这段代码的详细审查,包括语法逻辑、代码质量、代码性能和代码安全方面的改进意见:

1. 语法逻辑

问题:

  • 变量命名 show 作为一个布尔值或指针的变量名不够清晰,容易与关键字或函数名混淆。
  • 逻辑判断 if (show) 依赖于隐式转换,如果 m_transientChildShows 存储的是指针,这会检查指针是否非空;如果是布尔值,则检查是否为真。建议显式判断。

改进建议:

for (auto isShowing : m_transientChildShows) {
    if (isShowing) {
        parent()->setHideState(Show);
        return;
    }
}

或者更明确地:

for (const auto& isShowing : m_transientChildShows) {
    if (isShowing) {
        parent()->setHideState(Show);
        return;
    }
}

2. 代码质量

问题:

  • 缺少对 parent() 返回值的空指针检查。如果 parent() 返回 nullptr,调用 setHideState 会导致崩溃。
  • 注释说明不够详细,可以补充说明为什么在这种情况下需要阻止屏幕切换。

改进建议:

// Do not switch screen if any popup/transient child window is showing
// to avoid unexpected behavior or loss of focus
for (const auto& isShowing : m_transientChildShows) {
    if (isShowing) {
        if (auto dockParent = parent()) {
            dockParent->setHideState(Show);
        }
        return;
    }
}

3. 代码性能

问题:

  • 遍历 m_transientChildShows 是线性时间复杂度,如果容器很大可能会有性能问题。但通常情况下,弹窗数量不会很多,影响不大。
  • QTimer::singleShot(200, ...) 的延迟是硬编码的,可能需要根据实际需求调整或作为可配置参数。

改进建议:

  • 如果 m_transientChildShows 可能很大,可以考虑使用 std::any_of 或类似算法,或者维护一个单独的标志位来跟踪是否有弹窗显示。

4. 代码安全

问题:

  • 没有对 m_transientChildShows 的线程安全性进行说明。如果这个容器可能在多线程环境下访问,需要加锁。
  • parent() 的返回值没有检查,可能导致空指针解引用。

改进建议:

// Assuming m_transientChildShows is accessed only from the main thread
// If not, add appropriate synchronization
for (const auto& isShowing : m_transientChildShows) {
    if (isShowing) {
        if (auto dockParent = parent()) {
            dockParent->setHideState(Show);
        }
        return;
    }
}

综合改进后的代码:

void DockHelper::enterScreen(QScreen *screen)
{
    if (!screen) {
        return;
    }

    // Do not switch screen if any popup/transient child window is showing
    // to avoid unexpected behavior or loss of focus
    for (const auto& isShowing : m_transientChildShows) {
        if (isShowing) {
            if (auto dockParent = parent()) {
                dockParent->setHideState(Show);
            }
            return;
        }
    }

    QTimer::singleShot(200, [this, screen]() {
        if (auto dockParent = parent()) {
            dockParent->setDockScreen(screen);
            dockParent->setHideState(Show);
        }
    });
}

总结

  1. 语法逻辑:改进变量命名和显式判断。
  2. 代码质量:增加空指针检查和详细注释。
  3. 代码性能:考虑使用更高效的算法或维护标志位。
  4. 代码安全:确保线程安全和空指针检查。

这些改进将使代码更健壮、可读性更好,并减少潜在的错误。

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