Skip to content

fix: apply scale factor to GTK cursor theme size - #57

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:cursorsize
Feb 27, 2026
Merged

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

Conversation

@mhduiy

@mhduiy mhduiy commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

When the DConfig key "gtk-cursor-theme-size-base" changes, the derived "gtk-cursor-theme-size" value is now calculated by multiplying the base size with the current scale factor. Previously, the base size was used directly without scaling, which could lead to incorrect cursor sizes on high-DPI displays. The change includes validation for the scale factor, defaulting to 1.0 if an invalid value is read, and logs a warning in both error and update cases for debugging purposes.

fix: 应用缩放因子到GTK光标主题大小

当DConfig键"gtk-cursor-theme-size-base"发生变化时,现在通过将基础大小乘 以当前缩放因子来计算派生的"gtk-cursor-theme-size"值。之前,基础大小被直
接使用而没有进行缩放,这可能导致在高DPI显示器上光标大小不正确。此更改包
括对缩放因子的验证,如果读取到无效值则回退到1.0,并在错误和更新情况下记
录警告信息以便调试。

pms: BUG-343215

Summary by Sourcery

Bug Fixes:

  • Correct the derived GTK cursor theme size on high-DPI displays by factoring in the current scale factor instead of using the unscaled base size.

@sourcery-ai

sourcery-ai Bot commented Feb 26, 2026

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

Reviewer's Guide

Updates GTK cursor theme size handling so that the derived gtk-cursor-theme-size is computed from the base size multiplied by the current scale factor, with validation and logging for debugging.

Sequence diagram for applying scale factor to GTK cursor theme size

sequenceDiagram
    actor User
    participant Application
    participant XSettingsManager
    participant DConfigStore

    User->>Application: Change cursor size or display scaling
    Application->>XSettingsManager: handleDConfigChangedCb(key = gtk-cursor-theme-size-base)

    XSettingsManager->>DConfigStore: value(gtk-cursor-theme-size-base)
    DConfigStore-->>XSettingsManager: cursorSizeBase:int

    XSettingsManager->>DConfigStore: value(dcKeyScaleFactor)
    DConfigStore-->>XSettingsManager: scale:double

    alt invalid scale (scale <= 0)
        XSettingsManager->>XSettingsManager: scale = 1.0
        XSettingsManager->>Application: qWarning invalid scale factor
    end

    XSettingsManager->>Application: qWarning update gtk-cursor-theme-size
    XSettingsManager->>DConfigStore: setValue(gtk-cursor-theme-size, cursorSizeBase * scale)
    DConfigStore-->>XSettingsManager: ack

    XSettingsManager-->>Application: return
Loading

File-Level Changes

Change Details Files
Apply validated scale factor when updating derived GTK cursor theme size from the DConfig base key.
  • Read the current scale factor from the DConfig key referenced by dcKeyScaleFactor when gtk-cursor-theme-size-base changes.
  • Validate the scale factor, falling back to 1.0 and logging a warning if it is non-positive.
  • Log the computed gtk-cursor-theme-size value before updating for easier debugging.
  • Set gtk-cursor-theme-size to the product of cursorSizeBase and the validated scale factor, and return early from the handler.
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 found 1 issue, and left some high level feedback:

  • The scale factor logging on every gtk-cursor-theme-size-base change uses qWarning(), which may be too noisy for normal operation; consider using a lower log level (e.g., qDebug() or a conditional debug flag) for the non-error update message.
  • The multiplication of cursorSizeBase (int) and scale (double) produces a double that is passed directly to setValue; if the downstream consumer expects an integer cursor size, consider explicitly rounding or casting and documenting the chosen behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The scale factor logging on every `gtk-cursor-theme-size-base` change uses `qWarning()`, which may be too noisy for normal operation; consider using a lower log level (e.g., `qDebug()` or a conditional debug flag) for the non-error update message.
- The multiplication of `cursorSizeBase` (int) and `scale` (double) produces a double that is passed directly to `setValue`; if the downstream consumer expects an integer cursor size, consider explicitly rounding or casting and documenting the chosen behavior.

## Individual Comments

### Comment 1
<location path="src/plugin-qt/xsettings/impl/xsettingsmanager.cpp" line_range="222-227" />
<code_context>
+            qWarning() << "invalid scale factor:" << scale << ", fallback to 1.0";
+            scale = 1.0;
+        }
+        qWarning() << "update gtk-cursor-theme-size to" << cursorSizeBase * scale;
+        m_settingDconfig->setValue("gtk-cursor-theme-size", cursorSizeBase * scale);
         return;
</code_context>
<issue_to_address>
**suggestion:** Using qWarning for the normal update path may be too noisy in production logs.

Logging every successful update with `qWarning` will clutter production logs and may be interpreted as errors by log aggregation tools. Use `qDebug` (or a categorized debug log) for the normal update, and keep `qWarning` for exceptional cases like the invalid scale path.

