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 3 times, most recently from 0f7ca3d to 7ec31a9 Compare February 2, 2026 02:21
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

这段代码主要是在 DockHelper::enterScreen 函数中增加了一个逻辑判断,用于在切换屏幕前检查是否有弹出窗口或临时子窗口正在显示。以下是对这段代码的详细审查和改进建议:

1. 语法逻辑审查

当前逻辑:

// Do not switch screen if any popup/transient child window is showing
for (auto show : m_transientChildShows) {
    if (show) {
        parent()->setHideState(Show);
        return;
    }
}

潜在问题:

  • 逻辑一致性:注释说明是"不切换屏幕",但代码中调用了 parent()->setHideState(Show)。这可能会导致行为与注释不符——即虽然阻止了屏幕切换,但仍然改变了隐藏状态。
  • 变量命名show 作为布尔值的变量名略显歧义,建议改为更明确的名称如 isShowingisVisible
  • 空指针风险:虽然代码中检查了 if (show),但 m_transientChildShows 的元素类型未明确。如果它是指针类型,这个检查是合理的;如果是布尔值,这个检查略显冗余。

2. 代码质量改进

改进后的代码:

// Do not switch screen if any popup/transient child window is showing
for (auto isShowing : m_transientChildShows) {
    if (isShowing) {
        parent()->setHideState(Show);
        return;
    }
}

改进点:

  • 将变量名 show 改为 isShowing,提高可读性。
  • 保持原有逻辑不变,但使代码意图更清晰。

3. 代码性能审查

当前性能:

  • 遍历 m_transientChildShows 的时间复杂度是 O(n),其中 n 是临时子窗口的数量。如果 m_transientChildShows 通常很小(例如少于10个元素),这个性能是可以接受的。

潜在优化:

  • 如果 m_transientChildShows 经常很大,可以考虑:
    1. 维护一个计数器 m_visibleTransientChildCount,在窗口显示/隐藏时更新,避免遍历。
    2. 使用更高效的数据结构(如位掩码)来表示窗口状态。

4. 代码安全审查

潜在问题:

  • 线程安全:如果 m_transientChildShows 可能被多个线程访问,需要加锁保护。
  • 生命周期管理:如果 m_transientChildShows 存储的是指针,需要确保这些指针的有效性。
  • 异常安全:当前代码没有异常处理,如果 parent() 返回空指针或抛出异常,可能导致崩溃。

改进建议:

// Do not switch screen if any popup/transient child window is showing
for (auto isShowing : m_transientChildShows) {
    if (isShowing) {
        if (auto dock = parent()) {
            dock->setHideState(Show);
        }
        return;
    }
}

5. 其他建议

  1. 注释完善

    • 可以添加更详细的注释,说明为什么需要在有临时子窗口时阻止屏幕切换。
    • 例如:// Prevent screen switching when transient windows (like menus or dialogs) are visible to avoid UI inconsistency
  2. 日志记录

    • 可以添加日志记录,便于调试:
    if (isShowing) {
        qCDebug(DOCK_LOG) << "Skipping screen switch due to visible transient window";
        // ...
    }
  3. 函数提取

    • 如果这个逻辑可能在多处使用,可以提取为单独的函数:
    bool DockHelper::hasVisibleTransientWindows() const {
        for (auto isShowing : m_transientChildShows) {
            if (isShowing) {
                return true;
            }
        }
        return false;
    }

总结

这段代码的功能是合理的,但在可读性、安全性和可维护性方面有改进空间。主要建议是:

  1. 改进变量命名
  2. 添加空指针检查
  3. 考虑性能优化(如果需要)
  4. 完善注释和日志
  5. 提取重复逻辑为单独函数

这些改进将使代码更健壮、更易维护。

@yixinshark yixinshark merged commit 8e950ef into linuxdeepin:master Feb 3, 2026
9 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.

3 participants