From cd50c2508d80d5fb377ccac4ddb40089d19e26a9 Mon Sep 17 00:00:00 2001 From: Ivy233 Date: Fri, 13 Feb 2026 13:42:34 +0800 Subject: [PATCH] fix(dock): prioritize theme icon over cached window icon in preview MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- panels/dock/taskmanager/x11preview.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/panels/dock/taskmanager/x11preview.cpp b/panels/dock/taskmanager/x11preview.cpp index 31ac8d495..70acad0ab 100644 --- a/panels/dock/taskmanager/x11preview.cpp +++ b/panels/dock/taskmanager/x11preview.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -386,10 +386,10 @@ X11WindowPreviewContainer::X11WindowPreviewContainer(X11WindowMonitor *monitor, m_monitor->previewWindow(enter.data(TaskManager::WinIdRole).toInt()); } - // 获取图标,优先使用窗口图标,如果为空则使用应用图标 - QVariant iconData = enter.data(TaskManager::WinIconRole); + // 获取图标,优先使用主题图标(会跟随主题变化),如果为空则使用窗口图标 + QVariant iconData = enter.data(TaskManager::IconNameRole); if (iconData.toString().isEmpty()) { - iconData = enter.data(TaskManager::IconNameRole); + iconData = enter.data(TaskManager::WinIconRole); } updatePreviewIconFromString(iconData.toString()); updatePreviewTitle(enter.data(TaskManager::WinTitleRole).toString()); @@ -458,10 +458,10 @@ void X11WindowPreviewContainer::showPreviewWithModel(QAbstractItemModel *sourceM if (sourceModel && sourceModel->rowCount() > 0) { const QModelIndex &firstIndex = sourceModel->index(0, 0); - // 获取图标,优先使用窗口图标,如果为空则使用应用图标 - QVariant iconData = firstIndex.data(TaskManager::WinIconRole); + // 获取图标,优先使用主题图标(会跟随主题变化),如果为空则使用窗口图标 + QVariant iconData = firstIndex.data(TaskManager::IconNameRole); if (iconData.toString().isEmpty()) { - iconData = firstIndex.data(TaskManager::IconNameRole); + iconData = firstIndex.data(TaskManager::WinIconRole); } updatePreviewIconFromString(iconData.toString()); updatePreviewTitle(firstIndex.data(TaskManager::WinTitleRole).toString());