on xenial help sign in
Added Workspace config
f670b0eNick Dedekind
plugins/WindowManager/CMakeLists.txt+1
@@ -15,6 +15,7 @@ set(WINDOWMANAGER_SRC
15 Screen.cpp
15 Screen.cpp
16 ScreenAttached.cpp
16 ScreenAttached.cpp
17 Screens.cpp
17 Screens.cpp
18+ ScreensConfiguration.cpp
18 ScreenWindow.cpp
19 ScreenWindow.cpp
19 WindowManagerObjects.cpp
20 WindowManagerObjects.cpp
20 Workspace.cpp
21 Workspace.cpp
plugins/WindowManager/Screen.cpp−8
@@ -228,9 +228,6 @@ ConcreteScreen::ConcreteScreen(qtmir::Screen* wrapped)
228 m_currentWorspace->activate();
228 m_currentWorspace->activate();
229 }
229 }
230 });
230 });
231−
232− WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
233− WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
234}
231}
235
232
236void ConcreteScreen::resetCurrentWorkspace()
233void ConcreteScreen::resetCurrentWorkspace()
@@ -299,8 +296,3 @@ void ProxyScreen::setCurrentWorkspace(Workspace *workspace)
299 m_original->setCurrentWorkspace(p->proxyObject());
296 m_original->setCurrentWorkspace(p->proxyObject());
300 }
297 }
301}
298}
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:
124
124
125 Screen* proxyObject() const { return m_original.data(); }
125 Screen* proxyObject() const { return m_original.data(); }
126
126
127−public Q_SLOTS:
128− void addWorkspace();
129−
130private:
127private:
131 const QScopedPointer<WorkspaceModel> m_workspaces;
128 const QScopedPointer<WorkspaceModel> m_workspaces;
132 const QPointer<Screen> m_original;
129 const QPointer<Screen> m_original;
plugins/WindowManager/Screens.cpp+16−1
@@ -15,6 +15,7 @@
15 */
15 */
16
16
17#include "Screens.h"
17#include "Screens.h"
18+#include "ScreensConfiguration.h"
18#include "Screen.h"
19#include "Screen.h"
19#include "WorkspaceManager.h"
20#include "WorkspaceManager.h"
20
21
@@ -90,8 +91,9 @@ void Screens::activateScreen(const QVariant& vindex)
90}
91}
91
92
92
93
93−ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model)
94+ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model, ScreensConfiguration* config)
94 : Screens(model)
95 : Screens(model)
96+ , m_config(config)
95{
97{
96 m_self = this;
98 m_self = this;
97 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &ConcreteScreens::onScreenAdded);
99 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &ConcreteScreens::onScreenAdded);
@@ -100,11 +102,21 @@ ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model)
100
102
101 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
103 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
102 auto screenWrapper(new ConcreteScreen(screen));
104 auto screenWrapper(new ConcreteScreen(screen));
105+ m_config->load(screenWrapper);
106+
103 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
107 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
104 m_screens.push_back(screenWrapper);
108 m_screens.push_back(screenWrapper);
105 }
109 }
106}
110}
107
111
112+ConcreteScreens::~ConcreteScreens()
113+{
114+ Q_FOREACH(Screen* screen, m_screens) {
115+ m_config->save(screen);
116+ }
117+ delete m_config;
118+}
119+
108ConcreteScreens *ConcreteScreens::self()
120ConcreteScreens *ConcreteScreens::self()
109{
121{
110 return ConcreteScreens::m_self;
122 return ConcreteScreens::m_self;
@@ -141,6 +153,8 @@ void ConcreteScreens::onScreenAdded(qtmir::Screen *added)
141
153
142 beginInsertRows(QModelIndex(), count(), count());
154 beginInsertRows(QModelIndex(), count(), count());
143 auto screenWrapper(new ConcreteScreen(added));
155 auto screenWrapper(new ConcreteScreen(added));
156+ m_config->load(screenWrapper);
157+
144 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
158 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
145 m_screens.push_back(screenWrapper);
159 m_screens.push_back(screenWrapper);
146 endInsertRows();
160 endInsertRows();
@@ -155,6 +169,7 @@ void ConcreteScreens::onScreenRemoved(qtmir::Screen *removed)
155 while(iter.hasNext()) {
169 while(iter.hasNext()) {
156 auto screenWrapper = iter.next();
170 auto screenWrapper = iter.next();
157 if (screenWrapper->wrapped() == removed) {
171 if (screenWrapper->wrapped() == removed) {
172+ m_config->save(screenWrapper);
158
173
159 beginRemoveRows(QModelIndex(), index, index);
174 beginRemoveRows(QModelIndex(), index, index);
160 iter.remove();
175 iter.remove();
plugins/WindowManager/Screens.h+6−2
@@ -29,6 +29,7 @@ class Screens;
29
29
30class Screen;
30class Screen;
31class ProxyScreens;
31class ProxyScreens;
32+class ScreensConfiguration;
32
33
33class Screens : public QAbstractListModel
34class Screens : public QAbstractListModel
34{
35{
@@ -41,7 +42,7 @@ public:
41 ScreenRole = Qt::UserRole + 1
42 ScreenRole = Qt::UserRole + 1
42 };
43 };
43
44
44− ~Screens();
45+ virtual ~Screens();
45
46
46 /* QAbstractItemModel */
47 /* QAbstractItemModel */
47 QHash<int, QByteArray> roleNames() const override;
48 QHash<int, QByteArray> roleNames() const override;
@@ -79,7 +80,8 @@ class ConcreteScreens : public Screens
79{
80{
80 Q_OBJECT
81 Q_OBJECT
81public:
82public:
82− explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model);
83+ explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model, ScreensConfiguration* config);
84+ ~ConcreteScreens();
83
85
84 Q_INVOKABLE ProxyScreens *createProxy();
86 Q_INVOKABLE ProxyScreens *createProxy();
85 Q_INVOKABLE void sync(Screens *proxy);
87 Q_INVOKABLE void sync(Screens *proxy);
@@ -91,6 +93,8 @@ protected Q_SLOTS:
91 void onScreenRemoved(qtmir::Screen *screen);
93 void onScreenRemoved(qtmir::Screen *screen);
92
94
93private:
95private:
96+ ScreensConfiguration* m_config;
97+
94 static ConcreteScreens* m_self;
98 static ConcreteScreens* m_self;
95};
99};
96
100
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 @@
19#include "Screen.h"
19#include "Screen.h"
20#include "ScreenAttached.h"
20#include "ScreenAttached.h"
21#include "Screens.h"
21#include "Screens.h"
22+#include "ScreensConfiguration.h"
22#include "ScreenWindow.h"
23#include "ScreenWindow.h"
23#include "TopLevelWindowModel.h"
24#include "TopLevelWindowModel.h"
24#include "Window.h"
25#include "Window.h"
@@ -80,5 +81,5 @@ void WindowManagerPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
80 QQmlExtensionPlugin::initializeEngine(engine, uri);
81 QQmlExtensionPlugin::initializeEngine(engine, uri);
81
82
82 // Create Screens
83 // Create Screens
83− new ConcreteScreens(qtmir::get_screen_model());
84+ new ConcreteScreens(qtmir::get_screen_model(), new ScreensConfiguration());
84}
85}
plugins/WindowManager/WorkspaceModel.cpp+8−1
@@ -128,7 +128,6 @@ void WorkspaceModel::setSyncing(bool syncing)
128
128
129void WorkspaceModel::sync(WorkspaceModel *proxy)
129void WorkspaceModel::sync(WorkspaceModel *proxy)
130{
130{
131− qDebug() << "SYNC" << this << proxy;
132 if (!proxy) return;
131 if (!proxy) return;
133 const auto& proxyList = proxy->list();
132 const auto& proxyList = proxy->list();
134
133
@@ -238,3 +237,11 @@ void ProxyWorkspaceModel::move(int from, int to)
238{
237{
239 WorkspaceModel::move(from, to);
238 WorkspaceModel::move(from, to);
240}
239}
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:
77 QVector<Workspace*> m_workspaces;
77 QVector<Workspace*> m_workspaces;
78 QSet<Workspace*> m_unassignedWorkspaces;
78 QSet<Workspace*> m_unassignedWorkspaces;
79 bool m_syncing;
79 bool m_syncing;
80+
81+ friend class ProxyWorkspaceModel;
80};
82};
81
83
82class ProxyWorkspaceModel : public WorkspaceModel
84class ProxyWorkspaceModel : public WorkspaceModel
@@ -88,6 +90,9 @@ public:
88
90
89 Q_INVOKABLE void move(int from, int to) override;
91 Q_INVOKABLE void move(int from, int to) override;
90
92
93+public Q_SLOTS:
94+ void addWorkspace();
95+
91protected:
96protected:
92 const QPointer<WorkspaceModel> m_original;
97 const QPointer<WorkspaceModel> m_original;
93};
98};
tests/mocks/WindowManager/CMakeLists.txt+1
@@ -32,6 +32,7 @@ set(WINDOWMANAGER_SRC
32 ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
32 ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
33 MockScreens.cpp
33 MockScreens.cpp
34 MockScreenWindow.cpp
34 MockScreenWindow.cpp
35+ MockScreensConfiguration.cpp
35 WindowManagerPlugin.cpp
36 WindowManagerPlugin.cpp
36 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
37 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
37 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
38 ${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 @@
28#include "WorkspaceModel.h"
28#include "WorkspaceModel.h"
29#include "WindowManagementPolicy.h"
29#include "WindowManagementPolicy.h"
30#include "WindowManagerObjects.h"
30#include "WindowManagerObjects.h"
31+#include "ScreensConfiguration.h"
31
32
32#include <QtQml>
33#include <QtQml>
33
34
@@ -79,5 +80,5 @@ void WindowManagerPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
79 // Make sure we've initialized the wm policy.
80 // Make sure we've initialized the wm policy.
80 WindowManagementPolicy::instance();
81 WindowManagementPolicy::instance();
81 // Create Screens
82 // Create Screens
82− new ConcreteScreens(MockScreens::instance());
83+ new ConcreteScreens(MockScreens::instance(), new ScreensConfiguration());
83}
84}