Skip to content

feat: rewrite PopupHandle for Qt6 with Window popupType support#615

Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:popupwindow
Apr 28, 2026
Merged

feat: rewrite PopupHandle for Qt6 with Window popupType support#615
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:popupwindow

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

  1. Rewrite DPopupWindowHandle to work natively with Qt6
  2. Support Popup.Window popupType with window decorations (radius, border, shadow, blur)
  3. Implement screen edge avoidance for popup windows
  4. Add close-on-focus-loss behavior through event filters
  5. Simplify architecture: remove DPopupWindowHandleImpl and DVtableHook usage
  6. Remove global PopupMode enum and forceWindowMode property
  7. Update DQuickWindowAttached to support QQuickPopup objects

Log: Rewrite PopupHandle to support popupType Window mode in Qt6

Influence:

  1. Test Popup with popupType: Window – verify window decorations (radius, border, shadow, blur)
  2. Test screen edge avoidance: open popups near screen edges and verify positioning
  3. Test close-on-click-outside: click outside popup and verify it closes
  4. Test close-on-focus-loss: switch to other window and verify popup closes
  5. Test nested popups (submenus) – verify correct screen assignment and flipping behavior
  6. Test window properties: windowRadius, borderWidth, borderColor, shadowRadius, shadowOffset, shadowColor
  7. Test translucentBackground and enableBlurWindow properties
  8. Test menu popup behavior – ensure no regressions in Menu popup
  9. Test with different screen configurations (multiple monitors, different DPI)
  10. Verify no crash when popup is destroyed

feat: 重写PopupHandle以支持Qt6的Window模式

  1. 重写DPopupWindowHandle以原生支持Qt6
  2. 支持Popup.Window弹窗类型,添加窗口装饰(圆角、边框、阴影、模糊)
  3. 实现弹窗窗口的屏幕边缘避让
  4. 通过事件过滤器实现失去焦点自动关闭
  5. 简化架构:移除DPopupWindowHandleImpl和DVtableHook的使用
  6. 移除全局PopupMode枚举和forceWindowMode属性
  7. 更新DQuickWindowAttached以支持QQuickPopup对象

Log: 重写PopupHandle支持popupType为Window模式

Influence:

  1. 测试Popup的popupType: Window模式 – 验证窗口装饰(圆角、边框、阴影、 模糊)
  2. 测试屏幕边缘避让:在屏幕边缘打开弹窗,验证位置调整
  3. 测试点击外部关闭:点击弹窗外区域,验证弹窗关闭
  4. 测试失去焦点关闭:切换到其他窗口,验证弹窗关闭
  5. 测试嵌套弹窗(子菜单)– 验证正确的屏幕分配和翻转行为
  6. 测试窗口属性:windowRadius、borderWidth、borderColor、shadowRadius、 shadowOffset、shadowColor
  7. 测试translucentBackground和enableBlurWindow属性
  8. 测试菜单弹窗行为 – 确保菜单弹窗没有回归问题
  9. 测试不同屏幕配置(多显示器、不同DPI)
  10. 验证弹窗销毁时不会崩溃

Copy link
Copy Markdown

@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

Comment thread examples/qml-inspect/Example_Popup.qml
1. Rewrite DPopupWindowHandle to work natively with Qt6
2. Support Popup.Window popupType with window decorations (radius,
border, shadow, blur)
3. Implement screen edge avoidance for popup windows
4. Add close-on-focus-loss behavior through event filters
5. Simplify architecture: remove DPopupWindowHandleImpl and DVtableHook
usage
6. Remove global PopupMode enum and forceWindowMode property
7. Update DQuickWindowAttached to support QQuickPopup objects

Log: Rewrite PopupHandle to support popupType Window mode in Qt6

Influence:
1. Test Popup with popupType: Window – verify window decorations
(radius, border, shadow, blur)
2. Test screen edge avoidance: open popups near screen edges and verify
positioning
3. Test close-on-click-outside: click outside popup and verify it closes
4. Test close-on-focus-loss: switch to other window and verify popup
closes
5. Test nested popups (submenus) – verify correct screen assignment and
flipping behavior
6. Test window properties: windowRadius, borderWidth, borderColor,
shadowRadius, shadowOffset, shadowColor
7. Test translucentBackground and enableBlurWindow properties
8. Test menu popup behavior – ensure no regressions in Menu popup
9. Test with different screen configurations (multiple monitors,
different DPI)
10. Verify no crash when popup is destroyed

