Skip to content

Comments

fix(dock): prioritize theme icon over cached window icon in preview#1451

Closed
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Ivy233:fix-preview-icon-theme
Closed

fix(dock): prioritize theme icon over cached window icon in preview#1451
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Ivy233:fix-preview-icon-theme

Conversation

@Ivy233
Copy link
Contributor

@Ivy233 Ivy233 commented Feb 13, 2026

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

Summary by Sourcery

Bug Fixes:

  • Resolve stale window preview icons after icon theme changes by preferring theme icon names over cached window icon data.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Reorders 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 preview

sequenceDiagram
    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
Loading

Class diagram for X11WindowPreviewContainer icon selection changes

classDiagram
    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)
Loading

File-Level Changes

Change Details Files
Reverse icon priority in X11 window preview to prefer theme icons and fall back to cached window icons.
  • In X11WindowPreviewContainer constructor, fetch IconNameRole first for the preview icon and only fall back to WinIconRole when it is empty before updating the preview icon and title.
  • In showPreviewWithModel, apply the same IconNameRole-first, WinIconRole-fallback logic when choosing the preview icon for the first model index.
  • Update the inline comments (in Chinese) to describe the new priority: theme icon first, then window icon, and note that theme icons follow theme changes.
panels/dock/taskmanager/x11preview.cpp
Update SPDX file copyright years.
  • Extend the SPDX-FileCopyrightText year range from 2024 to 2024 - 2026 at the top of the file.
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 - I've reviewed your changes and they look great!


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.

// 获取图标,优先使用窗口图标,如果为空则使用应用图标
QVariant iconData = enter.data(TaskManager::WinIconRole);
// 获取图标,优先使用主题图标(会跟随主题变化),如果为空则使用窗口图标
QVariant iconData = enter.data(TaskManager::IconNameRole);
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是应用图标,而不是窗口图标,跟之前的注释完全不同,现在改成优先使用应用图标,这不正常吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已确认,该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
@Ivy233 Ivy233 force-pushed the fix-preview-icon-theme branch from cd50c25 to 83a0236 Compare February 24, 2026 05:18
@deepin-ci-robot
Copy link

[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.

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

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要修改了窗口预览容器中图标获取的逻辑顺序,以及更新了版权年份。以下是对这段diff的详细审查和改进建议:

1. 语法逻辑审查

修改内容分析:
代码将获取图标的优先级从“窗口图标优先”调整为“主题图标优先”。

  • 原逻辑:先尝试 WinIconRole(窗口图标),如果为空则尝试 IconNameRole(主题/应用图标)。
  • 新逻辑:先尝试 IconNameRole(主题/应用图标),如果为空则尝试 WinIconRole(窗口图标)。

逻辑合理性:
修改后的逻辑更符合现代桌面环境的用户体验。优先使用主题图标(IconNameRole)可以确保图标风格与当前系统主题保持一致(例如深色/浅色模式切换),只有当应用未注册主题图标时,才回退使用应用自带的窗口图标(WinIconRole)。这个逻辑是正确的。

代码一致性:
代码在两处(构造函数和 showPreviewWithModel 方法)进行了相同的修改,保持了内部逻辑的一致性,这一点做得很好。

2. 代码质量审查

优点:

  • 注释更新:代码注释准确地反映了新的逻辑(“优先使用主题图标...”),有助于后续维护。
  • 版权声明:更新了版权年份范围(2024 - 2026),符合规范。

改进意见:

  • 类型转换安全性
    当前代码直接使用 iconData.toString() 进行判断。
    if (iconData.toString().isEmpty()) { ... }
    如果 data() 返回的 QVariant 虽然有效但不是字符串类型(例如是一个 QIcon 对象),toString() 可能会返回一个空字符串或者非预期的字符串,导致逻辑判断错误。
    建议增加对 QVariant 类型的检查,或者确认 TaskManager 模型中这两个 Role 返回的数据类型始终为 String。如果模型设计如此,则当前写法尚可;如果不确定,建议优化。

3. 代码性能审查

  • 性能影响:极小。
    这里仅涉及 QAbstractItemModel::data 的调用和简单的字符串比较。由于这是在用户交互(鼠标悬停)时触发的,且仅针对单个窗口索引,性能开销可以忽略不计。

4. 代码安全审查

  • 空指针/空索引检查
    showPreviewWithModel 方法中,代码已经检查了 sourceModel 及其行数:
    if (sourceModel && sourceModel->rowCount() > 0) { ... }
    这保证了 firstIndex 的有效性,是安全的。
  • 数据有效性
    如前所述,依赖于模型返回正确的数据类型。如果模型返回空 QVarianttoString() 会返回空字符串,逻辑能正确进入 if 分支尝试下一个数据源,这是安全的。

5. 综合改进建议代码

为了增强代码的健壮性,建议对图标的获取逻辑进行微调,确保我们处理的是有效的字符串数据,或者处理模型可能直接返回 QIcon 的情况(假设 updatePreviewIconFromString 是唯一的处理入口,这里主要关注字符串获取)。

// 获取图标,优先使用主题图标(会跟随主题变化),如果为空则使用窗口图标
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);
}

总结:
这段 diff 的修改意图明确,逻辑正确,能够提升用户体验(图标一致性)。代码质量良好,注释更新及时。主要的风险点在于对 QVariant 数据类型的隐式假设,但在模型设计确定的情况下是安全的。代码可以合并。

@Ivy233 Ivy233 closed this Feb 24, 2026
@Ivy233 Ivy233 deleted the fix-preview-icon-theme branch February 24, 2026 08:46
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