```suggestion
        if (scale <= 0) {
            qWarning() << "invalid scale factor:" << scale << ", fallback to 1.0";
            scale = 1.0;
        }
        qDebug() << "update gtk-cursor-theme-size to" << cursorSizeBase * scale;
        m_settingDconfig->setValue("gtk-cursor-theme-size", cursorSizeBase * scale);
```
</issue_to_address>

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.

Comment thread src/plugin-qt/xsettings/impl/xsettingsmanager.cpp
When the DConfig key "gtk-cursor-theme-size-base" changes, the derived
"gtk-cursor-theme-size" value is now calculated by multiplying the base
size with the current scale factor. Previously, the base size was used
directly without scaling, which could lead to incorrect cursor sizes on
high-DPI displays. The change includes validation for the scale factor,
defaulting to 1.0 if an invalid value is read, and logs a warning in
both error and update cases for debugging purposes.

fix: 应用缩放因子到GTK光标主题大小

当DConfig键"gtk-cursor-theme-size-base"发生变化时,现在通过将基础大小乘
以当前缩放因子来计算派生的"gtk-cursor-theme-size"值。之前,基础大小被直
接使用而没有进行缩放,这可能导致在高DPI显示器上光标大小不正确。此更改包
括对缩放因子的验证,如果读取到无效值则回退到1.0,并在错误和更新情况下记
录警告信息以便调试。

pms: BUG-343215
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

这段代码主要修改了光标主题尺寸的计算逻辑,从直接使用基础尺寸改为根据缩放因子(scale factor)动态计算。以下是对这段代码的审查意见和改进建议:

1. 语法逻辑

当前状态:代码逻辑基本正确,但存在一些潜在问题。

改进建议:

  • dcKeyScaleFactor 变量在代码片段中未定义,需要确认它是否已在类中正确定义为常量或成员变量。
  • m_settingDconfig->value(dcKeyScaleFactor) 可能返回无效值,虽然做了 <=0 的检查,但建议增加对 NaN 的检查。

2. 代码质量

当前状态:代码可读性较好,有基本的错误处理和日志输出。

改进建议:

  • 建议将魔法数字 1.0 定义为常量,例如 const double DEFAULT_SCALE_FACTOR = 1.0;
  • 日志输出可以更详细,例如包含函数名或上下文信息:
    qWarning() << "XSettingsManager: invalid scale factor:" << scale << ", fallback to 1.0";

3. 代码性能

当前状态:性能影响较小,但可以优化。

改进建议:

  • m_settingDconfig->value(dcKeyScaleFactor) 可能被多次调用,如果 scale 在其他地方也需要使用,建议缓存该值。
  • 避免不必要的 toDouble() 转换,如果确定类型,可以直接使用 toInt() 或 toFloat()。

4. 代码安全

当前状态:有基本的错误处理,但可以增强。

改进建议:

  • 检查 m_settingDconfig 是否为空指针,避免潜在的空指针解引用。
  • 对 cursorSizeBase 也应进行有效性检查,例如:
    if (cursorSizeBase <= 0) {
        qWarning() << "Invalid cursor size base:" << cursorSizeBase;
        return;
    }
  • 考虑使用 qFuzzyCompare 或 qIsNaN 来检查浮点数有效性:
    if (scale <= 0 || qIsNaN(scale)) {
        qWarning() << "Invalid scale factor:" << scale << ", fallback to 1.0";
        scale = 1.0;
    }

改进后的代码示例:

void XSettingsManager::handleDConfigChangedCb(const QString &key)
{
    if (key == "gtk-cursor-theme-size-base") {
        int cursorSizeBase = m_settingDconfig->value(key).toInt();
        if (cursorSizeBase <= 0) {
            qWarning() << "XSettingsManager: Invalid cursor size base:" << cursorSizeBase;
            return;
        }

        double scale = m_settingDconfig->value(dcKeyScaleFactor).toDouble();
        if (scale <= 0 || qIsNaN(scale)) {
            qWarning() << "XSettingsManager: Invalid scale factor:" << scale << ", fallback to 1.0";
            scale = 1.0;
        }

        int finalSize = static_cast<int>(cursorSizeBase * scale);
        qDebug() << "XSettingsManager: Update gtk-cursor-theme-size to" << finalSize;
        m_settingDconfig->setValue("gtk-cursor-theme-size", finalSize);
        return;
    }
    // 其他处理逻辑...
}

总结

这段代码的功能是合理的,但可以通过增强错误处理、优化性能和改进日志输出来提升代码质量。建议在合并前进行单元测试,特别是针对边界情况(如 scale 为负数、NaN 或 cursorSizeBase 为 0 的情况)。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Feb 27, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 915053e into linuxdeepin:master Feb 27, 2026
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