feat: 重写PopupHandle以支持Qt6的Window模式

1. 重写DPopupWindowHandle以原生支持Qt6
2. 支持Popup.Window弹窗类型,添加窗口装饰(圆角、边框、阴影、模糊)
3. 实现弹窗窗口的屏幕边缘避让
4. 通过事件过滤器实现失去焦点自动关闭
5. 简化架构:移除DPopupWindowHandleImpl和DVtableHook的使用
6. 移除全局PopupMode枚举和forceWindowMode属性
7. 更新DQuickWindowAttached以支持QQuickPopup对象

Log: 重写PopupHandle支持popupType为Window模式

Influence:
1. 测试Popup的popupType: Window模式 – 验证窗口装饰(圆角、边框、阴影、
模糊)
2. 测试屏幕边缘避让:在屏幕边缘打开弹窗,验证位置调整
3. 测试点击外部关闭:点击弹窗外区域,验证弹窗关闭
4. 测试失去焦点关闭:切换到其他窗口,验证弹窗关闭
5. 测试嵌套弹窗(子菜单)– 验证正确的屏幕分配和翻转行为
6. 测试窗口属性:windowRadius、borderWidth、borderColor、shadowRadius、
shadowOffset、shadowColor
7. 测试translucentBackground和enableBlurWindow属性
8. 测试菜单弹窗行为 – 确保菜单弹窗没有回归问题
9. 测试不同屏幕配置(多显示器、不同DPI)
10. 验证弹窗销毁时不会崩溃
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

deepin pr auto review

Git Diff 代码审查报告

总体评价

这个 diff 主要对 DTK (Deepin Tool Kit) 的 Popup 窗口处理机制进行了重大重构,从自定义的 DPopupWindowHandle 实现转向使用 Qt 6 原生的 Popup.Window 类型。改动涉及 QML 文件、C++ 源代码和构建系统。整体上,这次改动是向 Qt 6 原生能力靠拢,减少了自定义实现,提高了代码可维护性,但也有一些需要注意的地方。

详细审查

1. 语法与逻辑

优点

  • 代码语法正确,符合 Qt/QML 和 C++ 的规范
  • 逻辑流程清晰,从旧的自定义实现平滑过渡到 Qt 6 原生实现
  • 事件处理逻辑正确,特别是 DPopupWindowHandle::eventFilter 中的事件处理

改进建议

  1. dpopupwindowhandle.cpp 中,adjustPopupPosition() 函数较长,可以考虑拆分为更小的函数:

    void DPopupWindowHandle::adjustPopupPosition()
    {
        if (!isEnabled() || !m_popupWin)
            return;
        
        const QSize size = m_popupWin->size();
        if (size.width() <= 0 || size.height() <= 0)
            return;
        
        QScreen *screen = determineScreen();
        if (!screen)
            return;
        
        QRectF rect(QPointF(m_popupWin->position()), QSizeF(size));
        adjustHorizontalPosition(rect, screen);
        adjustVerticalPosition(rect, screen);
        
        const QPoint newPos = rect.topLeft().toPoint();
        if (newPos != m_popupWin->position())
            m_popupWin->setPosition(newPos);
    }
  2. dquickwindow.cpp 中,setWindow() 函数中的 explicitEnable == True 应该是 explicitEnable == true(小写):

    if (explicitEnable == true) {
        ensurePlatformHandle();
    }

2. 代码质量

优点

  • 代码结构清晰,职责分离良好
  • 使用了现代 C++ 特性(如 QPointer)
  • 注释充分,特别是 adjustPopupPosition() 函数中的注释

改进建议

  1. dpopupwindowhandle.cpp 中,isPopupWindowisPopupItem 函数使用了 inherits 字符串比较,可以考虑使用更类型安全的方式:

    static bool isPopupWindow(QWindow *window)
    {
        return window && qobject_cast<QQuickPopupWindow*>(window);
    }
    
    static bool isPopupItem(QQuickItem *item)
    {
        return item && item->inherits("QQuickPopupItem");
    }
  2. dpopupwindowhandle_p.h 中,DPopupWindowHandle 类同时继承 QObjectQQuickItemChangeListener,但 QQuickItemChangeListener 是一个接口类,建议使用 Q_INTERFACES 宏:

    class DPopupWindowHandle : public QObject, public QQuickItemChangeListener
    {
        Q_OBJECT
        Q_INTERFACES(QQuickItemChangeListener)
        // ...
    };

3. 代码性能

优点

  • 使用了 QPointer 防止悬空指针
  • 事件过滤器中只处理必要的事件类型
  • 屏幕选择逻辑优化,避免不必要的计算

改进建议

  1. adjustPopupPosition() 函数中,可以考虑缓存屏幕边界信息,避免每次调用都重新计算:

    void DPopupWindowHandle::adjustPopupPosition()
    {
        // ...
        
        static QScreen* lastScreen = nullptr;
        static QRectF lastScreenBounds;
        
        QScreen *screen = determineScreen();
        if (screen != lastScreen) {
            lastScreen = screen;
            lastScreenBounds = screen->availableGeometry();
        }
        
        const QRectF bounds(lastScreenBounds);
        // ...
    }
  2. popupItem() 函数中,每次都遍历子项查找 PopupItem,可以考虑缓存结果:

    QQuickItem *DPopupWindowHandle::popupItem() const
    {
        if (!m_popup)
            return nullptr;
        
        if (m_cachedPopupItem)
            return m_cachedPopupItem;
        
        const auto children = m_popup->findChildren<QQuickItem *>(Qt::FindDirectChildrenOnly);
        auto it = std::find_if(children.begin(), children.end(), isPopupItem);
        if (it != children.end())
            m_cachedPopupItem = *it;
        
        return m_cachedPopupItem;
    }

4. 代码安全

优点

  • 使用了 QPointer 防止悬空指针
  • 在访问对象前进行了有效性检查
  • 事件过滤器中正确处理了事件

改进建议

  1. dpopupwindowhandle.cpp 中,updateEnabled() 函数中直接使用 popupTypeVar.toInt() == 1 比较可能不安全,建议使用枚举比较:

    void DPopupWindowHandle::updateEnabled()
    {
        if (!m_popup || !m_attached)
            return;
        
        QVariant popupTypeVar = m_popup->property("popupType");
        bool shouldEnable = popupTypeVar.isValid() && 
                           static_cast<QQuickPopup::PopupType>(popupTypeVar.toInt()) == QQuickPopup::Window;
        if (shouldEnable == m_enabled)
            return;
        m_enabled = shouldEnable;
        m_attached->setEnabled(shouldEnable);
    }
  2. dquickwindow.cpp 中,ensurePlatformHandle() 函数中添加了对 window 的空指针检查,但应该更早返回:

    bool DQuickWindowAttachedPrivate::ensurePlatformHandle()
    {
        if (handle)
            return true;
    
        if (!window) {
            qWarning() << "No window available for platform handle";
            return false;
        }
    
        if (!DPlatformHandle::setEnabledNoTitlebarForWindow(window, true)) {
            qWarning() << "Failed to enable NoTitlebar for the window:"  << window;
            return false;
        }
    
        // ...
    }
  3. eventFilter 中,应该检查事件是否被接受或忽略:

    bool DPopupWindowHandle::eventFilter(QObject *watched, QEvent *event)
    {
        if (watched == m_popupWin && event->type() == QEvent::Move) {
            adjustPopupPosition();
            return true; // 事件已处理
        }
    
        // ...
    
        return QObject::eventFilter(watched, event);
    }

其他建议

  1. 考虑添加单元测试,特别是针对 adjustPopupPosition() 函数的边界情况
  2. 在文档中记录新的 Popup.Window 模式与旧实现的差异
  3. 考虑添加迁移指南,帮助开发者从旧实现过渡到新实现

总结

这次改动总体上是积极的,它将 DTK 的 Popup 实现与 Qt 6 的原生能力对齐,减少了自定义代码,提高了可维护性。主要的改进点集中在代码结构优化、性能提升和安全性增强方面。建议在合并前进行充分的测试,特别是多显示器场景下的 Popup 行为。

@18202781743 18202781743 merged commit 4921481 into linuxdeepin:master Apr 28, 2026
20 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