Skip to content

fix: prevent icon size flickering when DPR changes with empty sourceSize#642

Open
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:master
Open

fix: prevent icon size flickering when DPR changes with empty sourceSize#642
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

@18202781743 18202781743 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor
  1. Fixed an issue where icon size flickering occurred under fractional
    scaling on Wayland, caused by Qt resetting devicePixelRatio without
    calling updateDevicePixelRatio when sourceSize is empty
  2. Added condition to call maybeUpdateUrl only when device pixel ratio
    actually changes in itemChange, ensuring consistent icon rendering

Log: Fixed icon flickering issue under Wayland fractional scaling when
sourceSize is empty

Influence:

  1. Test icon rendering under Wayland with fractional scaling (e.g.,
    125%, 150%)
  2. Verify no flickering when window moves between monitors with
    different DPIs
  3. Check icon display when sourceSize is explicitly set
  4. Test with empty sourceSize to ensure stable behavior
  5. Verify on non-Wayland platforms to maintain existing functionality

fix: 修复空sourceSize时DPR变化导致图标大小闪烁问题

  1. 修复了Wayland下分数缩放时,当sourceSize为空,Qt重置devicePixelRatio但
    未调用updateDevicePixelRatio导致的图标大小闪烁问题
  2. 在itemChange中添加条件判断,仅在设备像素比实际发生变化时才调用
    maybeUpdateUrl,确保图标渲染一致性

Log: 修复Wayland分数缩放下图标闪烁问题

Influence:

  1. 在Wayland环境下测试分数缩放(如125%、150%)时的图标渲染
  2. 验证窗口在不同DPI显示器间移动时无闪烁
  3. 检查显式设置sourceSize时的图标显示
  4. 测试空sourceSize情况以确保行为稳定
  5. 在非Wayland平台上验证以保持现有功能正常

PMS: BUG-366597

Summary by Sourcery

Prevent icon flickering caused by unnecessary icon URL updates when the device pixel ratio changes, particularly under Wayland fractional scaling with empty sourceSize.

Bug Fixes:

  • Avoid triggering icon URL updates unless the device pixel ratio actually changes to prevent icon size flickering under fractional scaling scenarios.

Chores:

  • Update the SPDX copyright years for dquickiconimage.cpp to include 2026.

@18202781743 18202781743 requested review from BLumia and mhduiy June 24, 2026 05:33
@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

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

Reviewer's Guide

Refines DQuickIconImage’s response to device pixel ratio changes so that icon URLs are recalculated only when the DPR actually updates, preventing icon size flicker under fractional scaling (especially on Wayland with empty sourceSize), and updates the file copyright years.

Sequence diagram for updated DPR handling in DQuickIconImage::itemChange

sequenceDiagram
    participant QQuickItem as QQuickItem
    participant DQuickIconImage as DQuickIconImage
    participant DPrivate as DQuickIconImagePrivate

    QQuickItem->>DQuickIconImage: itemChange(ItemSceneChange, value)
    DQuickIconImage->>DQuickIconImage: qmlEngine(this)
    alt qmlEngine is not null
        DQuickIconImage->>DPrivate: updateDevicePixelRatio(1.0)
        alt DPR actually changed (returns true)
            DQuickIconImage->>DPrivate: maybeUpdateUrl()
        else DPR unchanged (returns false)
            DQuickIconImage-->>QQuickItem: no URL update
        end
    else qmlEngine is null
        DQuickIconImage-->>QQuickItem: ignore change
    end
Loading

File-Level Changes

Change Details Files
Guard icon URL refresh behind a real devicePixelRatio change to avoid unnecessary reloads and flicker when Qt resets DPR with empty sourceSize.
  • In itemChange(DevicePixelRatioHasChanged), call the private updateDevicePixelRatio(1.0) helper and only proceed if it reports that the DPR actually changed.
  • Invoke maybeUpdateUrl() conditionally based on the updateDevicePixelRatio result so icons are not re-resolved when the effective DPR is unchanged.
  • Update the file’s SPDX copyright year range from 2020–2022 to 2020–2026.
