fix(dock): prioritize theme icon over cached window icon in preview#1451
fix(dock): prioritize theme icon over cached window icon in preview#1451Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReorders icon selection priority in the X11 dock window preview so that theme-based icons (IconNameRole) are used first and cached window icons (WinIconRole) are only used as a fallback, ensuring preview icons reflect current theme changes immediately while preserving a safe fallback path; also updates the SPDX copyright years. Sequence diagram for updated icon selection in X11 window previewsequenceDiagram
actor User
participant Dock as DockPanel
participant TaskModel as TaskManagerModel
participant Preview as X11WindowPreviewContainer
User->>Dock: Hover window item
Dock->>Preview: previewWindow(winId)
Preview->>TaskModel: data(index, IconNameRole)
TaskModel-->>Preview: iconName
alt iconName is not empty
Preview->>Preview: updatePreviewIconFromString(iconName)
else iconName is empty
Preview->>TaskModel: data(index, WinIconRole)
TaskModel-->>Preview: winIconData
Preview->>Preview: updatePreviewIconFromString(winIconData)
end
Preview->>TaskModel: data(index, WinTitleRole)
TaskModel-->>Preview: winTitle
Preview->>Preview: updatePreviewTitle(winTitle)
Preview-->>Dock: Preview updated with theme-aware icon
Dock-->>User: Show window preview with correct theme icon
Class diagram for X11WindowPreviewContainer icon selection changesclassDiagram
class X11WindowPreviewContainer {
- X11WindowMonitor* m_monitor
+ X11WindowPreviewContainer(X11WindowMonitor* monitor, QWidget* parent)
+ void showPreviewWithModel(QAbstractItemModel* sourceModel)
+ void updatePreviewIconFromString(QString iconData)
+ void updatePreviewTitle(QString title)
}
class X11WindowMonitor {
+ void previewWindow(int winId)
}
class QAbstractItemModel {
+ int rowCount(QModelIndex parent)
+ QModelIndex index(int row, int column, QModelIndex parent)
+ QVariant data(QModelIndex index, int role)
}
class QModelIndex {
+ int row()
+ int column()
+ bool isValid()
}
class QVariant {
+ QString toString()
+ int toInt()
}
class TaskManagerRoles {
<<enumeration>>
WinIdRole
WinIconRole
IconNameRole
WinTitleRole
}
X11WindowPreviewContainer --> X11WindowMonitor : uses
X11WindowPreviewContainer --> QAbstractItemModel : reads preview data
QAbstractItemModel --> QModelIndex : creates
X11WindowPreviewContainer --> QModelIndex : selects item
X11WindowPreviewContainer --> QVariant : handles role data
X11WindowPreviewContainer ..> TaskManagerRoles : accesses roles
%% Icon selection logic (new priority)
class IconSelectionPolicy {
+ QString selectIcon(QAbstractItemModel* model, QModelIndex index)
}
X11WindowPreviewContainer ..> IconSelectionPolicy : uses
%% Conceptual behavior of IconSelectionPolicy:
%% 1. Try IconNameRole (theme icon name, follows theme changes)
%% 2. If empty, fall back to WinIconRole (cached window icon)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
| // 获取图标,优先使用窗口图标,如果为空则使用应用图标 | ||
| QVariant iconData = enter.data(TaskManager::WinIconRole); | ||
| // 获取图标,优先使用主题图标(会跟随主题变化),如果为空则使用窗口图标 | ||
| QVariant iconData = enter.data(TaskManager::IconNameRole); |
There was a problem hiding this comment.
这里是应用图标,而不是窗口图标,跟之前的注释完全不同,现在改成优先使用应用图标,这不正常吧?
There was a problem hiding this comment.
已确认,该bug已经在linuxdeepin/qt5integration@f12a2f106ef56c6300f303e5d7c20918066ee3c3得到修复。
目前这个bug只在玲珑应用中出现(例如editor,movie,album),不过music没有这个问题。如果需要的话,可以换成deb包体。
When switching icon themes, the window preview icons were not updating because the code prioritized WinIconRole (Base64-encoded cached window icon data from X11 properties) over IconNameRole (theme icon name from desktop files). This change reverses the priority to use IconNameRole first, which loads icons dynamically from the current theme via QIcon::fromTheme(). Only when IconNameRole is empty does it fall back to WinIconRole. This ensures preview icons follow theme changes immediately, fixing the issue where old and new theme icons appeared mixed after switching themes. Influence: 1. Window preview icons now update immediately when switching icon themes 2. All preview icons display consistently in the current theme style 3. Fallback to cached window icons still works for windows without desktop files 4. No impact on preview functionality or performance fix(dock): 预览窗口优先使用主题图标而非缓存的窗口图标 切换图标主题时,窗口预览图标未更新,因为代码优先使用 WinIconRole (从 X11 属性获取的 Base64 编码缓存窗口图标数据)而非 IconNameRole (从 desktop 文件获取的主题图标名称)。 此更改反转了优先级,优先使用 IconNameRole,通过 QIcon::fromTheme() 从当前主题动态加载图标。仅当 IconNameRole 为空时才回退到 WinIconRole。 这确保预览图标立即跟随主题变化,修复了切换主题后新旧主题图标混合 显示的问题。 Influence: 1. 切换图标主题时窗口预览图标立即更新 2. 所有预览图标以当前主题样式一致显示 3. 对于没有 desktop 文件的窗口,仍可回退到缓存的窗口图标 4. 不影响预览功能和性能 PMS: BUG-341117
cd50c25 to
83a0236
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review这段代码主要修改了窗口预览容器中图标获取的逻辑顺序,以及更新了版权年份。以下是对这段diff的详细审查和改进建议: 1. 语法逻辑审查修改内容分析:
逻辑合理性: 代码一致性: 2. 代码质量审查优点:
改进意见:
3. 代码性能审查
4. 代码安全审查
5. 综合改进建议代码为了增强代码的健壮性,建议对图标的获取逻辑进行微调,确保我们处理的是有效的字符串数据,或者处理模型可能直接返回 // 获取图标,优先使用主题图标(会跟随主题变化),如果为空则使用窗口图标
QVariant iconData = index.data(TaskManager::IconNameRole);
QString iconName = iconData.toString();
// 如果主题图标名为空,尝试获取窗口图标
if (iconName.isEmpty()) {
iconData = index.data(TaskManager::WinIconRole);
// 假设 WinIconRole 也是返回图标名称字符串
// 如果 WinIconRole 可能返回 QIcon,这里需要额外处理,例如:
// if (iconData.canConvert<QIcon>()) { ... }
// 但根据现有上下文 updatePreviewIconFromString,我们假设它也是字符串
iconName = iconData.toString();
}
// 只有当最终获取到的字符串不为空时才更新,避免不必要的空字符串处理
if (!iconName.isEmpty()) {
updatePreviewIconFromString(iconName);
}总结: |
When switching icon themes, the window preview icons were not updating because the code prioritized WinIconRole (Base64-encoded cached window icon data from X11 properties) over IconNameRole (theme icon name from desktop files).
This change reverses the priority to use IconNameRole first, which loads icons dynamically from the current theme via QIcon::fromTheme(). Only when IconNameRole is empty does it fall back to WinIconRole.
This ensures preview icons follow theme changes immediately, fixing the issue where old and new theme icons appeared mixed after switching themes.
Influence:
fix(dock): 预览窗口优先使用主题图标而非缓存的窗口图标
切换图标主题时,窗口预览图标未更新,因为代码优先使用 WinIconRole
(从 X11 属性获取的 Base64 编码缓存窗口图标数据)而非 IconNameRole
(从 desktop 文件获取的主题图标名称)。
此更改反转了优先级,优先使用 IconNameRole,通过 QIcon::fromTheme()
从当前主题动态加载图标。仅当 IconNameRole 为空时才回退到 WinIconRole。
这确保预览图标立即跟随主题变化,修复了切换主题后新旧主题图标混合
显示的问题。
Influence:
PMS: BUG-341117
Summary by Sourcery
Bug Fixes: