Skip to content

fix: correct Xft/DPI property name in XSettings update - #40

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

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

Conversation

@mhduiy

@mhduiy mhduiy commented Dec 10, 2025 •

Copy link
Copy Markdown
Contributor
  1. Fixed incorrect property name used when updating Xft/DPI setting via D-Bus
  2. Changed property from internal DConfig key "xft.dpi" to actual XSettings property "Xft/DPI"
  3. Added missing QLoggingCategory include for proper logging functionality
  4. Added proper scaling calculation for DPI value before comparison

Log: Fixed incorrect XSettings property name when updating display DPI settings

Influence:

  1. Test display scaling changes to ensure DPI settings are properly applied
  2. Verify XSettings D-Bus interface receives correct property name "Xft/ DPI"
  3. Check that DConfig values are correctly synchronized with XSettings
  4. Test with different display scaling factors to ensure DPI calculation works correctly
  5. Verify that DPI changes are properly reflected in applications using XSettings

fix: 修正XSettings更新中Xft/DPI属性名称错误

  1. 修复通过D-Bus更新Xft/DPI设置时使用的错误属性名称
  2. 将属性从内部DConfig键"xft.dpi"更改为实际的XSettings属性"Xft/DPI"
  3. 添加缺失的QLoggingCategory包含以支持正确的日志功能
  4. 在比较前添加了DPI值的正确缩放计算

Log: 修复更新显示DPI设置时XSettings属性名称错误的问题

Influence:

  1. 测试显示缩放更改以确保DPI设置正确应用
  2. 验证XSettings D-Bus接口接收到正确的属性名称"Xft/DPI"
  3. 检查DConfig值是否正确与XSettings同步
  4. 使用不同的显示缩放因子测试以确保DPI计算正常工作
  5. 验证DPI更改是否正确反映在使用XSettings的应用程序中

pms: BUG-343127

Summary by Sourcery

Correct XSettings DPI updates and align them with the expected Xft/DPI property.

Bug Fixes:

  • Fix incorrect XSettings property name used when updating the Xft/DPI setting over D-Bus.
  • Correct DPI scaling calculation before comparing and syncing with stored configuration values.

Enhancements:

  • Include the missing QLoggingCategory header to enable proper categorized logging in the XSettings manager.

@sourcery-ai

sourcery-ai Bot commented Dec 10, 2025

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

Reviewer's Guide

Adjusts how DPI settings are synchronized between DConfig and XSettings by correcting the Xft/DPI property name used over D-Bus, ensuring proper scaling of the DPI value before persisting and broadcasting it, and enabling logging via QLoggingCategory.

Sequence diagram for updated DPI synchronization via XSettings

sequenceDiagram
    actor User
    participant DisplaySettingsUI
    participant XSettingsManager
    participant DConfig
    participant XSettingsDBus

    User->>DisplaySettingsUI: change display scale
    DisplaySettingsUI->>XSettingsManager: setScale(scale)
    XSettingsManager->>XSettingsManager: updateDPI()
    XSettingsManager->>DConfig: read dcKeyXftDpi
    DConfig-->>XSettingsManager: tempXftDpi
    XSettingsManager->>XSettingsManager: compute scaledDpi = (DPI_FALLBACK * 1024) * scale
    alt DPI changed
        XSettingsManager->>DConfig: setValue dcKeyXftDpi, scaledDpi
        XSettingsManager->>XSettingsManager: create XsSetting(prop = Xft/DPI, value = scaledDpi, type = HeadTypeInteger)
        XSettingsManager->>XSettingsDBus: update XSettings with prop Xft/DPI
        XSettingsDBus-->>Applications: broadcast updated XSettings
    else DPI unchanged
        XSettingsManager->>XSettingsManager: do nothing
    end
Loading

Updated class diagram for XSettingsManager DPI update logic

classDiagram
    class XSettingsManager {
        - DConfig* m_settingDconfig
        - int DPI_FALLBACK
        - double scale
        + updateDPI() void
    }

    class DConfig {
        + value(key QString) int
        + setValue(key QString, value int) void
    }

    class XsSetting {
        + QString prop
        + int value
        + int type
    }

    class QLoggingCategory {
        + QLoggingCategory(name const char*)
    }

    XSettingsManager --> DConfig : uses
    XSettingsManager --> XsSetting : creates
    XSettingsManager --> QLoggingCategory : logging
Loading

File-Level Changes

Change Details Files
Correct XSettings property name used when propagating DPI changes over D-Bus.
  • Replace use of the internal DConfig key as the XSettings property identifier with the actual XSettings property name
  • Ensure the XSettings update carries the value under "Xft/DPI" so XSettings-aware clients receive DPI updates correctly
src/plugin-qt/xsettings/impl/xsettingsmanager.cpp
Ensure scaled DPI value is computed before comparison and persisted consistently.
  • Compute scaled DPI using DPI_FALLBACK multiplied by 1024 and the current scale factor before comparing to stored value
  • Only update DConfig and XSettings when the newly computed scaled DPI differs from the stored DPI value
src/plugin-qt/xsettings/impl/xsettingsmanager.cpp
Enable categorized logging for the XSettings manager implementation.
  • Add missing QLoggingCategory include so any logging in this translation unit compiles and works correctly
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