src/private/dquickiconimage.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 left some high level feedback:

  • Consider adding a short comment explaining why updateDevicePixelRatio(1.0) is called with a hardcoded 1.0 here, so future readers understand the rationale for this specific value in the context of Qt’s DPR handling.
  • If updateDevicePixelRatio has observable side effects (e.g., recalculating internal state), it might be worth checking whether this logic should be centralized or reused from existing code paths to avoid duplicating DPR update behavior in multiple places.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding a short comment explaining why `updateDevicePixelRatio(1.0)` is called with a hardcoded 1.0 here, so future readers understand the rationale for this specific value in the context of Qt’s DPR handling.
- If `updateDevicePixelRatio` has observable side effects (e.g., recalculating internal state), it might be worth checking whether this logic should be centralized or reused from existing code paths to avoid duplicating DPR update behavior in multiple places.

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.

BLumia
BLumia previously approved these changes Jun 24, 2026
1. Fixed an issue where icon size flickering occurred under fractional
scaling on Wayland, caused by Qt resetting devicePixelRatio without
calling updateDevicePixelRatio when sourceSize is empty
2. Added condition to call maybeUpdateUrl only when device pixel ratio
actually changes in itemChange, ensuring consistent icon rendering

Log: Fixed icon flickering issue under Wayland fractional scaling when
sourceSize is empty

Influence:
1. Test icon rendering under Wayland with fractional scaling (e.g.,
125%, 150%)
2. Verify no flickering when window moves between monitors with
different DPIs
3. Check icon display when sourceSize is explicitly set
4. Test with empty sourceSize to ensure stable behavior
5. Verify on non-Wayland platforms to maintain existing functionality

fix: 修复空sourceSize时DPR变化导致图标大小闪烁问题

1. 修复了Wayland下分数缩放时,当sourceSize为空,Qt重置devicePixelRatio但
未调用updateDevicePixelRatio导致的图标大小闪烁问题
2. 在itemChange中添加条件判断,仅在设备像素比实际发生变化时才调用
maybeUpdateUrl,确保图标渲染一致性

Log: 修复Wayland分数缩放下图标闪烁问题

Influence:
1. 在Wayland环境下测试分数缩放(如125%、150%)时的图标渲染
2. 验证窗口在不同DPI显示器间移动时无闪烁
3. 检查显式设置sourceSize时的图标显示
4. 测试空sourceSize情况以确保行为稳定
5. 在非Wayland平台上验证以保持现有功能正常

PMS: BUG-366597
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码精准修复了设备像素比变化时的逻辑穿透缺陷,质量优秀
逻辑完全正确,无任何安全与性能问题,符合满分标准

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修复了 DQuickIconImage::itemChange 函数中 ItemDevicePixelRatioHasChanged 分支的 Q_FALLTHROUGH() 逻辑穿透问题。原代码在设备像素比变化时会错误落入 ItemEnabledHasChanged 分支,修复后增加了独立作用域并正确调用 d->updateDevicePixelRatio(1.0)d->maybeUpdateUrl()break
建议:保持当前的独立分支处理模式。

  • 2.代码质量(优秀)✓

消除了容易引起误解的穿透逻辑,增加了清晰的作用域隔离,版权年份同步更新至2026年,符合规范。
建议:无需额外改进。

  • 3.代码性能(高效)✓

仅在设备像素比实际变化且 updateDevicePixelRatio 返回成功时才触发 maybeUpdateUrl 进行图标刷新,无多余性能开销。
建议:无需额外改进。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅涉及状态分支逻辑修正,未引入任何命令注入、内存越界等安全风险,同时降低了原逻辑在程序退出阶段可能因错误分支触发的异常崩溃风险。
建议:继续保持安全的编码实践。

■ 【改进建议代码示例】

void DQuickIconImage::itemChange(ItemChange change, const ItemChangeData &value)
{
    Q_D(DQuickIconImage);

    switch (change) {
    case ItemDevicePixelRatioHasChanged: {
        if (d->updateDevicePixelRatio(1.0)) {
            d->maybeUpdateUrl();
        }
    }
        break;
    case ItemEnabledHasChanged: {
        // ###!(Chen Bin): When the program exits, it will be called
        // again, but the engine has been freed, causing subsequent
        // operations to crash.
        if (!engine())
            return;

        d->_q_reload();
    }
        break;
    default:
        break;
    }
}

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

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

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