Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Nov 13, 2025

  1. Added device pixel ratio scaling to icon size calculation
  2. This ensures icons appear sharp and properly sized on high DPI screens
  3. Previously used fixed PREVIEW_TITLE_HEIGHT resulted in blurry icons on high DPI displays
  4. Now scales the icon pixmap according to the device's pixel ratio

fix: 为高DPI显示器缩放任务管理器预览图标

  1. 在图标尺寸计算中添加设备像素比缩放
  2. 确保在高DPI屏幕上图标显示清晰且尺寸正确
  3. 之前使用的固定PREVIEW_TITLE_HEIGHT在高DPI显示器上会导致图标模糊
  4. 现在根据设备的像素比缩放图标像素图

PMS: BUG-336089

Summary by Sourcery

Bug Fixes:

  • Replace fixed PREVIEW_TITLE_HEIGHT with a size scaled by qApp->devicePixelRatio to prevent blurry icons on high DPI screens.

1. Added device pixel ratio scaling to icon size calculation
2. This ensures icons appear sharp and properly sized on high DPI
screens
3. Previously used fixed PREVIEW_TITLE_HEIGHT resulted in blurry icons
on high DPI displays
4. Now scales the icon pixmap according to the device's pixel ratio

fix: 为高DPI显示器缩放任务管理器预览图标

1. 在图标尺寸计算中添加设备像素比缩放
2. 确保在高DPI屏幕上图标显示清晰且尺寸正确
3. 之前使用的固定PREVIEW_TITLE_HEIGHT在高DPI显示器上会导致图标模糊
4. 现在根据设备的像素比缩放图标像素图

PMS: BUG-336089
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 13, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces DPI-aware scaling when generating task manager preview icons by computing and applying a scaled size based on the device pixel ratio, replacing the previous fixed-height approach to ensure sharp rendering on high-DPI displays.

Sequence diagram for DPI-aware icon rendering in task manager preview

sequenceDiagram
participant "X11WindowPreviewContainer"
participant "QIcon"
participant "QApplication"
participant "Device"

"X11WindowPreviewContainer"->>"QApplication": get devicePixelRatio()
"QApplication"->>"Device": query pixel ratio
"Device"-->>"QApplication": return pixel ratio
"QApplication"-->>"X11WindowPreviewContainer": return pixel ratio
"X11WindowPreviewContainer"->>"QIcon": request icon pixmap with scaled size
"QIcon"-->>"X11WindowPreviewContainer": return scaled pixmap
Loading

Class diagram for updated icon scaling in X11WindowPreviewContainer

classDiagram
class X11WindowPreviewContainer {
  +void updatePreviewIconFromString(QString stringData)
}
class QApplication {
  +double devicePixelRatio()
}
class QIcon {
  +QPixmap pixmap(int width, int height)
}
X11WindowPreviewContainer --> QApplication : uses
X11WindowPreviewContainer --> QIcon : uses
Loading

File-Level Changes

Change Details Files
Enabled DPI-aware scaling for task manager preview icons
  • Compute scaledSize as PREVIEW_TITLE_HEIGHT multiplied by the app’s devicePixelRatio()
  • Use scaledSize for the QIcon::pixmap() call instead of the fixed PREVIEW_TITLE_HEIGHT
panels/dock/taskmanager/x11preview.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

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.

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `panels/dock/taskmanager/x11preview.cpp:773-774` </location>
<code_context>
     } else {
         // is (likely) icon name from theme
-        pix = QIcon::fromTheme(stringData).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT);
+        const int scaledSize = PREVIEW_TITLE_HEIGHT * qApp->devicePixelRatio();
+        pix = QIcon::fromTheme(stringData).pixmap(scaledSize, scaledSize);
     }

</code_context>

<issue_to_address>
**suggestion:** Consider using qRound or qCeil for scaledSize to avoid fractional pixel values.

Multiplying by devicePixelRatio() can produce non-integer values, which may cause issues with pixmap(). Applying qRound or qCeil will ensure scaledSize is always an integer, leading to more reliable rendering.

```suggestion
#include <QtMath>
        const int scaledSize = qRound(PREVIEW_TITLE_HEIGHT * qApp->devicePixelRatio());
        pix = QIcon::fromTheme(stringData).pixmap(scaledSize, scaledSize);
```
</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.

@deepin-ci-robot
Copy link

deepin pr auto review

这是一个关于窗口预览图标显示的改进,主要涉及高DPI显示的适配。让我来分析这个改动:

  1. 语法逻辑:
  • 语法正确,符合C++标准
  • 逻辑清晰,添加了对设备像素比(devicePixelRatio)的考虑
  1. 代码质量改进:
  • 添加了const限定符,保证scaledSize不会被意外修改,提高了代码的安全性
  • 使用有意义的变量名scaledSize,提高了代码可读性
  • 保持了原有的错误处理逻辑(pix.isNull())
  1. 性能优化:
  • 这个改动实际上是在显示质量上做优化,而不是性能
  • 对于高DPI显示器,现在会生成更清晰的图标
  • 计算devicePixelRatio的开销很小,对性能影响微乎其微
  1. 安全性改进:
  • 使用qApp->devicePixelRatio()获取系统缩放比例,比硬编码更安全
  • 保持了原有的错误处理机制,确保在图标加载失败时有适当的处理

建议:

  1. 可以考虑添加注释说明为什么要考虑devicePixelRatio,帮助其他开发者理解这个改动
  2. 如果PREVIEW_TITLE_HEIGHT是一个宏定义,可以考虑将其改为constexpr常量,以提高类型安全性

总的来说,这是一个很好的改进,主要解决了在高DPI显示器上图标模糊的问题,代码质量也有所提升。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@wjyrich wjyrich merged commit d5017dd into linuxdeepin:master Nov 13, 2025
9 of 11 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