on xenial help sign in
merge new prereq
commit01de8a1b46d9ad3c97323a45ece54129b8a94235 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 23 Feb 2017, 12:40 (10 years ago) parent563bcf42710ca1
41 files changed+1278−332
CMakeLists.txt+4−1 debian/control+2 plugins/WindowManager/CMakeLists.txt+17−2 plugins/WindowManager/Screen.cpp+124 plugins/WindowManager/Screen.h+46 tests/mocks/Unity/Screens/screenwindow.cpp → plugins/WindowManager/ScreenWindow.cpp+16−3 tests/mocks/Unity/Screens/screenwindow.h → plugins/WindowManager/ScreenWindow.h+13−6 plugins/WindowManager/Screens.cpp+129 plugins/WindowManager/Screens.h+71 plugins/WindowManager/WindowManagerPlugin.cpp+27 plugins/WindowManager/Workspace.cpp+63 plugins/WindowManager/Workspace.h+44 plugins/WindowManager/WorkspaceManager.cpp+47 plugins/WindowManager/WorkspaceManager.h+41 plugins/WindowManager/WorkspaceModel.cpp+90 plugins/WindowManager/WorkspaceModel.h+63 qml/Components/VirtualTouchPad.qml+1−1 qml/OrientedShell.qml+1−1 qml/ShellApplication.qml+1−1 qml/ShellScreen.qml+1−1 src/CMakeLists.txt+2−1 src/ShellApplication.cpp+29−16 src/ShellApplication.h+5−3 src/main.cpp+1−7 tests/mocks/CMakeLists.txt+1 tests/mocks/Unity/CMakeLists.txt−1 tests/mocks/Unity/Screens/CMakeLists.txt−15 tests/mocks/Unity/Screens/plugin.cpp−42 tests/mocks/Unity/Screens/plugin.h−25 tests/mocks/Unity/Screens/qmldir−2 tests/mocks/Unity/Screens/screens.h−162 tests/mocks/WindowManager/CMakeLists.txt+35 tests/mocks/WindowManager/Screen.cpp+65 tests/mocks/WindowManager/Screen.h+56 tests/mocks/WindowManager/ScreenWindow.cpp+48 tests/mocks/WindowManager/ScreenWindow.h+49 tests/mocks/Unity/Screens/screens.cpp → tests/mocks/WindowManager/Screens.cpp+29−42 tests/mocks/WindowManager/Screens.h+65 tests/mocks/WindowManager/WindowManagerPlugin.cpp+58 tests/mocks/WindowManager/WindowManagerPlugin.h+32 tests/mocks/WindowManager/qmldir+2
CMakeLists.txt+4−1
@@ -71,6 +71,7 @@ find_package(Qt5Concurrent 5.6 REQUIRED)
7171find_package(Qt5Sql 5.6 REQUIRED)
7272
7373pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=27)
74+pkg_check_modules(QTMIRSERVER REQUIRED qtmirserver>=0.6.0)
7475pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
7576pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
7677pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
@@ -112,7 +113,9 @@ if(SHELL_PLUGINDIR STREQUAL "")
112113 message(FATAL_ERROR "Could not determine plugin import dir.")
113114endif()
114115
115−set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra")
116+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-permissive -pedantic -Wall -Wextra")
117+
118+set (CMAKE_CXX_STANDARD 14)
116119
117120if ("${CMAKE_BUILD_TYPE}" STREQUAL "release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "relwithdebinfo")
118121 option(Werror "Treat warnings as errors" ON)
debian/control+2
@@ -68,6 +68,7 @@ Build-Depends: cmake,
6868 qtdeclarative5-private-dev (>= 5.6),
6969 qtdeclarative5-ubuntu-content1,
7070 qtdeclarative5-ubuntu-settings-components (>= 0.11),
71+ qtmir-dev (>= 0.6.0),
7172 ttf-ubuntu-font-family,
7273 xvfb,
7374Standards-Version: 3.9.4
@@ -131,6 +132,7 @@ Depends: dmz-cursor-theme,
131132 qml-module-ubuntu-web,
132133 qtdeclarative5-qtmir-plugin (>= 0.4.8),
133134 qtdeclarative5-ubuntu-telephony0.1,
135+ qtmir-desktop (>= 0.6.0) | qtmir-android (>= 0.6.0),
134136 ubuntu-system-settings (>= 0.4),
135137 unity-launcher-impl-10,
136138 unity8-common (= ${source:Version}),
plugins/WindowManager/CMakeLists.txt+17−2
@@ -1,16 +1,31 @@
1+include_directories(
2+ SYSTEM
3+ ${QTMIRSERVER_INCLUDE_DIRS}
4+)
5+
16set(WINDOWMANAGER_SRC
27 TopLevelWindowModel.cpp
38 Window.cpp
49 WindowManagerPlugin.cpp
10+ Screens.cpp
11+ Screen.cpp
12+ ScreenWindow.cpp
13+ Workspace.cpp
14+ WorkspaceManager.cpp
15+ WorkspaceModel.cpp
516 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
617 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
718 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
819 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
920 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
10− )
21+)
1122
1223add_library(windowmanager-qml SHARED ${WINDOWMANAGER_SRC})
1324
25+target_link_libraries(windowmanager-qml
26+ ${QTMIRSERVER_LDFLAGS}
27+)
28+
1429qt5_use_modules(windowmanager-qml Qml Quick Gui)
1530
16−add_unity8_plugin(WindowManager 0.1 WindowManager TARGETS windowmanager-qml)
31+add_unity8_plugin(WindowManager 1.0 WindowManager TARGETS windowmanager-qml)
plugins/WindowManager/Screen.cppnew file+124
@@ -0,0 +1,124 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Screen.h"
18+#include "WorkspaceModel.h"
19+#include "WorkspaceManager.h"
20+#include "Workspace.h"
21+
22+Screen::Screen(qtmir::Screen* screen)
23+ : m_wrapped(screen)
24+ , m_workspaces(new WorkspaceModel)
25+{
26+ connect(m_wrapped, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
27+ connect(m_wrapped, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
28+ connect(m_wrapped, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
29+ connect(m_wrapped, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
30+ connect(m_wrapped, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
31+ connect(m_wrapped, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
32+ connect(m_wrapped, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
33+ connect(m_wrapped, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
34+ connect(m_wrapped, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
35+ connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
36+
37+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
38+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
39+}
40+
41+qtmir::OutputId Screen::outputId() const
42+{
43+ return m_wrapped->outputId();
44+}
45+
46+bool Screen::used() const
47+{
48+ return m_wrapped->used();
49+}
50+
51+QString Screen::name() const
52+{
53+ return m_wrapped->name();
54+}
55+
56+float Screen::scale() const
57+{
58+ return m_wrapped->scale();
59+}
60+
61+QSizeF Screen::physicalSize() const
62+{
63+ return m_wrapped->physicalSize();
64+}
65+
66+qtmir::FormFactor Screen::formFactor() const
67+{
68+ return m_wrapped->formFactor();
69+}
70+
71+qtmir::OutputTypes Screen::outputType() const
72+{
73+ return m_wrapped->outputType();
74+}
75+
76+MirPowerMode Screen::powerMode() const
77+{
78+ return m_wrapped->powerMode();
79+}
80+
81+Qt::ScreenOrientation Screen::orientation() const
82+{
83+ return m_wrapped->orientation();
84+}
85+
86+QPoint Screen::position() const
87+{
88+ return m_wrapped->position();
89+}
90+
91+QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
92+{
93+ return m_wrapped->availableModes();
94+}
95+
96+uint Screen::currentModeIndex() const
97+{
98+ return m_wrapped->currentModeIndex();
99+}
100+
101+bool Screen::isActive() const
102+{
103+ return m_wrapped->isActive();
104+}
105+
106+qtmir::ScreenConfiguration *Screen::beginConfiguration() const
107+{
108+ return m_wrapped->beginConfiguration();
109+}
110+
111+bool Screen::applyConfiguration(qtmir::ScreenConfiguration *configuration)
112+{
113+ return m_wrapped->applyConfiguration(configuration);
114+}
115+
116+void Screen::setActive(bool active)
117+{
118+ m_wrapped->setActive(active);
119+}
120+
121+QScreen *Screen::qscreen() const
122+{
123+ return m_wrapped->qscreen();
124+}
plugins/WindowManager/Screen.hnew file+46
@@ -0,0 +1,46 @@
1+#ifndef SCREEN_H
2+#define SCREEN_H
3+
4+#include <qtmir/screen.h>
5+#include <QScopedPointer>
6+
7+class WorkspaceModel;
8+
9+class Screen : public qtmir::Screen
10+{
11+ Q_OBJECT
12+ Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
13+
14+public:
15+ explicit Screen(qtmir::Screen*const wrapped);
16+
17+ qtmir::OutputId outputId() const override;
18+ bool used() const override;
19+ QString name() const override;
20+ float scale() const override;
21+ QSizeF physicalSize() const override;
22+ qtmir::FormFactor formFactor() const override;
23+ qtmir::OutputTypes outputType() const override;
24+ MirPowerMode powerMode() const override;
25+ Qt::ScreenOrientation orientation() const override;
26+ QPoint position() const override;
27+ QQmlListProperty<qtmir::ScreenMode> availableModes() override;
28+ uint currentModeIndex() const override;
29+ bool isActive() const override;
30+ void setActive(bool active) override;
31+
32+ QScreen* qscreen() const override;
33+
34+ qtmir::ScreenConfiguration *beginConfiguration() const override;
35+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override;
36+
37+ qtmir::Screen* wrapped() const { return m_wrapped; }
38+
39+ WorkspaceModel* workspaces() const { return m_workspaces.data(); }
40+
41+private:
42+ qtmir::Screen*const m_wrapped;
43+ const QScopedPointer<WorkspaceModel> m_workspaces;
44+};
45+
46+#endif // SCREEN_H
tests/mocks/Unity/Screens/screenwindow.cpp → plugins/WindowManager/ScreenWindow.cpprenamed+16−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2016 Canonical, Ltd.
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -14,10 +14,22 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#include "screenwindow.h"
17+#include "ScreenWindow.h"
18+#include "Screen.h"
1819
19−ScreenWindow::ScreenWindow(QWindow *parent)
20+// Qt
21+#include <QGuiApplication>
22+#include <QDebug>
23+
24+ScreenWindow::ScreenWindow(QQuickWindow *parent)
2025 : QQuickWindow(parent)
26+{
27+ if (qGuiApp->platformName() != QLatin1String("mirserver")) {
28+ qCritical("Not using 'mirserver' QPA plugin. Using ScreenWindow may produce unknown results.");
29+ }
30+}
31+
32+ScreenWindow::~ScreenWindow()
2133{
2234}
2335
@@ -32,4 +44,5 @@ void ScreenWindow::setScreenWrapper(Screen *screen)
3244 m_screen = screen;
3345 Q_EMIT screenWrapperChanged();
3446 }
47+ QQuickWindow::setScreen(screen->qscreen());
3548}
tests/mocks/Unity/Screens/screenwindow.h → plugins/WindowManager/ScreenWindow.hrenamed+13−6
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2016 Canonical, Ltd.
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -14,20 +14,27 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef SCREENWINDOW_H
18−#define SCREENWINDOW_H
17+#ifndef UNITY_SCREENWINDOW_H
18+#define UNITY_SCREENWINDOW_H
1919
2020#include <QQuickWindow>
2121#include <QPointer>
2222
23−#include "screens.h"
23+#include "Screen.h"
2424
25+class ScreenAdapter;
26+
27+/*
28+ * ScreenWindow - wrapper of QQuickWindow to enable QML to specify destination screen.
29+**/
2530class ScreenWindow : public QQuickWindow
2631{
2732 Q_OBJECT
2833 Q_PROPERTY(Screen *screen READ screenWrapper WRITE setScreenWrapper NOTIFY screenWrapperChanged)
34+ Q_PROPERTY(int winId READ winId CONSTANT)
2935public:
30− ScreenWindow(QWindow *parent = 0);
36+ explicit ScreenWindow(QQuickWindow *parent = 0);
37+ ~ScreenWindow();
3138
3239 Screen *screenWrapper() const;
3340 void setScreenWrapper(Screen *screen);
@@ -39,4 +46,4 @@ private:
3946 QPointer<Screen> m_screen;
4047};
4148
42−#endif // SCREENWINDOW_H
49+#endif // UNITY_SCREENWINDOW_H
plugins/WindowManager/Screens.cppnew file+129
@@ -0,0 +1,129 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Screens.h"
18+#include "Screen.h"
19+
20+// qtmirserver
21+#include <qtmir/qtmir.h>
22+#include <qtmir/screens.h>
23+#include <QGuiApplication>
24+
25+// Qt
26+#include <QScreen>
27+#include <QWindow>
28+
29+Screens::Screens(QObject *parent)
30+ : QAbstractListModel(parent)
31+ , m_wrapped(qtmir::get_screen_model())
32+{
33+ if (qGuiApp->platformName() != QLatin1String("mirserver")) {
34+ qCritical("Not using 'mirserver' QPA plugin. Using qGuiApp may produce unknown results.");
35+ }
36+
37+ connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &Screens::onScreenAdded);
38+ connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
39+ connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &Screens::activeScreenChanged);
40+
41+ Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
42+ m_screenList.push_back(new Screen(screen));
43+ }
44+}
45+
46+QHash<int, QByteArray> Screens::roleNames() const
47+{
48+ QHash<int, QByteArray> roles;
49+ roles[ScreenRole] = "screen";
50+ return roles;
51+}
52+
53+QVariant Screens::data(const QModelIndex &index, int role) const
54+{
55+ if (!index.isValid() || index.row() >= m_screenList.size()) {
56+ return QVariant();
57+ }
58+
59+ switch(role) {
60+ case ScreenRole:
61+ return QVariant::fromValue(m_screenList.at(index.row()));
62+ } // switch
63+
64+ return QVariant();
65+}
66+
67+int Screens::rowCount(const QModelIndex &) const
68+{
69+ return count();
70+}
71+
72+int Screens::count() const
73+{
74+ return m_screenList.size();
75+}
76+
77+QVariant Screens::activeScreen() const
78+{
79+ for (int i = 0; i < m_screenList.count(); i++) {
80+ if (m_screenList[i]->isActive()) return i;
81+ }
82+ return QVariant();
83+}
84+
85+void Screens::activateScreen(const QVariant& vindex)
86+{
87+ bool ok = false;
88+ int index = vindex.toInt(&ok);
89+ if (!ok || index < 0 || m_screenList.count() <= index) return;
90+
91+ auto screen = m_screenList.at(index);
92+ screen->setActive(true);
93+}
94+
95+void Screens::onScreenAdded(qtmir::Screen *screen)
96+{
97+ Q_FOREACH(auto screenWrapper, m_screenList) {
98+ if (screenWrapper->wrapped() == screen) return;
99+ }
100+
101+ beginInsertRows(QModelIndex(), count(), count());
102+ auto screenWrapper(new Screen(screen));
103+ m_screenList.push_back(screenWrapper);
104+ endInsertRows();
105+ Q_EMIT screenAdded(screenWrapper);
106+ Q_EMIT countChanged();
107+}
108+
109+void Screens::onScreenRemoved(qtmir::Screen *screen)
110+{
111+ int index = 0;
112+ QMutableListIterator<Screen*> iter(m_screenList);
113+ while(iter.hasNext()) {
114+ auto screenWrapper = iter.next();
115+ if (screenWrapper->wrapped() == screen) {
116+
117+ beginRemoveRows(QModelIndex(), index, index);
118+ iter.remove();
119+ endRemoveRows();
120+
121+ Q_EMIT screenRemoved(screenWrapper);
122+ Q_EMIT countChanged();
123+
124+ screenWrapper->deleteLater();
125+ break;
126+ }
127+ index++;
128+ }
129+}
plugins/WindowManager/Screens.hnew file+71
@@ -0,0 +1,71 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_SCREENS_H
18+#define UNITY_SCREENS_H
19+
20+#include <QAbstractListModel>
21+#include <QSharedPointer>
22+
23+class Screen;
24+namespace qtmir
25+{
26+class Screen;
27+class Screens;
28+}
29+
30+class Screens : public QAbstractListModel
31+{
32+ Q_OBJECT
33+ Q_PROPERTY(int count READ count NOTIFY countChanged)
34+ Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
35+
36+public:
37+ enum ItemRoles {
38+ ScreenRole = Qt::UserRole + 1
39+ };
40+
41+ explicit Screens(QObject *parent = 0);
42+ virtual ~Screens() noexcept = default;
43+
44+ /* QAbstractItemModel */
45+ QHash<int, QByteArray> roleNames() const override;
46+ QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
47+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
48+
49+ int count() const;
50+ QVariant activeScreen() const;
51+
52+public Q_SLOTS:
53+ void activateScreen(const QVariant& index);
54+
55+Q_SIGNALS:
56+ void countChanged();
57+ void activeScreenChanged();
58+
59+ void screenAdded(Screen* screen);
60+ void screenRemoved(Screen* screen);
61+
62+private Q_SLOTS:
63+ void onScreenAdded(qtmir::Screen *screen);
64+ void onScreenRemoved(qtmir::Screen *screen);
65+
66+private:
67+ QList<Screen*> m_screenList;
68+ QSharedPointer<qtmir::Screens> m_wrapped;
69+};
70+
71+#endif // SCREENS_H
plugins/WindowManager/WindowManagerPlugin.cpp+27
@@ -16,16 +16,43 @@
1616
1717#include "WindowManagerPlugin.h"
1818
19+#include "Screens.h"
20+#include "Screen.h"
21+#include "ScreenWindow.h"
1922#include "TopLevelWindowModel.h"
2023#include "Window.h"
24+#include "WorkspaceManager.h"
25+#include "Workspace.h"
26+#include "WorkspaceModel.h"
2127
2228#include <QtQml>
2329
30+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
31+{
32+ Q_UNUSED(engine)
33+ Q_UNUSED(scriptEngine)
34+ return WorkspaceManager::instance();
35+}
36+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
37+ Q_UNUSED(engine);
38+ Q_UNUSED(scriptEngine);
39+ return new Screens();
40+}
41+
2442void WindowManagerPlugin::registerTypes(const char *uri)
2543{
2644 qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
45+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
46+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", "Not a creatable type");
47+ qmlRegisterSingletonType<Screens>(uri, 1, 0, "Screens", screensSingleton);
48+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", "ScreenMode is not creatable.");
2749
2850 qRegisterMetaType<Window*>("Window*");
51+ qRegisterMetaType<Workspace*>("Workspace*");
2952
3053 qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
54+ qRegisterMetaType<Screen*>("Screen*");
55+
56+ qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
57+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
3158}
plugins/WindowManager/Workspace.cppnew file+63
@@ -0,0 +1,63 @@
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 "Workspace.h"
18+#include "WorkspaceModel.h"
19+
20+Workspace::Workspace(QObject *parent)
21+ : QObject(parent)
22+ , m_model(nullptr)
23+{
24+
25+}
26+
27+Workspace::~Workspace()
28+{
29+ unassign();
30+}
31+
32+void Workspace::assign(WorkspaceModel *model)
33+{
34+ bool wasAssinged = false;
35+ if (m_model) {
36+ disconnect(model);
37+ m_model->remove(this);
38+ wasAssinged = true;
39+ }
40+
41+ m_model = model;
42+ if (model) {
43+ model->append(this);
44+
45+ connect(model, &QObject::destroyed, this, [this]() {
46+ m_model = nullptr;
47+ Q_EMIT unassigned();
48+ });
49+ Q_EMIT assigned();
50+ } else if (wasAssinged) {
51+ Q_EMIT unassigned();
52+ }
53+}
54+
55+void Workspace::unassign()
56+{
57+ if (m_model) {
58+ m_model->remove(this);
59+ m_model = nullptr;
60+
61+ Q_EMIT unassigned();
62+ }
63+}
plugins/WindowManager/Workspace.hnew file+44
@@ -0,0 +1,44 @@
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 WORKSPACE_H
18+#define WORKSPACE_H
19+
20+#include <QObject>
21+
22+class WorkspaceModel;
23+
24+class Workspace : public QObject
25+{
26+ Q_OBJECT
27+public:
28+ explicit Workspace(QObject *parent = 0);
29+ ~Workspace();
30+
31+ Q_INVOKABLE void assign(WorkspaceModel* model);
32+
33+public Q_SLOT:
34+ void unassign();
35+
36+Q_SIGNALS:
37+ void assigned();
38+ void unassigned();
39+
40+private:
41+ WorkspaceModel* m_model;
42+};
43+
44+#endif // WORKSPACE_H
plugins/WindowManager/WorkspaceManager.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 "WorkspaceManager.h"
18+#include "Workspace.h"
19+
20+// Qt
21+#include <QGuiApplication>
22+#include <QScreen>
23+#include <QQmlEngine>
24+
25+WorkspaceManager *WorkspaceManager::instance()
26+{
27+ static WorkspaceManager* workspaceManager(new WorkspaceManager());
28+ return workspaceManager;
29+}
30+
31+WorkspaceManager::WorkspaceManager()
32+{
33+}
34+Workspace *WorkspaceManager::createWorkspace()
35+{
36+ auto workspace = new Workspace(this);
37+ QQmlEngine::setObjectOwnership(workspace, QQmlEngine::CppOwnership);
38+ m_allWorkspaces.append(workspace);
39+ workspace->assign(this);
40+ return workspace;
41+}
42+
43+void WorkspaceManager::destroyWorkspace(Workspace *workspace)
44+{
45+ workspace->deleteLater();
46+}
47+
plugins/WindowManager/WorkspaceManager.hnew file+41
@@ -0,0 +1,41 @@
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 WORKSPACEMANAGER_H
18+#define WORKSPACEMANAGER_H
19+
20+#include "WorkspaceModel.h"
21+
22+class Workspace;
23+
24+class WorkspaceManager : public WorkspaceModel
25+{
26+ Q_OBJECT
27+public:
28+ static WorkspaceManager* instance();
29+
30+private:
31+ WorkspaceManager();
32+
33+public Q_SLOTS:
34+ Workspace* createWorkspace();
35+ void destroyWorkspace(Workspace* workspace);
36+
37+private:
38+ QVector<Workspace*> m_allWorkspaces;
39+};
40+
41+#endif // WORKSPACEMANAGER_H
plugins/WindowManager/WorkspaceModel.cppnew file+90
@@ -0,0 +1,90 @@
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 "WorkspaceModel.h"
18+#include "Workspace.h"
19+
20+Q_LOGGING_CATEGORY(WORKSPACES, "Workspaces", QtInfoMsg)
21+
22+#define DEBUG_MSG qCDebug(WORKSPACES).nospace().noquote() << __func__
23+#define INFO_MSG qCInfo(WORKSPACES).nospace().noquote() << __func__
24+
25+WorkspaceModel::WorkspaceModel(QObject *parent)
26+ : QAbstractListModel(parent)
27+{
28+}
29+
30+void WorkspaceModel::append(Workspace *workspace)
31+{
32+ insert(m_workspaces.count(), workspace);
33+}
34+
35+void WorkspaceModel::insert(int index, Workspace *workspace)
36+{
37+ beginInsertRows(QModelIndex(), index, index);
38+ m_workspaces.append(workspace);
39+ endInsertRows();
40+ Q_EMIT countChanged();
41+}
42+
43+void WorkspaceModel::remove(Workspace *workspace)
44+{
45+ int index = m_workspaces.indexOf(workspace);
46+ if (index < 0) return;
47+
48+ beginRemoveRows(QModelIndex(), index, index);
49+ m_workspaces.removeAt(index);
50+ endRemoveRows();
51+ Q_EMIT countChanged();
52+}
53+
54+void WorkspaceModel::move(int from, int to)
55+{
56+ if (from == to) return;
57+ DEBUG_MSG << " from=" << from << " to=" << to;
58+
59+ if (from >= 0 && from < m_workspaces.size() && to >= 0 && to < m_workspaces.size()) {
60+ QModelIndex parent;
61+
62+ beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
63+#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
64+ const auto &window = m_windowModel.takeAt(from);
65+ m_workspaces.insert(to, window);
66+#else
67+ m_workspaces.move(from, to);
68+#endif
69+ endMoveRows();
70+ Q_EMIT countChanged();
71+ }
72+}
73+
74+int WorkspaceModel::rowCount(const QModelIndex &) const
75+{
76+ return m_workspaces.count();
77+}
78+
79+QVariant WorkspaceModel::data(const QModelIndex &index, int role) const
80+{
81+ if (index.row() < 0 || index.row() >= m_workspaces.size())
82+ return QVariant();
83+
84+ if (role == WorkspaceRole) {
85+ Workspace *workspace = m_workspaces.at(index.row());
86+ return QVariant::fromValue(workspace);
87+ } else {
88+ return QVariant();
89+ }
90+}
plugins/WindowManager/WorkspaceModel.hnew file+63
@@ -0,0 +1,63 @@
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 WORKSPACEMODEL_H
18+#define WORKSPACEMODEL_H
19+
20+#include <QAbstractListModel>
21+#include <QLoggingCategory>
22+
23+Q_DECLARE_LOGGING_CATEGORY(WORKSPACES)
24+
25+class Workspace;
26+
27+class WorkspaceModel : public QAbstractListModel
28+{
29+ Q_OBJECT
30+ Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
31+public:
32+ /**
33+ * @brief The Roles supported by the model
34+ *
35+ * WorkspaceRole - A workspace.
36+ */
37+ enum Roles {
38+ WorkspaceRole = Qt::UserRole
39+ };
40+
41+ explicit WorkspaceModel(QObject *parent = 0);
42+
43+ void append(Workspace* workspace);
44+ void insert(int index, Workspace* workspace);
45+ void remove(Workspace* workspace);
46+ void move(int from, int to);
47+
48+ // From QAbstractItemModel
49+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
50+ QVariant data(const QModelIndex& index, int role) const override;
51+ QHash<int, QByteArray> roleNames() const override {
52+ QHash<int, QByteArray> roleNames { {WorkspaceRole, "workspace"} };
53+ return roleNames;
54+ }
55+
56+Q_SIGNALS:
57+ void countChanged();
58+
59+protected:
60+ QVector<Workspace*> m_workspaces;
61+};
62+
63+#endif // WORKSPACEMODEL_H
qml/Components/VirtualTouchPad.qml+1−1
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import QtQuick.Layouts 1.1
1919import Ubuntu.Components 1.3
2020import Qt.labs.settings 1.0
21−import Unity.Screens 0.1
21+import WindowManager 1.0
2222import UInput 0.1
2323import "../Components"
2424
qml/OrientedShell.qml+1−1
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import QtQuick.Window 2.2
1919import Unity.InputInfo 0.1
2020import Unity.Session 0.1
21−import Unity.Screens 0.1
21+import WindowManager 1.0
2222import Utils 0.1
2323import GSettings 1.0
2424import "Components"
qml/ShellApplication.qml+1−1
@@ -16,7 +16,7 @@
1616
1717import QtQuick 2.4
1818import QtQuick.Window 2.2
19−import Unity.Screens 0.1
19+import WindowManager 1.0
2020import Unity.Application 0.1
2121
2222Instantiator {
qml/ShellScreen.qml+1−1
@@ -16,7 +16,7 @@
1616
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
19−import Unity.Screens 0.1
19+import WindowManager 1.0
2020import Cursor 1.1
2121import "Components"
2222
src/CMakeLists.txt+2−1
@@ -7,6 +7,7 @@ include_directories(
77 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
88 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
99 ${CONNECTIVITY_INCLUDE_DIRS}
10+ ${QTMIRSERVER_INCLUDE_DIRS}
1011)
1112
1213include_directories(
@@ -45,7 +46,7 @@ qt5_use_modules(${SHELL_APP} DBus Gui Qml Quick Test)
4546if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
4647 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
4748endif()
48−target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} UbuntuGestures connectivity-qt1 unity8-private)
49+target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} UbuntuGestures connectivity-qt1 unity8-private qtmirserver)
4950
5051if (ENABLE_TOUCH_EMULATION)
5152 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
src/ShellApplication.cpp+29−16
@@ -33,14 +33,39 @@
3333#include "UnityCommandLineParser.h"
3434#include "DebuggingController.h"
3535
36−ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
37− : QGuiApplication(argc, argv)
36+#include <QDebug>
37+
38+#include <qtmir/windowmanagementpolicy.h>
39+
40+class WindowManagementPolicy : public qtmir::WindowManagementPolicy
41+{
42+public:
43+ WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate& dd)
44+ : qtmir::WindowManagementPolicy(tools, dd)
45+ {}
46+
47+// virtual void advise_adding_to_workspace(
48+// std::shared_ptr<miral::Workspace> const& workspace,
49+// std::vector<miral::Window> const& windows) override
50+// {
51+// }
52+
53+// virtual void advise_removing_from_workspace(
54+// std::shared_ptr<miral::Workspace> const& workspace,
55+// std::vector<miral::Window> const& windows) override
56+// {
57+// }
58+};
59+
60+
61+ShellApplication::ShellApplication(int & argc, char ** argv)
62+ : qtmir::MirServerApplication(argc, argv, {})
3863 , m_qmlArgs(this)
3964{
4065 setApplicationName(QStringLiteral("unity8"));
4166 setOrganizationName(QStringLiteral("Canonical"));
4267
43− setupQmlEngine(isMirServer);
68+ setupQmlEngine();
4469
4570 if (m_qmlArgs.deviceName().isEmpty()) {
4671 char buffer[200];
@@ -89,18 +114,9 @@ ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
89114 #endif
90115
91116 if (m_qmlArgs.mode().compare("greeter") == 0) {
92−// QSize primaryScreenSize = this->primaryScreen()->size();
93−// m_shellView->setHeight(primaryScreenSize.height());
94−// m_shellView->setWidth(primaryScreenSize.width());
95−// m_shellView->show();
96−// m_shellView->requestActivate();
97117 if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
98118 qDebug() << "Unable to send unity8-greeter-started event to Upstart";
99119 }
100−// } else if (isMirServer || parser.hasFullscreen()) {
101−// m_shellView->showFullScreen();
102−// } else {
103−// m_shellView->show();
104120 }
105121}
106122
@@ -120,16 +136,13 @@ void ShellApplication::destroyResources()
120136 m_qmlEngine = nullptr;
121137}
122138
123−void ShellApplication::setupQmlEngine(bool isMirServer)
139+void ShellApplication::setupQmlEngine()
124140{
125141 m_qmlEngine = new QQmlApplicationEngine(this);
126142
127143 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
128144
129145 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
130− if (!isMirServer) {
131− prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
132− }
133146 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
134147
135148 m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
src/ShellApplication.h+5−3
@@ -28,17 +28,19 @@
2828#include "MouseTouchAdaptor.h"
2929#endif
3030
31−class ShellApplication : public QGuiApplication
31+#include <qtmir/mirserverapplication.h>
32+
33+class ShellApplication : public qtmir::MirServerApplication
3234{
3335 Q_OBJECT
3436public:
35− ShellApplication(int & argc, char ** argv, bool isMirServer);
37+ ShellApplication(int & argc, char ** argv);
3638 virtual ~ShellApplication();
3739
3840 void destroyResources();
3941
4042private:
41− void setupQmlEngine(bool isMirServer);
43+ void setupQmlEngine();
4244 ApplicationArguments m_qmlArgs;
4345
4446 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
src/main.cpp+1−7
@@ -27,17 +27,11 @@ int main(int argc, const char *argv[])
2727{
2828 qSetMessagePattern("[%{time yyyy-MM-dd:hh:mm:ss.zzz}] %{if-category}%{category}: %{endif}%{message}");
2929
30− bool isMirServer = qgetenv("QT_QPA_PLATFORM") == "mirserver";
31− if (!isMirServer && qgetenv("QT_QPA_PLATFORM") == "ubuntumirclient") {
32− setenv("QT_QPA_PLATFORM", "mirserver", 1 /* overwrite */);
33− isMirServer = true;
34− }
35−
3630 if (enableQmlDebugger(argc, argv)) {
3731 QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true);
3832 }
3933
40− ShellApplication *application = new ShellApplication(argc, (char**)argv, isMirServer);
34+ ShellApplication *application = new ShellApplication(argc, (char**)argv);
4135
4236 UnixSignalHandler signalHandler([]{
4337 QGuiApplication::exit(0);
tests/mocks/CMakeLists.txt+1
@@ -43,6 +43,7 @@ add_subdirectory(SessionBroadcast)
4343add_subdirectory(Ubuntu)
4444add_subdirectory(Unity)
4545add_subdirectory(QtMultimedia)
46+add_subdirectory(WindowManager)
4647add_subdirectory(Wizard)
4748add_subdirectory(Utils)
4849add_subdirectory(UInput)
tests/mocks/Unity/CMakeLists.txt−1
@@ -6,7 +6,6 @@ add_subdirectory(InputInfo)
66add_subdirectory(Launcher)
77add_subdirectory(Notifications)
88add_subdirectory(DashCommunicator)
9−add_subdirectory(Screens)
109add_subdirectory(Platform)
1110
1211pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
tests/mocks/Unity/Screens/CMakeLists.txtdeleted−15
@@ -1,15 +0,0 @@
1−include_directories(
2− ${CMAKE_CURRENT_SOURCE_DIR}
3−)
4−
5−set(MockScreens_SOURCES
6− plugin.cpp
7− screens.cpp
8− screenwindow.cpp
9−)
10−
11−add_library(MockScreensPlugin MODULE ${MockScreens_SOURCES})
12−
13−qt5_use_modules(MockScreensPlugin Gui Qml Quick)
14−
15−add_unity8_mock(Unity.Screens 0.1 Unity/Screens PREFIX mocks TARGETS MockScreensPlugin)
tests/mocks/Unity/Screens/plugin.cppdeleted−42
@@ -1,42 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "plugin.h"
18−#include "screens.h"
19−#include "screenwindow.h"
20−
21−#include <QScreen>
22−
23−namespace {
24−QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
25− Q_UNUSED(engine);
26− Q_UNUSED(scriptEngine);
27− return new Screens();
28−}
29−}
30−
31−void UnityScreensPlugin::registerTypes(const char* uri)
32−{
33− Q_ASSERT(QLatin1String(uri) == QLatin1String("Unity.Screens"));
34−
35− qRegisterMetaType<QScreen*>("QScreen*");
36− qRegisterMetaType<ScreenMode*>("ScreenMode*");
37− qmlRegisterUncreatableType<ScreenMode>(uri, 0, 1, "ScreenMode", "ScreenMode is not creatable.");
38−
39− qmlRegisterSingletonType<Screens>(uri, 0, 1, "Screens", screensSingleton);
40− qmlRegisterType<ScreenWindow>(uri, 0, 1, "ScreenWindow");
41− qmlRegisterRevision<QWindow,1>(uri, 0, 1);
42−}
tests/mocks/Unity/Screens/plugin.hdeleted−25
@@ -1,25 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include <QQmlExtensionPlugin>
18−#include <QtQml/qqml.h>
19−
20−class UnityScreensPlugin : public QQmlExtensionPlugin {
21− Q_OBJECT
22− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
23−public:
24− void registerTypes(const char* uri) override;
25−};
tests/mocks/Unity/Screens/qmldirdeleted−2
@@ -1,2 +0,0 @@
1−module Unity.Screens
2−plugin MockScreensPlugin
tests/mocks/Unity/Screens/screens.hdeleted−162
@@ -1,162 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef SCREENS_H
18−#define SCREENS_H
19−
20−#include <QAbstractListModel>
21−#include <QScreen>
22−#include <QQmlListProperty>
23−
24−class Screen;
25−
26−class Screens : public QAbstractListModel
27−{
28− Q_OBJECT
29−
30− Q_PROPERTY(int count READ count NOTIFY countChanged)
31−
32−public:
33− enum ItemRoles {
34− ScreenRole = Qt::UserRole + 1,
35− OutputTypeRole,
36− EnabledRole,
37− NameRole,
38− ScaleRole,
39− FormFactorRole,
40− GeometryRole,
41− SizesRole
42− };
43−
44− enum OutputTypes {
45− Unknown,
46− VGA,
47− DVII,
48− DVID,
49− DVIA,
50− Composite,
51− SVideo,
52− LVDS,
53− Component,
54− NinePinDIN,
55− DisplayPort,
56− HDMIA,
57− HDMIB,
58− TV,
59− EDP
60− };
61− Q_ENUM(OutputTypes)
62−
63− enum FormFactor {
64− FormFactorUnknown,
65− FormFactorPhone,
66− FormFactorTablet,
67− FormFactorMonitor,
68− FormFactorTV,
69− FormFactorProjector,
70− };
71−
72− explicit Screens(QObject *parent = 0);
73− virtual ~Screens() noexcept;
74−
75− /* QAbstractItemModel */
76− QHash<int, QByteArray> roleNames() const override;
77− QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
78− int rowCount(const QModelIndex &parent = QModelIndex()) const override;
79−
80− int count() const;
81−
82−public Q_SLOTS:
83− void activateScreen(int index);
84−
85−Q_SIGNALS:
86− void countChanged();
87− void screenAdded(QScreen *screen);
88− void screenRemoved(QScreen *screen);
89−
90−private:
91− QList<Screen *> m_screenList;
92−};
93−
94−class ScreenMode : public QObject
95−{
96− Q_OBJECT
97− Q_PROPERTY(qreal refreshRate MEMBER refreshRate CONSTANT)
98− Q_PROPERTY(QSize size MEMBER size CONSTANT)
99−public:
100− ScreenMode() {}
101− ScreenMode(qreal refreshRate, QSize size):refreshRate(refreshRate),size(size) {}
102− ScreenMode(const ScreenMode& other)
103− : QObject(nullptr),
104− refreshRate{other.refreshRate},size{other.size}
105− {}
106−
107− qreal refreshRate;
108− QSize size;
109−};
110−
111−class Screen : public QObject
112−{
113− Q_OBJECT
114−
115− Q_PROPERTY(bool active MEMBER m_active NOTIFY activeChanged)
116−
117− Q_PROPERTY(bool used MEMBER m_used NOTIFY usedChanged)
118− Q_PROPERTY(QString name MEMBER m_name NOTIFY nameChanged)
119− Q_PROPERTY(Screens::OutputTypes outputType MEMBER m_outputType NOTIFY outputTypeChanged)
120− Q_PROPERTY(float scale MEMBER m_scale NOTIFY scaleChanged)
121− Q_PROPERTY(Screens::FormFactor formFactor MEMBER m_formFactor NOTIFY formFactorChanged)
122− Q_PROPERTY(QPoint position MEMBER m_position NOTIFY positionChanged)
123− Q_PROPERTY(uint currentModeIndex MEMBER m_currentModeIndex NOTIFY currentModeIndexChanged)
124− Q_PROPERTY(QQmlListProperty<ScreenMode> availableModes READ availableModes NOTIFY availableModesChanged)
125− Q_PROPERTY(QSizeF physicalSize MEMBER m_physicalSize NOTIFY physicalSizeChanged)
126−public:
127− Screen(QObject* parent = 0);
128− ~Screen();
129−
130− QQmlListProperty<ScreenMode> availableModes();
131−
132− Q_INVOKABLE Screen* beginConfiguration();
133− Q_INVOKABLE void applyConfiguration();
134−
135−Q_SIGNALS:
136− void activeChanged();
137− void usedChanged();
138− void nameChanged();
139− void outputTypeChanged();
140− void scaleChanged();
141− void formFactorChanged();
142− void positionChanged();
143− void currentModeIndexChanged();
144− void availableModesChanged();
145− void physicalSizeChanged();
146−
147−public:
148− bool m_active{false};
149− bool m_used{true};
150− QString m_name;
151− Screens::OutputTypes m_outputType{Screens::Unknown};
152− float m_scale{1.0};
153− Screens::FormFactor m_formFactor{Screens::FormFactorMonitor};
154− QPoint m_position;
155− uint m_currentModeIndex{0};
156− QList<ScreenMode*> m_sizes;
157− QSizeF m_physicalSize;
158−};
159−
160−Q_DECLARE_METATYPE(ScreenMode)
161−
162−#endif // SCREENS_H
tests/mocks/WindowManager/CMakeLists.txtnew file+35
@@ -0,0 +1,35 @@
1+include_directories(
2+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager
3+)
4+
5+include_directories(
6+ SYSTEM
7+ ${QTMIRSERVER_INCLUDE_DIRS}
8+)
9+
10+set(WINDOWMANAGER_SRC
11+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/TopLevelWindowModel.cpp
12+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Window.cpp
13+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
14+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceManager.cpp
15+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceModel.cpp
16+ WindowManagerPlugin.cpp
17+ Screens.cpp
18+ Screen.cpp
19+ ScreenWindow.cpp
20+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
21+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
22+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
23+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
24+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
25+)
26+
27+add_library(MockWindowManager-qml SHARED ${WINDOWMANAGER_SRC})
28+
29+target_link_libraries(MockWindowManager-qml
30+ ${QTMIRSERVER_LDFLAGS}
31+)
32+
33+qt5_use_modules(MockWindowManager-qml Qml Quick Gui)
34+
35+add_unity8_mock(WindowManager 1.0 WindowManager TARGETS MockWindowManager-qml)
tests/mocks/WindowManager/Screen.cppnew file+65
@@ -0,0 +1,65 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Screen.h"
18+#include "WorkspaceModel.h"
19+#include "WorkspaceManager.h"
20+#include "Workspace.h"
21+
22+Screen::Screen()
23+ : m_workspaces(new WorkspaceModel)
24+{
25+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
26+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
27+}
28+
29+QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
30+{
31+ return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
32+}
33+
34+qtmir::ScreenConfiguration *Screen::beginConfiguration() const
35+{
36+ auto config = new qtmir::ScreenConfiguration;
37+ config->valid = true;
38+ config->id = m_id;
39+ config->used = m_used;
40+ config->topLeft = m_position;
41+ config->currentModeIndex = m_currentModeIndex;
42+ config->powerMode = m_powerMode;
43+ config->scale = m_scale;
44+ config->formFactor = m_formFactor;
45+ return config;
46+}
47+
48+bool Screen::applyConfiguration(qtmir::ScreenConfiguration *configuration)
49+{
50+ m_used = configuration->used;
51+ m_position = configuration->topLeft;
52+ m_currentModeIndex = configuration->currentModeIndex;
53+ m_powerMode = configuration->powerMode;
54+ m_scale = configuration->scale;
55+ m_formFactor = configuration->formFactor;
56+
57+// m_orientation = configuration->orientation;
58+ return true;
59+}
60+
61+void Screen::setActive(bool active)
62+{
63+ m_active = active;
64+ Q_EMIT activeChanged(active);
65+}
tests/mocks/WindowManager/Screen.hnew file+56
@@ -0,0 +1,56 @@
1+#ifndef MOCK_SCREEN_H
2+#define MOCK_SCREEN_H
3+
4+#include <qtmir/screen.h>
5+#include <QScopedPointer>
6+
7+class WorkspaceModel;
8+
9+class Screen : public qtmir::Screen
10+{
11+ Q_OBJECT
12+ Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
13+
14+public:
15+ Screen();
16+
17+ qtmir::OutputId outputId() const override { return m_id; }
18+ bool used() const override { return m_used; }
19+ QString name() const override { return m_name; }
20+ float scale() const override { return m_scale; }
21+ QSizeF physicalSize() const override { return m_physicalSize; }
22+ qtmir::FormFactor formFactor() const override { return m_formFactor; }
23+ qtmir::OutputTypes outputType() const override { return m_outputType; }
24+ MirPowerMode powerMode() const override { return m_powerMode; }
25+ Qt::ScreenOrientation orientation() const override { return m_orientation; }
26+ QPoint position() const override { return m_position; }
27+ QQmlListProperty<qtmir::ScreenMode> availableModes() override;
28+ uint currentModeIndex() const override { return m_currentModeIndex; }
29+ bool isActive() const override { return m_active; }
30+ void setActive(bool active) override;
31+
32+ QScreen* qscreen() const override { return nullptr; }
33+
34+ qtmir::ScreenConfiguration *beginConfiguration() const override;
35+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override;
36+
37+ WorkspaceModel* workspaces() const { return m_workspaces.data(); }
38+
39+public:
40+ qtmir::OutputId m_id{0};
41+ bool m_active{false};
42+ bool m_used{true};
43+ QString m_name;
44+ qtmir::OutputTypes m_outputType{qtmir::Unknown};
45+ MirPowerMode m_powerMode{mir_power_mode_on};
46+ Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
47+ float m_scale{1.0};
48+ qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
49+ QPoint m_position;
50+ uint m_currentModeIndex{0};
51+ QList<qtmir::ScreenMode*> m_sizes;
52+ QSizeF m_physicalSize;
53+ const QScopedPointer<WorkspaceModel> m_workspaces;
54+};
55+
56+#endif // MOCK_SCREEN_H
tests/mocks/WindowManager/ScreenWindow.cppnew file+48
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ScreenWindow.h"
18+#include "Screen.h"
19+
20+// Qt
21+#include <QGuiApplication>
22+#include <QDebug>
23+
24+ScreenWindow::ScreenWindow(QQuickWindow *parent)
25+ : QQuickWindow(parent)
26+{
27+ if (qGuiApp->platformName() != QLatin1String("mirserver")) {
28+ qCritical("Not using 'mirserver' QPA plugin. Using ScreenWindow may produce unknown results.");
29+ }
30+}
31+
32+ScreenWindow::~ScreenWindow()
33+{
34+}
35+
36+Screen *ScreenWindow::screenWrapper() const
37+{
38+ return m_screen.data();
39+}
40+
41+void ScreenWindow::setScreenWrapper(Screen *screen)
42+{
43+ if (m_screen != screen) {
44+ m_screen = screen;
45+ Q_EMIT screenWrapperChanged();
46+ }
47+ QQuickWindow::setScreen(screen->qscreen());
48+}
tests/mocks/WindowManager/ScreenWindow.hnew file+49
@@ -0,0 +1,49 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_SCREENWINDOW_H
18+#define UNITY_SCREENWINDOW_H
19+
20+#include <QQuickWindow>
21+#include <QPointer>
22+
23+#include "Screen.h"
24+
25+class ScreenAdapter;
26+
27+/*
28+ * ScreenWindow - wrapper of QQuickWindow to enable QML to specify destination screen.
29+**/
30+class ScreenWindow : public QQuickWindow
31+{
32+ Q_OBJECT
33+ Q_PROPERTY(Screen *screen READ screenWrapper WRITE setScreenWrapper NOTIFY screenWrapperChanged)
34+ Q_PROPERTY(int winId READ winId CONSTANT)
35+public:
36+ explicit ScreenWindow(QQuickWindow *parent = 0);
37+ ~ScreenWindow();
38+
39+ Screen *screenWrapper() const;
40+ void setScreenWrapper(Screen *screen);
41+
42+Q_SIGNALS:
43+ void screenWrapperChanged();
44+
45+private:
46+ QPointer<Screen> m_screen;
47+};
48+
49+#endif // UNITY_SCREENWINDOW_H
tests/mocks/Unity/Screens/screens.cpp → tests/mocks/WindowManager/Screens.cpprenamed+29−42
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -14,14 +14,20 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#include "screens.h"
17+#include "Screens.h"
18+#include "Screen.h"
1819
19−// Qt
20+// qtmirserver
21+#include <qtmir/qtmir.h>
22+#include <qtmir/screens.h>
2023#include <QGuiApplication>
21−#include <QDebug>
2224
23−Screens::Screens(QObject *parent) :
24− QAbstractListModel(parent)
25+// Qt
26+#include <QScreen>
27+#include <QWindow>
28+
29+Screens::Screens(QObject *parent)
30+ : QAbstractListModel(parent)
2531{
2632 bool ok = false;
2733 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
@@ -29,13 +35,14 @@ Screens::Screens(QObject *parent) :
2935 QPoint lastPoint(0,0);
3036 for (int i = 0; i < screenCount; ++i) {
3137 auto screen = new Screen();
38+ screen->m_id = qtmir::OutputId{i};
3239 screen->m_active = i == 0;
3340 screen->m_name = QString("Monitor %1").arg(i);
3441 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
35− screen->m_sizes.append(new ScreenMode(50, QSize(640,480)));
36− screen->m_sizes.append(new ScreenMode(60, QSize(1280,1024)));
37− screen->m_sizes.append(new ScreenMode(60, QSize(1440,900)));
38− screen->m_sizes.append(new ScreenMode(60, QSize(1920,1080)));
42+ screen->m_sizes.append(new qtmir::ScreenMode(50, QSize(640,480)));
43+ screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
44+ screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
45+ screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
3946 screen->m_currentModeIndex = 3;
4047 screen->m_physicalSize = QSize(800,568);
4148 m_screenList.append(screen);
@@ -44,12 +51,6 @@ Screens::Screens(QObject *parent) :
4451 }
4552}
4653
47−Screens::~Screens() noexcept
48−{
49− qDeleteAll(m_screenList);
50− m_screenList.clear();
51−}
52−
5354QHash<int, QByteArray> Screens::roleNames() const
5455{
5556 QHash<int, QByteArray> roles;
@@ -66,7 +67,7 @@ QVariant Screens::data(const QModelIndex &index, int role) const
6667 switch(role) {
6768 case ScreenRole:
6869 return QVariant::fromValue(m_screenList.at(index.row()));
69− }
70+ } // switch
7071
7172 return QVariant();
7273}
@@ -81,34 +82,20 @@ int Screens::count() const
8182 return m_screenList.size();
8283}
8384
84−void Screens::activateScreen(int)
85+QVariant Screens::activeScreen() const
8586{
86− qWarning("Not Implemented");
87−}
88−
89−Screen::Screen(QObject* parent)
90− : QObject(parent)
91−{
92−}
93−
94−Screen::~Screen()
95−{
96− qDeleteAll(m_sizes);
97− m_sizes.clear();
98−}
99−
100−QQmlListProperty<ScreenMode> Screen::availableModes()
101−{
102− return QQmlListProperty<ScreenMode>(this, m_sizes);
87+ for (int i = 0; i < m_screenList.count(); i++) {
88+ if (m_screenList[i]->isActive()) return i;
89+ }
90+ return QVariant();
10391}
10492
105−Screen *Screen::beginConfiguration()
93+void Screens::activateScreen(const QVariant& vindex)
10694{
107− qWarning("Not Implemented");
108− return nullptr;
109−}
95+ bool ok = false;
96+ int index = vindex.toInt(&ok);
97+ if (!ok || index < 0 || m_screenList.count() <= index) return;
11098
111−void Screen::applyConfiguration()
112−{
113− qWarning("Not Implemented");
99+ auto screen = m_screenList.at(index);
100+ screen->setActive(true);
114101}
tests/mocks/WindowManager/Screens.hnew file+65
@@ -0,0 +1,65 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_SCREENS_H
18+#define UNITY_SCREENS_H
19+
20+#include <QAbstractListModel>
21+#include <QSharedPointer>
22+
23+class Screen;
24+namespace qtmir
25+{
26+class Screens;
27+}
28+
29+class Screens : public QAbstractListModel
30+{
31+ Q_OBJECT
32+ Q_PROPERTY(int count READ count NOTIFY countChanged)
33+ Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
34+
35+public:
36+ enum ItemRoles {
37+ ScreenRole = Qt::UserRole + 1
38+ };
39+
40+ explicit Screens(QObject *parent = 0);
41+ virtual ~Screens() noexcept = default;
42+
43+ /* QAbstractItemModel */
44+ QHash<int, QByteArray> roleNames() const override;
45+ QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
46+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
47+
48+ int count() const;
49+ QVariant activeScreen() const;
50+
51+public Q_SLOTS:
52+ void activateScreen(const QVariant& index);
53+
54+Q_SIGNALS:
55+ void countChanged();
56+ void activeScreenChanged();
57+
58+ void screenAdded(Screen* screen);
59+ void screenRemoved(Screen* screen);
60+
61+private:
62+ QList<Screen*> m_screenList;
63+};
64+
65+#endif // SCREENS_H
tests/mocks/WindowManager/WindowManagerPlugin.cppnew file+58
@@ -0,0 +1,58 @@
1+/*
2+ * Copyright (C) 2016 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 "WindowManagerPlugin.h"
18+
19+#include "Screens.h"
20+#include "Screen.h"
21+#include "ScreenWindow.h"
22+#include "TopLevelWindowModel.h"
23+#include "Window.h"
24+#include "WorkspaceManager.h"
25+#include "Workspace.h"
26+#include "WorkspaceModel.h"
27+
28+#include <QtQml>
29+
30+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
31+{
32+ Q_UNUSED(engine)
33+ Q_UNUSED(scriptEngine)
34+ return WorkspaceManager::instance();
35+}
36+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
37+ Q_UNUSED(engine);
38+ Q_UNUSED(scriptEngine);
39+ return new Screens();
40+}
41+
42+void WindowManagerPlugin::registerTypes(const char *uri)
43+{
44+ qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
45+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
46+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", "Not a creatable type");
47+ qmlRegisterSingletonType<Screens>(uri, 1, 0, "Screens", screensSingleton);
48+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", "ScreenMode is not creatable.");
49+
50+ qRegisterMetaType<Window*>("Window*");
51+ qRegisterMetaType<Workspace*>("Workspace*");
52+
53+ qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
54+ qRegisterMetaType<Screen*>("Screen*");
55+
56+ qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
57+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
58+}
tests/mocks/WindowManager/WindowManagerPlugin.hnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2016 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 WINDOWMANAGER_PLUGIN_H
18+#define WINDOWMANAGER_PLUGIN_H
19+
20+#include <QtQml/QQmlEngine>
21+#include <QtQml/QQmlExtensionPlugin>
22+
23+class WindowManagerPlugin : public QQmlExtensionPlugin
24+{
25+ Q_OBJECT
26+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27+
28+public:
29+ void registerTypes(const char *uri) override;
30+};
31+
32+#endif // WINDOWMANAGER_PLUGIN_H
tests/mocks/WindowManager/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module WindowManager
2+plugin MockWindowManager-qml