on xenial help sign in
update to latest backend code
3a0ec61Michael Zanetti
plugins/WindowManager/Screens.cpp−4
@@ -29,10 +29,6 @@
29Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
29Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
30 : m_wrapped(model)
30 : m_wrapped(model)
31{
31{
32− if (qGuiApp->platformName() != QLatin1String("mirserver")) {
33− qCritical("Not using 'mirserver' QPA plugin. Using qGuiApp may produce unknown results.");
34− }
35−
36 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &Screens::onScreenAdded);
32 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &Screens::onScreenAdded);
37 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
33 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
38 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &Screens::activeScreenChanged);
34 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &Screens::activeScreenChanged);
plugins/WindowManager/TopLevelWindowModel.cpp+60−3
@@ -29,13 +29,13 @@
29// local
29// local
30#include "Window.h"
30#include "Window.h"
31#include "Workspace.h"
31#include "Workspace.h"
32−#include "windowmanagementpolicy.h"
32+#include "wmpolicyinterface.h"
33
33
34// qtmir
34// qtmir
35#include <qtmir/mirserverapplication.h>
35#include <qtmir/mirserverapplication.h>
36#include <qtmir/windowmodelnotifier.h>
36#include <qtmir/windowmodelnotifier.h>
37
37
38−Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel")
38+Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
39
39
40#define DEBUG_MSG qCDebug(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
40#define DEBUG_MSG qCDebug(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
41#define INFO_MSG qCInfo(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
41#define INFO_MSG qCInfo(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
@@ -109,6 +109,8 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
109
109
110 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
110 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
111 this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
111 this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
112+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
113+ this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
112
114
113 if (m_workspace && m_applicationManager) {
115 if (m_workspace && m_applicationManager) {
114 refreshWindows();
116 refreshWindows();
@@ -397,6 +399,7 @@ void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface */*surf
397void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
399void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
398 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
400 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
399{
401{
402+ if (!m_workspace || !m_applicationManager) return;
400 if (workspace != m_workspace->workspace()) return;
403 if (workspace != m_workspace->workspace()) return;
401
404
402 Q_FOREACH(auto surface, surfaces) {
405 Q_FOREACH(auto surface, surfaces) {
@@ -431,6 +434,59 @@ void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral
431 }
434 }
432}
435}
433
436
437+void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
438+ const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
439+{
440+ if (workspace != m_workspace->workspace()) return;
441+
442+ int start = -1;
443+ int end = -1;
444+ for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
445+ auto surface = *iter;
446+ iter++;
447+
448+ // Do removals in adjacent blocks.
449+ start = end = indexOf(surface);
450+ if (start == -1) {
451+ // probably a child surface
452+ m_allSurfaces.remove(surface);
453+ continue;
454+ }
455+ while(iter != surfaces.constEnd()) {
456+ int index = indexOf(*iter);
457+ if (index != end+1) {
458+ break;
459+ }
460+ end++;
461+ iter++;
462+ }
463+
464+ if (m_modelState == IdleState) {
465+ beginRemoveRows(QModelIndex(), start, end);
466+ m_modelState = RemovingState;
467+ } else {
468+ Q_ASSERT(m_modelState == ResettingState);
469+ // No point in signaling anything if we're resetting the whole model
470+ }
471+
472+ for (int index = start; index <= end; index++) {
473+ auto window = m_windowModel[start].window;
474+ window->setSurface(nullptr);
475+ window->setFocused(false);
476+
477+ m_windowModel.removeAt(start);
478+ m_allSurfaces.remove(window->surface());
479+ }
480+
481+ if (m_modelState == RemovingState) {
482+ endRemoveRows();
483+ Q_EMIT countChanged();
484+ Q_EMIT listChanged();
485+ m_modelState = IdleState;
486+ }
487+ }
488+}
489+
434void TopLevelWindowModel::removeAt(int index)
490void TopLevelWindowModel::removeAt(int index)
435{
491{
436 if (m_modelState == IdleState) {
492 if (m_modelState == IdleState) {
@@ -774,7 +830,8 @@ void TopLevelWindowModel::refreshWindows()
774 m_windowModel.clear();
830 m_windowModel.clear();
775 m_allSurfaces.clear();
831 m_allSurfaces.clear();
776
832
833+ if (!m_workspace || !m_applicationManager) return;
777− WindowManagementPolicy::instance()->forEachWindowInWorkspace(m_workspace->workspace(), [this](const miral::Window &window) {
834+ WMPolicyInterface::instance()->forEachWindowInWorkspace(m_workspace->workspace(), [this](const miral::Window &window) {
778 auto surface = m_surfaceManager->surfaceFor(window);
835 auto surface = m_surfaceManager->surfaceFor(window);
779 if (surface) {
836 if (surface) {
780 if (surface->parentSurface()) {
837 if (surface->parentSurface()) {
plugins/WindowManager/TopLevelWindowModel.h+4−1
@@ -195,7 +195,10 @@ Q_SIGNALS:
195
195
196private Q_SLOTS:
196private Q_SLOTS:
197 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
197 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
198− void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace, const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
198+ void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
199+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
200+ void onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
201+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
199 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
202 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
200
203
201 void onModificationsStarted();
204 void onModificationsStarted();
plugins/WindowManager/Workspace.cpp+5−5
@@ -19,13 +19,13 @@
19#include "WorkspaceManager.h"
19#include "WorkspaceManager.h"
20#include "TopLevelWindowModel.h"
20#include "TopLevelWindowModel.h"
21
21
22−#include "windowmanagementpolicy.h"
22+#include "wmpolicyinterface.h"
23
23
24int nextWorkspace = 0;
24int nextWorkspace = 0;
25
25
26Workspace::Workspace(QObject *parent)
26Workspace::Workspace(QObject *parent)
27 : QObject(parent)
27 : QObject(parent)
28− , m_workspace(WindowManagementPolicy::instance()->createWorkspace())
28+ , m_workspace(WMPolicyInterface::instance()->createWorkspace())
29 , m_model(nullptr)
29 , m_model(nullptr)
30 , m_active(false)
30 , m_active(false)
31{
31{
@@ -38,7 +38,7 @@ Workspace::Workspace(QObject *parent)
38 Q_EMIT activeChanged(m_active);
38 Q_EMIT activeChanged(m_active);
39
39
40 if (m_active) {
40 if (m_active) {
41− WindowManagementPolicy::instance()->setActiveWorkspace(m_workspace);
41+ WMPolicyInterface::instance()->setActiveWorkspace(m_workspace);
42 }
42 }
43 }
43 }
44 });
44 });
@@ -67,7 +67,7 @@ Workspace::~Workspace()
67
67
68void Workspace::moveWindowsTo(Workspace *workspace)
68void Workspace::moveWindowsTo(Workspace *workspace)
69{
69{
70− WindowManagementPolicy::instance()->moveWorkspaceContentToWorkspace(workspace->m_workspace, m_workspace);
70+ WMPolicyInterface::instance()->moveWorkspaceContentToWorkspace(workspace->m_workspace, m_workspace);
71}
71}
72
72
73void Workspace::activate()
73void Workspace::activate()
@@ -110,7 +110,7 @@ void Workspace::unassign()
110
110
111void Workspace::release()
111void Workspace::release()
112{
112{
113− WindowManagementPolicy::instance()->releaseWorkspace(m_workspace);
113+ WMPolicyInterface::instance()->releaseWorkspace(m_workspace);
114 deleteLater();
114 deleteLater();
115}
115}
116
116
plugins/WindowManager/WorkspaceModel.h+1−1
@@ -48,7 +48,7 @@ public:
48 virtual void move(int from, int to);
48 virtual void move(int from, int to);
49
49
50 int indexOf(Workspace *workspace) const;
50 int indexOf(Workspace *workspace) const;
51− Workspace* get(int index) const;
51+ Q_INVOKABLE Workspace* get(int index) const;
52
52
53 // From QAbstractItemModel
53 // From QAbstractItemModel
54 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
54 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
qml/Shell.qml+2
@@ -187,6 +187,7 @@ StyledItem {
187 if (ApplicationManager.findApplication(appId)) {
187 if (ApplicationManager.findApplication(appId)) {
188 ApplicationManager.requestFocusApplication(appId);
188 ApplicationManager.requestFocusApplication(appId);
189 } else {
189 } else {
190+ print("calling startApplication. active workspace is", WorkspaceManager.activeWorkspace)
190 ApplicationManager.startApplication(appId);
191 ApplicationManager.startApplication(appId);
191 }
192 }
192 }
193 }
@@ -277,6 +278,7 @@ StyledItem {
277 objectName: "topLevelSurfaceList"
278 objectName: "topLevelSurfaceList"
278 applicationManager: ApplicationManager // it's a singleton
279 applicationManager: ApplicationManager // it's a singleton
279 surfaceManager: SurfaceManager
280 surfaceManager: SurfaceManager
281+ workspace: WorkspaceManager.activeWorkspace
280 }
282 }
281
283
282 Stage {
284 Stage {
qml/Stage/Spread/ScreensAndWorkspaces.qml+6−3
@@ -10,6 +10,8 @@ Item {
10
10
11 property string background
11 property string background
12
12
13+ property var screensProxy: Screens.createProxy();
14+
13 Row {
15 Row {
14 id: row
16 id: row
15 anchors.bottom: parent.bottom
17 anchors.bottom: parent.bottom
@@ -19,7 +21,7 @@ Item {
19 spacing: units.gu(1)
21 spacing: units.gu(1)
20
22
21 Repeater {
23 Repeater {
22− model: Screens
24+ model: screensProxy
23
25
24 delegate: Item {
26 delegate: Item {
25 height: root.height - units.gu(6)
27 height: root.height - units.gu(6)
@@ -92,8 +94,7 @@ Item {
92 Action {
94 Action {
93 text: "Add workspace"
95 text: "Add workspace"
94 onTriggered: {
96 onTriggered: {
95− var workspace = WorkspaceManager.createWorkspace();
97+ screen.addWorkspace();
96− workspaces.workspaceModel.append(workspace);
97 }
98 }
98 }
99 }
99 }
100 }
@@ -114,6 +115,8 @@ Item {
114 background: root.background
115 background: root.background
115
116
116 workspaceModel: model.screen.workspaces
117 workspaceModel: model.screen.workspaces
118+
119+ onCommitScreenSetup: Screens.sync(root.screensProxy)
117 }
120 }
118 }
121 }
119 }
122 }
qml/Stage/Spread/Workspaces.qml+17−8
@@ -13,6 +13,8 @@ Item {
13 property alias workspaceModel: listView.model
13 property alias workspaceModel: listView.model
14 property var background // TODO: should be stored in the workspace data
14 property var background // TODO: should be stored in the workspace data
15
15
16+ signal commitScreenSetup();
17+
16 DropArea {
18 DropArea {
17 anchors.fill: root
19 anchors.fill: root
18
20
@@ -20,7 +22,7 @@ Item {
20
22
21 onEntered: {
23 onEntered: {
22 var index = listView.getDropIndex(drag);
24 var index = listView.getDropIndex(drag);
23− listView.model.insert(index, drag.source.workspace)
25+ drag.source.workspace.assign(workspaceModel, index)
24 listView.dropItemIndex = index;
26 listView.dropItemIndex = index;
25 drag.source.inDropArea = true;
27 drag.source.inDropArea = true;
26 }
28 }
@@ -33,7 +35,7 @@ Item {
33 }
35 }
34
36
35 onExited: {
37 onExited: {
36− listView.model.remove(listView.dropItemIndex, 1);
38+ drag.source.workspace.unassign()
37 listView.dropItemIndex = -1;
39 listView.dropItemIndex = -1;
38 drag.source.inDropArea = false;
40 drag.source.inDropArea = false;
39 }
41 }
@@ -86,7 +88,6 @@ Item {
86
88
87 function progressiveScroll(mouseX) {
89 function progressiveScroll(mouseX) {
88 var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
90 var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
89− print("p", progress, mouseX)
90 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
91 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
91 }
92 }
92
93
@@ -222,9 +223,10 @@ Item {
222
223
223 onReleased: {
224 onReleased: {
224 var result = fakeDragItem.Drag.drop();
225 var result = fakeDragItem.Drag.drop();
225− if (result == Qt.IgnoreAction) {
226+// if (result == Qt.IgnoreAction) {
226− WorkspaceManager.destroyWorkspace(fakeDragItem.workspace);
227+// WorkspaceManager.destroyWorkspace(fakeDragItem.workspace);
227− }
228+// }
229+ root.commitScreenSetup();
228 drag.target = null;
230 drag.target = null;
229 }
231 }
230
232
@@ -232,7 +234,10 @@ Item {
232 onDraggingChanged: {
234 onDraggingChanged: {
233 if (drag.active) {
235 if (drag.active) {
234 print("drai", draggedIndex)
236 print("drai", draggedIndex)
237+ var ws = listView.model.get(draggedIndex);
238+ print("ws:", ws)
239+ ws.unassign();
235− listView.model.remove(draggedIndex, 1)
240+// listView.model.remove(draggedIndex, 1)
236 }
241 }
237 }
242 }
238
243
@@ -248,7 +253,7 @@ Item {
248 var itemCoords = clickedItem.mapToItem(listView, -listView.leftMargin, 0);
253 var itemCoords = clickedItem.mapToItem(listView, -listView.leftMargin, 0);
249 fakeDragItem.x = itemCoords.x
254 fakeDragItem.x = itemCoords.x
250 fakeDragItem.y = itemCoords.y
255 fakeDragItem.y = itemCoords.y
251− fakeDragItem.workspace = model.workspace
256+ fakeDragItem.workspace = listView.model.get(draggedIndex)
252
257
253 var mouseCoordsInItem = mapToItem(clickedItem, mouseX, mouseY);
258 var mouseCoordsInItem = mapToItem(clickedItem, mouseX, mouseY);
254 fakeDragItem.Drag.hotSpot.x = mouseCoordsInItem.x
259 fakeDragItem.Drag.hotSpot.x = mouseCoordsInItem.x
@@ -258,6 +263,10 @@ Item {
258 drag.target = fakeDragItem;
263 drag.target = fakeDragItem;
259 }
264 }
260
265
266+ onClicked: {
267+ WorkspaceManager.activeWorkspace = fakeDragItem.workspace
268+ }
269+
261 WorkspacePreview {
270 WorkspacePreview {
262 id: fakeDragItem
271 id: fakeDragItem
263 height: listView.height
272 height: listView.height
src/CMakeLists.txt+1
@@ -32,6 +32,7 @@ set(SOURCE_FILES
32 UnityCommandLineParser.cpp
32 UnityCommandLineParser.cpp
33 UnixSignalHandler.cpp
33 UnixSignalHandler.cpp
34 DebuggingController.cpp
34 DebuggingController.cpp
35+ WindowManagementPolicy.cpp
35 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
36 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
36)
37)
37
38
src/UnityApplication.cpp+1−1
@@ -32,7 +32,7 @@
32#include "CachingNetworkManagerFactory.h"
32#include "CachingNetworkManagerFactory.h"
33#include "UnityCommandLineParser.h"
33#include "UnityCommandLineParser.h"
34#include "DebuggingController.h"
34#include "DebuggingController.h"
35−#include "windowmanagementpolicy.h"
35+#include "WindowManagementPolicy.h"
36
36
37#include <QDebug>
37#include <QDebug>
38
38
src/libunity8-private/windowmanagementpolicy.cpp → src/WindowManagementPolicy.cpprenamed+2−11
@@ -14,27 +14,18 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#include "windowmanagementpolicy.h"
17+#include "WindowManagementPolicy.h"
18−
19−#include <QDebug>
20−
21−WindowManagementPolicy* WindowManagementPolicy::m_self = nullptr;
22
18
23WindowManagementPolicy::WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate &dd)
19WindowManagementPolicy::WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate &dd)
24 : qtmir::WindowManagementPolicy(tools, dd)
20 : qtmir::WindowManagementPolicy(tools, dd)
25 , m_dummyWorkspace(this->tools.create_workspace())
21 , m_dummyWorkspace(this->tools.create_workspace())
26{
22{
27− m_self = this;
23+ wmPolicyInterface = this;
28
24
29 // we must always have a active workspace.
25 // we must always have a active workspace.
30 m_activeWorkspace = m_dummyWorkspace;
26 m_activeWorkspace = m_dummyWorkspace;
31}
27}
32
28
33−WindowManagementPolicy *WindowManagementPolicy::instance()
34−{
35− return m_self;
36−}
37−
38void WindowManagementPolicy::advise_new_window(miral::WindowInfo const& window_info)
29void WindowManagementPolicy::advise_new_window(miral::WindowInfo const& window_info)
39{
30{
40 qtmir::WindowManagementPolicy::advise_new_window(window_info);
31 qtmir::WindowManagementPolicy::advise_new_window(window_info);
src/libunity8-private/windowmanagementpolicy.h → src/WindowManagementPolicy.hrenamed+10−9
@@ -18,32 +18,33 @@
18#define UNITY_WINDOWMANAGEMENTPOLICY_H
18#define UNITY_WINDOWMANAGEMENTPOLICY_H
19
19
20#include <qtmir/windowmanagementpolicy.h>
20#include <qtmir/windowmanagementpolicy.h>
21+#include "wmpolicyinterface.h"
21
22
22#include <unordered_set>
23#include <unordered_set>
23
24
24−class Q_DECL_EXPORT WindowManagementPolicy : public qtmir::WindowManagementPolicy
25+class Q_DECL_EXPORT WindowManagementPolicy : public qtmir::WindowManagementPolicy,
26+ public WMPolicyInterface
25{
27{
26public:
28public:
27 WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate& dd);
29 WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate& dd);
28
30
29− static WindowManagementPolicy *instance();
30−
31 void advise_new_window(miral::WindowInfo const& window_info) override;
31 void advise_new_window(miral::WindowInfo const& window_info) override;
32
32
33+ // From WMPolicyInterface
33− std::shared_ptr<miral::Workspace> createWorkspace();
34+ std::shared_ptr<miral::Workspace> createWorkspace() override;
35+
34− void releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace);
36+ void releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
35
37
36 void forEachWindowInWorkspace(
38 void forEachWindowInWorkspace(
37 std::shared_ptr<miral::Workspace> const& workspace,
39 std::shared_ptr<miral::Workspace> const& workspace,
38− std::function<void(miral::Window const& window)> const& callback);
40+ std::function<void(miral::Window const& window)> const& callback) override;
39
41
40 void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &toWorkspace,
42 void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &toWorkspace,
41− const std::shared_ptr<miral::Workspace> &fromWorkspace);
43+ const std::shared_ptr<miral::Workspace> &fromWorkspace) override;
42
44
43− void setActiveWorkspace(const std::shared_ptr<miral::Workspace>& workspace);
45+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace>& workspace) override;
44
46
45private:
47private:
46− static WindowManagementPolicy* m_self;
47 std::weak_ptr<miral::Workspace> m_activeWorkspace;
48 std::weak_ptr<miral::Workspace> m_activeWorkspace;
48
49
49 std::unordered_set<std::shared_ptr<miral::Workspace>> m_workspaces;
50 std::unordered_set<std::shared_ptr<miral::Workspace>> m_workspaces;
src/libunity8-private/CMakeLists.txt+1−10
@@ -4,26 +4,17 @@ set(VERSION ${SOVERSION}.0.0)
4
4
5project(lib${LIB_NAME})
5project(lib${LIB_NAME})
6
6
7−include_directories(
8− SYSTEM
9− ${QTMIRSERVER_INCLUDE_DIRS}
10−)
11−
12set(lib${LIB_NAME}_SRCS
7set(lib${LIB_NAME}_SRCS
13 abstractdbusservicemonitor.cpp
8 abstractdbusservicemonitor.cpp
14 unitydbusobject.cpp
9 unitydbusobject.cpp
15 unitydbusvirtualobject.cpp
10 unitydbusvirtualobject.cpp
16− windowmanagementpolicy.cpp
11+ wmpolicyinterface.cpp
17 )
12 )
18
13
19add_library(${LIB_NAME} SHARED
14add_library(${LIB_NAME} SHARED
20 ${lib${LIB_NAME}_SRCS}
15 ${lib${LIB_NAME}_SRCS}
21 )
16 )
22
17
23−target_link_libraries(${LIB_NAME}
24− ${QTMIRSERVER_LDFLAGS}
25− )
26−
27set_target_properties(${LIB_NAME} PROPERTIES
18set_target_properties(${LIB_NAME} PROPERTIES
28 VERSION ${VERSION}
19 VERSION ${VERSION}
29 SOVERSION ${SOVERSION}
20 SOVERSION ${SOVERSION}
src/libunity8-private/wmpolicyinterface.cppnew file+24
@@ -0,0 +1,24 @@
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 "wmpolicyinterface.h"
18+
19+WMPolicyInterface* wmPolicyInterface = nullptr;
20+
21+WMPolicyInterface *WMPolicyInterface::instance()
22+{
23+ return wmPolicyInterface;
24+}
src/libunity8-private/wmpolicyinterface.hnew file+51
@@ -0,0 +1,51 @@
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 WMPOLICYINTERFACE_H
18+#define WMPOLICYINTERFACE_H
19+
20+#include <memory>
21+#include <functional>
22+
23+#include <qglobal.h>
24+
25+namespace miral {
26+class Workspace;
27+class Window;
28+}
29+
30+class Q_DECL_EXPORT WMPolicyInterface
31+{
32+public:
33+ static WMPolicyInterface *instance();
34+
35+ virtual std::shared_ptr<miral::Workspace> createWorkspace() = 0;
36+
37+ virtual void releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace) = 0;
38+
39+ virtual void forEachWindowInWorkspace(
40+ std::shared_ptr<miral::Workspace> const& workspace,
41+ std::function<void(miral::Window const& window)> const& callback) = 0;
42+
43+ virtual void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &toWorkspace,
44+ const std::shared_ptr<miral::Workspace> &fromWorkspace) = 0;
45+
46+ virtual void setActiveWorkspace(const std::shared_ptr<miral::Workspace>& workspace) = 0;
47+};
48+
49+extern Q_DECL_EXPORT WMPolicyInterface* wmPolicyInterface;
50+
51+#endif // WMPOLICYINTERFACE_H
tests/mocks/Unity/Application/CMakeLists.txt+1
@@ -4,6 +4,7 @@ include_directories(
4 SYSTEM
4 SYSTEM
5 ${MIRTEST_INCLUDE_DIRS}
5 ${MIRTEST_INCLUDE_DIRS}
6 ${MIRAL_INCLUDE_DIRS}
6 ${MIRAL_INCLUDE_DIRS}
7+ ${libunity8-private_SOURCE_DIR}
7)
8)
8
9
9set(FakeUnityApplicationQml_SOURCES
10set(FakeUnityApplicationQml_SOURCES
tests/mocks/Unity/Application/SurfaceManager.cpp+1−1
@@ -18,7 +18,7 @@
18
18
19#include "ApplicationInfo.h"
19#include "ApplicationInfo.h"
20#include "VirtualKeyboard.h"
20#include "VirtualKeyboard.h"
21−#include "../../WindowManager/windowmanagementpolicy.h"
21+#include "../../WindowManager/WindowManagementPolicy.h"
22
22
23#include <paths.h>
23#include <paths.h>
24#include <mirtest/mir/test/doubles/stub_surface.h>
24#include <mirtest/mir/test/doubles/stub_surface.h>
tests/mocks/WindowManager/CMakeLists.txt+3−1
@@ -7,13 +7,15 @@ include_directories(
7 ${CMAKE_CURRENT_SOURCE_DIR}
7 ${CMAKE_CURRENT_SOURCE_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
9 ${CMAKE_SOURCE_DIR}/plugins/WindowManager
9 ${CMAKE_SOURCE_DIR}/plugins/WindowManager
10+ ${libunity8-private_SOURCE_DIR}
10)
11)
11
12
12add_library(mockwindowmanagmentpolicy SHARED
13add_library(mockwindowmanagmentpolicy SHARED
13− windowmanagementpolicy.cpp
14+ WindowManagementPolicy.cpp
14)
15)
15target_link_libraries(mockwindowmanagmentpolicy
16target_link_libraries(mockwindowmanagmentpolicy
16 ${MIRAL_LDFLAGS}
17 ${MIRAL_LDFLAGS}
18+ unity8-private
17)
19)
18qt5_use_modules(mockwindowmanagmentpolicy Core)
20qt5_use_modules(mockwindowmanagmentpolicy Core)
19
21
tests/mocks/WindowManager/windowmanagementpolicy.cpp → tests/mocks/WindowManager/WindowManagementPolicy.cpprenamed+9−6
@@ -14,20 +14,23 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#include "windowmanagementpolicy.h"
17+#include "WindowManagementPolicy.h"
18
18
19−WindowManagementPolicy *WindowManagementPolicy::instance()
19+#include <QDebug>
20−{
21− static WindowManagementPolicy* inst(new WindowManagementPolicy());
22− return inst;
23−}
24
20
25WindowManagementPolicy::WindowManagementPolicy()
21WindowManagementPolicy::WindowManagementPolicy()
26 : m_dummyWorkspace(std::shared_ptr<miral::Workspace>())
22 : m_dummyWorkspace(std::shared_ptr<miral::Workspace>())
27{
23{
24+ wmPolicyInterface = this;
28 m_activeWorkspace = m_dummyWorkspace;
25 m_activeWorkspace = m_dummyWorkspace;
29}
26}
30
27
28+WindowManagementPolicy *WindowManagementPolicy::instance()
29+{
30+ static WindowManagementPolicy* wmPolicy(new WindowManagementPolicy);
31+ return wmPolicy;
32+}
33+
31std::shared_ptr<miral::Workspace> WindowManagementPolicy::createWorkspace()
34std::shared_ptr<miral::Workspace> WindowManagementPolicy::createWorkspace()
32{
35{
33 auto workspace = std::make_shared<miral::Workspace>();
36 auto workspace = std::make_shared<miral::Workspace>();
tests/mocks/WindowManager/windowmanagementpolicy.h → tests/mocks/WindowManager/WindowManagementPolicy.hrenamed+13−7
@@ -17,6 +17,8 @@
17#ifndef MOCKWINDOMANAGEMENTPOLICY_H
17#ifndef MOCKWINDOMANAGEMENTPOLICY_H
18#define MOCKWINDOMANAGEMENTPOLICY_H
18#define MOCKWINDOMANAGEMENTPOLICY_H
19
19
20+#include "wmpolicyinterface.h"
21+
20#include <QObject>
22#include <QObject>
21#include <QMultiMap>
23#include <QMultiMap>
22#include <QVector>
24#include <QVector>
@@ -30,26 +32,30 @@ class Workspace {};
30}
32}
31
33
32// A Fake window management policy for the mock.
34// A Fake window management policy for the mock.
33−class Q_DECL_EXPORT WindowManagementPolicy : public QObject
35+class Q_DECL_EXPORT WindowManagementPolicy : public QObject,
36+ public WMPolicyInterface
34{
37{
35 Q_OBJECT
38 Q_OBJECT
36public:
39public:
37 WindowManagementPolicy();
40 WindowManagementPolicy();
38
41
42+ // for use in mocks
39 static WindowManagementPolicy *instance();
43 static WindowManagementPolicy *instance();
40
44
45+ // From WMPolicyInterface
41− std::shared_ptr<miral::Workspace> createWorkspace();
46+ std::shared_ptr<miral::Workspace> createWorkspace() override;
47+
42− void releaseWorkspace(const std::shared_ptr<miral::Workspace>& workspace);
48+ void releaseWorkspace(const std::shared_ptr<miral::Workspace>& workspace) override;
43
49
44 void forEachWindowInWorkspace(std::shared_ptr<miral::Workspace> const& workspace,
50 void forEachWindowInWorkspace(std::shared_ptr<miral::Workspace> const& workspace,
45− std::function<void(miral::Window const&)> const& callback);
51+ std::function<void(miral::Window const&)> const& callback) override;
46
52
47 void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace>& to,
53 void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace>& to,
48− const std::shared_ptr<miral::Workspace>& from);
54+ const std::shared_ptr<miral::Workspace>& from) override;
49
55
50− void addWindow(const miral::Window& window);
56+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace>& workspace) override;
51
57
52− void setActiveWorkspace(const std::shared_ptr<miral::Workspace>& workspace);
58+ void addWindow(const miral::Window& window);
53
59
54Q_SIGNALS:
60Q_SIGNALS:
55 void windowAdded(const miral::Window& window);
61 void windowAdded(const miral::Window& window);
tests/mocks/WindowManager/WindowManagerPlugin.cpp+9
@@ -25,6 +25,7 @@
25#include "WorkspaceManager.h"
25#include "WorkspaceManager.h"
26#include "Workspace.h"
26#include "Workspace.h"
27#include "WorkspaceModel.h"
27#include "WorkspaceModel.h"
28+#include "WindowManagementPolicy.h"
28
29
29#include <QtQml>
30#include <QtQml>
30
31
@@ -60,3 +61,11 @@ void WindowManagerPlugin::registerTypes(const char *uri)
60 qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
61 qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
61 qmlRegisterRevision<QWindow,1>(uri, 1, 0);
62 qmlRegisterRevision<QWindow,1>(uri, 1, 0);
62}
63}
64+
65+void WindowManagerPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
66+{
67+ QQmlExtensionPlugin::initializeEngine(engine, uri);
68+
69+ // Make sure we've initialized the wm policy.
70+ WindowManagementPolicy::instance();
71+}
tests/mocks/WindowManager/WindowManagerPlugin.h+1
@@ -27,6 +27,7 @@ class WindowManagerPlugin : public QQmlExtensionPlugin
27
27
28public:
28public:
29 void registerTypes(const char *uri) override;
29 void registerTypes(const char *uri) override;
30+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
30};
31};
31
32
32#endif // WINDOWMANAGER_PLUGIN_H
33#endif // WINDOWMANAGER_PLUGIN_H
tests/qmltests/tst_Shell.qml+1−1
@@ -73,7 +73,7 @@ Rectangle {
73
73
74 QtObject {
74 QtObject {
75 id: _screenWindow
75 id: _screenWindow
76− property bool primary: false
76+ property bool primary: true
77 }
77 }
78 property alias screenWindow: _screenWindow
78 property alias screenWindow: _screenWindow
79
79