Skip to content

fix: font not updating in windowed launcher popup on system font change#1483

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
electricface:swt/fix-bug335169-way4
Mar 9, 2026
Merged

fix: font not updating in windowed launcher popup on system font change#1483
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
electricface:swt/fix-bug335169-way4

Conversation

@electricface
Copy link
Member

@electricface electricface commented Mar 6, 2026

Rebase PopupWindow on QQuickApplicationWindow instead of
QQuickWindowQmlImpl so that all QQuickControl descendants (including
dynamically created context menus) participate in Qt's standard
font inheritance chain.
Previously, QQuickControlPrivate::resolveFont() fell back to
QGuiApplication::font() for controls inside PopupWindow because
the window was not recognized as a QQuickApplicationWindow.
This meant controls created after a font change (e.g. AppItemMenu
opened via right-click) always got the stale QGuiApplication font
rather than DTK's custom font size.

Log: Fix windowed launcher popup menu font not updating when system font size is changed
PMS: BUG-335169

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 6, 2026

Reviewer's Guide

Adds font propagation support to PopupWindow so that popup-based UIs (panel popups, menus, tooltips) inherit and dynamically react to system font changes, wiring this through a new font Q_PROPERTY and using Qt Quick Templates2 private APIs, plus the necessary build-system updates and QML bindings.

Sequence diagram for font change propagation to popup controls

sequenceDiagram
    participant User
    participant SystemSettings
    participant DDTKFontManager as DDTK_fontManager
    participant PanelPopupQML as PanelPopupWindow_qml
    participant PopupWindow
    participant ContentItem as QQuickItem_contentItem
    participant QQuickControlPrivate

    User->>SystemSettings: changeFontSize(newSize)
    SystemSettings-->>DDTKFontManager: update t6.font(newSize)
    DDTKFontManager-->>PanelPopupQML: t6.family, t6.pixelSize changed
    PanelPopupQML-->>PopupWindow: update font.family, font.pixelSize via binding
    PopupWindow->>PopupWindow: setFont(QFont from QML)
    PopupWindow->>PopupWindow: resolve with QGuiApplication::font()
    PopupWindow->>PopupWindow: propagateFontToContentItem(m_font)
    PopupWindow->>ContentItem: contentItem()
    PopupWindow->>QQuickControlPrivate: updateFontRecur(contentItem, m_font)
    QQuickControlPrivate-->>ContentItem: applyFontToControlsRecursively(m_font)
    ContentItem-->>User: popup menu re-rendered with new font size
Loading

Class diagram for updated PopupWindow font propagation

classDiagram
    class QQuickWindowQmlImpl

    class PopupWindow {
        <<QML_NAMED_ELEMENT_PopupWindow>>
        +PopupWindow(parent: QWindow*)
        +QFont font() const
        +void setFont(font: QFont const&)
        +void resetFont()
        +void mouseReleaseEvent(event: QMouseEvent*)
        +void mousePressEvent(event: QMouseEvent*)
        +void mouseMoveEvent(event: QMouseEvent*)
        +void fontChanged()
        -void propagateFontToContentItem(font: QFont const&)
        -bool m_dragging
        -bool m_pressing
        -QFont m_font
        -bool m_hasExplicitFont
    }

    PopupWindow --|> QQuickWindowQmlImpl
Loading

Architecture/flow diagram for font propagation across components

flowchart LR
    SystemFonts["System font settings"] --> DDTKFontManager["D.DTK.fontManager.t6"]
    DDTKFontManager --> PanelPopupWindowQML["PanelPopupWindow_qml<br/>font.family,font.pixelSize bindings"]
    PanelPopupWindowQML --> PopupWindow["PopupWindow<br/>Q_PROPERTY font"]
    PopupWindow --> QQuickItemContentItem["QQuickItem contentItem()"]
    QQuickItemContentItem --> QQuickControlPrivate["QQuickControlPrivate::updateFontRecur"]
    QQuickControlPrivate --> PopupControls["QQuickControl descendants<br/>(menus, tooltips, panels)"]

    User["User"] --> SystemFonts
    PopupControls --> User
Loading

File-Level Changes