1. Fixed incorrect property name used when updating Xft/DPI setting via
D-Bus
2. Changed property from internal DConfig key "xft.dpi" to actual
XSettings property "Xft/DPI"
3. Added missing QLoggingCategory include for proper logging
functionality
4. Added proper scaling calculation for DPI value before comparison

Log: Fixed incorrect XSettings property name when updating display DPI
settings

Influence:
1. Test display scaling changes to ensure DPI settings are properly
applied
2. Verify XSettings D-Bus interface receives correct property name "Xft/
DPI"
3. Check that DConfig values are correctly synchronized with XSettings
4. Test with different display scaling factors to ensure DPI calculation
works correctly
5. Verify that DPI changes are properly reflected in applications using
XSettings

fix: 修正XSettings更新中Xft/DPI属性名称错误

1. 修复通过D-Bus更新Xft/DPI设置时使用的错误属性名称
2. 将属性从内部DConfig键"xft.dpi"更改为实际的XSettings属性"Xft/DPI"
3. 添加缺失的QLoggingCategory包含以支持正确的日志功能
4. 在比较前添加了DPI值的正确缩放计算

Log: 修复更新显示DPI设置时XSettings属性名称错误的问题

Influence:
1. 测试显示缩放更改以确保DPI设置正确应用
2. 验证XSettings D-Bus接口接收到正确的属性名称"Xft/DPI"
3. 检查DConfig值是否正确与XSettings同步
4. 使用不同的显示缩放因子测试以确保DPI计算正常工作
5. 验证DPI更改是否正确反映在使用XSettings的应用程序中

pms: BUG-343127

@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 there - I've reviewed your changes - here's some feedback:

  • The new #include <qlogging.h> looks mismatched with the description mentioning QLoggingCategory; consider including the specific header you actually need (e.g. <QLoggingCategory> or the project’s logging header) to avoid pulling in broader/incorrect Qt logging APIs.
  • The literal "Xft/DPI" is now embedded directly in XsSetting; if this value is used elsewhere or tied to a protocol spec, consider centralizing it as a named constant (e.g. in xsdatainfo.h) to avoid typos and keep it consistent with other XSettings keys.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `#include <qlogging.h>` looks mismatched with the description mentioning `QLoggingCategory`; consider including the specific header you actually need (e.g. `<QLoggingCategory>` or the project’s logging header) to avoid pulling in broader/incorrect Qt logging APIs.
- The literal "Xft/DPI" is now embedded directly in `XsSetting`; if this value is used elsewhere or tied to a protocol spec, consider centralizing it as a named constant (e.g. in `xsdatainfo.h`) to avoid typos and keep it consistent with other XSettings keys.

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

deepin pr auto review

我来对这段代码进行审查和分析:

  1. 语法逻辑:
  • 代码语法正确,没有明显的语法错误。
  • 变量命名清晰,符合命名规范。
  1. 代码质量:
  • 在修改中,将 setting.prop 从变量 dcKeyXftDpi 改为硬编码字符串 "Xft/DPI",这不是一个好的实践。建议保持使用变量 dcKeyXftDpi,这样更容易维护和修改。
  • 新增的 scaledDpi 计算行位置合适,逻辑清晰。
  1. 代码性能:
  • scaledDpi 的计算使用了 static_cast<int>,这是合理的类型转换方式。
  • 计算表达式 (DPI_FALLBACK * 1024) * scale 中,1024 是一个魔法数字,建议定义为一个常量,并添加注释说明其用途。
  1. 代码安全:
  • 类型转换使用了 static_cast<int> 而不是 C 风格的强制转换,这是更安全的做法。
  • 在进行数值计算和转换时,没有溢出检查,建议添加边界检查以确保数值安全。

改进建议:

  1. 恢复使用变量而不是硬编码字符串:
setting.prop = dcKeyXftDpi;  // 而不是 "Xft/DPI"
  1. 定义常量并添加注释:
// DPI 缩放因子,用于提高精度
constexpr int DPI_SCALE_FACTOR = 1024;
scaledDpi = static_cast<int>((DPI_FALLBACK * DPI_SCALE_FACTOR) * scale);
  1. 添加边界检查:
scaledDpi = static_cast<int>((DPI_FALLBACK * DPI_SCALE_FACTOR) * scale);
// 确保 scaledDpi 在合理范围内
if (scaledDpi < DPI_MIN || scaledDpi > DPI_MAX) {
    qWarning() << "Calculated DPI out of range:" << scaledDpi;
    scaledDpi = qBound(DPI_MIN, scaledDpi, DPI_MAX);
}
  1. 考虑添加日志记录,便于调试:
if (tempXftDpi != scaledDpi) {
    qDebug() << "Updating DPI from" << tempXftDpi << "to" << scaledDpi;
    m_settingDconfig->setValue(dcKeyXftDpi, scaledDpi);
    // ...
}

这些改进将使代码更加健壮、可维护和安全。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@mhduiy

mhduiy commented Dec 11, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Dec 11, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 6b5efd0 into linuxdeepin:master Dec 11, 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