Skip to content

fix: correct default scale factor initialization - #50

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:scale
Dec 29, 2025
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:scale

Conversation

@mhduiy

@mhduiy mhduiy commented Dec 29, 2025 •

Copy link
Copy Markdown
Contributor

When the scale-factor setting from dconfig is invalid (<= 0), the code incorrectly used the invalid value to populate the "ALL" key in the ScaleFactors map. This would propagate an invalid scale factor (likely 0 or negative) to the system. The fix ensures that when no valid scale factor is configured, the recommendedScaleFactor parameter is used as the default value for all screens, providing a sensible fallback.

Log: Fixed an issue where an invalid display scale factor setting could cause incorrect scaling.

Influence:

  1. Test display scaling when dconfig scale-factor is set to 0 or a negative value.
  2. Verify that the recommended scale factor is applied correctly in such cases.
  3. Ensure overall display scaling behavior remains consistent for valid settings.

fix: 修正默认缩放因子初始化错误

当从 dconfig 读取的 scale-factor 设置无效(<= 0)时,代码错误地使用了
该无效值来填充 ScaleFactors 映射中的 "ALL" 键。这会导致将无效的缩放因子
(可能为 0 或负数)传播到系统。此修复确保当没有配置有效的缩放因子时,使
用 recommendedScaleFactor 参数作为所有屏幕的默认值,提供了一个合理的回退
方案。

Log: 修复了无效的显示缩放因子设置可能导致缩放不正确的问题。

Influence:

  1. 测试当 dconfig 的 scale-factor 设置为 0 或负值时的显示缩放。
  2. 验证在此类情况下,推荐的缩放因子被正确应用。
  3. 确保对于有效的设置,整体显示缩放行为保持一致。

PMS: BUG-345701

Summary by Sourcery

Bug Fixes:

  • Prevent invalid (non-positive) configured scale-factor values from being propagated as the default scale factor by falling back to the recommended scale factor.

When the scale-factor setting from dconfig is invalid (<= 0), the code
incorrectly used the invalid value to populate the "ALL" key in the
ScaleFactors map. This would propagate an invalid scale factor (likely
0 or negative) to the system. The fix ensures that when no valid scale
factor is configured, the recommendedScaleFactor parameter is used as
the default value for all screens, providing a sensible fallback.

Log: Fixed an issue where an invalid display scale factor setting could
cause incorrect scaling.

Influence:
1. Test display scaling when dconfig scale-factor is set to 0 or a
negative value.
2. Verify that the recommended scale factor is applied correctly in
such cases.
3. Ensure overall display scaling behavior remains consistent for valid
settings.

fix: 修正默认缩放因子初始化错误

当从 dconfig 读取的 scale-factor 设置无效(<= 0)时,代码错误地使用了
该无效值来填充 ScaleFactors 映射中的 "ALL" 键。这会导致将无效的缩放因子
(可能为 0 或负数)传播到系统。此修复确保当没有配置有效的缩放因子时,使
用 recommendedScaleFactor 参数作为所有屏幕的默认值,提供了一个合理的回退
方案。

Log: 修复了无效的显示缩放因子设置可能导致缩放不正确的问题。

Influence:
1. 测试当 dconfig 的 scale-factor 设置为 0 或负值时的显示缩放。
2. 验证在此类情况下,推荐的缩放因子被正确应用。
3. 确保对于有效的设置,整体显示缩放行为保持一致。

PMS: BUG-345701
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来对这个代码修改进行审查:

  1. 语法逻辑:
    修改前的代码存在一个逻辑错误:当value <= 0时,将value(此时为无效值<=0)插入到map中,这显然是不合理的。修改后使用recommendedScaleFactor作为默认值是正确的,因为recommendedScaleFactor应该是一个有效的推荐缩放值。

  2. 代码质量:

  • 代码修改解决了原有的逻辑问题,提高了代码的可靠性。
  • 变量命名清晰,"recommendedScaleFactor"和"value"的命名都很好地表达了其用途。
  • 代码结构清晰,逻辑判断和处理步骤明确。
  1. 代码性能:
  • 这个修改不会对性能产生显著影响,只是改变了插入map的值。
  • 建议可以考虑在value <= 0的情况下直接使用recommendedScaleFactor,避免不必要的value获取。
  1. 代码安全:
  • 修改后的代码更安全,避免了将无效的缩放值(<=0)设置到系统中。
  • 建议可以添加对recommendedScaleFactor的有效性检查,确保它也是一个合理的正值。

改进建议:

  1. 可以考虑添加对recommendedScaleFactor的有效性检查:
if (value <= 0 && recommendedScaleFactor > 0) {
    ScaleFactors map;
    map.insert("ALL", recommendedScaleFactor);
    setScreenScaleFactors(map, false);
}
  1. 如果可能,建议将"ALL"定义为常量字符串,避免魔法字符串:
const QString ALL_SCREENS = "ALL";
// ...
map.insert(ALL_SCREENS, recommendedScaleFactor);
  1. 考虑添加日志记录,便于调试和追踪:
qDebug() << "Setting scale factor for all screens to:" << recommendedScaleFactor;

总体来说,这个修改是必要的,它修复了一个可能导致系统使用无效缩放值的bug。修改后的代码更加合理和安全。

@sourcery-ai

sourcery-ai Bot commented Dec 29, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes default display scale factor initialization so that when an invalid dconfig scale-factor (<= 0) is read, the system falls back to the recommendedScaleFactor for all screens instead of propagating the invalid value.

Sequence diagram for fallback to recommended scale factor on invalid dconfig value

sequenceDiagram
    participant XSettingsManager
    participant DConfig
    participant DisplaySystem

    XSettingsManager->>DConfig: read_scale_factor
    DConfig-->>XSettingsManager: value
    XSettingsManager->>XSettingsManager: adjustScaleFactor recommendedScaleFactor
    alt value <= 0
        XSettingsManager->>XSettingsManager: set ALL scale factor = recommendedScaleFactor
        XSettingsManager->>DisplaySystem: setScreenScaleFactors map false
    else value > 0
        XSettingsManager->>XSettingsManager: use configured scale factor
        XSettingsManager->>DisplaySystem: apply configured scale factors
    end
Loading

Flow diagram for scale factor initialization logic

flowchart TD
    A[Read scale factor from dconfig] --> B{value <= 0}
    B -->|Yes| C[Create ScaleFactors map]
    C --> D[Insert ALL with recommendedScaleFactor]
    D --> E[Call setScreenScaleFactors map false]
    B -->|No| F[Use existing valid scale factor handling]
Loading

File-Level Changes

Change Details Files
Use recommendedScaleFactor as the default scale factor when dconfig scale-factor is invalid (<= 0).
  • Read scale-factor from dconfig and check if the value is less than or equal to zero.
  • When the value is invalid, construct a ScaleFactors map with the "ALL" key set to recommendedScaleFactor instead of the invalid value.
  • Call setScreenScaleFactors with the corrected map to ensure a sensible fallback scale factor is applied.
src/plugin-qt/xsettings/impl/xsettingsmanager.cpp

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

@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.

Hey - I've reviewed your changes and they look great!


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.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@mhduiy

mhduiy commented Dec 29, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Dec 29, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit ca8424c into linuxdeepin:master Dec 29, 2025
7 of 8 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