Skip to content

Commit

Permalink
fix: [background] Unable to obtain the correct wallpaper in multi Wor…
Browse files Browse the repository at this point in the history
…kspace after reboot.

Log: When starting the desktop, read the configuration file to obtain the correct workspace.

Bug: https://pms.uniontech.com/bug-view-197559.html
  • Loading branch information
LiHua000 authored and deepin-bot[bot] committed Jul 11, 2023
1 parent 793cace commit 5f470ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/plugins/desktop/ddplugin-background/backgroundservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BackgroundService::BackgroundService(QObject *parent)
wmInter->setTimeout(200);
qInfo() << "create com.deepin.wm end";

currentWorkspaceIndex = getCurrentWorkspaceIndex();
connect(wmInter, &WMInter::WorkspaceSwitched, this, &BackgroundService::onWorkspaceSwitched);
}

Expand All @@ -37,3 +38,20 @@ QString BackgroundService::getDefaultBackground()
{
return QString("/usr/share/backgrounds/default_background.jpg");
}

int BackgroundService::getCurrentWorkspaceIndex()
{
QString configPath = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/kwinrc";
QSettings settings(configPath, QSettings::IniFormat);

bool ok = false;
int currentIdx = settings.value("Workspace/CurrentDesktop", 1).toInt(&ok);
qInfo() << "get currentWorkspaceIndex form config : " << currentIdx;

if (!ok || currentIdx < 1) {
currentIdx = 1;
qWarning() << "No CurrentWorkspaceIndex obtained, Check if the configuration file has changed";
}

return currentIdx;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected slots:
void onWorkspaceSwitched(int from, int to);

protected:
int getCurrentWorkspaceIndex();
int currentWorkspaceIndex = 1; // worksapce index is started with 1.
WMInter *wmInter = nullptr;
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/desktop/ddplugin-background/backgroundwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ QString BackgroundWM::getBackgroundFromWm(const QString &screen)
QString BackgroundWM::getBackgroundFromConfig(const QString &screen)
{
QString path;
QString homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first();
QFile wmFile(homePath + "/.config/deepinwmrc");
QString configPath = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first();
QFile wmFile(configPath + "/deepinwmrc");
if (wmFile.open(QIODevice::ReadOnly | QIODevice::Text)) {

// Find the background path based on the workspace and screen name
Expand Down

0 comments on commit 5f470ec

Please sign in to comment.