Skip to content

fix(xsettings): apply X11 scaling live - #148

Open
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:fix-x11-live-scaling
Open

fix(xsettings): apply X11 scaling live#148
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:fix-x11-live-scaling

Conversation

@mhduiy

@mhduiy mhduiy commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • refresh XSettings DPI values immediately after screen scale factors change
  • republish Xft/DPI even when its persisted value is unchanged
  • add focused tests for DPI persistence and publication

Verification

  • built plugin-dde-xsettings and tst-xftdpiupdate
  • tst-xftdpiupdate: 4 passed, 0 failed
  • X11 smoke test observed DevicePixelRatioChange from 2 to 1.98958

Summary by Sourcery

Ensure X11 Xft/DPI settings are updated and republished in response to screen scaling changes, and add targeted tests and build wiring for the new DPI update logic.

Bug Fixes:

  • Refresh XSettings DPI values when screen scale factors change and always publish the Xft/DPI setting to X11 even if its persisted value is unchanged.

Enhancements:

  • Introduce an XftDpiUpdate helper to encapsulate DPI persistence and publication logic.

Build:

  • Exclude test sources from the plugin build and wire in an optional tests subdirectory for the xsettings module.

Tests:

  • Add a Qt-based unit test binary and test cases to verify Xft/DPI persistence and republishing behavior.

1. Refresh DPI settings after screen scale factors change.
2. Republish Xft DPI even when the persisted value is unchanged.
3. Add tests for DPI persistence and XSettings publication.

Log: Apply X11 scale changes without restarting XSettings.
Influence: X11 applications receive scaling updates live.

fix(xsettings): 实时应用 X11 缩放

1. 屏幕缩放比例变化后立即刷新 DPI 设置。
2. 持久化数值未变化时仍重新发布 Xft DPI。
3. 添加 DPI 持久化和 XSettings 发布测试。

Log: X11 缩放变化无需重启 XSettings 即可生效。
Influence: X11 应用可以实时接收缩放变化。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @mhduiy, 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
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@sourcery-ai

sourcery-ai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Applies X11 Xft/DPI scaling updates immediately when screen scale factors change, refactors DPI update logic into a reusable helper, always republishes the Xft/DPI XSettings entry while persisting only when needed, and adds a focused QtTest-based unit test plus CMake wiring for it.

Sequence diagram for live Xft/DPI update on screen scale change

sequenceDiagram
    actor System
    participant XSettingsManager
    participant DConfig as m_settingDconfig
    participant XSettingsVector as xsSettngVec

    System->>XSettingsManager: setScreenScaleFactors(factors, emitSignal)
    XSettingsManager->>XSettingsManager: setScreenScaleFactorsForQt(factors)
    XSettingsManager->>XSettingsManager: updateDPI()
    XSettingsManager->>DConfig: value(dcKeyXftDpi)
    DConfig-->>XSettingsManager: tempXftDpi
    XSettingsManager->>XSettingsManager: makeXftDpiUpdate(tempXftDpi, scaledDpi)
    XSettingsManager-->>XSettingsManager: XftDpiUpdate update
    alt update.needsPersist
        XSettingsManager->>DConfig: setValue(dcKeyXftDpi, scaledDpi)
    end
    XSettingsManager->>XSettingsVector: push_back(update.setting)
Loading

File-Level Changes

Change Details Files
Refactor Xft/DPI update behavior into a helper that decides both persistence and XSettings publication.
  • Introduce XftDpiUpdate struct with needsPersist flag and XsSetting payload for Xft/DPI updates
  • Add makeXftDpiUpdate helper that compares stored vs scaled DPI and constructs the XSettings entry
  • Update SPDX-FileCopyrightText year range in common header
src/plugin-qt/xsettings/modules/common/common.h
Ensure DPI is recomputed and XSettings updated immediately after screen scale factor changes.
  • Call updateDPI() at the end of setScreenScaleFactors to apply scaling live
  • Use makeXftDpiUpdate in updateDPI() to decide whether to persist the new DPI value to config
  • Always push the Xft/DPI setting into the xsSettngVec, even when the stored DPI value does not change
src/plugin-qt/xsettings/impl/xsettingsmanager.cpp
Integrate unit tests into the xsettings plugin build, excluding test sources from the main target.
  • Exclude test sources from the plugin-dde-xsettings SRCS list using list(FILTER ... EXCLUDE REGEX "/tests/")
  • Conditionally add the tests subdirectory when BUILD_TESTING is enabled
  • Update SPDX-FileCopyrightText year range in the xsettings CMakeLists
src/plugin-qt/xsettings/CMakeLists.txt
Add a QtTest-based unit test verifying Xft/DPI persistence rules and publication behavior, and hook it into CTest.
  • Implement XftDpiUpdateTest with tests for persisting changed DPI values and republishing unchanged ones
  • Verify XsSetting properties (prop, type, integer value) for Xft/DPI in both test cases
  • Add a tests CMakeLists to build tst-xftdpiupdate, link against Qt6::Core and Qt6::Test, and register it as a CTest
src/plugin-qt/xsettings/tests/tst_xftdpiupdate.cpp
src/plugin-qt/xsettings/tests/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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了屏幕缩放比例修改时未更新DPI及未重新发布设置的问题,重构逻辑清晰并补充了单元测试
逻辑正确且提升了代码可维护性,因部分细节可进一步优化扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

xsettingsmanager.cppsetScreenScaleFactors 函数末尾补充了 updateDPI() 调用,修复了缩放比例变化时未更新DPI的缺陷。updateDPI 内部通过 makeXftDpiUpdate 统一处理 DPI 更新逻辑,确保即使值未改变也会推入 xsSettngVec 重新发布。common.h 中新增的结构体和内联函数语法正确,测试用例覆盖了值改变与未改变两种场景。
潜在问题:假设 XsSetting 结构体的成员定义顺序与 { HeadTypeInteger, QStringLiteral("Xft/DPI"), scaledDpi } 初始化列表完全一致,若未来成员顺序调整可能导致隐蔽的逻辑错误。
建议:考虑在 XsSetting 结构体中使用指定初始化器(C++20)或显式构造函数,以增强初始化的健壮性。

  • 2.代码质量(良好)✓

提取了 makeXftDpiUpdate 辅助函数,消除了 updateDPI 中的重复代码,提升了可读性。新增的单元测试验证了核心逻辑,CMakeLists 配置合理排除了测试源文件并支持条件编译。
潜在问题:无。
建议:无。

  • 3.代码性能(无性能问题)✓

新增的内联函数和向量推入操作开销极小,不影响原有性能表现。
潜在问题:无。
建议:无。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅涉及本地配置更新和内存数据结构操作,无外部输入处理,不存在安全风险。

  • 建议:无需修复。

■ 【改进建议代码示例】

// common.h 中建议使用更安全的初始化方式(若支持C++20)
inline XftDpiUpdate makeXftDpiUpdate(int storedDpi, int scaledDpi)
{
    return {
        storedDpi != scaledDpi,
        XsSetting{ HeadTypeInteger, QStringLiteral("Xft/DPI"), scaledDpi },
    };
}

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.40
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #154

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.41
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #155

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.

2 participants