Skip to content

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

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

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.

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

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.

1 participant