Skip to content

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

Open
electricface wants to merge 1 commit intolinuxdeepin:masterfrom
electricface:swt/fix-bug335169-way4
Open

fix: fix font not updating in windowed launcher popup on system font change#1483
electricface wants to merge 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

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@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 from 573168c to 79c38ee Compare March 8, 2026 05:54
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 79c38ee to 0e7df7e Compare March 8, 2026 05:55
@deepin-ci-robot
Copy link

deepin pr auto review

这份 Git diff 展示了对 PopupWindow 类及其相关构建文件的修改,主要是将基类从 QQuickWindowQmlImpl 更改为 QQuickApplicationWindow,并更新了版权年份。以下是对语法逻辑、代码质量、代码性能和代码安全的详细审查意见:

1. 语法逻辑

  • 基类变更的合理性

    • 审查:代码将 PopupWindow 的基类从 QQuickWindowQmlImpl(Qt Quick 模块内部类)修改为 QQuickApplicationWindow(Qt Quick Templates 模块的公共 API)。
    • 意见:这是一个积极的改进QQuickWindowQmlImpl 是 Qt 内部实现细节(位于 private 头文件中),直接使用它会导致代码在 Qt 版本升级时非常脆弱。QQuickApplicationWindow 是 Qt Quick Templates 2 提供的标准基类,专门用于应用窗口,提供了更稳定的 API 和更多功能(如菜单、工具栏等)。
    • 注意QQuickApplicationWindow 继承自 QQuickWindow,而原来的 QQuickWindowQmlImpl 也继承自 QQuickWindow。这确保了基本的窗口功能(如 setMinimumSize)依然有效。
  • CMakeLists.txt 依赖更新

    • 审查:在主 CMakeLists.txt 中添加了 QuickTemplates2,在 frame/CMakeLists.txt 中添加了 Qt${QT_VERSION_MAJOR}::QuickTemplates2Private
    • 意见:这是必要的。QQuickApplicationWindow 属于 Qt Quick Templates 2 模块,因此必须链接该模块。
    • 潜在风险:在 frame/CMakeLists.txt 中链接了 QuickTemplates2Private。虽然代码中引入了 qquickapplicationwindow_p.h(私有头文件),但通常情况下,如果仅仅使用 QQuickApplicationWindow 作为基类,公共头文件 #include <QQuickApplicationWindow> 就足够了。如果代码中确实需要访问私有成员(d_func),那么链接 Private 库是正确的;否则,应尽量避免链接 Private 库以减少对内部 API 的依赖。鉴于头文件变更包含 _p.h,假设这是有意为之。
  • 版权年份更新

    • 审查:将版权年份从 2023/2024 更新为 2023-2026。
    • 意见:格式规范,符合开源项目维护惯例。

2. 代码质量

  • API 稳定性:如前所述,从内部类迁移到公共 API 类显著提高了代码的可维护性和兼容性,这是代码质量的一大提升。
  • 代码一致性:所有对父类方法(如 mousePressEvent)的调用都已正确更新为新的基类名称,保证了逻辑的一致性。
  • 字体设置
    • 审查:在 PanelPopupWindow.qml 中添加了 font.familyfont.pixelSize 设置。
    • 意见:这有助于统一 UI 风格。但需确认 D.DTK.fontManager.t6 是否在所有环境下都有效,以及这是否是全局样式的最佳位置。如果这是一个通用的 PopupWindow,硬编码字体可能会影响其作为通用组件的复用性。建议确认是否所有使用此组件的地方都需要这种特定字体。

3. 代码性能

  • 性能影响QQuickApplicationWindow 相比 QQuickWindowQmlImpl 可能包含更多的逻辑(如布局管理、附加属性等)。虽然对于单个窗口来说这种开销通常可以忽略不计,但在极端性能敏感的场景下(例如大量创建销毁窗口),需要留意是否有轻微的初始化开销。但在常规 GUI 应用中,这通常不是问题。

4. 代码安全

  • 私有头文件依赖
    • 风险:在 popupwindow.h 中引入了 #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>。虽然基类改为了公共类,但直接包含私有头文件(_p.h)仍然存在风险。这通常意味着代码可能访问了 QQuickApplicationWindow 的私有成员。
    • 建议
      1. 检查 popupwindow.cpppopupwindow.h 中是否真的使用了 QQuickApplicationWindow 的私有成员(例如 Q_D 宏)。
      2. 如果没有使用私有成员,强烈建议将头文件改为公共头文件 #include <QQuickApplicationWindow>,并移除 CMake 中对 QuickTemplates2Private 的依赖。这能进一步提高代码的稳定性和安全性。
      3. 如果必须使用私有成员,请确保代码中有相应的版本检查(如 #if QT_VERSION >= ...),因为 Qt 的私有 API 在不同版本间变化剧烈。

总结与改进建议

这次修改的主要方向是正确的,将依赖从不稳定的内部 API 迁移到了稳定的公共 API。

主要改进建议:

  1. 移除私有头文件依赖(关键)
    请检查是否真的需要 qquickapplicationwindow_p.h。如果不需要访问私有成员,请修改 popupwindow.h

    // 修改前
    #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
    
    // 修改后建议
    #include <QQuickApplicationWindow>

    同时修改 frame/CMakeLists.txt,移除 Qt${QT_VERSION_MAJOR}::QuickTemplates2Private,只保留公共的 Qt${QT_VERSION_MAJOR}::QuickTemplates2

  2. QML 字体设置
    审查 PanelPopupWindow.qml 中硬编码的字体设置是否适用于所有场景,或者是否应该由具体的使用者(父组件)来决定字体样式。

  3. 测试覆盖
    由于基类发生了变化,建议重点测试以下功能:

    • 窗口的焦点处理(QQuickApplicationWindow 有不同的焦点行为)。
    • 鼠标事件的传递(mousePressEvent 等)。
    • Wayland 协议下的窗口行为(代码中提到了 Wayland 相关的 flags)。

总体而言,除了对私有头文件的依赖需要进一步确认和清理外,这是一次高质量的代码重构。

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.

这个符号可能没导出吧,

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