Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple workspace backgrounds support
- Fix background not updated after setting a new wallpaper - Fix there're chances that wm dbus are not ready while launcher's trying to get the wallpaper. Change-Id: I434f82978a400cdfb532a52200185b36af770ba3
- Loading branch information
Showing
5 changed files
with
132 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (C) 2016 Deepin Technology Co., Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
**/ | ||
|
||
#include "backgroundmanager.h" | ||
|
||
#include <QGSettings> | ||
|
||
using namespace com::deepin; | ||
|
||
static const QString DefaultWallpaper = "/usr/share/backgrounds/default_background.jpg"; | ||
|
||
BackgroundManager::BackgroundManager(QObject *parent) | ||
: QObject(parent), | ||
m_currentWorkspace(0), | ||
m_wmInter(new wm("com.deepin.wm", "/com/deepin/wm", QDBusConnection::sessionBus(), this)), | ||
m_gsettings(new QGSettings("com.deepin.dde.appearance", "", this)) | ||
{ | ||
auto updateBackgrounds = [this] { | ||
setBackgrounds(m_gsettings->get("background-uris")); | ||
}; | ||
auto updateWorkspace = [this] (int, int to) { | ||
setCurrentWorkspace(to); | ||
}; | ||
|
||
connect(m_gsettings, &QGSettings::changed, updateBackgrounds); | ||
connect(m_wmInter, &__wm::WorkspaceSwitched, updateWorkspace); | ||
|
||
updateBackgrounds(); | ||
updateWorkspace(0, 0); | ||
} | ||
|
||
QString BackgroundManager::currentWorkspaceBackground() const | ||
{ | ||
if (m_backgrounds.length() >= m_currentWorkspace + 1) { | ||
return m_backgrounds.at(m_currentWorkspace); | ||
} | ||
|
||
return DefaultWallpaper; | ||
} | ||
|
||
void BackgroundManager::setBackgrounds(QVariant backgrounsVariant) | ||
{ | ||
m_backgrounds = backgrounsVariant.toStringList(); | ||
|
||
QString background = currentWorkspaceBackground(); | ||
if (background != m_currentWorkspaceBackground) { | ||
m_currentWorkspaceBackground = background; | ||
|
||
emit currentWorkspaceBackgroundChanged(background); | ||
} | ||
} | ||
|
||
int BackgroundManager::currentWorkspace() const | ||
{ | ||
return m_currentWorkspace; | ||
} | ||
|
||
void BackgroundManager::setCurrentWorkspace(int currentWorkspace) | ||
{ | ||
if (m_currentWorkspace != currentWorkspace) { | ||
m_currentWorkspace = currentWorkspace; | ||
QString background = currentWorkspaceBackground(); | ||
|
||
if (m_currentWorkspaceBackground != background) { | ||
m_currentWorkspaceBackground = background; | ||
|
||
emit currentWorkspaceBackgroundChanged(background); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (C) 2016 Deepin Technology Co., Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
**/ | ||
|
||
#ifndef BACKGROUNDMANAGER_H | ||
#define BACKGROUNDMANAGER_H | ||
|
||
#include <QObject> | ||
|
||
#include <com_deepin_wm.h> | ||
|
||
class QGSettings; | ||
|
||
class BackgroundManager : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit BackgroundManager(QObject *parent = 0); | ||
|
||
QString currentWorkspaceBackground() const; | ||
|
||
int currentWorkspace() const; | ||
void setCurrentWorkspace(int currentWorkspace); | ||
|
||
signals: | ||
void currentWorkspaceBackgroundChanged(const QString &background); | ||
|
||
private slots: | ||
void setBackgrounds(QVariant backgroundsVariant); | ||
|
||
private: | ||
int m_currentWorkspace; | ||
QString m_currentWorkspaceBackground; | ||
QStringList m_backgrounds; | ||
|
||
com::deepin::wm *m_wmInter; | ||
QGSettings *m_gsettings; | ||
}; | ||
|
||
#endif // BACKGROUNDMANAGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters