on xenial help sign in
Added Workspace config
commitf670b0e50a9c30908692902007e87f532581c29b authorNick Dedekind <nick.dedekind@canonical.com> dateThu 23 Mar 2017, 11:54 (10 years ago) parent4711c55
13 files changed+214−17
plugins/WindowManager/CMakeLists.txt+1 plugins/WindowManager/Screen.cpp−8 plugins/WindowManager/Screen.h−3 plugins/WindowManager/Screens.cpp+16−1 plugins/WindowManager/Screens.h+6−2 plugins/WindowManager/ScreensConfiguration.cpp+94 plugins/WindowManager/ScreensConfiguration.h+32 plugins/WindowManager/WindowManagerPlugin.cpp+2−1 plugins/WindowManager/WorkspaceModel.cpp+8−1 plugins/WindowManager/WorkspaceModel.h+5 tests/mocks/WindowManager/CMakeLists.txt+1 tests/mocks/WindowManager/MockScreensConfiguration.cpp+47 tests/mocks/WindowManager/WindowManagerPlugin.cpp+2−1
plugins/WindowManager/CMakeLists.txt+1
@@ -15,6 +15,7 @@ set(WINDOWMANAGER_SRC
1515 Screen.cpp
1616 ScreenAttached.cpp
1717 Screens.cpp
18+ ScreensConfiguration.cpp
1819 ScreenWindow.cpp
1920 WindowManagerObjects.cpp
2021 Workspace.cpp
plugins/WindowManager/Screen.cpp−8
@@ -228,9 +228,6 @@ ConcreteScreen::ConcreteScreen(qtmir::Screen* wrapped)
228228 m_currentWorspace->activate();
229229 }
230230 });
231−
232− WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
233− WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
234231}
235232
236233void ConcreteScreen::resetCurrentWorkspace()
@@ -299,8 +296,3 @@ void ProxyScreen::setCurrentWorkspace(Workspace *workspace)
299296 m_original->setCurrentWorkspace(p->proxyObject());
300297 }
301298}
302−
303−void ProxyScreen::addWorkspace()
304−{
305− (new ProxyWorkspace(WorkspaceManager::instance()->createWorkspace()))->assign(workspaces());
306−}
plugins/WindowManager/Screen.h−3
@@ -124,9 +124,6 @@ public:
124124
125125 Screen* proxyObject() const { return m_original.data(); }
126126
127−public Q_SLOTS:
128− void addWorkspace();
129−
130127private:
131128 const QScopedPointer<WorkspaceModel> m_workspaces;
132129 const QPointer<Screen> m_original;
plugins/WindowManager/Screens.cpp+16−1
@@ -15,6 +15,7 @@
1515 */
1616
1717#include "Screens.h"
18+#include "ScreensConfiguration.h"
1819#include "Screen.h"
1920#include "WorkspaceManager.h"
2021
@@ -90,8 +91,9 @@ void Screens::activateScreen(const QVariant& vindex)
9091}
9192
9293
93−ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model)
94+ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model, ScreensConfiguration* config)
9495 : Screens(model)
96+ , m_config(config)
9597{
9698 m_self = this;
9799 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &ConcreteScreens::onScreenAdded);
@@ -100,11 +102,21 @@ ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model)
100102
101103 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
102104 auto screenWrapper(new ConcreteScreen(screen));
105+ m_config->load(screenWrapper);
106+
103107 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
104108 m_screens.push_back(screenWrapper);
105109 }
106110}
107111
112+ConcreteScreens::~ConcreteScreens()
113+{
114+ Q_FOREACH(Screen* screen, m_screens) {
115+ m_config->save(screen);
116+ }
117+ delete m_config;
118+}
119+
108120ConcreteScreens *ConcreteScreens::self()
109121{
110122 return ConcreteScreens::m_self;
@@ -141,6 +153,8 @@ void ConcreteScreens::onScreenAdded(qtmir::Screen *added)
141153
142154 beginInsertRows(QModelIndex(), count(), count());
143155 auto screenWrapper(new ConcreteScreen(added));
156+ m_config->load(screenWrapper);
157+
144158 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
145159 m_screens.push_back(screenWrapper);
146160 endInsertRows();
@@ -155,6 +169,7 @@ void ConcreteScreens::onScreenRemoved(qtmir::Screen *removed)
155169 while(iter.hasNext()) {
156170 auto screenWrapper = iter.next();
157171 if (screenWrapper->wrapped() == removed) {
172+ m_config->save(screenWrapper);
158173
159174 beginRemoveRows(QModelIndex(), index, index);
160175 iter.remove();
plugins/WindowManager/Screens.h+6−2
@@ -29,6 +29,7 @@ class Screens;
2929
3030class Screen;
3131class ProxyScreens;
32+class ScreensConfiguration;
3233
3334class Screens : public QAbstractListModel
3435{
@@ -41,7 +42,7 @@ public:
4142 ScreenRole = Qt::UserRole + 1
4243 };
4344
44− ~Screens();
45+ virtual ~Screens();
4546
4647 /* QAbstractItemModel */
4748 QHash<int, QByteArray> roleNames() const override;
@@ -79,7 +80,8 @@ class ConcreteScreens : public Screens
7980{
8081 Q_OBJECT
8182public:
82− explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model);
83+ explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model, ScreensConfiguration* config);
84+ ~ConcreteScreens();
8385
8486 Q_INVOKABLE ProxyScreens *createProxy();
8587 Q_INVOKABLE void sync(Screens *proxy);
@@ -91,6 +93,8 @@ protected Q_SLOTS:
9193 void onScreenRemoved(qtmir::Screen *screen);
9294
9395private:
96+ ScreensConfiguration* m_config;
97+
9498 static ConcreteScreens* m_self;
9599};
96100
plugins/WindowManager/ScreensConfiguration.cppnew file+94
@@ -0,0 +1,94 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ScreensConfiguration.h"
18+#include "Screen.h"
19+#include "Workspace.h"
20+#include "WorkspaceManager.h"
21+
22+#include <QJsonObject>
23+#include <QJsonDocument>
24+#include <QJsonArray>
25+#include <QFile>
26+#include <QStandardPaths>
27+
28+namespace
29+{
30+QJsonArray jsonScreens;
31+}
32+
33+ScreensConfiguration::ScreensConfiguration()
34+{
35+ const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
36+ QFile f(dbPath + "workspaces");
37+
38+ if (f.open(QIODevice::ReadOnly)) {
39+ QByteArray saveData = f.readAll();
40+ QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
41+ QJsonObject json(loadDoc.object());
42+ jsonScreens = json["screens"].toArray();
43+ }
44+}
45+
46+ScreensConfiguration::~ScreensConfiguration()
47+{
48+ const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
49+ QFile f(dbPath + "workspaces");
50+ if (f.open(QIODevice::WriteOnly)) {
51+ QJsonObject json;
52+ json["screens"] = jsonScreens;
53+ QJsonDocument saveDoc(json);
54+ f.write(saveDoc.toJson());
55+ }
56+}
57+
58+void ScreensConfiguration::load(Screen *screen)
59+{
60+ int workspaces = 2;
61+ for (auto iter = jsonScreens.begin(); iter != jsonScreens.end(); ++iter) {
62+ QJsonObject jsonScreen = (*iter).toObject();
63+ if (jsonScreen["name"] == screen->name()) {
64+ QJsonValue jsonWorkspaces = jsonScreen["workspaces"];
65+ workspaces = jsonWorkspaces.toInt(workspaces);
66+ break;
67+ }
68+ }
69+
70+ for (int i = 0; i < workspaces; i++) {
71+ WorkspaceManager::instance()->createWorkspace()->assign(screen->workspaces());
72+ }
73+}
74+
75+void ScreensConfiguration::save(Screen *screen)
76+{
77+ QJsonObject newJsonScreen;
78+ newJsonScreen["name"] = screen->name();
79+ newJsonScreen["workspaces"] = screen->workspaces()->rowCount();
80+
81+ auto iter = jsonScreens.begin();
82+ for (; iter != jsonScreens.end(); ++iter) {
83+ QJsonObject jsonScreen = (*iter).toObject();
84+ if (jsonScreen["name"] == screen->name()) {
85+ break;
86+ }
87+ }
88+
89+ if (iter == jsonScreens.end()) {
90+ jsonScreens.push_back(newJsonScreen);
91+ } else {
92+ *iter = newJsonScreen;
93+ }
94+}
plugins/WindowManager/ScreensConfiguration.hnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef SCREENSCONFIGURATION_H
18+#define SCREENSCONFIGURATION_H
19+
20+class Screen;
21+
22+class ScreensConfiguration
23+{
24+public:
25+ explicit ScreensConfiguration();
26+ ~ScreensConfiguration();
27+
28+ void load(Screen* screen);
29+ void save(Screen* screen);
30+};
31+
32+#endif // SCREENSCONFIGURATION_H
plugins/WindowManager/WindowManagerPlugin.cpp+2−1
@@ -19,6 +19,7 @@
1919#include "Screen.h"
2020#include "ScreenAttached.h"
2121#include "Screens.h"
22+#include "ScreensConfiguration.h"
2223#include "ScreenWindow.h"
2324#include "TopLevelWindowModel.h"
2425#include "Window.h"
@@ -80,5 +81,5 @@ void WindowManagerPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
8081 QQmlExtensionPlugin::initializeEngine(engine, uri);
8182
8283 // Create Screens
83− new ConcreteScreens(qtmir::get_screen_model());
84+ new ConcreteScreens(qtmir::get_screen_model(), new ScreensConfiguration());
8485}
plugins/WindowManager/WorkspaceModel.cpp+8−1
@@ -128,7 +128,6 @@ void WorkspaceModel::setSyncing(bool syncing)
128128
129129void WorkspaceModel::sync(WorkspaceModel *proxy)
130130{
131− qDebug() << "SYNC" << this << proxy;
132131 if (!proxy) return;
133132 const auto& proxyList = proxy->list();
134133
@@ -238,3 +237,11 @@ void ProxyWorkspaceModel::move(int from, int to)
238237{
239238 WorkspaceModel::move(from, to);
240239}
240+
241+void ProxyWorkspaceModel::addWorkspace()
242+{
243+ auto newWorkspace = WorkspaceManager::instance()->createWorkspace();
244+ m_original->m_unassignedWorkspaces.insert(newWorkspace);
245+
246+ (new ProxyWorkspace(newWorkspace))->assign(this);
247+}
plugins/WindowManager/WorkspaceModel.h+5
@@ -77,6 +77,8 @@ protected:
7777 QVector<Workspace*> m_workspaces;
7878 QSet<Workspace*> m_unassignedWorkspaces;
7979 bool m_syncing;
80+
81+ friend class ProxyWorkspaceModel;
8082};
8183
8284class ProxyWorkspaceModel : public WorkspaceModel
@@ -88,6 +90,9 @@ public:
8890
8991 Q_INVOKABLE void move(int from, int to) override;
9092
93+public Q_SLOTS:
94+ void addWorkspace();
95+
9196protected:
9297 const QPointer<WorkspaceModel> m_original;
9398};
tests/mocks/WindowManager/CMakeLists.txt+1
@@ -32,6 +32,7 @@ set(WINDOWMANAGER_SRC
3232 ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
3333 MockScreens.cpp
3434 MockScreenWindow.cpp
35+ MockScreensConfiguration.cpp
3536 WindowManagerPlugin.cpp
3637 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
3738 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
tests/mocks/WindowManager/MockScreensConfiguration.cppnew file+47
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ScreensConfiguration.h"
18+#include "Screen.h"
19+#include "Workspace.h"
20+#include "WorkspaceManager.h"
21+
22+namespace
23+{
24+const int DefaultWorkspacesCount = 2;
25+QHash<QString, int> screensConfig;
26+}
27+
28+ScreensConfiguration::ScreensConfiguration()
29+{
30+}
31+
32+ScreensConfiguration::~ScreensConfiguration()
33+{
34+}
35+
36+void ScreensConfiguration::load(Screen *screen)
37+{
38+ int workspaces = screensConfig.value(screen->name(), DefaultWorkspacesCount);
39+ for (int i = 0; i < workspaces; i++) {
40+ WorkspaceManager::instance()->createWorkspace()->assign(screen->workspaces());
41+ }
42+}
43+
44+void ScreensConfiguration::save(Screen *screen)
45+{
46+ screensConfig[screen->name()] = screen->workspaces()->rowCount();
47+}
tests/mocks/WindowManager/WindowManagerPlugin.cpp+2−1
@@ -28,6 +28,7 @@
2828#include "WorkspaceModel.h"
2929#include "WindowManagementPolicy.h"
3030#include "WindowManagerObjects.h"
31+#include "ScreensConfiguration.h"
3132
3233#include <QtQml>
3334
@@ -79,5 +80,5 @@ void WindowManagerPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
7980 // Make sure we've initialized the wm policy.
8081 WindowManagementPolicy::instance();
8182 // Create Screens
82− new ConcreteScreens(MockScreens::instance());
83+ new ConcreteScreens(MockScreens::instance(), new ScreensConfiguration());
8384}