Change Details Files
Add a font Q_PROPERTY to PopupWindow and propagate its value to all QQuickControl descendants so popup content follows system font changes.
  • Introduce a QFont-backed font Q_PROPERTY on PopupWindow with getter, setter, resetter, and fontChanged signal.
  • Track explicit font vs default state via m_hasExplicitFont and resolve the assigned font against QGuiApplication::font() to avoid redundant updates.
  • Implement propagateFontToContentItem() that calls QQuickControlPrivate::updateFontRecur() starting from the window contentItem().
  • Include QQuickItem and qquickcontrol_p_p headers to support font propagation logic.
frame/popupwindow.h
frame/popupwindow.cpp
Bind PanelPopupWindow’s font to the global DTK font manager and wire up Qt Quick Templates2 private linkage in the build system.
  • Bind PanelPopupWindow.font.family and font.pixelSize to D.DTK.fontManager.t6 so popup UIs respond dynamically to system font changes without per-applet overrides.
  • Add Qt QuickTemplates2 to the top-level Qt find_package call and link QtQuickTemplates2Private in frame/CMakeLists.txt to access QQuickControlPrivate APIs used by PopupWindow.
frame/qml/PanelPopupWindow.qml
CMakeLists.txt
frame/CMakeLists.txt

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

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.

Hey - I've left some high level feedback:

  • In resetFont() you reset to a default-constructed QFont, which breaks the symmetry with setFont() (which resolves against QGuiApplication::font()); consider resetting to QGuiApplication::font() (or clearing the resolve mask appropriately) so that reset restores the effective system font rather than an uninitialized default.
  • The m_hasExplicitFont flag is set but never read; either remove it to simplify the implementation or make use of it (for example to distinguish between explicit and inherited fonts when reacting to external font changes).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `resetFont()` you reset to a default-constructed `QFont`, which breaks the symmetry with `setFont()` (which resolves against `QGuiApplication::font()`); consider resetting to `QGuiApplication::font()` (or clearing the resolve mask appropriately) so that reset restores the effective system font rather than an uninitialized default.
- The `m_hasExplicitFont` flag is set but never read; either remove it to simplify the implementation or make use of it (for example to distinguish between explicit and inherited fonts when reacting to external font changes).

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.

@electricface electricface force-pushed the swt/fix-bug335169-way4 branch from d829f56 to 573168c Compare March 8, 2026 03:33
@electricface electricface changed the title fix(dock): Launcher popup menu in small window mode fails to update with system font size changes fix: fix font not updating in windowed launcher popup on system font change Mar 8, 2026
@electricface electricface force-pushed the swt/fix-bug335169-way4 branch 2 times, most recently from 79c38ee to 0e7df7e Compare March 8, 2026 05:55
DS_BEGIN_NAMESPACE
PopupWindow::PopupWindow(QWindow *parent)
: QQuickWindowQmlImpl(parent)
: QQuickApplicationWindow(parent)
Copy link
Contributor

Choose a reason for hiding this comment

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

这个符号可能没导出吧,

@electricface electricface force-pushed the swt/fix-bug335169-way4 branch from 0e7df7e to 3b008e3 Compare March 8, 2026 08:04
@electricface electricface changed the title fix: fix font not updating in windowed launcher popup on system font change fix: font not updating in windowed launcher popup on system font change Mar 8, 2026
@18202781743 18202781743 requested a review from Copilot March 9, 2026 02:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the launcher/panel popup window implementation to participate in Qt Quick Controls’ standard font inheritance chain, fixing stale fonts in dynamically created controls after a system font size change.

Changes:

  • Rebased PopupWindow from QQuickWindowQmlImpl to QQuickApplicationWindow.
  • Added explicit font settings to PanelPopupWindow.qml to align popup UI with DTK font settings.
  • Updated CMake dependencies to add Qt Quick Templates 2 support.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
frame/qml/PanelPopupWindow.qml Sets popup window font properties to DTK-managed font values.
frame/popupwindow.h Changes the window base class to QQuickApplicationWindow and updates includes.
frame/popupwindow.cpp Updates constructor/base calls and event handler base invocations accordingly.
frame/CMakeLists.txt Links against Qt Quick Templates 2 private target to support new base class/include.
CMakeLists.txt Adds QuickTemplates2 to the required Qt components.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to 12
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>

DS_BEGIN_NAMESPACE
class PopupWindow : public QQuickWindowQmlImpl
class PopupWindow : public QQuickApplicationWindow
{
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

PopupWindow is only using the public QQuickApplicationWindow type, but the header includes the private Qt header QtQuickTemplates2/private/qquickapplicationwindow_p.h. This unnecessarily pulls in Qt private APIs/headers and forces consumers/builds to have the corresponding private dev package. Prefer including the public header for QQuickApplicationWindow (and only using the private header if you actually need private symbols).

Copilot uses AI. Check for mistakes.
Comment on lines 95 to 103
target_link_libraries(dde-shell-frame
PUBLIC
Dtk${DTK_VERSION_MAJOR}::Core
Dtk${DTK_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::QuickTemplates2Private
PRIVATE
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Qt::QuickTemplates2Private is being added as a PUBLIC link dependency of dde-shell-frame. Since popupwindow.h is not part of PUBLIC_HEADERS, exporting a private Qt module through the public interface is likely unintended and can break downstream consumers at CMake configure time (private Qt targets often aren't available to consumers). Make this dependency PRIVATE and link the public Qt::QuickTemplates2 module as needed instead.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +72
font.family: D.DTK.fontManager.t6.family
font.pixelSize: D.DTK.fontManager.t6.pixelSize
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Only font.family and font.pixelSize are being set here, which can drop other attributes carried by DTK fonts (weight, style, letterSpacing, etc.) and makes the binding less consistent with other QML that assigns the whole DTK font (e.g. font: D.DTK.fontManager.t6). Consider binding the full font property to the DTK font instead of copying individual fields.

Suggested change
font.family: D.DTK.fontManager.t6.family
font.pixelSize: D.DTK.fontManager.t6.pixelSize
font: D.DTK.fontManager.t6

Copilot uses AI. Check for mistakes.
system font change

Rebase PopupWindow on QQuickApplicationWindow instead of
QQuickWindowQmlImpl so that all QQuickControl descendants (including
dynamically created context menus) participate in Qt's standard
font inheritance chain.
Previously, QQuickControlPrivate::resolveFont() fell back to
QGuiApplication::font() for controls inside PopupWindow because
the window was not recognized as a QQuickApplicationWindow.
This meant controls created after a font change (e.g. AppItemMenu
opened via right-click) always got the stale QGuiApplication font
rather than DTK's custom font size.

Log: Fix windowed launcher popup menu font not updating when system font size is changed
PMS: BUG-335169
@electricface electricface force-pushed the swt/fix-bug335169-way4 branch from 3b008e3 to 3f3f6d7 Compare March 9, 2026 02:38
@deepin-ci-robot
Copy link

deepin pr auto review

这份代码 diff 主要对项目中的 PopupWindow 类及其构建配置进行了重构,从使用 QQuickWindowQmlImpl 改为使用 QQuickApplicationWindow,并更新了相关的版权年份和依赖项。

以下是对语法逻辑、代码质量、代码性能和代码安全方面的详细审查意见:

1. 语法逻辑

  • 继承变更 (popupwindow.h/cpp):

    • 变更内容: PopupWindow 的基类从 QQuickWindowQmlImpl 变更为 QQuickApplicationWindow
    • 审查意见: 逻辑合理QQuickWindowQmlImpl 是 Qt Quick 模块的内部实现类(位于 private/qquickwindowmodule_p.h),通常不推荐在公共 API 中直接使用,因为它在不同 Qt 版本间可能发生变化。而 QQuickApplicationWindow 是 Qt Quick Templates 模块提供的标准公共类,专门用于应用程序窗口,更适合作为基类。
    • 依赖更新: 相应地,CMakeLists.txt 中添加了 Qt::QuickTemplates2Qt::QuickTemplates2Private 的依赖,这是必要的,因为 QQuickApplicationWindow 属于该模块。
  • 包含头文件 (popupwindow.h):

    • 变更内容: 从 #include <private/qquickwindowmodule_p.h> 改为 #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
    • 审查意见: 注意风险。虽然基类变成了公共类 QQuickApplicationWindow,但包含的头文件仍然是 _p.h(Private 头文件)。这通常意味着代码中可能访问了该类的私有 API(Private API)。如果代码仅仅是继承并使用公共接口,应包含公共头文件 <QQuickApplicationWindow>。如果必须使用私有 API(例如访问 d_func()),则目前的包含是正确的,但需注意私有 API 的兼容性风险。

2. 代码质量

  • 版权年份更新:

    • 变更内容: 将版权年份从 2023/2024 更新为 2023 - 2026
    • 审查意见: 良好。符合维护代码时的常规操作,表明维护周期的延长。
  • CMake 配置:

    • 变更内容: 在根目录和子目录的 CMakeLists.txt 中显式添加了 QuickTemplates2 依赖,并在链接库中添加了 Qt::QuickTemplates2Private
    • 审查意见: 良好。显式声明依赖有助于构建系统正确处理链接顺序和模块包含。
  • QML 属性设置 (PanelPopupWindow.qml):

    • 变更内容: 添加了 font: D.DTK.fontManager.t6
    • 审查意见: 良好。统一设置字体有助于保持 UI 的一致性。

3. 代码性能

  • 基类切换:
    • 审查意见: QQuickApplicationWindow 相比 QQuickWindowQmlImpl 提供了更多功能(如菜单栏、工具栏的支持),但这通常伴随着轻微的内存开销或初始化复杂度的增加。对于 PopupWindow 这种主要用于弹出菜单的场景,如果不需要 ApplicationWindow 的附加功能,理论上 QQuickWindow 可能更轻量。
    • 建议: 请确认 PopupWindow 是否真的需要 QQuickApplicationWindow 的特性(例如附加属性 contentItem 的特定行为或与 Qt Quick Controls 的集成)。如果只是为了替换不稳定的 QmlImpl,确保新基类不会引入不必要的重绘或布局计算。

4. 代码安全

  • 私有 API 的使用:
    • 审查意见: 高风险。在 frame/CMakeLists.txtframe/plugin/CMakeLists.txt 中链接了 Qt::QuickTemplates2Private。在 popupwindow.h 中包含了 private 头文件。
    • 建议: 使用私有 API 会使得代码高度依赖于特定版本的 Qt。Qt 的私有 API 在小版本更新(例如 6.5 -> 6.6)中就可能发生破坏性变更。
    • 改进建议:
      1. 严格审查 PopupWindow 的实现,确认是否真的需要访问 QQuickApplicationWindow 的私有成员。
      2. 如果不需要访问私有成员,请修改 popupwindow.h,删除 private 头文件包含,改为 #include <QQuickApplicationWindow>,并从 CMake 中移除 Qt::QuickTemplates2Private 依赖。
      3. 如果必须使用私有 API,建议在代码中增加编译时的 Qt 版本检查(#if QT_VERSION < ...),以防止在未来版本中因 API 变更导致编译失败或运行时崩溃。

总结与改进建议

  1. 头文件包含优化:
    检查 popupwindow.cpppopupwindow.h。如果 PopupWindow 类的实现中没有调用 Q_D 宏或访问 QQuickApplicationWindowPrivate 的成员,请将头文件改为公共头文件:

    // popupwindow.h
    // #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> // 删除此行
    #include <QQuickApplicationWindow> // 使用公共头文件

    并在 CMakeLists.txt 中移除 Qt::QuickTemplates2Private

  2. Wayland 兼容性:
    PopupWindow 构造函数中设置了 setMinimumSize(QSize(1, 1)) 以防止 Wayland 协议错误。基类的变更不应影响这一点,但建议在测试阶段重点测试 Wayland 环境下的弹窗行为,因为 QQuickApplicationWindow 的窗口类型处理逻辑可能与 QQuickWindowQmlImpl 有细微差别。

  3. 代码格式:
    frame/qml/PanelPopupWindow.qml 文件末尾缺少换行符(diff 显示 No newline at end of file)。虽然不影响功能,但建议添加换行符以符合大多数代码规范。

总体而言,这次改动将基类从内部实现类迁移到了标准的公共类,方向是正确的,有助于代码的长期维护。但需要警惕对 Private API 的依赖,尽量解耦以保证跨版本的兼容性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@electricface
Copy link
Member Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 9, 2026

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit c8ea867 into linuxdeepin:master Mar 9, 2026
11 of 12 checks passed
@electricface electricface deleted the swt/fix-bug335169-way4 branch March 9, 2026 03:06
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