Skip to content

Commit

Permalink
fix: 切换主题外观桌面壁纸被替换
Browse files Browse the repository at this point in the history
当桌面壁纸为用户自定义的壁纸时, 主题应该切换为自定义主题
当用户去修改主题的其它选项(非壁纸)时, 桌面壁纸不随主题变化

Log: 修复切换主题外观桌面壁纸被替换的问题
Resolve: linuxdeepin/developer-center#4198
  • Loading branch information
dengbo11 committed May 5, 2023
1 parent 0319eb8 commit cb72504
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
33 changes: 33 additions & 0 deletions src/service/impl/appearancemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ void AppearanceManager::doUpdateWallpaperURIs()
}

setPropertyWallpaperURIs(monitorWallpaperUris);
// 如果是用户自己设置的桌面壁纸, 需要将主题更新为自定义
if (!monitorWallpaperUris.first().startsWith("/usr/share/wallpapers/deepin")) {
updateCustomTheme(TYPEWALLPAPER, monitorWallpaperUris.first());
}
}

void AppearanceManager::setPropertyWallpaperURIs(QMap<QString, QString> monitorWallpaperUris)
Expand Down Expand Up @@ -1617,6 +1621,10 @@ void AppearanceManager::applyGlobalTheme(KeyFile &theme, const QString &themeNam
};
auto setGlobalFile = [&theme, &themeName, &defTheme, &themePath, this](const QString &key, const QString &type) {
QString themeValue = theme.getStr(themeName, key);
// 如果是用户自定义的桌面壁纸, 切换主题的外观时, 不重新设置壁纸
if (isSkipSetWallpaper(themePath) && type == TYPEWALLPAPER) {
return;
}
if (themeValue.isEmpty() && !defTheme.isEmpty())
themeValue = theme.getStr(defTheme, key);
if (!themeValue.isEmpty()) {
Expand All @@ -1643,6 +1651,31 @@ void AppearanceManager::applyGlobalTheme(KeyFile &theme, const QString &themeNam
globalThemeUpdating = false;
}

// 自定义主题在切换主题外观时跳过设置桌面壁纸
bool AppearanceManager::isSkipSetWallpaper(const QString &themePath)
{
if (!themePath.endsWith("custom")) {
return false;
}

KeyFile theme(',');
theme.loadFile(themePath + "/index.theme");
QStringList themeNames {"DefaultTheme", "DarkTheme"};
for (const auto &name : themeNames) {
QString themeName = theme.getStr("Deepin Theme", name);
if (themeName.isEmpty()) {
continue;
}

QString themeValue = theme.getStr(themeName, "Wallpaper");
if (!themeValue.startsWith("/usr/share/wallpapers/deepin")) {
return true;
}
}

return false;
}

void AppearanceManager::updateCustomTheme(const QString &type, const QString &value)
{
if (!globalThemeUpdating) {
Expand Down
1 change: 1 addition & 0 deletions src/service/impl/appearancemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public Q_SLOTS:
QVector<Background> backgroundListVerify(const QVector<Background>& backgrounds);
QString getWallpaperUri(const QString &index, const QString &monitorName);
void initGlobalTheme();
bool isSkipSetWallpaper(const QString &themePath);

Q_SIGNALS:
void Changed(const QString &ty, const QString &value);
Expand Down
4 changes: 1 addition & 3 deletions src/service/modules/subthemes/customtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CustomTheme::CustomTheme(QObject *parent)
void CustomTheme::updateValue(const QString &type, const QString &value, const QString &oldTheme, const QVector<QSharedPointer<Theme>> &globalThemes)
{
static const QMap<QString, QString> typekeyMap = {
{ TYPEBACKGROUND, "Wallpaper" },
{ TYPEWALLPAPER, "Wallpaper" },
{ TYPEGREETERBACKGROUND, "LockBackground" },
{ TYPEICON, "IconTheme" },
{ TYPECURSOR, "CursorTheme" },
Expand All @@ -33,9 +33,7 @@ void CustomTheme::updateValue(const QString &type, const QString &value, const Q
{ TYPEMONOSPACEFONT, "MonospaceFont" },
{ TYPEFONTSIZE, "FontSize" },
{ TYPEACTIVECOLOR, "ActiveColor" },
// { TYPESTANDARDFONT, "DockBackground" },
{ TYPEDOCKOPACITY, "DockOpacity" },
// { TYPESTANDARDFONT, "LauncherOpacity" },
{ TYPWINDOWRADIUS, "WindowRadius" },
{ TYPEWINDOWOPACITY, "WindowOpacity" }
};
Expand Down

0 comments on commit cb72504

Please sign in to comment.