Skip to content

fix(dock): disable smooth rendering for tray icons#1493

Merged
BLumia merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix
Mar 10, 2026
Merged

fix(dock): disable smooth rendering for tray icons#1493
BLumia merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Mar 10, 2026

Set smooth: false on icon items to fix rendering artifacts.

修复托盘图标渲染伪影问题,禁用平滑渲染。

Log: 修复托盘图标渲染问题
PMS: BUG-312985 BUG-312991 BUG-306813 BUG-271229
Influence: 托盘和任务栏图标渲染更清晰,避免模糊伪影。

Set smooth: false on icon items to fix rendering artifacts.

修复托盘图标渲染伪影问题,禁用平滑渲染。

Log: 修复托盘图标渲染问题
PMS: BUG-312985 BUG-312991 BUG-306813 BUG-271229
Influence: 托盘和任务栏图标渲染更清晰,避免模糊伪影。
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @re2zero, 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

deepin pr auto review

这段代码主要针对 QML 中的图像渲染性能进行了优化,通过调整 smooth 属性来控制平滑处理。以下是对这段 diff 的详细审查和改进建议:

1. 语法逻辑审查

  • 版权声明格式统一
    • AppletItemButton.qml, ActionLegacyTrayPluginDelegate.qmlPanelPluginPage.qml 中,版权年份从 20242024-2026 统一修改为了 2024 - 2026。注意年份中间增加了空格(-),这种格式更符合规范,修改是正确的。
  • 属性设置逻辑
    • AppletItemButton.qmlActionLegacyTrayPluginDelegate.qml 直接在声明时设置 smooth: false,逻辑清晰。
    • AppItem.qml 使用了条件判断 smooth: iconSize > 32,这是一个很好的优化策略,因为小图标关闭平滑可以减少锯齿感(像素风格),大图标开启平滑则更美观。
    • PanelPluginPage.qml 使用了 Component.onCompleted 来动态设置 contentItem.smooth。这种方式虽然可行,但依赖于 contentItem 在完成时已经实例化,且 contentItem 是 Button 的私有属性(尽管在 Qt 中常被访问),这种方式不如直接在声明时绑定属性稳健。

2. 代码质量审查

  • 一致性
    • 对于小尺寸图标(如 16x16),统一设置 smooth: false 是合理的,这有助于保持像素风格的清晰度,避免小图标模糊。
    • AppItem.qml 中的逻辑判断体现了对不同尺寸图标的差异化处理,提升了代码质量。
  • 代码风格
    • PanelPluginPage.qml 中的 Component.onCompleted 写法略显笨拙。如果可能,建议尝试在声明时直接设置属性,或者确认是否可以通过样式(Style)统一控制。

3. 代码性能审查

  • 性能优化显著
    • smooth: false 禁用了双线性过滤(Bilinear Filtering),改用最近邻插值(Nearest-Neighbor Interpolation)。对于低分辨率图标(如 Dock 栏常见的 16x16, 24x24, 32x32),这能显著减少 GPU 的纹理采样开销,提升渲染性能。
    • AppItem.qml 中仅对大于 32px 的图标开启平滑,这是一个非常明智的性能/质量平衡点。小于等于 32px 的图标通常不需要平滑,且开启后反而显得模糊。
  • 潜在问题
    • PanelPluginPage.qml 中,Component.onCompleted 意味着属性设置发生在对象创建之后。虽然这对性能影响微乎其微,但在高频创建销毁的场景下,直接属性绑定会比 JavaScript 回调更高效。

4. 代码安全审查

  • 空值检查
    • PanelPluginPage.qml 中包含了 if (contentItem) 的检查,这是很好的防御性编程习惯,防止因 contentItem 未准备好而导致的运行时错误。
  • 类型安全
    • 代码假设 contentItem 具有 smooth 属性。在 Qt Quick Controls 中,Button 的 contentItem 通常是 Item 类型,并不直接保证有 smooth 属性(除非它是一个 Image 或 Icon)。如果 contentItem 被替换为一个不包含 smooth 属性的组件(如 Text 或 Row),这行代码在运行时虽然不会报错(QML 的属性访问容错性),但也无法生效。

改进建议

针对 panels/dock/tray/quickpanel/PanelPluginPage.qml 的修改,建议进行如下优化,以提高代码的健壮性和可维护性:

原代码:

        Component.onCompleted: {
            if (contentItem) {
                contentItem.smooth = false
            }
        }

改进建议 1(如果 contentItem 是 Image):
如果 contentItem 确定是一个 Image 或者支持 smooth 属性的组件,建议在定义时直接绑定,或者使用属性别名。

        // 假设 btn 是一个 Button 或者其子类,且 contentItem 可以被控制
        // 如果无法直接修改 btn 的定义,确保 contentItem 确实是 Image 类型
        onContentItemChanged: {
            if (contentItem && contentItem.hasOwnProperty("smooth")) {
                contentItem.smooth = false
            }
        }

理由onContentItemChangedComponent.onCompleted 更安全,因为 contentItem 可能在加载过程中被延迟赋值或动态替换。同时增加 hasOwnProperty 检查增加了类型安全性。

改进建议 2(通用性更强的写法):
如果 btn 是自定义组件,最好的做法是在该组件内部暴露 smooth 属性,而不是在外部操作其内部 contentItem

// 在 btn 所在的组件定义中
property bool iconSmooth: false
contentItem: Image {
    smooth: btn.iconSmooth
    // ...
}

理由:封装性更好,符合 QML 的组件化设计思想。

总结
整体 diff 的意图非常明确且正确,即通过禁用小图标的平滑处理来提升渲染性能和视觉清晰度。主要的改进点在于 PanelPluginPage.qml 的实现方式,建议从运行时修改属性改为声明时绑定或监听变化,以获得更好的稳定性和性能。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@BLumia
Copy link
Member

BLumia commented Mar 10, 2026

关联: linuxdeepin/dde-launchpad#728

@BLumia BLumia merged commit dcdd974 into linuxdeepin:master Mar 10, 2026
9 of 12 checks passed
@re2zero re2zero deleted the bugfix branch March 10, 2026 09:19
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