on b3c03fa help sign in
111 files changed+3939−871
since splitsnapshots
unifiedsplit
CMakeLists.txt+6−2 debian/control+5−3 debian/unity8.install+4 plugins/Cursor/CMakeLists.txt+1 plugins/Cursor/InputDispatcherFilter.cpp+175 plugins/Cursor/InputDispatcherFilter.h+62 plugins/Cursor/MousePointer.cpp+63−78 plugins/Cursor/MousePointer.h+5−4 plugins/UInput/plugin.cpp+7−1 plugins/Unity/CMakeLists.txt+1 plugins/Unity/Debug/CMakeLists.txt+30 plugins/Unity/Debug/consolelog.cpp+221 plugins/Unity/Debug/consolelog.h+87 plugins/Unity/Debug/plugin.cpp+31 src/ShellView.h → plugins/Unity/Debug/plugin.h+9−11 plugins/Unity/Debug/qmldir+3 plugins/WindowManager/CMakeLists.txt+23−2 plugins/WindowManager/Screen.cpp+179 plugins/WindowManager/Screen.h+71 plugins/WindowManager/ScreenWindow.cpp+48 plugins/WindowManager/ScreenWindow.h+49 plugins/WindowManager/Screens.cpp+202 tests/mocks/Unity/Screens/screens.h → plugins/WindowManager/Screens.h+42−34 plugins/WindowManager/TopLevelWindowModel.cpp+232−43 plugins/WindowManager/TopLevelWindowModel.h+24 plugins/WindowManager/WindowManagerPlugin.cpp+31−1 plugins/WindowManager/Workspace.cpp+146 plugins/WindowManager/Workspace.h+100 plugins/WindowManager/WorkspaceManager.cpp+111 plugins/WindowManager/WorkspaceManager.h+56 plugins/WindowManager/WorkspaceModel.cpp+187 plugins/WindowManager/WorkspaceModel.h+88 qml/CMakeLists.txt+1−1 qml/Components/PanelState/PanelState.qml−1 qml/Components/PanelState/qmldir+1−1 qml/Components/VirtualTouchPad.qml+14−20 qml/DisabledScreenNotice.qml+2−1 qml/Greeter/Greeter.qml+21−3 qml/Greeter/SecondaryGreeter.qml+75 qml/OrientedShell.qml+7−10 qml/Panel/Panel.qml+14−14 qml/Shell.qml+48−12 qml/ShellApplication.qml+48 src/SecondaryWindow.h → qml/ShellNotifier.qml+12−12 qml/ShellScreen.qml+63 qml/Stage/DecoratedWindow.qml+3−1 qml/Stage/FakeMaximizeDelegate.qml+12−11 qml/Stage/Stage.qml+26−24 qml/qmldir+1 src/ApplicationArguments.cpp+11−2 src/ApplicationArguments.h+17−15 src/CMakeLists.txt+9−4 src/DebuggingController.cpp+12−1 src/DebuggingController.h+14 src/SecondaryWindow.cpp−40 src/ShellApplication.cpp−216 src/ShellView.cpp−63 src/UnityApplication.cpp+131 src/ShellApplication.h → src/UnityApplication.h+10−20 src/UnityCommandLineParser.cpp+8 src/UnityCommandLineParser.h+4−1 src/libunity8-private/CMakeLists.txt+10 src/libunity8-private/windowmanagementpolicy.cpp+87 src/libunity8-private/windowmanagementpolicy.h+53 src/main.cpp+4−8 tests/mocks/CMakeLists.txt+1 tests/mocks/Cursor/Cursor.qml+49−2 tests/mocks/GSettings.1.0/plugin.cpp+12 tests/mocks/GSettings.1.0/plugin.h+1 tests/mocks/UInput/plugin.cpp+6−1 tests/mocks/Unity/Application/CMakeLists.txt+25−1 tests/mocks/Unity/Application/SurfaceManager.cpp+60−2 tests/mocks/Unity/Application/SurfaceManager.h+14 tests/mocks/Unity/Application/plugin.cpp+7−1 tests/mocks/Unity/CMakeLists.txt−1 tests/mocks/Unity/InputInfo/InputWindow.qml+68 tests/mocks/Unity/InputInfo/mockcontroller.cpp+24−2 tests/mocks/Unity/InputInfo/mockcontroller.h+5−1 tests/mocks/Unity/InputInfo/plugin.cpp+1−2 tests/mocks/Unity/InputInfo/qmldir+2 tests/mocks/Unity/Screens/CMakeLists.txt−14 tests/mocks/Unity/Screens/plugin.cpp−29 tests/mocks/Unity/Screens/qmldir−2 tests/mocks/Unity/Screens/screens.cpp−71 tests/mocks/WindowManager/CMakeLists.txt+47 tests/mocks/WindowManager/MockScreens.cpp+140 tests/mocks/Unity/Screens/plugin.h → tests/mocks/WindowManager/MockScreens.h+27−6 tests/mocks/WindowManager/ScreenWindow.cpp+48 tests/mocks/WindowManager/ScreenWindow.h+49 tests/mocks/WindowManager/WindowManagerPlugin.cpp+62 tests/mocks/WindowManager/WindowManagerPlugin.h+32 tests/mocks/WindowManager/qmldir+2 tests/mocks/WindowManager/windowmanagementpolicy.cpp+98 tests/mocks/WindowManager/windowmanagementpolicy.h+66 tests/qmltests/ApplicationMenuDataLoader.qml+1−4 tests/qmltests/ApplicationMenus/tst_MenuBar.qml−2 tests/qmltests/Components/tst_VirtualTouchPad.qml+2−2 tests/qmltests/Panel/tst_ActiveCallHint.qml−2 tests/qmltests/Panel/tst_Panel.qml+14−14 tests/qmltests/Stage/tst_ApplicationWindow.qml−2 tests/qmltests/Stage/tst_DecoratedWindow.qml+5−3 tests/qmltests/Stage/tst_DesktopStage.qml+9−6 tests/qmltests/Stage/tst_PhoneStage.qml+1−3 tests/qmltests/Stage/tst_SurfaceContainer.qml−2 tests/qmltests/Stage/tst_TabletStage.qml+1−3 tests/qmltests/Stage/tst_WindowDecoration.qml−2 tests/qmltests/Stage/tst_WindowResizeArea.qml+1−8 tests/qmltests/Tutorial/tst_Tutorial.qml+1−3 tests/qmltests/tst_OrientedShell.qml+19−5 tests/qmltests/tst_Shell.qml+20−15 tests/uqmlscene/main.cpp+2
CMakeLists.txt+6−2
@@ -70,7 +70,8 @@ find_package(Qt5DBus 5.6 REQUIRED)
7070find_package(Qt5Concurrent 5.6 REQUIRED)
7171find_package(Qt5Sql 5.6 REQUIRED)
7272
73−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=26)
73+pkg_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)
@@ -79,6 +80,7 @@ pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
7980pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
8081pkg_check_modules(UAL REQUIRED ubuntu-app-launch-2)
8182pkg_check_modules(UBUNTUGESTURES REQUIRED UbuntuGestures)
83+pkg_check_modules(MIRAL REQUIRED miral)
8284
8385### Check UbuntuGestures private headers. No pkg-config (.pc) file is provided for them
8486find_path(UBUNTUGESTUREPRIV
@@ -113,7 +115,9 @@ if(SHELL_PLUGINDIR STREQUAL "")
113115 message(FATAL_ERROR "Could not determine plugin import dir.")
114116endif()
115117
116−set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra")
118+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-permissive -pedantic -Wall -Wextra")
119+
120+set (CMAKE_CXX_STANDARD 14)
117121
118122if ("${CMAKE_BUILD_TYPE}" STREQUAL "release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "relwithdebinfo")
119123 option(Werror "Treat warnings as errors" ON)
debian/control+5−3
@@ -31,6 +31,7 @@ Build-Depends: cmake,
3131 libqmenumodel-dev (>= 0.2.11),
3232 libqt5svg5-dev,
3333 libqt5xmlpatterns5-dev,
34+ libqtmirserver-dev (>= 0.6.0),
3435 libsystemsettings-dev,
3536 libubuntu-app-launch2-dev,
3637 libubuntu-download-manager-common-dev,
@@ -38,7 +39,7 @@ Build-Depends: cmake,
3839 libubuntugestures5-private-dev (>= 1.3.2030),
3940 libudev-dev,
4041 libudm-common-dev,
41− libunity-api-dev (>= 8.2),
42+ libunity-api-dev (>= 8.3),
4243 libusermetricsoutput1-dev,
4344# Need those X11 libs touch emulation from mouse events in manual QML tests on a X11 desktop
4445 libx11-dev[!arm64 !armhf],
@@ -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}),
@@ -162,7 +164,7 @@ Depends: qml-module-qtquick-layouts,
162164 qttranslations5-l10n,
163165 ubuntu-thumbnailer-impl-0,
164166 ubuntu-wallpapers,
165− unity-application-impl-26,
167+ unity-application-impl-27,
166168 unity-notifications-impl-3,
167169 unity-plugin-scopes | unity-scopes-impl,
168170 unity-scopes-impl-12,
@@ -212,7 +214,7 @@ Depends: dbus-test-runner,
212214 ${misc:Depends},
213215 ${shlibs:Depends},
214216Provides: unity-application-impl,
215− unity-application-impl-26,
217+ unity-application-impl-27,
216218 unity8-fake-env,
217219Replaces: unity8-autopilot (<< 8.02+15.04.20150422-0ubuntu1),
218220 unity8-fake-env,
debian/unity8.install+4
@@ -16,7 +16,11 @@ usr/share/unity8/Rotation
1616usr/share/unity8/DeviceConfiguration.qml
1717usr/share/unity8/OrientedShell.qml
1818usr/share/unity8/DisabledScreenNotice.qml
19+usr/share/unity8/qmldir
1920usr/share/unity8/Shell.qml
21+usr/share/unity8/ShellApplication.qml
22+usr/share/unity8/ShellNotifier.qml
23+usr/share/unity8/ShellScreen.qml
2024usr/share/unity8/Stage
2125usr/share/unity8/Tutorial
2226usr/share/unity8/Wizard
plugins/Cursor/CMakeLists.txt+1
@@ -15,6 +15,7 @@ set(QMLPLUGIN_SRC
1515 CursorImageInfo.cpp
1616 CursorImageProvider.cpp
1717 MousePointer.cpp
18+ InputDispatcherFilter.cpp
1819 # We need to run moc on this header
1920 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h
2021 )
plugins/Cursor/InputDispatcherFilter.cppnew file+175
@@ -0,0 +1,175 @@
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+#include "InputDispatcherFilter.h"
18+#include "MousePointer.h"
19+
20+#include <QEvent>
21+#include <QGuiApplication>
22+#include <QQuickWindow>
23+#include <QScreen>
24+#include <QtMath>
25+#include <qpa/qplatformnativeinterface.h>
26+#include <qpa/qplatformscreen.h>
27+
28+InputDispatcherFilter *InputDispatcherFilter::instance()
29+{
30+ static InputDispatcherFilter filter;
31+ return &filter;
32+}
33+
34+InputDispatcherFilter::InputDispatcherFilter(QObject *parent)
35+ : QObject(parent)
36+ , m_pushing(false)
37+{
38+ QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface();
39+ m_inputDispatcher = static_cast<QObject*>(ni->nativeResourceForIntegration("InputDispatcher"));
40+ if (m_inputDispatcher) {
41+ m_inputDispatcher->installEventFilter(this);
42+ }
43+}
44+
45+void InputDispatcherFilter::registerPointer(MousePointer *pointer)
46+{
47+ // allow first registered pointer to be visible.
48+ m_pointers.insert(pointer);
49+}
50+
51+void InputDispatcherFilter::unregisterPointer(MousePointer *pointer)
52+{
53+ m_pointers.remove(pointer);
54+}
55+
56+bool InputDispatcherFilter::eventFilter(QObject *o, QEvent *e)
57+{
58+ if (o != m_inputDispatcher) return false;
59+
60+ switch (e->type()) {
61+ case QEvent::MouseMove:
62+ case QEvent::MouseButtonPress:
63+ case QEvent::MouseButtonRelease:
64+ {
65+ // if we don't have any pointers, filter all mouse events.
66+ auto pointer = currentPointer();
67+ if (!pointer) return true;
68+
69+ QMouseEvent* me = static_cast<QMouseEvent*>(e);
70+
71+ // Local position gives relative change of mouse pointer.
72+ QPointF movement = me->localPos();
73+
74+ // Adjust the position
75+ QPointF oldPos = pointer->window()->geometry().topLeft() + pointer->position();
76+ QPointF newPos = adjustedPositionForMovement(oldPos, movement);
77+
78+ QScreen* currentScreen = screenAt(newPos);
79+ if (currentScreen) {
80+ QRect screenRect = currentScreen->geometry();
81+ qreal newX = (oldPos + movement).x();
82+ qreal newY = (oldPos + movement).y();
83+
84+ if (newX <= screenRect.left() && newY < screenRect.top() + pointer->topBoundaryOffset()) { // top left corner
85+ const auto distance = qSqrt(qPow(newX, 2) + qPow(newY- screenRect.top() - pointer->topBoundaryOffset(), 2));
86+ Q_EMIT pushedTopLeftCorner(currentScreen, qAbs(distance), me->buttons());
87+ m_pushing = true;
88+ } else if (newX >= screenRect.right()-1 && newY < screenRect.top() + pointer->topBoundaryOffset()) { // top right corner
89+ const auto distance = qSqrt(qPow(newX-screenRect.right(), 2) + qPow(newY - screenRect.top() - pointer->topBoundaryOffset(), 2));
90+ Q_EMIT pushedTopRightCorner(currentScreen, qAbs(distance), me->buttons());
91+ m_pushing = true;
92+ } else if (newX < 0 && newY >= screenRect.bottom()-1) { // bottom left corner
93+ const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-screenRect.bottom(), 2));
94+ Q_EMIT pushedBottomLeftCorner(currentScreen, qAbs(distance), me->buttons());
95+ m_pushing = true;
96+ } else if (newX >= screenRect.right()-1 && newY >= screenRect.bottom()-1) { // bottom right corner
97+ const auto distance = qSqrt(qPow(newX-screenRect.right(), 2) + qPow(newY-screenRect.bottom(), 2));
98+ Q_EMIT pushedBottomRightCorner(currentScreen, qAbs(distance), me->buttons());
99+ m_pushing = true;
100+ } else if (newX < screenRect.left()) { // left edge
101+ Q_EMIT pushedLeftBoundary(currentScreen, qAbs(newX), me->buttons());
102+ m_pushing = true;
103+ } else if (newX >= screenRect.right()) { // right edge
104+ Q_EMIT pushedRightBoundary(currentScreen, newX - (screenRect.right() - 1), me->buttons());
105+ m_pushing = true;
106+ } else if (newY < screenRect.top() + pointer->topBoundaryOffset()) { // top edge
107+ Q_EMIT pushedTopBoundary(currentScreen, qAbs(newY - screenRect.top() - pointer->topBoundaryOffset()), me->buttons());
108+ m_pushing = true;
109+ } else if (Q_LIKELY(newX > 0 && newX < screenRect.right()-1 && newY > 0 && newY < screenRect.bottom()-1)) { // normal pos, not pushing
110+ if (m_pushing) {
111+ Q_EMIT pushStopped(currentScreen);
112+ m_pushing = false;
113+ }
114+ }
115+ }
116+
117+ // Send the event
118+ QMouseEvent eCopy(me->type(), me->localPos(), newPos, me->button(), me->buttons(), me->modifiers());
119+ eCopy.setTimestamp(me->timestamp());
120+ o->event(&eCopy);
121+ return true;
122+ }
123+ default:
124+ break;
125+ }
126+ return false;
127+}
128+
129+QPointF InputDispatcherFilter::adjustedPositionForMovement(const QPointF &pt, const QPointF &movement) const
130+{
131+ QPointF adjusted = pt + movement;
132+
133+ auto screen = screenAt(adjusted); // first check if our move was to a screen with an enabled pointer.
134+ if (screen) {
135+ return adjusted;
136+ } else if ((screen = screenAt(pt))) { // then check if our old position was valid
137+ QRectF screenBounds = screen->geometry();
138+ // bound the new position to the old screen geometry
139+ adjusted.rx() = qMax(screenBounds.left(), qMin(adjusted.x(), screenBounds.right()-1));
140+ adjusted.ry() = qMax(screenBounds.top(), qMin(adjusted.y(), screenBounds.bottom()-1));
141+ } else {
142+ auto screens = QGuiApplication::screens();
143+
144+ // center of first screen with a pointer.
145+ Q_FOREACH(QScreen* screen, screens) {
146+ Q_FOREACH(MousePointer* pointer, m_pointers) {
147+ if (pointer->isEnabled() && pointer->screen() == screen) {
148+ return screen->geometry().center();
149+ }
150+ }
151+ }
152+ }
153+ return adjusted;
154+}
155+
156+QScreen *InputDispatcherFilter::screenAt(const QPointF &pt) const
157+{
158+ Q_FOREACH(MousePointer* pointer, m_pointers) {
159+ if (!pointer->isEnabled()) continue;
160+
161+ QScreen* screen = pointer->screen();
162+ if (screen && screen->geometry().contains(pt.toPoint()))
163+ return screen;
164+ }
165+ return nullptr;
166+}
167+
168+MousePointer *InputDispatcherFilter::currentPointer() const
169+{
170+ Q_FOREACH(MousePointer* pointer, m_pointers) {
171+ if (!pointer->isEnabled()) continue;
172+ return pointer;
173+ }
174+ return nullptr;
175+}
plugins/Cursor/InputDispatcherFilter.hnew file+62
@@ -0,0 +1,62 @@
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 INPUTDISPATCHERFILTER_H
18+#define INPUTDISPATCHERFILTER_H
19+
20+#include <QObject>
21+#include <QPointF>
22+#include <QSet>
23+
24+class MousePointer;
25+class QScreen;
26+
27+class InputDispatcherFilter : public QObject
28+{
29+ Q_OBJECT
30+public:
31+ static InputDispatcherFilter *instance();
32+
33+ void registerPointer(MousePointer* pointer);
34+ void unregisterPointer(MousePointer* pointer);
35+
36+Q_SIGNALS:
37+ void pushedLeftBoundary(QScreen* screen, qreal amount, Qt::MouseButtons buttons);
38+ void pushedRightBoundary(QScreen* screen, qreal amount, Qt::MouseButtons buttons);
39+ void pushedTopBoundary(QScreen* screen, qreal amount, Qt::MouseButtons buttons);
40+ void pushedTopLeftCorner(QScreen* screen, qreal amount, Qt::MouseButtons buttons);
41+ void pushedTopRightCorner(QScreen* screen, qreal amount, Qt::MouseButtons buttons);
42+ void pushedBottomLeftCorner(QScreen* screen, qreal amount, Qt::MouseButtons buttons);
43+ void pushedBottomRightCorner(QScreen* screen, qreal amount, Qt::MouseButtons buttons);
44+ void pushStopped(QScreen* screen);
45+
46+protected:
47+ InputDispatcherFilter(QObject* parent = nullptr);
48+
49+ bool eventFilter(QObject *o, QEvent *e) override;
50+
51+ QPointF adjustedPositionForMovement(const QPointF& pt, const QPointF& movement) const;
52+ QScreen* screenAt(const QPointF& pt) const;
53+
54+ MousePointer* currentPointer() const;
55+
56+private:
57+ QObject* m_inputDispatcher;
58+ QSet<MousePointer*> m_pointers;
59+ bool m_pushing;
60+};
61+
62+#endif // INPUTDISPATCHERFILTER_H
plugins/Cursor/MousePointer.cpp+63−78
@@ -16,84 +16,74 @@
1616
1717#include "MousePointer.h"
1818#include "CursorImageProvider.h"
19−
20−// Unity API
21−#include <unity/shell/application/MirPlatformCursor.h>
19+#include "InputDispatcherFilter.h"
2220
2321#include <QQuickWindow>
24−#include <QGuiApplication>
25−#include <QtMath>
2622
27−#include <qpa/qwindowsysteminterface.h>
23+// Unity API
24+#include <unity/shell/application/MirPlatformCursor.h>
2825
2926MousePointer::MousePointer(QQuickItem *parent)
3027 : MirMousePointerInterface(parent)
3128 , m_cursorName(QStringLiteral("left_ptr"))
3229 , m_themeName(QStringLiteral("default"))
3330{
34−}
35−
36−void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
37− Qt::KeyboardModifiers modifiers)
38−{
39− if (!parentItem()) {
40− return;
41− }
42−
43− if (!movement.isNull()) {
44− Q_EMIT mouseMoved();
45− }
46−
47− m_accumulatedMovement += movement;
48− // don't apply the fractional part
49− QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
50− m_accumulatedMovement -= appliedMovement;
51−
52− qreal newX = x() + appliedMovement.x();
53− qreal newY = y() + appliedMovement.y();
54− const qreal sceneWidth = parentItem()->width();
55− const qreal sceneHeight = parentItem()->height();
56−
57− if (newX <= 0 && newY < m_topBoundaryOffset) { // top left corner
58− const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-m_topBoundaryOffset, 2));
59− Q_EMIT pushedTopLeftCorner(qAbs(distance), buttons);
60− m_pushing = true;
61− } else if (newX >= sceneWidth-1 && newY < m_topBoundaryOffset) { // top right corner
62− const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-m_topBoundaryOffset, 2));
63− Q_EMIT pushedTopRightCorner(qAbs(distance), buttons);
64− m_pushing = true;
65− } else if (newX < 0 && newY >= sceneHeight-1) { // bottom left corner
66− const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-sceneHeight, 2));
67− Q_EMIT pushedBottomLeftCorner(qAbs(distance), buttons);
68− m_pushing = true;
69− } else if (newX >= sceneWidth-1 && newY >= sceneHeight-1) { // bottom right corner
70− const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-sceneHeight, 2));
71− Q_EMIT pushedBottomRightCorner(qAbs(distance), buttons);
72− m_pushing = true;
73− } else if (newX < 0) { // left edge
74− Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
75− m_pushing = true;
76− } else if (newX >= sceneWidth) { // right edge
77− Q_EMIT pushedRightBoundary(newX - (sceneWidth - 1), buttons);
78− m_pushing = true;
79− } else if (newY < m_topBoundaryOffset) { // top edge
80− Q_EMIT pushedTopBoundary(qAbs(newY - m_topBoundaryOffset), buttons);
81− m_pushing = true;
82− } else if (Q_LIKELY(newX > 0 && newX < sceneWidth-1 && newY > 0 && newY < sceneHeight-1)) { // normal pos, not pushing
83− if (m_pushing) {
31+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedLeftBoundary,
32+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
33+ if (window() && window()->screen() == screen) {
34+ Q_EMIT pushedLeftBoundary(amount, buttons);
35+ }
36+ });
37+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedRightBoundary,
38+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
39+ if (window() && window()->screen() == screen) {
40+ Q_EMIT pushedRightBoundary(amount, buttons);
41+ }
42+ });
43+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedTopBoundary,
44+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
45+ if (window() && window()->screen() == screen) {
46+ Q_EMIT pushedTopBoundary(amount, buttons);
47+ }
48+ });
49+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedTopLeftCorner,
50+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
51+ if (window() && window()->screen() == screen) {
52+ Q_EMIT pushedTopLeftCorner(amount, buttons);
53+ }
54+ });
55+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedTopRightCorner,
56+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
57+ if (window() && window()->screen() == screen) {
58+ Q_EMIT pushedTopRightCorner(amount, buttons);
59+ }
60+ });
61+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedBottomLeftCorner,
62+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
63+ if (window() && window()->screen() == screen) {
64+ Q_EMIT pushedBottomLeftCorner(amount, buttons);
65+ }
66+ });
67+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedBottomRightCorner,
68+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
69+ if (window() && window()->screen() == screen) {
70+ Q_EMIT pushedBottomRightCorner(amount, buttons);
71+ }
72+ });
73+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushStopped,
74+ this, [this](QScreen* screen) {
75+ if (window() && window()->screen() == screen) {
8476 Q_EMIT pushStopped();
85− m_pushing = false;
8677 }
87− }
78+ });
8879
89− applyItemConfinement(newX, newY);
90−
91− setX(qBound(0.0, newX, sceneWidth - 1));
92− setY(qBound(0.0, newY, sceneHeight - 1));
80+ InputDispatcherFilter::instance()->registerPointer(this);
81+}
9382
94− QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
95− QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/,
96− buttons, modifiers);
83+MousePointer::~MousePointer()
84+{
85+ registerScreen(nullptr);
86+ InputDispatcherFilter::instance()->unregisterPointer(this);
9787}
9888
9989void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
@@ -121,17 +111,6 @@ void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
121111 }
122112}
123113
124−void MousePointer::handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers)
125−{
126− if (!parentItem()) {
127− return;
128− }
129−
130− QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
131− QWindowSystemInterface::handleWheelEvent(window(), timestamp, scenePosition /* local */, scenePosition /* global */,
132− QPoint() /* pixelDelta */, angleDelta, modifiers, Qt::ScrollUpdate);
133−}
134−
135114int MousePointer::topBoundaryOffset() const
136115{
137116 return m_topBoundaryOffset;
@@ -182,7 +161,7 @@ void MousePointer::registerScreen(QScreen *screen)
182161 if (m_registeredScreen) {
183162 auto previousCursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
184163 if (previousCursor) {
185− previousCursor->setMousePointer(nullptr);
164+ previousCursor->unregisterMousePointer(this);
186165 } else {
187166 qCritical("QPlatformCursor is not a MirPlatformCursor! Cursor module only works in a Mir server.");
188167 }
@@ -193,7 +172,7 @@ void MousePointer::registerScreen(QScreen *screen)
193172 if (m_registeredScreen) {
194173 auto cursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
195174 if (cursor) {
196− cursor->setMousePointer(this);
175+ cursor->registerMousePointer(this);
197176 } else {
198177 qCritical("QPlaformCursor is not a MirPlatformCursor! Cursor module only works in Mir.");
199178 }
@@ -216,6 +195,12 @@ void MousePointer::setThemeName(const QString &themeName)
216195 }
217196}
218197
198+void MousePointer::moveTo(const QPoint &position)
199+{
200+ setPosition(position);
201+ Q_EMIT mouseMoved();
202+}
203+
219204void MousePointer::setCustomCursor(const QCursor &customCursor)
220205{
221206 CursorImageProvider::instance()->setCustomCursor(customCursor);
plugins/Cursor/MousePointer.h+5−4
@@ -31,6 +31,7 @@ class MousePointer : public MirMousePointerInterface {
3131 Q_PROPERTY(int topBoundaryOffset READ topBoundaryOffset WRITE setTopBoundaryOffset NOTIFY topBoundaryOffsetChanged)
3232public:
3333 MousePointer(QQuickItem *parent = nullptr);
34+ ~MousePointer();
3435
3536 void setCursorName(const QString &qtCursorName) override;
3637 QString cursorName() const override { return m_cursorName; }
@@ -38,6 +39,8 @@ public:
3839 void setThemeName(const QString &themeName) override;
3940 QString themeName() const override { return m_themeName; }
4041
42+ void moveTo(const QPoint& position) override;
43+
4144 void setCustomCursor(const QCursor &) override;
4245
4346 QQuickItem* confiningItem() const;
@@ -46,10 +49,7 @@ public:
4649 int topBoundaryOffset() const;
4750 void setTopBoundaryOffset(int topBoundaryOffset);
4851
49−public Q_SLOTS:
50− void handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
51− Qt::KeyboardModifiers modifiers) override;
52− void handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers) override;
52+ QScreen* screen() const { return m_registeredScreen; }
5353
5454Q_SIGNALS:
5555 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
@@ -79,6 +79,7 @@ private:
7979 QPointer<QScreen> m_registeredScreen;
8080 QString m_cursorName;
8181 QString m_themeName;
82+ bool m_active;
8283
8384 // Accumulated, unapplied, mouse movement.
8485 QPointF m_accumulatedMovement;
plugins/UInput/plugin.cpp+7−1
@@ -19,8 +19,14 @@
1919
2020#include <QtQml/qqml.h>
2121
22+
23+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
24+{
25+ return new UInput;
26+}
27+
2228void UInputPlugin::registerTypes(const char *uri)
2329{
2430 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<UInput>(uri, 0, 1, "UInput");
31+ qmlRegisterSingletonType<UInput>(uri, 0, 1, "UInput", uinputSingleton);
2632}
plugins/Unity/CMakeLists.txt+1
@@ -1,5 +1,6 @@
11add_subdirectory(ApplicationMenu)
22add_subdirectory(Connectivity)
3+add_subdirectory(Debug)
34add_subdirectory(Indicators)
45add_subdirectory(Launcher)
56add_subdirectory(Session)
plugins/Unity/Debug/CMakeLists.txtnew file+30
@@ -0,0 +1,30 @@
1+include_directories(
2+ ${CMAKE_CURRENT_SOURCE_DIR}
3+ ${CMAKE_CURRENT_BINARY_DIR}
4+)
5+
6+include_directories(
7+ SYSTEM
8+ ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
9+ ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
10+ ${GIO_INCLUDE_DIRS}
11+)
12+
13+set(QMLPLUGIN_SRC
14+ consolelog.cpp
15+ plugin.cpp
16+ )
17+
18+add_library(Debug-qml SHARED
19+ ${QMLPLUGIN_SRC}
20+ )
21+
22+# Because this is an internal support library, we want
23+# to expose all symbols in it. Consider changing this
24+# either to a static library or just using the
25+# files directly in targets.
26+set_target_properties(Debug-qml PROPERTIES COMPILE_FLAGS -fvisibility=default)
27+
28+qt5_use_modules(Debug-qml Qml Quick Concurrent)
29+
30+add_unity8_plugin(Unity.Debug 0.1 Unity/Debug TARGETS Debug-qml)
plugins/Unity/Debug/consolelog.cppnew file+221
@@ -0,0 +1,221 @@
1+/*
2+ * Copyright 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 Lesser 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 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 "consolelog.h"
18+
19+#include <unistd.h>
20+#include <stdio.h>
21+#include <thread>
22+#include <iostream>
23+#include <sys/ioctl.h>
24+
25+#include <functional>
26+
27+namespace
28+{
29+
30+int wait_fd(std::function<int(void)> fn)
31+{
32+ int ret = -1;
33+ bool fd_blocked = false;
34+ do
35+ {
36+ ret = fn();
37+ fd_blocked = (errno == EINTR || errno == EBUSY);
38+ if (fd_blocked)
39+ QThread::msleep(10);
40+ }
41+ while (ret < 0);
42+ return ret;
43+}
44+
45+#define PIPE_WAIT(val) wait_fd(std::bind(pipe, val))
46+#define DUP_WAIT(fd) wait_fd(std::bind(dup, fd))
47+#define DUP2_WAIT(fd1, fd2) wait_fd(std::bind(dup2, fd1, fd2))
48+#define CLOSE_WAIT(fd) wait_fd(std::bind(close, fd))
49+
50+}
51+
52+LogRedirector::LogRedirector()
53+ : m_ref(0)
54+ , m_stop(false)
55+{
56+ setObjectName("ConsoleLog");
57+
58+ // make stdout & stderr streams unbuffered
59+ // so that we don't need to flush the streams
60+ // before capture and after capture
61+ // (fflush can cause a deadlock if the stream is currently being used)
62+ setvbuf(stdout,NULL,_IONBF,0);
63+ setvbuf(stderr,NULL,_IONBF,0);
64+}
65+
66+void LogRedirector::run()
67+{
68+ PIPE_WAIT(m_pipe);
69+
70+ int oldStdOut = DUP_WAIT(fileno(stdout));
71+ int oldStdErr = DUP_WAIT(fileno(stderr));
72+
73+ DUP2_WAIT(m_pipe[WRITE], fileno(stdout));
74+ DUP2_WAIT(m_pipe[WRITE], fileno(stderr));
75+ CLOSE_WAIT(m_pipe[WRITE]);
76+
77+ while(true) {
78+ {
79+ QMutexLocker lock(&m_mutex);
80+ if (m_stop) break;
81+ }
82+ checkLog();
83+ QThread::msleep(50);
84+ }
85+
86+ DUP2_WAIT(oldStdOut, fileno(stdout));
87+ DUP2_WAIT(oldStdErr, fileno(stderr));
88+
89+ CLOSE_WAIT(oldStdOut);
90+ CLOSE_WAIT(oldStdErr);
91+ CLOSE_WAIT(m_pipe[READ]);
92+}
93+
94+
95+void LogRedirector::checkLog()
96+{
97+ // Do not allow read to block with no data.
98+ // If we stop the thread while waiting a read,
99+ // it will block the main thread waiting for this thread to stop.
100+ int count = 0;
101+ ioctl(m_pipe[READ], FIONREAD, &count);
102+ if (count <= 0) return;
103+
104+ std::string captured;
105+ std::string buf;
106+ const int bufSize = 1024;
107+ buf.resize(bufSize);
108+ int bytesRead = 0;
109+ bytesRead = read(m_pipe[READ], &(*buf.begin()), bufSize);
110+ while(bytesRead == bufSize)
111+ {
112+ captured += buf;
113+ bytesRead = 0;
114+ bytesRead = read(m_pipe[READ], &(*buf.begin()), bufSize);
115+ }
116+ if (bytesRead > 0)
117+ {
118+ buf.resize(bytesRead);
119+ captured += buf;
120+ }
121+
122+ if (!captured.empty()) {
123+ Q_EMIT log(QString::fromStdString(captured));
124+ }
125+}
126+
127+LogRedirector *LogRedirector::instance()
128+{
129+ static LogRedirector* log = nullptr;
130+ if (!log) {
131+ log = new LogRedirector();
132+ }
133+ return log;
134+}
135+
136+void LogRedirector::add(ConsoleLog* logger)
137+{
138+ QMutexLocker lock(&m_mutex);
139+ connect(this, &LogRedirector::log, logger, &ConsoleLog::logged, Qt::UniqueConnection);
140+
141+ m_ref++;
142+ if (!LogRedirector::instance()->isRunning()) {
143+ m_stop = false;
144+ LogRedirector::instance()->start();
145+ }
146+}
147+
148+void LogRedirector::remove(ConsoleLog* logger)
149+{
150+ QMutexLocker lock(&m_mutex);
151+ disconnect(this, &LogRedirector::log, logger, &ConsoleLog::logged);
152+
153+ m_ref = qMax(m_ref-1, 0);
154+ if (m_ref == 0 && LogRedirector::instance()->isRunning()) {
155+ m_stop = true;
156+ lock.unlock();
157+ LogRedirector::instance()->wait();
158+ }
159+}
160+
161+ConsoleLog::ConsoleLog(QObject *parent)
162+ : QObject(parent)
163+ , m_enabled(false)
164+ , m_maxLines(60)
165+{
166+ auto updateEnabled = [this]() {
167+ if (m_enabled) {
168+ LogRedirector::instance()->add(this);
169+ } else {
170+ LogRedirector::instance()->remove(this);
171+ }
172+ };
173+ connect(this, &ConsoleLog::enabledChanged, this, updateEnabled);
174+}
175+
176+ConsoleLog::~ConsoleLog()
177+{
178+ if (m_enabled) {
179+ LogRedirector::instance()->remove(this);
180+ }
181+}
182+
183+void ConsoleLog::setEnabled(bool enabled)
184+{
185+ if (m_enabled == enabled) {
186+ return;
187+ }
188+
189+ m_enabled = enabled;
190+ Q_EMIT enabledChanged();
191+}
192+
193+QString ConsoleLog::out() const
194+{
195+ return m_out.join("\n");
196+}
197+
198+void ConsoleLog::setMaxLines(int maxLines)
199+{
200+ if (m_maxLines == maxLines) {
201+ return;
202+ }
203+
204+ m_maxLines = maxLines;
205+ while (m_out.count() > m_maxLines) {
206+ m_out.removeLast();
207+ }
208+ Q_EMIT outChanged();
209+ Q_EMIT maxLinesChanged();
210+}
211+
212+void ConsoleLog::logged(QString captured)
213+{
214+ QStringList li = captured.split("\n", QString::SkipEmptyParts);
215+ li << m_out;
216+ m_out = li;
217+ while (m_out.count() > m_maxLines) {
218+ m_out.removeLast();
219+ }
220+ Q_EMIT outChanged();
221+}
plugins/Unity/Debug/consolelog.hnew file+87
@@ -0,0 +1,87 @@
1+/*
2+ * Copyright 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 Lesser 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 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 CONSOLELOG_H
18+#define CONSOLELOG_H
19+
20+#include <QThread>
21+#include <QMutex>
22+#include <QSet>
23+
24+class ConsoleLog;
25+
26+class LogRedirector : public QThread
27+{
28+ Q_OBJECT
29+public:
30+ static LogRedirector *instance();
31+
32+ void add(ConsoleLog* logger);
33+ void remove(ConsoleLog* logger);
34+
35+private Q_SLOTS:
36+ void checkLog();
37+
38+Q_SIGNALS:
39+ void log(QString log);
40+
41+private:
42+ LogRedirector();
43+ void run() Q_DECL_OVERRIDE;
44+
45+ QMutex m_mutex;
46+ int m_pipe[2];
47+ int m_ref;
48+ bool m_stop;
49+
50+ enum PIPES { READ, WRITE };
51+};
52+
53+class ConsoleLog : public QObject
54+{
55+ Q_OBJECT
56+ Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
57+ Q_PROPERTY(QString out READ out NOTIFY outChanged)
58+ Q_PROPERTY(int maxLines READ maxLines WRITE setMaxLines NOTIFY maxLinesChanged)
59+public:
60+ explicit ConsoleLog(QObject *parent = 0);
61+ ~ConsoleLog();
62+
63+ bool isEnabled() const { return m_enabled; }
64+ void setEnabled(bool enabled);
65+
66+ QString out() const;
67+
68+ int maxLines() const { return m_maxLines; }
69+ void setMaxLines(int maxLines);
70+
71+public Q_SLOTS:
72+ void logged(QString captured);
73+
74+Q_SIGNALS:
75+ void enabledChanged();
76+ void outChanged();
77+ void maxLinesChanged();
78+
79+private:
80+ void updateEnabled();
81+
82+ QStringList m_out;
83+ bool m_enabled;
84+ int m_maxLines;
85+};
86+
87+#endif // CONSOLELOG_H
plugins/Unity/Debug/plugin.cppnew file+31
@@ -0,0 +1,31 @@
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+// Qt
18+#include <QtQml/qqml.h>
19+
20+// self
21+#include "plugin.h"
22+
23+// local
24+#include "consolelog.h"
25+
26+void UnityDebugPlugin::registerTypes(const char *uri)
27+{
28+ Q_ASSERT(uri == QLatin1String("Unity.Debug"));
29+
30+ qmlRegisterType<ConsoleLog>(uri, 0, 1, "ConsoleLog");
31+}
src/ShellView.h → plugins/Unity/Debug/plugin.hrenamed+9−11
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -14,21 +14,19 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef UNITY_SHELL_VIEW_H
18−#define UNITY_SHELL_VIEW_H
17+#ifndef UNITYDEBUG_PLUGIN_H
18+#define UNITYDEBUG_PLUGIN_H
1919
20−#include <QQuickView>
20+#include <QtQml/QQmlEngine>
21+#include <QtQml/QQmlExtensionPlugin>
2122
22−class ShellView : public QQuickView
23+class UnityDebugPlugin : public QQmlExtensionPlugin
2324{
2425 Q_OBJECT
26+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
2527
2628public:
27− ShellView(QQmlEngine *engine, QObject *qmlArgs);
28−
29−private Q_SLOTS:
30− void onWidthChanged(int);
31− void onHeightChanged(int);
29+ void registerTypes(const char *uri) override;
3230};
3331
34−#endif // UNITY_SHELL_VIEW_H
32+#endif
plugins/Unity/Debug/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.Debug
2+plugin Debug-qml
3+typeinfo Debug.qmltypes
plugins/WindowManager/CMakeLists.txt+23−2
@@ -1,16 +1,37 @@
1+include_directories(
2+ SYSTEM
3+ ${QTMIRSERVER_INCLUDE_DIRS}
4+)
5+
6+include_directories(
7+ ${CMAKE_CURRENT_SOURCE_DIR}
8+ ${libunity8-private_SOURCE_DIR}
9+)
10+
111set(WINDOWMANAGER_SRC
212 TopLevelWindowModel.cpp
313 Window.cpp
414 WindowManagerPlugin.cpp
15+ Screens.cpp
16+ Screen.cpp
17+ ScreenWindow.cpp
18+ Workspace.cpp
19+ WorkspaceManager.cpp
20+ WorkspaceModel.cpp
521 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
622 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
723 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
824 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
925 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
10− )
26+)
1127
1228add_library(windowmanager-qml SHARED ${WINDOWMANAGER_SRC})
1329
30+target_link_libraries(windowmanager-qml
31+ ${QTMIRSERVER_LDFLAGS}
32+ unity8-private
33+)
34+
1435qt5_use_modules(windowmanager-qml Qml Quick Gui)
1536
16−add_unity8_plugin(WindowManager 0.1 WindowManager TARGETS windowmanager-qml)
37+add_unity8_plugin(WindowManager 1.0 WindowManager TARGETS windowmanager-qml)
plugins/WindowManager/Screen.cppnew file+179
@@ -0,0 +1,179 @@
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 "WorkspaceManager.h"
19+#include "Workspace.h"
20+
21+Screen::Screen(qtmir::Screen* screen)
22+ : m_wrapped(screen)
23+ , m_workspaces(new WorkspaceModel)
24+{
25+ connect(m_wrapped, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
26+ connect(m_wrapped, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
27+ connect(m_wrapped, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
28+ connect(m_wrapped, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
29+ connect(m_wrapped, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
30+ connect(m_wrapped, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
31+ connect(m_wrapped, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
32+ connect(m_wrapped, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
33+ connect(m_wrapped, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
34+ connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
35+
36+ // Connect the active workspace to activate the screen.
37+ connect(m_workspaces.data(), &WorkspaceModel::workspaceAdded, this, [this](Workspace* workspace) {
38+ connect(workspace, &Workspace::activeChanged, this, [this](bool active) {
39+ if (active) activate();
40+ });
41+ if (workspace->isActive()) activate();
42+ });
43+ connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
44+ disconnect(workspace, &Workspace::activeChanged, this, 0);
45+ });
46+
47+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
48+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
49+}
50+
51+Screen::Screen(const Screen &other)
52+ : qtmir::Screen(nullptr)
53+ , m_wrapped(other.m_wrapped)
54+ , m_workspaces(new WorkspaceModelProxy(other.m_workspaces.data()))
55+{
56+ connect(m_wrapped, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
57+ connect(m_wrapped, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
58+ connect(m_wrapped, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
59+ connect(m_wrapped, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
60+ connect(m_wrapped, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
61+ connect(m_wrapped, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
62+ connect(m_wrapped, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
63+ connect(m_wrapped, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
64+ connect(m_wrapped, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
65+ connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
66+}
67+
68+qtmir::OutputId Screen::outputId() const
69+{
70+ return m_wrapped->outputId();
71+}
72+
73+bool Screen::used() const
74+{
75+ return m_wrapped->used();
76+}
77+
78+QString Screen::name() const
79+{
80+ return m_wrapped->name();
81+}
82+
83+float Screen::scale() const
84+{
85+ return m_wrapped->scale();
86+}
87+
88+QSizeF Screen::physicalSize() const
89+{
90+ return m_wrapped->physicalSize();
91+}
92+
93+qtmir::FormFactor Screen::formFactor() const
94+{
95+ return m_wrapped->formFactor();
96+}
97+
98+qtmir::OutputTypes Screen::outputType() const
99+{
100+ return m_wrapped->outputType();
101+}
102+
103+MirPowerMode Screen::powerMode() const
104+{
105+ return m_wrapped->powerMode();
106+}
107+
108+Qt::ScreenOrientation Screen::orientation() const
109+{
110+ return m_wrapped->orientation();
111+}
112+
113+QPoint Screen::position() const
114+{
115+ return m_wrapped->position();
116+}
117+
118+QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
119+{
120+ return m_wrapped->availableModes();
121+}
122+
123+uint Screen::currentModeIndex() const
124+{
125+ return m_wrapped->currentModeIndex();
126+}
127+
128+bool Screen::isActive() const
129+{
130+ return m_wrapped->isActive();
131+}
132+
133+qtmir::ScreenConfiguration *Screen::beginConfiguration() const
134+{
135+ return m_wrapped->beginConfiguration();
136+}
137+
138+bool Screen::applyConfiguration(qtmir::ScreenConfiguration *configuration)
139+{
140+ return m_wrapped->applyConfiguration(configuration);
141+}
142+
143+WorkspaceModel *Screen::workspaces() const
144+{
145+ return m_workspaces.data();
146+}
147+
148+void Screen::sync(Screen *proxy)
149+{
150+ if (!proxy) return;
151+
152+ workspaces()->sync(proxy->workspaces());
153+}
154+
155+void Screen::activate()
156+{
157+ setActive(true);
158+}
159+
160+void Screen::setActive(bool active)
161+{
162+ m_wrapped->setActive(active);
163+}
164+
165+QScreen *Screen::qscreen() const
166+{
167+ return m_wrapped->qscreen();
168+}
169+
170+ScreenProxy::ScreenProxy(ScreenProxy::Screen *const screen)
171+ : Screen(*screen)
172+ , m_original(screen)
173+{
174+}
175+
176+void ScreenProxy::addWorkspace()
177+{
178+ (new WorkspaceProxy(WorkspaceManager::instance()->createWorkspace()))->assign(workspaces());
179+}
plugins/WindowManager/Screen.hnew file+71
@@ -0,0 +1,71 @@
1+#ifndef SCREEN_H
2+#define SCREEN_H
3+
4+#include <qtmir/screen.h>
5+#include <QScopedPointer>
6+#include <QPointer>
7+
8+#include "WorkspaceModel.h"
9+
10+class ScreenProxy;
11+
12+class Screen : public qtmir::Screen
13+{
14+ Q_OBJECT
15+ Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
16+
17+public:
18+ explicit Screen(qtmir::Screen*const wrapped);
19+
20+ qtmir::OutputId outputId() const override;
21+ bool used() const override;
22+ QString name() const override;
23+ float scale() const override;
24+ QSizeF physicalSize() const override;
25+ qtmir::FormFactor formFactor() const override;
26+ qtmir::OutputTypes outputType() const override;
27+ MirPowerMode powerMode() const override;
28+ Qt::ScreenOrientation orientation() const override;
29+ QPoint position() const override;
30+ QQmlListProperty<qtmir::ScreenMode> availableModes() override;
31+ uint currentModeIndex() const override;
32+ bool isActive() const override;
33+ void setActive(bool active) override;
34+
35+ QScreen* qscreen() const override;
36+
37+ qtmir::ScreenConfiguration *beginConfiguration() const override;
38+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override;
39+
40+ qtmir::Screen* wrapped() const { return m_wrapped; }
41+
42+ WorkspaceModel* workspaces() const;
43+
44+ void sync(Screen* proxy);
45+
46+public Q_SLOTS:
47+ void activate();
48+
49+protected:
50+ Screen(Screen const& other);
51+
52+ qtmir::Screen*const m_wrapped;
53+ const QScopedPointer<WorkspaceModel> m_workspaces;
54+};
55+
56+class ScreenProxy : public Screen
57+{
58+ Q_OBJECT
59+public:
60+ explicit ScreenProxy(Screen*const screen);
61+
62+ Screen* proxyObject() const { return m_original.data(); }
63+
64+public Q_SLOTS:
65+ void addWorkspace();
66+
67+private:
68+ const QPointer<Screen> m_original;
69+};
70+
71+#endif // SCREEN_H
plugins/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+}
plugins/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
plugins/WindowManager/Screens.cppnew file+202
@@ -0,0 +1,202 @@
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+#include "WorkspaceManager.h"
20+
21+// qtmirserver
22+#include <qtmir/screens.h>
23+#include <QGuiApplication>
24+
25+// Qt
26+#include <QScreen>
27+#include <QWindow>
28+
29+Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
30+ : m_wrapped(model)
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);
37+ connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
38+ connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &Screens::activeScreenChanged);
39+
40+ Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
41+ m_screens.push_back(new Screen(screen));
42+ }
43+}
44+
45+Screens::~Screens()
46+{
47+ qDeleteAll(m_screens);
48+ m_screens.clear();
49+}
50+
51+Screens::Screens(const Screens &other)
52+ : QAbstractListModel(nullptr)
53+ , m_wrapped(other.m_wrapped)
54+{
55+}
56+
57+QHash<int, QByteArray> Screens::roleNames() const
58+{
59+ QHash<int, QByteArray> roles;
60+ roles[ScreenRole] = "screen";
61+ return roles;
62+}
63+
64+QVariant Screens::data(const QModelIndex &index, int role) const
65+{
66+ if (!index.isValid() || index.row() >= m_screens.size()) {
67+ return QVariant();
68+ }
69+
70+ switch(role) {
71+ case ScreenRole:
72+ return QVariant::fromValue(m_screens.at(index.row()));
73+ } // switch
74+
75+ return QVariant();
76+}
77+
78+int Screens::rowCount(const QModelIndex &) const
79+{
80+ return count();
81+}
82+
83+int Screens::count() const
84+{
85+ return m_screens.size();
86+}
87+
88+QVariant Screens::activeScreen() const
89+{
90+ for (int i = 0; i < m_screens.count(); i++) {
91+ if (m_screens[i]->isActive()) return i;
92+ }
93+ return QVariant();
94+}
95+
96+ScreensProxy *Screens::createProxy()
97+{
98+ return new ScreensProxy(this);
99+}
100+
101+void Screens::sync(Screens *proxy)
102+{
103+ if (!proxy) return;
104+
105+ const auto& proxyList = proxy->list();
106+ for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
107+ m_screens[i]->sync(proxyList[i]);
108+ }
109+
110+ // need to clean up all the workspaces we unassigned.
111+ WorkspaceManager::instance()->destroyFloatingWorkspaces();
112+}
113+
114+void Screens::activateScreen(const QVariant& vindex)
115+{
116+ bool ok = false;
117+ int index = vindex.toInt(&ok);
118+ if (!ok || index < 0 || m_screens.count() <= index) return;
119+
120+ auto screen = m_screens.at(index);
121+ screen->setActive(true);
122+}
123+
124+void Screens::onScreenAdded(qtmir::Screen *added)
125+{
126+ Q_FOREACH(auto screenWrapper, m_screens) {
127+ if (screenWrapper->wrapped() == added) return;
128+ }
129+
130+ beginInsertRows(QModelIndex(), count(), count());
131+ auto screenWrapper(new Screen(added));
132+ m_screens.push_back(screenWrapper);
133+ endInsertRows();
134+ Q_EMIT screenAdded(screenWrapper);
135+ Q_EMIT countChanged();
136+}
137+
138+void Screens::onScreenRemoved(qtmir::Screen *removed)
139+{
140+ int index = 0;
141+ QMutableVectorIterator<Screen*> iter(m_screens);
142+ while(iter.hasNext()) {
143+ auto screenWrapper = iter.next();
144+ if (screenWrapper->wrapped() == removed) {
145+
146+ beginRemoveRows(QModelIndex(), index, index);
147+ iter.remove();
148+ endRemoveRows();
149+
150+ Q_EMIT screenRemoved(screenWrapper);
151+ Q_EMIT countChanged();
152+
153+ screenWrapper->deleteLater();
154+ break;
155+ }
156+ index++;
157+ }
158+}
159+
160+ScreensProxy::ScreensProxy(Screens * const screens)
161+ : Screens(*screens)
162+ , m_original(screens)
163+{
164+ connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
165+ Q_FOREACH(auto screen, m_screens) {
166+ auto proxy = static_cast<ScreenProxy*>(screen);
167+ if (proxy->proxyObject() == added) return;
168+ }
169+
170+ beginInsertRows(QModelIndex(), count(), count());
171+ auto screenWrapper(new ScreenProxy(added));
172+ m_screens.push_back(screenWrapper);
173+ endInsertRows();
174+ Q_EMIT screenAdded(screenWrapper);
175+ Q_EMIT countChanged();
176+ });
177+
178+ connect(screens, &Screens::screenAdded, this, [this](Screen *removed) {
179+ int index = 0;
180+ QMutableVectorIterator<Screen*> iter(m_screens);
181+ while(iter.hasNext()) {
182+ auto proxy = static_cast<ScreenProxy*>(iter.next());
183+ if (proxy->proxyObject() == removed) {
184+
185+ beginRemoveRows(QModelIndex(), index, index);
186+ iter.remove();
187+ endRemoveRows();
188+
189+ Q_EMIT screenRemoved(proxy);
190+ Q_EMIT countChanged();
191+
192+ delete proxy;
193+ break;
194+ }
195+ index++;
196+ }
197+ });
198+
199+ Q_FOREACH(Screen* screen, screens->list()) {
200+ m_screens.push_back(new ScreenProxy(screen));
201+ }
202+}
tests/mocks/Unity/Screens/screens.h → plugins/WindowManager/Screens.hrenamed+42−34
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016 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,47 +14,38 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef SCREENS_H
18−#define SCREENS_H
17+#ifndef UNITY_SCREENS_H
18+#define UNITY_SCREENS_H
1919
2020#include <QAbstractListModel>
21−#include <QScreen>
21+#include <QSharedPointer>
22+#include <QPointer>
23+
24+namespace qtmir
25+{
26+class Screen;
27+class Screens;
28+}
2229
2330class Screen;
31+class ScreensProxy;
2432
2533class Screens : public QAbstractListModel
2634{
2735 Q_OBJECT
28−
2936 Q_PROPERTY(int count READ count NOTIFY countChanged)
37+ Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
3038
3139public:
3240 enum ItemRoles {
33− ScreenRole = Qt::UserRole + 1,
34− OutputTypeRole
41+ ScreenRole = Qt::UserRole + 1
3542 };
3643
37− enum OutputTypes {
38− Unknown,
39− VGA,
40− DVII,
41− DVID,
42− DVIA,
43− Composite,
44− SVideo,
45− LVDS,
46− Component,
47− NinePinDIN,
48− DisplayPort,
49− HDMIA,
50− HDMIB,
51− TV,
52− EDP
53− };
54− Q_ENUM(OutputTypes)
44+ explicit Screens(const QSharedPointer<qtmir::Screens>& model);
45+ ~Screens();
5546
56− explicit Screens(QObject *parent = 0);
57− virtual ~Screens() noexcept;
47+ Q_INVOKABLE ScreensProxy *createProxy();
48+ Q_INVOKABLE void sync(Screens *proxy);
5849
5950 /* QAbstractItemModel */
6051 QHash<int, QByteArray> roleNames() const override;
@@ -62,21 +53,38 @@ public:
6253 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
6354
6455 int count() const;
56+ QVariant activeScreen() const;
57+
58+ const QVector<Screen*>& list() const { return m_screens; }
59+
60+public Q_SLOTS:
61+ void activateScreen(const QVariant& index);
6562
6663Q_SIGNALS:
6764 void countChanged();
68− void screenAdded(QScreen *screen);
69− void screenRemoved(QScreen *screen);
65+ void activeScreenChanged();
7066
71−private:
72− QList<Screen *> m_screenList;
67+ void screenAdded(Screen* screen);
68+ void screenRemoved(Screen* screen);
69+
70+private Q_SLOTS:
71+ void onScreenAdded(qtmir::Screen *screen);
72+ void onScreenRemoved(qtmir::Screen *screen);
73+
74+protected:
75+ Screens(const Screens& other);
76+
77+ QVector<Screen*> m_screens;
78+ QSharedPointer<qtmir::Screens> m_wrapped;
7379};
7480
75−class Screen
81+class ScreensProxy : public Screens
7682{
7783public:
78− Screens::OutputTypes outputTypes = Screens::Unknown;
79− QScreen *qScreen = nullptr;
84+ ScreensProxy(Screens*const screens);
85+
86+private:
87+ const QPointer<Screens> m_original;
8088};
8189
8290#endif // SCREENS_H
plugins/WindowManager/TopLevelWindowModel.cpp+232−43
@@ -24,11 +24,16 @@
2424#include <unity/shell/application/SurfaceManagerInterface.h>
2525
2626// Qt
27−#include <QGuiApplication>
2827#include <QDebug>
2928
3029// local
3130#include "Window.h"
31+#include "Workspace.h"
32+#include "windowmanagementpolicy.h"
33+
34+// qtmir
35+#include <qtmir/mirserverapplication.h>
36+#include <qtmir/windowmodelnotifier.h>
3237
3338Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
3439
@@ -55,35 +60,24 @@ void TopLevelWindowModel::setApplicationManager(unityapi::ApplicationManagerInte
5560 beginResetModel();
5661
5762 if (m_applicationManager) {
58− m_windowModel.clear();
5963 disconnect(m_applicationManager, 0, this, 0);
6064 }
6165
6266 m_applicationManager = value;
6367
64− if (m_applicationManager) {
65− connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
66− this, [this](const QModelIndex &/*parent*/, int first, int last) {
67− for (int i = first; i <= last; ++i) {
68− auto application = m_applicationManager->get(i);
69− addApplication(application);
70− }
71− });
68+ if (m_applicationManager && m_workspace) {
7269
73− connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
74− this, [this](const QModelIndex &/*parent*/, int first, int last) {
75− for (int i = first; i <= last; ++i) {
76− auto application = m_applicationManager->get(i);
77− removeApplication(application);
78− }
79− });
70+ if (m_workspace->isActive()) {
71+ connectApplicationManager();
72+ }
8073
81− for (int i = 0; i < m_applicationManager->rowCount(); ++i) {
82− auto application = m_applicationManager->get(i);
83− addApplication(application);
74+ if (m_surfaceManager) {
75+ refreshWindows();
8476 }
8577 }
8678
79+ Q_EMIT applicationManagerChanged(m_applicationManager);
80+
8781 endResetModel();
8882 m_modelState = IdleState;
8983}
@@ -96,6 +90,11 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
9690
9791 DEBUG_MSG << "(" << surfaceManager << ")";
9892
93+ Q_ASSERT(m_modelState == IdleState);
94+ m_modelState = ResettingState;
95+
96+ beginResetModel();
97+
9998 if (m_surfaceManager) {
10099 disconnect(m_surfaceManager, 0, this, 0);
101100 }
@@ -107,9 +106,71 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
107106 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
108107 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
109108 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
109+
110+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
111+ this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
112+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
113+ this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
114+
115+ if (m_workspace && m_applicationManager) {
116+ refreshWindows();
117+ }
110118 }
111119
112120 Q_EMIT surfaceManagerChanged(m_surfaceManager);
121+
122+ endResetModel();
123+ m_modelState = IdleState;
124+}
125+
126+void TopLevelWindowModel::setWorkspace(Workspace *workspace)
127+{
128+ if (workspace == m_workspace) {
129+ return;
130+ }
131+
132+ DEBUG_MSG << "(" << workspace << ")";
133+
134+ Q_ASSERT(m_modelState == IdleState);
135+ m_modelState = ResettingState;
136+
137+ beginResetModel();
138+
139+ if (m_workspace) {
140+ m_windowModel.clear();
141+ m_allSurfaces.clear();
142+ if (m_applicationManager) {
143+ disconnect(m_applicationManager, 0, this, 0);
144+ }
145+ }
146+
147+ disconnect(m_applicationManager, 0 ,this, 0);
148+
149+ m_workspace = workspace;
150+
151+ if (m_workspace) {
152+ connect(m_workspace, &Workspace::activeChanged, this, [this](bool active) {
153+ if (m_applicationManager) {
154+ if (!active) disconnect(m_applicationManager, 0, this, 0);
155+ else {
156+ connectApplicationManager();
157+ }
158+ }
159+ });
160+
161+ if (m_applicationManager && m_workspace->isActive()) {
162+ connectApplicationManager();
163+ }
164+
165+ if (m_surfaceManager && m_applicationManager) {
166+ refreshWindows();
167+ }
168+ }
169+
170+ Q_EMIT workspaceChanged(workspace);
171+
172+ endResetModel();
173+ m_modelState = IdleState;
113174}
114175
115176void TopLevelWindowModel::addApplication(unityapi::ApplicationInfoInterface *application)
@@ -179,6 +240,7 @@ void TopLevelWindowModel::prependSurfaceHelper(unityapi::MirSurfaceInterface *su
179240 Window *window = createWindow(surface);
180241
181242 m_windowModel.prepend(ModelEntry(window, application));
243+ m_allSurfaces.insert(surface);
182244 if (surface) {
183245 connectSurface(surface);
184246 }
@@ -313,6 +375,7 @@ void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surf
313375 auto window = m_windowModel[i].window;
314376 window->setSurface(nullptr);
315377 window->setFocused(false);
378+ m_allSurfaces.remove(surface);
316379 INFO_MSG << " Removed surface from entry. After: " << toString();
317380 }
318381}
@@ -328,38 +391,102 @@ Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface
328391 return qmlWindow;
329392}
330393
331−void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface *surface)
394+
395+void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface */*surface*/)
332396{
333− DEBUG_MSG << "(" << surface << ")";
397+}
334398
335− if (surface->parentSurface()) {
336− // Wrap it in a Window so that we keep focusedWindow() up to date.
337− Window *window = createWindow(surface);
338− connect(surface, &QObject::destroyed, window, [=](){
339− window->setSurface(nullptr);
340− window->deleteLater();
341− });
342− } else {
343− if (surface->type() == Mir::InputMethodType) {
344− setInputMethodWindow(createWindow(surface));
399+void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
400+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
401+{
402+ if (!m_workspace || !m_applicationManager) return;
403+ if (workspace != m_workspace->workspace()) return;
404+
405+ Q_FOREACH(auto surface, surfaces) {
406+ if (m_allSurfaces.contains(surface)) continue;
407+
408+ if (surface->parentSurface()) {
409+ // Wrap it in a Window so that we keep focusedWindow() up to date.
410+ Window *window = createWindow(surface);
411+ connect(surface, &QObject::destroyed, window, [=](){
412+ window->setSurface(nullptr);
413+ window->deleteLater();
414+ });
345415 } else {
346− auto *application = m_applicationManager->findApplicationWithSurface(surface);
347− if (application) {
348− prependSurface(surface, application);
416+ if (surface->type() == Mir::InputMethodType) {
417+ setInputMethodWindow(createWindow(surface));
349418 } else {
350− // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
351− // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
352− // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
353− Window *promptWindow = createWindow(surface);
354− connect(surface, &QObject::destroyed, promptWindow, [=](){
355− promptWindow->setSurface(nullptr);
356− promptWindow->deleteLater();
357− });
419+ auto *application = m_applicationManager->findApplicationWithSurface(surface);
420+ if (application) {
421+ prependSurface(surface, application);
422+ } else {
423+ // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
424+ // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
425+ // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
426+ Window *promptWindow = createWindow(surface);
427+ connect(surface, &QObject::destroyed, promptWindow, [=](){
428+ promptWindow->setSurface(nullptr);
429+ promptWindow->deleteLater();
430+ });
431+ }
358432 }
359433 }
360434 }
361435}
362436
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+
363490void TopLevelWindowModel::removeAt(int index)
364491{
365492 if (m_modelState == IdleState) {
@@ -376,6 +503,7 @@ void TopLevelWindowModel::removeAt(int index)
376503 window->setFocused(false);
377504
378505 m_windowModel.removeAt(index);
506+ m_allSurfaces.remove(window->surface());
379507
380508 if (m_modelState == RemovingState) {
381509 endRemoveRows();
@@ -444,6 +572,26 @@ QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
444572 }
445573}
446574
575+void TopLevelWindowModel::connectApplicationManager()
576+{
577+ connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
578+ this, [this](const QModelIndex &/*parent*/, int first, int last) {
579+ for (int i = first; i <= last; ++i) {
580+ auto application = m_applicationManager->get(i);
581+ addApplication(application);
582+ }
583+ });
584+
585+ connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
586+ this, [this](const QModelIndex &/*parent*/, int first, int last) {
587+ for (int i = first; i <= last; ++i) {
588+ auto application = m_applicationManager->get(i);
589+ removeApplication(application);
590+ }
591+ });
592+}
593+
594+
447595int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
448596{
449597 for (int i=0; i<m_windowModel.count(); i++) {
@@ -674,3 +822,44 @@ void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
674822 }
675823 }
676824}
825+
826+void TopLevelWindowModel::refreshWindows()
827+{
828+ DEBUG_MSG << "()";
829+
830+ m_windowModel.clear();
831+ m_allSurfaces.clear();
832+
833+ if (!m_workspace || !m_applicationManager) return;
834+ WindowManagementPolicy::instance()->forEachWindowInWorkspace(m_workspace->workspace(), [this](const miral::Window &window) {
835+ auto surface = m_surfaceManager->surfaceFor(window);
836+ if (surface) {
837+ if (surface->parentSurface()) {
838+ // Wrap it in a Window so that we keep focusedWindow() up to date.
839+ Window *window = createWindow(surface);
840+ connect(surface, &QObject::destroyed, window, [=](){
841+ window->setSurface(nullptr);
842+ window->deleteLater();
843+ });
844+ } else {
845+ if (surface->type() == Mir::InputMethodType) {
846+ setInputMethodWindow(createWindow(surface));
847+ } else {
848+ auto *application = m_applicationManager->findApplicationWithSurface(surface);
849+ if (application) {
850+ prependSurface(surface, application);
851+ } else {
852+ // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
853+ // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
854+ // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
855+ Window *promptWindow = createWindow(surface);
856+ connect(surface, &QObject::destroyed, promptWindow, [=](){
857+ promptWindow->setSurface(nullptr);
858+ promptWindow->deleteLater();
859+ });
860+ }
861+ }
862+ }
863+ }
864+ });
865+}
plugins/WindowManager/TopLevelWindowModel.h+24
@@ -20,9 +20,14 @@
2020#include <QAbstractListModel>
2121#include <QLoggingCategory>
2222
23+#include <memory>
24+
2325Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
2426
2527class Window;
28+class Workspace;
29+
30+namespace miral { class Workspace; }
2631
2732namespace unity {
2833 namespace shell {
@@ -70,6 +75,11 @@ class TopLevelWindowModel : public QAbstractListModel
7075 */
7176 Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
7277
78+ Q_PROPERTY(Workspace* workspace
79+ READ workspace
80+ WRITE setWorkspace
81+ NOTIFY workspaceChanged)
82+
7383 Q_PROPERTY(unity::shell::application::SurfaceManagerInterface* surfaceManager
7484 READ surfaceManager
7585 WRITE setSurfaceManager
@@ -111,6 +121,9 @@ public:
111121
112122 // Own API
113123
124+ Workspace* workspace() const { return m_workspace; }
125+ void setWorkspace(Workspace* workspace);
126+
114127 unity::shell::application::MirSurfaceInterface* inputMethodSurface() const;
115128 Window* focusedWindow() const;
116129
@@ -178,8 +191,14 @@ Q_SIGNALS:
178191
179192 void nextIdChanged();
180193
194+ void workspaceChanged(Workspace*);
195+
181196private Q_SLOTS:
182197 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
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);
183202 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
184203
185204 void onModificationsStarted();
@@ -208,6 +227,7 @@ private:
208227 void prependSurfaceHelper(unity::shell::application::MirSurfaceInterface *surface,
209228 unity::shell::application::ApplicationInfoInterface *application);
210229
230+ void connectApplicationManager();
211231 void connectWindow(Window *window);
212232 void connectSurface(unity::shell::application::MirSurfaceInterface *surface);
213233
@@ -219,6 +239,7 @@ private:
219239 void activateEmptyWindow(Window *window);
220240
221241 void activateTopMostWindowWithoutId(int forbiddenId);
242+ void refreshWindows();
222243
223244 Window *createWindow(unity::shell::application::MirSurfaceInterface *surface);
224245
@@ -235,6 +256,9 @@ private:
235256 QVector<ModelEntry> m_windowModel;
236257 Window* m_inputMethodWindow{nullptr};
237258 Window* m_focusedWindow{nullptr};
259+ Workspace* m_workspace{nullptr};
260+ // track all the surfaces we've been told about.
261+ QSet<unity::shell::application::MirSurfaceInterface*> m_allSurfaces;
238262
239263 int m_nextId{1};
240264 // Just something big enough that we don't risk running out of unused id numbers.
plugins/WindowManager/WindowManagerPlugin.cpp+31−1
@@ -16,16 +16,46 @@
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>
29+#include <qtmir/qtmir.h>
30+
31+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
32+{
33+ Q_UNUSED(engine)
34+ Q_UNUSED(scriptEngine)
35+ return WorkspaceManager::instance();
36+}
37+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
38+ Q_UNUSED(engine);
39+ Q_UNUSED(scriptEngine);
40+ return new Screens(qtmir::get_screen_model());
41+}
2342
2443void WindowManagerPlugin::registerTypes(const char *uri)
2544{
2645 qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
46+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
47+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", "Not a creatable type");
48+ qmlRegisterSingletonType<Screens>(uri, 1, 0, "Screens", screensSingleton);
49+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", "ScreenMode is not creatable.");
50+ qmlRegisterUncreatableType<Workspace>(uri, 1, 0, "Workspace", "Workspace is not creatable.");
2751
28− qRegisterMetaType<Window*>("Window*");
52+ qRegisterMetaType<Screen*>("Screen*");
53+ qRegisterMetaType<ScreensProxy*>("ScreensProxy*");
54+ qRegisterMetaType<Workspace*>("Workspace*");
2955
56+ qRegisterMetaType<Window*>("Window*");
3057 qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
58+
59+ qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
60+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
3161}
plugins/WindowManager/Workspace.cppnew file+146
@@ -0,0 +1,146 @@
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+#include "WorkspaceManager.h"
20+#include "TopLevelWindowModel.h"
21+
22+#include "windowmanagementpolicy.h"
23+
24+int nextWorkspace = 0;
25+
26+Workspace::Workspace(QObject *parent)
27+ : QObject(parent)
28+ , m_workspace(WindowManagementPolicy::instance()->createWorkspace())
29+ , m_model(nullptr)
30+ , m_active(false)
31+{
32+ setObjectName((QString("Wks%1").arg(nextWorkspace++)));
33+
34+ connect(WorkspaceManager::instance(), &WorkspaceManager::activeWorkspaceChanged, this, [this]() {
35+ bool newActive = WorkspaceManager::instance()->activeWorkspace() == this;
36+ if (newActive != m_active) {
37+ m_active = newActive;
38+ Q_EMIT activeChanged(m_active);
39+
40+ if (m_active) {
41+ WindowManagementPolicy::instance()->setActiveWorkspace(m_workspace);
42+ }
43+ }
44+ });
45+}
46+
47+Workspace::Workspace(const Workspace &other)
48+ : QObject(nullptr)
49+ , m_workspace(other.m_workspace)
50+ , m_model(nullptr)
51+ , m_active(other.m_active)
52+{
53+ setObjectName(other.objectName());
54+
55+ connect(&other, &Workspace::activeChanged, this, [this](bool active) {
56+ m_active = active;
57+ Q_EMIT activeChanged(m_active);
58+ });
59+}
60+
61+Workspace::~Workspace()
62+{
63+ if (m_model) {
64+ m_model->remove(this);
65+ }
66+}
67+
68+void Workspace::moveWindowsTo(Workspace *workspace)
69+{
70+ WindowManagementPolicy::instance()->moveWorkspaceContentToWorkspace(workspace->m_workspace, m_workspace);
71+}
72+
73+void Workspace::activate()
74+{
75+ WorkspaceManager::instance()->setActiveWorkspace(this);
76+}
77+
78+void Workspace::assign(WorkspaceModel *model, const QVariant& vIndex)
79+{
80+ if (m_model == model) return;
81+
82+ if (m_model) {
83+ disconnect(m_model, 0, this, 0);
84+ m_model->remove(this);
85+ }
86+
87+ m_model = model;
88+
89+ if (model) {
90+ int index = m_model->rowCount();
91+ if (vIndex.isValid() && vIndex.canConvert(QVariant::Int)) {
92+ index = vIndex.toInt();
93+ }
94+ m_model->insert(index, this);
95+
96+ connect(m_model, &QObject::destroyed, this, [this]() {
97+ m_model = nullptr;
98+ Q_EMIT unassigned();
99+ });
100+ Q_EMIT assigned();
101+ } else {
102+ Q_EMIT unassigned();
103+ }
104+}
105+
106+void Workspace::unassign()
107+{
108+ assign(nullptr);
109+}
110+
111+void Workspace::release()
112+{
113+ WindowManagementPolicy::instance()->releaseWorkspace(m_workspace);
114+ deleteLater();
115+}
116+
117+bool Workspace::isAssigned() const
118+{
119+ return m_model != nullptr;
120+}
121+
122+WorkspaceProxy::WorkspaceProxy(Workspace * const workspace)
123+ : Workspace(*workspace)
124+ , m_original(workspace)
125+{
126+}
127+
128+void WorkspaceProxy::assign(WorkspaceModel *model, const QVariant &index)
129+{
130+ Workspace::assign(model, index);
131+}
132+
133+void WorkspaceProxy::unassign()
134+{
135+ Workspace::unassign();
136+}
137+
138+bool WorkspaceProxy::isActive() const
139+{
140+ return m_original ? m_original->isActive() : false;
141+}
142+
143+void WorkspaceProxy::activate()
144+{
145+ if (m_original) m_original->activate();
146+}
plugins/WindowManager/Workspace.hnew file+100
@@ -0,0 +1,100 @@
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 WINDOWMANAGER_WORKSPACE_H
18+#define WINDOWMANAGER_WORKSPACE_H
19+
20+#include <QObject>
21+#include <QVariant>
22+#include <QPointer>
23+
24+#include <memory>
25+#include <functional>
26+
27+class WorkspaceModel;
28+class TopLevelWindowModel;
29+
30+namespace miral { class Workspace; }
31+
32+namespace unity {
33+ namespace shell {
34+ namespace application {
35+ class MirSurfaceInterface;
36+ }
37+ }
38+}
39+
40+class Workspace : public QObject
41+{
42+ Q_OBJECT
43+ Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
44+public:
45+ ~Workspace();
46+
47+ virtual void assign(WorkspaceModel* model, const QVariant& index = QVariant());
48+ virtual void unassign();
49+ void release();
50+
51+ virtual bool isActive() const { return m_active; }
52+ bool isAssigned() const;
53+
54+ void moveWindowsTo(Workspace* workspace);
55+
56+ std::shared_ptr<miral::Workspace> workspace() const { return m_workspace; }
57+
58+
59+public Q_SLOTS:
60+ virtual void activate();
61+
62+Q_SIGNALS:
63+ void assigned();
64+ void unassigned();
65+
66+ void activeChanged(bool);
67+
68+protected:
69+ Workspace(QObject *parent = 0);
70+ Workspace(Workspace const& other);
71+
72+ std::shared_ptr<miral::Workspace> m_workspace;
73+ WorkspaceModel* m_model;
74+ bool m_active;
75+
76+ friend class WorkspaceManager;
77+};
78+
79+class WorkspaceProxy : public Workspace
80+{
81+ Q_OBJECT
82+public:
83+ WorkspaceProxy(Workspace*const workspace);
84+
85+ Q_INVOKABLE void assign(WorkspaceModel* model, const QVariant& index = QVariant()) override;
86+
87+ bool isActive() const override;
88+
89+ void activate() override;
90+
91+ Workspace* proxyObject() const { return m_original.data(); }
92+
93+public Q_SLOTS:
94+ void unassign() override;
95+
96+private:
97+ const QPointer<Workspace> m_original;
98+};
99+
100+#endif // WINDOWMANAGER_WORKSPACE_H
plugins/WindowManager/WorkspaceManager.cppnew file+111
@@ -0,0 +1,111 @@
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+#include "TopLevelWindowModel.h"
20+
21+// Qt
22+#include <QGuiApplication>
23+#include <QScreen>
24+#include <QQmlEngine>
25+
26+WorkspaceManager *WorkspaceManager::instance()
27+{
28+ static WorkspaceManager* workspaceManager(new WorkspaceManager());
29+ return workspaceManager;
30+}
31+
32+WorkspaceManager::WorkspaceManager()
33+ : m_activeWorkspace(nullptr)
34+{
35+}
36+
37+Workspace *WorkspaceManager::createWorkspace()
38+{
39+ auto workspace = new Workspace(this);
40+ QQmlEngine::setObjectOwnership(workspace, QQmlEngine::CppOwnership);
41+ m_allWorkspaces.insert(workspace);
42+ m_floatingWorkspaces.append(workspace);
43+
44+ connect(workspace, &Workspace::assigned, this, [this, workspace]() {
45+ m_floatingWorkspaces.removeOne(workspace);
46+ Q_EMIT floatingWorkspacesChanged();
47+ });
48+ connect(workspace, &Workspace::unassigned, this, [this, workspace]() {
49+ m_floatingWorkspaces.append(workspace);
50+ Q_EMIT floatingWorkspacesChanged();
51+ });
52+
53+ if (m_allWorkspaces.count() == 0 && m_activeWorkspace) {
54+ setActiveWorkspace(nullptr);
55+ Q_EMIT activeWorkspaceChanged();
56+ } else if (m_allWorkspaces.count() == 1) {
57+ setActiveWorkspace(workspace);
58+ }
59+
60+ return workspace;
61+}
62+
63+void WorkspaceManager::destroyWorkspace(Workspace *workspace)
64+{
65+ if (!workspace) return;
66+
67+ if (workspace->isAssigned()) {
68+ workspace->unassign();
69+ }
70+ m_floatingWorkspaces.removeOne(workspace);
71+ m_allWorkspaces.remove(workspace);
72+ Q_EMIT floatingWorkspacesChanged();
73+
74+ if (m_activeWorkspace == workspace) {
75+ Q_ASSERT(false); // Shouldn't happen, should have chosen something by now.
76+ // just choose anything.
77+ setActiveWorkspace(m_allWorkspaces.count() ? *m_allWorkspaces.begin() : nullptr);
78+ }
79+ if (m_activeWorkspace) {
80+ workspace->moveWindowsTo(m_activeWorkspace);
81+ }
82+
83+ disconnect(workspace, 0, this, 0);
84+ workspace->release();
85+}
86+
87+QQmlListProperty<Workspace> WorkspaceManager::floatingWorkspaces()
88+{
89+ return QQmlListProperty<Workspace>(this, m_floatingWorkspaces);
90+}
91+
92+void WorkspaceManager::destroyFloatingWorkspaces()
93+{
94+ QList<Workspace*> dpCpy(m_floatingWorkspaces);
95+ Q_FOREACH(auto workspace, dpCpy) {
96+ destroyWorkspace(workspace);
97+ }
98+}
99+
100+Workspace *WorkspaceManager::activeWorkspace() const
101+{
102+ return m_activeWorkspace;
103+}
104+
105+void WorkspaceManager::setActiveWorkspace(Workspace *workspace)
106+{
107+ if (workspace != m_activeWorkspace) {
108+ m_activeWorkspace = workspace;
109+ Q_EMIT activeWorkspaceChanged();
110+ }
111+}
plugins/WindowManager/WorkspaceManager.hnew file+56
@@ -0,0 +1,56 @@
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+#include <QQmlListProperty>
22+
23+class Workspace;
24+class ScreensProxy;
25+
26+class WorkspaceManager : public QObject
27+{
28+ Q_OBJECT
29+ Q_PROPERTY(Workspace* activeWorkspace READ activeWorkspace WRITE setActiveWorkspace NOTIFY activeWorkspaceChanged)
30+ Q_PROPERTY(QQmlListProperty<Workspace> floatingWorkspaces READ floatingWorkspaces NOTIFY floatingWorkspacesChanged)
31+
32+public:
33+ static WorkspaceManager* instance();
34+
35+ Workspace* activeWorkspace() const;
36+ void setActiveWorkspace(Workspace* workspace);
37+
38+ Workspace* createWorkspace();
39+ void destroyWorkspace(Workspace* workspace);
40+
41+ QQmlListProperty<Workspace> floatingWorkspaces();
42+ void destroyFloatingWorkspaces();
43+
44+Q_SIGNALS:
45+ void activeWorkspaceChanged();
46+ void floatingWorkspacesChanged();
47+
48+private:
49+ WorkspaceManager();
50+
51+ QSet<Workspace*> m_allWorkspaces;
52+ QList<Workspace*> m_floatingWorkspaces;
53+ Workspace* m_activeWorkspace;
54+};
55+
56+#endif // WORKSPACEMANAGER_H
plugins/WindowManager/WorkspaceModel.cppnew file+187
@@ -0,0 +1,187 @@
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 "WorkspaceManager.h"
19+#include "Workspace.h"
20+
21+Q_LOGGING_CATEGORY(WORKSPACES, "Workspaces", QtInfoMsg)
22+
23+#define DEBUG_MSG qCDebug(WORKSPACES).nospace().noquote() << __func__
24+#define INFO_MSG qCInfo(WORKSPACES).nospace().noquote() << __func__
25+
26+WorkspaceModel::WorkspaceModel(QObject *parent)
27+ : QAbstractListModel(parent)
28+{
29+}
30+
31+void WorkspaceModel::append(Workspace *workspace)
32+{
33+ insert(m_workspaces.count(), workspace);
34+}
35+
36+void WorkspaceModel::insert(int index, Workspace *workspace)
37+{
38+ beginInsertRows(QModelIndex(), index, index);
39+
40+ m_workspaces.insert(index, workspace);
41+
42+ endInsertRows();
43+
44+ Q_EMIT workspaceAdded(workspace);
45+ Q_EMIT countChanged();
46+}
47+
48+void WorkspaceModel::remove(Workspace *workspace)
49+{
50+ int index = m_workspaces.indexOf(workspace);
51+ if (index < 0) return;
52+
53+ beginRemoveRows(QModelIndex(), index, index);
54+
55+ m_workspaces.removeAt(index);
56+
57+ endRemoveRows();
58+
59+ Q_EMIT workspaceRemoved(workspace);
60+ Q_EMIT countChanged();
61+}
62+
63+void WorkspaceModel::move(int from, int to)
64+{
65+ if (from == to) return;
66+ DEBUG_MSG << " from=" << from << " to=" << to;
67+
68+ if (from >= 0 && from < m_workspaces.size() && to >= 0 && to < m_workspaces.size()) {
69+ QModelIndex parent;
70+
71+ beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
72+#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
73+ const auto &window = m_windowModel.takeAt(from);
74+ m_workspaces.insert(to, window);
75+#else
76+ m_workspaces.move(from, to);
77+#endif
78+ endMoveRows();
79+ Q_EMIT countChanged();
80+ }
81+}
82+
83+int WorkspaceModel::indexOf(Workspace *workspace) const
84+{
85+ return m_workspaces.indexOf(workspace);
86+}
87+
88+Workspace *WorkspaceModel::get(int index) const
89+{
90+ if (index < 0 || index >= rowCount()) return nullptr;
91+ return m_workspaces.at(index);
92+}
93+
94+int WorkspaceModel::rowCount(const QModelIndex &) const
95+{
96+ return m_workspaces.count();
97+}
98+
99+QVariant WorkspaceModel::data(const QModelIndex &index, int role) const
100+{
101+ if (index.row() < 0 || index.row() >= m_workspaces.size())
102+ return QVariant();
103+
104+ if (role == WorkspaceRole) {
105+ Workspace *workspace = m_workspaces.at(index.row());
106+ return QVariant::fromValue(workspace);
107+ } else {
108+ return QVariant();
109+ }
110+}
111+
112+void WorkspaceModel::sync(WorkspaceModel *proxy)
113+{
114+ if (!proxy) return;
115+ const auto& proxyList = proxy->list();
116+
117+ // check for removals
118+ int removedIndexWhichWasActive = -1;
119+ QVector<Workspace*> dpCpy(this->list());
120+ Q_FOREACH(auto workspace, dpCpy) {
121+
122+ bool found = false;
123+ Q_FOREACH(auto p, proxyList) {
124+ auto workspaceProxy = static_cast<WorkspaceProxy*>(p);
125+ if (workspaceProxy->proxyObject() == workspace) {
126+ found = true;
127+ break;
128+ }
129+ }
130+ if (!found) {
131+ if (workspace->isActive()) {
132+ removedIndexWhichWasActive = indexOf(workspace);
133+ }
134+ workspace->unassign();
135+ }
136+ }
137+
138+ // existing
139+ QSet<Workspace*> newWorkspaces;
140+ for (int i = 0; i < proxyList.count(); i++) {
141+ auto workspaceProxy = static_cast<WorkspaceProxy*>(proxyList[i]);
142+ auto workspace = workspaceProxy->proxyObject();
143+
144+ int oldIndex = this->indexOf(workspace);
145+
146+ if (oldIndex < 0) {
147+ workspace->assign(this, QVariant(i));
148+ } else if (oldIndex != i) {
149+ this->move(oldIndex, i);
150+ }
151+ newWorkspaces.insert(workspace);
152+ }
153+
154+ // Make sure we have at least one workspace in the model.
155+ if (rowCount() == 0) {
156+ Workspace* workspace = WorkspaceManager::instance()->createWorkspace();
157+ workspace->assign(this);
158+ (new WorkspaceProxy(workspace))->assign(proxy);
159+ }
160+
161+ if (removedIndexWhichWasActive != -1) {
162+ int newActiveIndex = qMin(removedIndexWhichWasActive, this->rowCount()-1);
163+ Workspace* newActiveWorkspace = newActiveIndex >= 0 ? this->get(newActiveIndex) : nullptr;
164+
165+ WorkspaceManager::instance()->setActiveWorkspace(newActiveWorkspace);
166+ }
167+}
168+
169+
170+WorkspaceModelProxy::WorkspaceModelProxy(WorkspaceModel * const model)
171+ : m_original(model)
172+{
173+ Q_FOREACH(auto workspace, model->list()) {
174+ (new WorkspaceProxy(workspace))->assign(this);
175+ }
176+}
177+
178+WorkspaceModelProxy::~WorkspaceModelProxy()
179+{
180+ qDeleteAll(m_workspaces.toList()); // make a copy so the list doesnt edit itself during delete.
181+ m_workspaces.clear();
182+}
183+
184+void WorkspaceModelProxy::move(int from, int to)
185+{
186+ WorkspaceModel::move(from, to);
187+}
plugins/WindowManager/WorkspaceModel.hnew file+88
@@ -0,0 +1,88 @@
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+#include <QPointer>
23+
24+Q_DECLARE_LOGGING_CATEGORY(WORKSPACES)
25+
26+class Workspace;
27+class WorkspaceModelProxy;
28+
29+class WorkspaceModel : public QAbstractListModel
30+{
31+ Q_OBJECT
32+ Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
33+public:
34+ /**
35+ * @brief The Roles supported by the model
36+ *
37+ * WorkspaceRole - A workspace.
38+ */
39+ enum Roles {
40+ WorkspaceRole = Qt::UserRole
41+ };
42+
43+ explicit WorkspaceModel(QObject *parent = 0);
44+
45+ void append(Workspace *workspace);
46+ void insert(int index, Workspace *workspace);
47+ void remove(Workspace* workspace);
48+ virtual void move(int from, int to);
49+
50+ int indexOf(Workspace *workspace) const;
51+ Workspace* get(int index) const;
52+
53+ // From QAbstractItemModel
54+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
55+ QVariant data(const QModelIndex& index, int role) const override;
56+ QHash<int, QByteArray> roleNames() const override {
57+ QHash<int, QByteArray> roleNames { {WorkspaceRole, "workspace"} };
58+ return roleNames;
59+ }
60+
61+ const QVector<Workspace*>& list() const { return m_workspaces; }
62+
63+ void sync(WorkspaceModel* proxy);
64+
65+Q_SIGNALS:
66+ void countChanged();
67+
68+ void workspaceAdded(Workspace *workspace);
69+ void workspaceRemoved(Workspace *workspace);
70+
71+protected:
72+ QVector<Workspace*> m_workspaces;
73+};
74+
75+class WorkspaceModelProxy : public WorkspaceModel
76+{
77+ Q_OBJECT
78+public:
79+ WorkspaceModelProxy(WorkspaceModel*const model);
80+ ~WorkspaceModelProxy();
81+
82+ Q_INVOKABLE void move(int from, int to) override;
83+
84+private:
85+ const QPointer<WorkspaceModel> m_original;
86+};
87+
88+#endif // WORKSPACEMODEL_H
qml/CMakeLists.txt+1−1
@@ -1,4 +1,4 @@
1−file(GLOB QML_JS_FILES *.qml *.js)
1+file(GLOB QML_JS_FILES *.qml *.js qmldir)
22
33install(FILES ${QML_JS_FILES}
44 DESTINATION ${SHELL_APP_DIR}
qml/Components/PanelState/PanelState.qml−1
@@ -14,7 +14,6 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−pragma Singleton
1817import QtQuick 2.4
1918
2019QtObject {
qml/Components/PanelState/qmldir+1−1
@@ -1 +1 @@
1−singleton PanelState 1.0 PanelState.qml
1+PanelState 1.0 PanelState.qml
qml/Components/VirtualTouchPad.qml+14−20
@@ -18,22 +18,20 @@ 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
2525Item {
2626 id: root
27− property var uinput: UInput {
28− Component.onCompleted: createMouse();
29− Component.onDestruction: removeMouse();
30− }
3127
3228 Component.onCompleted: {
29+ UInput.createMouse();
3330 if (!settings.touchpadTutorialHasRun) {
3431 root.runTutorial()
3532 }
3633 }
34+ Component.onDestruction: UInput.removeMouse()
3735
3836 function runTutorial() {
3937 // If the tutorial animation is started too early, e.g. in Component.onCompleted,
@@ -85,7 +83,7 @@ Item {
8583 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
8684 && clickTimer.running) {
8785 clickTimer.stop();
88− uinput.pressMouse(UInput.ButtonLeft)
86+ UInput.pressMouse(UInput.ButtonLeft)
8987 isDoubleClick = true;
9088 }
9189 isClick = true;
@@ -104,7 +102,7 @@ Item {
104102
105103 onReleased: {
106104 if (isDoubleClick || isDrag) {
107− uinput.releaseMouse(UInput.ButtonLeft)
105+ UInput.releaseMouse(UInput.ButtonLeft)
108106 isDoubleClick = false;
109107 }
110108 if (isClick) {
@@ -120,8 +118,8 @@ Item {
120118 interval: 200
121119 property int button: UInput.ButtonLeft
122120 onTriggered: {
123− uinput.pressMouse(button);
124− uinput.releaseMouse(button);
121+ UInput.pressMouse(button);
122+ UInput.releaseMouse(button);
125123 }
126124 function scheduleClick(button) {
127125 clickTimer.button = button;
@@ -138,7 +136,7 @@ Item {
138136 isDrag = true;
139137 }
140138
141− uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
139+ UInput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
142140 }
143141
144142 function scroll(touchPoints) {
@@ -166,7 +164,7 @@ Item {
166164 dh /= 2;
167165 dv /= 2;
168166
169− uinput.scrollMouse(dh, dv);
167+ UInput.scrollMouse(dh, dv);
170168 }
171169
172170 touchPoints: [
@@ -189,8 +187,8 @@ Item {
189187 objectName: "leftButton"
190188 Layout.fillWidth: true
191189 Layout.fillHeight: true
192− onPressed: uinput.pressMouse(UInput.ButtonLeft);
193− onReleased: uinput.releaseMouse(UInput.ButtonLeft);
190+ onPressed: UInput.pressMouse(UInput.ButtonLeft);
191+ onReleased: UInput.releaseMouse(UInput.ButtonLeft);
194192 property bool highlight: false
195193 UbuntuShape {
196194 anchors.fill: parent
@@ -204,8 +202,8 @@ Item {
204202 objectName: "rightButton"
205203 Layout.fillWidth: true
206204 Layout.fillHeight: true
207− onPressed: uinput.pressMouse(UInput.ButtonRight);
208− onReleased: uinput.releaseMouse(UInput.ButtonRight);
205+ onPressed: UInput.pressMouse(UInput.ButtonRight);
206+ onReleased: UInput.releaseMouse(UInput.ButtonRight);
209207 property bool highlight: false
210208 UbuntuShape {
211209 anchors.fill: parent
@@ -239,14 +237,10 @@ Item {
239237 }
240238 }
241239
242− Screens {
243− id: screens
244− }
245−
246240 InputMethod {
247241 id: inputMethod
248242 // Don't resize when there is only one screen to avoid resize clashing with the InputMethod in the Shell.
249− enabled: screens.count > 1 && settings.oskEnabled && !tutorial.running
243+ enabled: Screens.count > 1 && settings.oskEnabled && !tutorial.running
250244 objectName: "inputMethod"
251245 anchors.fill: parent
252246 }
qml/DisabledScreenNotice.qml+2−1
@@ -28,8 +28,9 @@ Item {
2828 property var screen: Screen
2929 property var orientationLock: OrientationLock
3030
31+ property alias deviceConfiguration: _deviceConfiguration
3132 DeviceConfiguration {
32− id: deviceConfiguration
33+ id: _deviceConfiguration
3334 name: applicationArguments.deviceName
3435 }
3536
qml/Greeter/Greeter.qml+21−3
@@ -25,6 +25,7 @@ import Unity.Launcher 0.1
2525import Unity.Session 0.1
2626
2727import "." 0.1
28+import ".." 0.1
2829import "../Components"
2930
3031Showable {
@@ -227,7 +228,7 @@ Showable {
227228 if (forcedUnlock && shown) {
228229 hideView();
229230 if (hideNow) {
230− root.hideNow(); // skip hide animation
231+ ShellNotifier.greeter.hide(true); // skip hide animation
231232 }
232233 }
233234 }
@@ -375,7 +376,7 @@ Showable {
375376 onEmergencyCall: root.emergencyCall()
376377 onRequiredChanged: {
377378 if (!loader.item.required) {
378− root.hide();
379+ ShellNotifier.greeter.hide(false);
379380 }
380381 }
381382 }
@@ -498,12 +499,29 @@ Showable {
498499 onRequestAuthenticationUser: d.selectUser(d.getUserIndex(user))
499500 }
500501
502+ Connections {
503+ target: ShellNotifier.greeter
504+ onHide: {
505+ if (now) {
506+ root.hideNow(); // skip hide animation
507+ } else {
508+ root.hide();
509+ }
510+ }
511+ }
512+
513+ Binding {
514+ target: ShellNotifier.greeter
515+ property: "shown"
516+ value: root.shown
517+ }
518+
501519 Connections {
502520 target: DBusUnitySessionService
503521 onLockRequested: root.forceShow()
504522 onUnlocked: {
505523 root.forcedUnlock = true;
506− root.hideNow();
524+ ShellNotifier.greeter.hide(true);
507525 }
508526 }
509527
qml/Greeter/SecondaryGreeter.qmlnew file+75
@@ -0,0 +1,75 @@
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+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+
20+import "../Components"
21+import ".." 0.1
22+
23+Showable {
24+ id: root
25+
26+ readonly property bool active: required || hasLockedApp
27+
28+ readonly property bool hasLockedApp: lockedApp !== ""
29+ readonly property bool locked: false
30+ readonly property bool waiting: false
31+ readonly property bool fullyShown: shown
32+
33+ property string lockedApp: ""
34+
35+ function forceShow() { show(); }
36+ property var notifyAppFocusRequested: (function(appId) { return; })
37+ property var notifyUserRequestedApp: (function(appId) { return; })
38+ property var notifyShowingDashFromDrag: (function(appId) { return false; })
39+
40+ showAnimation: StandardAnimation { property: "opacity"; to: 1 }
41+ hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
42+
43+ shown: ShellNotifier.greeter.shown
44+ Component.onCompleted: opacity = shown ? 1 : 0
45+ visible: opacity != 0
46+
47+ Rectangle {
48+ anchors.fill: parent
49+ color: UbuntuColors.purple
50+ }
51+
52+ MouseArea {
53+ anchors.fill: parent
54+ acceptedButtons: Qt.AllButtons
55+ onWheel: wheel.accepted = true
56+ }
57+
58+ Connections {
59+ target: ShellNotifier.greeter
60+ onHide: {
61+ if (now) {
62+ root.hideNow(); // skip hide animation
63+ } else {
64+ root.hide();
65+ }
66+ }
67+ onShownChanged: {
68+ if (ShellNotifier.greeter.shown) {
69+ root.show();
70+ } else {
71+ root.hide();
72+ }
73+ }
74+ }
75+}
qml/OrientedShell.qml+7−10
@@ -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"
@@ -32,15 +32,16 @@ Item {
3232 implicitWidth: units.gu(40)
3333 implicitHeight: units.gu(71)
3434
35+ property alias deviceConfiguration: _deviceConfiguration
36+ property alias orientations: d.orientations
37+
3538 onWidthChanged: calculateUsageMode();
3639
3740 DeviceConfiguration {
38− id: deviceConfiguration
41+ id: _deviceConfiguration
3942 name: applicationArguments.deviceName
4043 }
4144
42− property alias orientations: d.orientations
43−
4445 Item {
4546 id: d
4647
@@ -157,10 +158,6 @@ Item {
157158 return false;
158159 }
159160
160− Screens {
161− id: screens
162− }
163−
164161 property int orientation
165162 onPhysicalOrientationChanged: {
166163 if (!orientationLocked) {
@@ -258,7 +255,7 @@ Item {
258255
259256 Shell {
260257 id: shell
261− objectName: "shell"
258+ objectName: "shell-"+screenWindow.objectName
262259 width: root.width
263260 height: root.height
264261 orientation: root.angleToOrientation(orientationAngle)
@@ -272,7 +269,7 @@ Item {
272269 // have multiple keyboards around. For now we only enable one keyboard at a time
273270 // thus hiding it here if there is a physical one around or if we have a second
274271 // screen (the virtual touchpad & osk on the phone) attached.
275− oskEnabled: (keyboardsModel.count === 0 && screens.count === 1) ||
272+ oskEnabled: (keyboardsModel.count === 0 && Screens.count === 1) ||
276273 forceOSKEnabled
277274
278275 usageScenario: {
qml/Panel/Panel.qml+14−14
@@ -47,8 +47,8 @@ Item {
4747 property bool fullscreenMode: false
4848 property real panelAreaShowProgress: 1.0
4949 property bool greeterShown: false
50−
5150 property string mode: "staged"
51+ property PanelState panelState
5252
5353 MouseArea {
5454 id: backMouseEater
@@ -65,14 +65,14 @@ Item {
6565 }
6666
6767 Binding {
68− target: PanelState
68+ target: panelState
6969 property: "panelHeight"
7070 value: minimizedPanelHeight
7171 }
7272
7373 RegisteredApplicationMenuModel {
7474 id: registeredMenuModel
75− persistentSurfaceId: PanelState.focusedPersistentSurfaceId
75+ persistentSurfaceId: panelState.focusedPersistentSurfaceId
7676 }
7777
7878 QtObject {
@@ -83,11 +83,11 @@ Item {
8383 !indicators.shown &&
8484 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
8585
86− property bool showWindowDecorationControls: (revealControls && PanelState.decorationsVisible) ||
87− PanelState.decorationsAlwaysVisible
86+ property bool showWindowDecorationControls: (revealControls && panelState.decorationsVisible) ||
87+ panelState.decorationsAlwaysVisible
8888
8989 property bool showPointerMenu: revealControls &&
90− (PanelState.decorationsVisible || mode == "staged")
90+ (panelState.decorationsVisible || mode == "staged")
9191
9292 property bool enablePointerMenu: revealControls &&
9393 applicationMenus.available &&
@@ -139,7 +139,7 @@ Item {
139139 fill: panelAreaBackground
140140 bottomMargin: -units.gu(1)
141141 }
142− visible: PanelState.dropShadow
142+ visible: panelState.dropShadow
143143 source: "graphics/rectangular_dropshadow.sci"
144144 }
145145
@@ -192,12 +192,12 @@ Item {
192192 visible: opacity != 0
193193 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
194194
195− active: PanelState.decorationsVisible || PanelState.decorationsAlwaysVisible
195+ active: panelState.decorationsVisible || panelState.decorationsAlwaysVisible
196196 windowIsMaximized: true
197− onCloseClicked: PanelState.closeClicked()
198− onMinimizeClicked: PanelState.minimizeClicked()
199− onMaximizeClicked: PanelState.restoreClicked()
200− closeButtonShown: PanelState.closeButtonShown
197+ onCloseClicked: panelState.closeClicked()
198+ onMinimizeClicked: panelState.minimizeClicked()
199+ onMaximizeClicked: panelState.restoreClicked()
200+ closeButtonShown: panelState.closeButtonShown
201201 }
202202
203203 Loader {
@@ -219,7 +219,7 @@ Item {
219219 anchors.left: parent.left
220220 anchors.margins: units.gu(1)
221221 height: menuBarLoader.height
222− enableKeyFilter: valid && PanelState.decorationsVisible
222+ enableKeyFilter: valid && panelState.decorationsVisible
223223 unityMenuModel: __applicationMenus.model
224224
225225 Connections {
@@ -267,7 +267,7 @@ Item {
267267 }
268268
269269 showRowTitle: !expanded
270− rowTitle: PanelState.title
270+ rowTitle: panelState.title
271271 rowItemDelegate: ActionItem {
272272 id: actionItem
273273 property int ownIndex: index
qml/Shell.qml+48−12
@@ -1,4 +1,4 @@
1−/*
1+/*
22 * Copyright (C) 2013-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
@@ -38,12 +38,14 @@ import "Notifications"
3838import "Stage"
3939import "Tutorial"
4040import "Wizard"
41+import "Components/PanelState"
4142import Unity.Notifications 1.0 as NotificationBackend
4243import Unity.Session 0.1
4344import Unity.DashCommunicator 0.1
4445import Unity.Indicators 0.1 as Indicators
4546import Cursor 1.1
4647import WindowManager 1.0
48+import Unity.Debug 0.1 as Debug
4749
4850
4951StyledItem {
@@ -259,21 +261,22 @@ StyledItem {
259261 schema.id: "com.canonical.Unity8"
260262 }
261263
264+ PanelState {
265+ id: panelState
266+ objectName: "panelState"
267+ }
268+
262269 Item {
263270 id: stages
264271 objectName: "stages"
265272 width: parent.width
266273 height: parent.height
267274
268− SurfaceManager {
269− id: surfaceMan
270− objectName: "surfaceManager"
271− }
272275 TopLevelWindowModel {
273276 id: topLevelSurfaceList
274277 objectName: "topLevelSurfaceList"
275278 applicationManager: ApplicationManager // it's a singleton
276− surfaceManager: surfaceMan
279+ surfaceManager: SurfaceManager
277280 }
278281
279282 Stage {
@@ -315,6 +318,7 @@ StyledItem {
315318 altTabPressed: physicalKeysMapper.altTabPressed
316319 oskEnabled: shell.oskEnabled
317320 spreadEnabled: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
321+ panelState: panelState
318322
319323 onSpreadShownChanged: {
320324 panel.indicators.hide();
@@ -369,8 +373,13 @@ StyledItem {
369373 objectName: "greeterLoader"
370374 anchors.fill: parent
371375 anchors.topMargin: panel.panelHeight
372− sourceComponent: shell.mode != "shell" ? integratedGreeter :
373− Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
376+ sourceComponent: {
377+ if (shell.mode != "shell") {
378+ if (screenWindow.primary) return integratedGreeter;
379+ return secondaryGreeter;
380+ }
381+ return Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
382+ }
374383 onLoaded: {
375384 item.objectName = "greeter"
376385 }
@@ -420,6 +429,13 @@ StyledItem {
420429 }
421430 }
422431
432+ Component {
433+ id: secondaryGreeter
434+ SecondaryGreeter {
435+ hides: [launcher, panel.indicators]
436+ }
437+ }
438+
423439 Timer {
424440 // See powerConnection for why this is useful
425441 id: showGreeterDelayed
@@ -533,6 +549,7 @@ StyledItem {
533549 fullscreenMode: (focusedSurfaceIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0 && !stage.spreadShown)
534550 || greeter.hasLockedApp
535551 greeterShown: greeter && greeter.shown
552+ panelState: panelState
536553 }
537554
538555 Launcher {
@@ -772,12 +789,13 @@ StyledItem {
772789
773790 Cursor {
774791 id: cursor
775− objectName: "cursor"
776− visible: shell.hasMouse
792+ objectName: "Pointer-"+screenWindow.objectName
793+
777794 z: itemGrabber.z + 1
795+ opacity: 0
778796 topBoundaryOffset: panel.panelHeight
779−
780− confiningItem: stage.itemConfiningMouseCursor
797+ enabled: shell.hasMouse && screenWindow.active
798+ visible: enabled
781799
782800 property bool mouseNeverMoved: true
783801 Binding {
@@ -789,6 +807,8 @@ StyledItem {
789807 when: cursor.mouseNeverMoved && cursor.visible
790808 }
791809
810+ confiningItem: stage.itemConfiningMouseCursor
811+
792812 height: units.gu(3)
793813
794814 readonly property var previewRectangle: stage.previewRectangle.target &&
@@ -875,4 +895,20 @@ StyledItem {
875895 }
876896 }
877897 }
898+
899+ Loader {
900+ z: shutdownFadeOutRectangle.z + 1
901+ active: DebuggingController.logOverlay
902+
903+ sourceComponent: Text {
904+ width: shell.width
905+ height: shell.height
906+
907+ text: consoleLog.out
908+ Debug.ConsoleLog {
909+ id: consoleLog
910+ enabled: true
911+ }
912+ }
913+ }
878914}
qml/ShellApplication.qmlnew file+48
@@ -0,0 +1,48 @@
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+import QtQuick 2.4
18+import QtQuick.Window 2.2
19+import WindowManager 1.0
20+
21+Instantiator {
22+ id: root
23+ model: Screens
24+
25+ ShellScreen {
26+ id: window
27+ objectName: "screen"+index
28+ screen: model.screen
29+ visibility: applicationArguments.hasFullscreen ? Window.FullScreen : Window.Windowed
30+ flags: applicationArguments.hasFrameless ? Qt.FramelessWindowHint : 0
31+
32+ Binding {
33+ when: applicationArguments.hasGeometry
34+ target: window
35+ property: "width"
36+ value: applicationArguments.windowGeometry.width
37+ }
38+ Binding {
39+ when: applicationArguments.hasGeometry
40+ target: window
41+ property: "height"
42+ value: applicationArguments.windowGeometry.height
43+ }
44+
45+ Component.onCompleted: screen.active = primary
46+ primary: index == 0
47+ }
48+}
src/SecondaryWindow.h → qml/ShellNotifier.qmlrenamed+12−12
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -14,17 +14,17 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef UNITY_SECONDARY_WINDOW_H
18−#define UNITY_SECONDARY_WINDOW_H
19−
20−#include <QQuickView>
17+/*
18+ Shared signals & properties on multi-window desktop
19+ */
2120
22−class SecondaryWindow : public QQuickView
23−{
24− Q_OBJECT
21+pragma Singleton
22+import QtQuick 2.4
2523
26−public:
27− SecondaryWindow(QQmlEngine *engine);
28−};
24+QtObject {
25+ property var greeter: QtObject {
26+ signal hide(bool now)
2927
30−#endif // UNITY_SECONDARY_WINDOW_H
28+ property bool shown: true
29+ }
30+}
qml/ShellScreen.qmlnew file+63
@@ -0,0 +1,63 @@
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+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+import WindowManager 1.0
20+import Cursor 1.1
21+import "Components"
22+
23+ScreenWindow {
24+ id: screenWindow
25+
26+ color: "black"
27+ title: "Unity8 Shell"
28+ property bool primary: false
29+
30+ DeviceConfiguration {
31+ id: deviceConfiguration
32+ name: applicationArguments.deviceName
33+ }
34+
35+ Loader {
36+ width: screenWindow.width
37+ height: screenWindow.height
38+
39+ sourceComponent: {
40+ if (Screens.count > 1 && primary && deviceConfiguration.category !== "desktop") {
41+ return disabledScreenComponent;
42+ }
43+ return shellComponent;
44+ }
45+ }
46+
47+ Component {
48+ id: shellComponent
49+ OrientedShell {
50+ implicitWidth: screenWindow.width
51+ implicitHeight: screenWindow.height
52+
53+ deviceConfiguration {
54+ name: Screens.count > 1 ? "desktop" : applicationArguments.deviceName
55+ }
56+ }
57+ }
58+
59+ Component {
60+ id: disabledScreenComponent
61+ DisabledScreenNotice {}
62+ }
63+}
qml/Stage/DecoratedWindow.qml+3−1
@@ -72,6 +72,8 @@ FocusScope {
7272
7373 readonly property Item clientAreaItem: applicationWindow
7474
75+ property PanelState panelState
76+
7577 signal closeClicked()
7678 signal maximizeClicked()
7779 signal maximizeHorizontallyClicked()
@@ -225,7 +227,7 @@ FocusScope {
225227 enableMenus: {
226228 return active &&
227229 surface &&
228− (PanelState.focusedPersistentSurfaceId === surface.persistentId && !PanelState.decorationsVisible)
230+ (panelState.focusedPersistentSurfaceId === surface.persistentId && !panelState.decorationsVisible)
229231 }
230232 menu: sharedAppModel.model
231233
qml/Stage/FakeMaximizeDelegate.qml+12−11
@@ -35,6 +35,7 @@ Rectangle {
3535 property int leftMargin
3636 property real appContainerWidth
3737 property real appContainerHeight
38+ property PanelState panelState
3839
3940 readonly property real hintThreshold: 0.1
4041
@@ -178,7 +179,7 @@ Rectangle {
178179 ParallelAnimation {
179180 id: fakeMaximizeAnimation
180181 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
181− UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
182+ UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: panelState.panelHeight }
182183 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: appContainerWidth - leftMargin }
183184 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight }
184185 }
@@ -186,39 +187,39 @@ Rectangle {
186187 ParallelAnimation {
187188 id: fakeMaximizeLeftAnimation
188189 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
189− UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
190+ UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: panelState.panelHeight }
190191 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
191− UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight - PanelState.panelHeight }
192+ UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight - panelState.panelHeight }
192193 }
193194
194195 ParallelAnimation {
195196 id: fakeMaximizeRightAnimation
196197 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
197− UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
198+ UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: panelState.panelHeight }
198199 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
199− UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight - PanelState.panelHeight }
200+ UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight - panelState.panelHeight }
200201 }
201202
202203 ParallelAnimation {
203204 id: fakeMaximizeTopLeftAnimation
204205 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
205− UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
206+ UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: panelState.panelHeight }
206207 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
207− UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight - PanelState.panelHeight)/2 }
208+ UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight - panelState.panelHeight)/2 }
208209 }
209210
210211 ParallelAnimation {
211212 id: fakeMaximizeTopRightAnimation
212213 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
213− UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: PanelState.panelHeight }
214+ UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: panelState.panelHeight }
214215 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
215− UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight - PanelState.panelHeight)/2 }
216+ UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight - panelState.panelHeight)/2 }
216217 }
217218
218219 ParallelAnimation {
219220 id: fakeMaximizeBottomLeftAnimation
220221 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
221− UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight + PanelState.panelHeight)/2 }
222+ UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight + panelState.panelHeight)/2 }
222223 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
223224 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }
224225 }
@@ -226,7 +227,7 @@ Rectangle {
226227 ParallelAnimation {
227228 id: fakeMaximizeBottomRightAnimation
228229 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
229− UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight + PanelState.panelHeight)/2 }
230+ UbuntuNumberAnimation { target: fakeRectangle; properties: "y"; duration: UbuntuAnimation.BriskDuration; to: (appContainerHeight + panelState.panelHeight)/2 }
230231 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
231232 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }
232233 }
qml/Stage/Stage.qml+26−24
@@ -47,6 +47,7 @@ FocusScope {
4747 property bool oskEnabled: false
4848 property rect inputMethodRect
4949 property real rightEdgePushProgress: 0
50+ property PanelState panelState
5051
5152 // Configuration
5253 property string mode: "staged"
@@ -352,20 +353,20 @@ FocusScope {
352353 Component.onCompleted: priv.updateMainAndSideStageIndexes();
353354
354355 Connections {
355− target: PanelState
356+ target: panelState
356357 onCloseClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
357358 onMinimizeClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestMinimize(); } }
358359 onRestoreClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestRestore(); } }
359360 }
360361
361362 Binding {
362− target: PanelState
363+ target: panelState
363364 property: "decorationsVisible"
364365 value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.maximized // FIXME for Locally integrated menus
365366 }
366367
367368 Binding {
368− target: PanelState
369+ target: panelState
369370 property: "title"
370371 value: {
371372 if (priv.focusedAppDelegate !== null) {
@@ -380,7 +381,7 @@ FocusScope {
380381 }
381382
382383 Binding {
383− target: PanelState
384+ target: panelState
384385 property: "focusedPersistentSurfaceId"
385386 value: {
386387 if (priv.focusedAppDelegate !== null) {
@@ -394,21 +395,21 @@ FocusScope {
394395 }
395396
396397 Binding {
397− target: PanelState
398+ target: panelState
398399 property: "dropShadow"
399400 value: priv.focusedAppDelegate && !priv.focusedAppDelegate.maximized && priv.foregroundMaximizedAppDelegate !== null && mode == "windowed"
400401 }
401402
402403 Binding {
403− target: PanelState
404+ target: panelState
404405 property: "closeButtonShown"
405406 value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized && !priv.focusedAppDelegate.isDash
406407 }
407408
408409 Component.onDestruction: {
409− PanelState.title = "";
410− PanelState.decorationsVisible = false;
411− PanelState.dropShadow = false;
410+ panelState.title = "";
411+ panelState.decorationsVisible = false;
412+ panelState.dropShadow = false;
412413 }
413414
414415 Instantiator {
@@ -672,7 +673,7 @@ FocusScope {
672673 Item {
673674 id: boundariesForWindowPlacement
674675 anchors.fill: parent
675− anchors.topMargin: PanelState.panelHeight
676+ anchors.topMargin: panelState.panelHeight
676677 visible: false
677678 }
678679
@@ -764,7 +765,7 @@ FocusScope {
764765 target: appDelegate
765766 property: "y"
766767 value: appDelegate.requestedY -
767− Math.min(appDelegate.requestedY - PanelState.panelHeight,
768+ Math.min(appDelegate.requestedY - panelState.panelHeight,
768769 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
769770 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
770771 && root.inputMethodRect.height > 0
@@ -1148,7 +1149,7 @@ FocusScope {
11481149 progress: 0
11491150 targetHeight: spreadItem.stackHeight
11501151 targetX: spreadMaths.targetX
1151− startY: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1152+ startY: appDelegate.fullscreen ? 0 : panelState.panelHeight
11521153 targetY: spreadMaths.targetY
11531154 targetAngle: spreadMaths.targetAngle
11541155 targetScale: spreadMaths.targetScale
@@ -1267,9 +1268,9 @@ FocusScope {
12671268 PropertyChanges {
12681269 target: appDelegate
12691270 x: stageMaths.itemX
1270− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1271+ y: appDelegate.fullscreen ? 0 : panelState.panelHeight
12711272 requestedWidth: appContainer.width
1272− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1273+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
12731274 visuallyMaximized: true
12741275 visible: appDelegate.x < root.width
12751276 }
@@ -1295,10 +1296,10 @@ FocusScope {
12951296 PropertyChanges {
12961297 target: appDelegate
12971298 x: stageMaths.itemX
1298− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1299+ y: appDelegate.fullscreen ? 0 : panelState.panelHeight
12991300 z: stageMaths.itemZ
13001301 requestedWidth: stageMaths.itemWidth
1301− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1302+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
13021303 visuallyMaximized: true
13031304 visible: appDelegate.x < root.width
13041305 }
@@ -1363,9 +1364,9 @@ FocusScope {
13631364 PropertyChanges {
13641365 target: appDelegate
13651366 windowedX: root.leftMargin
1366− windowedY: PanelState.panelHeight
1367+ windowedY: panelState.panelHeight
13671368 windowedWidth: (appContainer.width - root.leftMargin)/2
1368− windowedHeight: appContainer.height - PanelState.panelHeight
1369+ windowedHeight: appContainer.height - panelState.panelHeight
13691370 }
13701371 },
13711372 State {
@@ -1382,9 +1383,9 @@ FocusScope {
13821383 PropertyChanges {
13831384 target: appDelegate
13841385 windowedX: root.leftMargin
1385− windowedY: PanelState.panelHeight
1386+ windowedY: panelState.panelHeight
13861387 windowedWidth: (appContainer.width - root.leftMargin)/2
1387− windowedHeight: (appContainer.height - PanelState.panelHeight)/2
1388+ windowedHeight: (appContainer.height - panelState.panelHeight)/2
13881389 }
13891390 },
13901391 State {
@@ -1401,7 +1402,7 @@ FocusScope {
14011402 PropertyChanges {
14021403 target: appDelegate
14031404 windowedX: root.leftMargin
1404− windowedY: (appContainer.height + PanelState.panelHeight)/2
1405+ windowedY: (appContainer.height + panelState.panelHeight)/2
14051406 windowedWidth: (appContainer.width - root.leftMargin)/2
14061407 windowedHeight: appContainer.height/2
14071408 }
@@ -1423,8 +1424,8 @@ FocusScope {
14231424 State {
14241425 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
14251426 extend: "normal"
1426− PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: PanelState.panelHeight;
1427− windowedWidth: windowedWidth; windowedHeight: appContainer.height - PanelState.panelHeight }
1427+ PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: panelState.panelHeight;
1428+ windowedWidth: windowedWidth; windowedHeight: appContainer.height - panelState.panelHeight }
14281429 },
14291430 State {
14301431 name: "minimized"; when: appDelegate.minimized
@@ -1540,7 +1541,7 @@ FocusScope {
15401541 ]
15411542
15421543 Binding {
1543− target: PanelState
1544+ target: panelState
15441545 property: "decorationsAlwaysVisible"
15451546 value: appDelegate && appDelegate.maximized && touchControls.overlayShown
15461547 }
@@ -1785,6 +1786,7 @@ FocusScope {
17851786 leftMargin: root.leftMargin
17861787 appContainerWidth: appContainer.width
17871788 appContainerHeight: appContainer.height
1789+ panelState: root.panelState
17881790 }
17891791
17901792 MouseArea {
qml/qmldirnew file+1
@@ -0,0 +1 @@
1+singleton ShellNotifier 0.1 ShellNotifier.qml
src/ApplicationArguments.cpp+11−2
@@ -16,7 +16,16 @@
1616
1717#include "ApplicationArguments.h"
1818
19−ApplicationArguments::ApplicationArguments(QObject *parent)
20− : QObject(parent)
19+ApplicationArguments::ApplicationArguments(QCoreApplication *app)
20+ : QObject(app)
21+ , UnityCommandLineParser(*app)
2122{
2223}
24+
25+void ApplicationArguments::setDeviceName(const QString &deviceName)
26+{
27+ if (deviceName != m_deviceName) {
28+ m_deviceName = deviceName;
29+ Q_EMIT deviceNameChanged(m_deviceName);
30+ }
31+}
src/ApplicationArguments.h+17−15
@@ -23,31 +23,33 @@
2323#include <QSize>
2424#include <QString>
2525
26−class ApplicationArguments : public QObject
26+#include "UnityCommandLineParser.h"
27+
28+class ApplicationArguments : public QObject,
29+ public UnityCommandLineParser
2730{
2831 Q_OBJECT
2932 Q_PROPERTY(QString deviceName READ deviceName NOTIFY deviceNameChanged)
3033 Q_PROPERTY(QString mode READ mode CONSTANT)
34+
35+ Q_PROPERTY(bool hasGeometry READ hasGeometry CONSTANT)
36+ Q_PROPERTY(QSize windowGeometry READ windowGeometry CONSTANT)
37+ Q_PROPERTY(bool hasTestability READ hasTestability CONSTANT)
38+ Q_PROPERTY(bool hasFrameless READ hasFrameless CONSTANT)
39+ Q_PROPERTY(bool hasFullscreen READ hasFullscreen CONSTANT)
40+#ifdef UNITY8_ENABLE_TOUCH_EMULATION
41+ Q_PROPERTY(bool hasMouseToTouch READ hasMouseToTouch CONSTANT)
42+#endif
43+
3144public:
32− ApplicationArguments(QObject *parent = nullptr);
45+ ApplicationArguments(QCoreApplication *app);
3346
34− void setDeviceName(const QString &deviceName) {
35− if (deviceName != m_deviceName) {
36− m_deviceName = deviceName;
37− Q_EMIT deviceNameChanged(m_deviceName);
38− }
39− }
40− QString deviceName() const { return m_deviceName; }
47+ void setDeviceName(const QString &deviceName);
4148
42− void setMode(const QString &mode) { m_mode = mode; }
43− QString mode() const { return m_mode; }
49+ bool hasGeometry() const { return m_windowGeometry.isValid(); }
4450
4551Q_SIGNALS:
4652 void deviceNameChanged(const QString&);
47−
48−private:
49− QString m_deviceName;
50− QString m_mode;
5153};
5254
5355#endif // APPLICATION_ARGUMENTS_H
src/CMakeLists.txt+9−4
@@ -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(
@@ -27,9 +28,7 @@ set(SOURCE_FILES
2728 ApplicationArguments.cpp
2829 main.cpp
2930 CachingNetworkManagerFactory.cpp
30− SecondaryWindow.cpp
31− ShellApplication.cpp
32− ShellView.cpp
31+ UnityApplication.cpp
3332 UnityCommandLineParser.cpp
3433 UnixSignalHandler.cpp
3534 DebuggingController.cpp
@@ -47,7 +46,13 @@ qt5_use_modules(${SHELL_APP} DBus Gui Qml Quick Test)
4746if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
4847 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
4948endif()
50−target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} UbuntuGestures connectivity-qt1 unity8-private)
49+target_link_libraries(${SHELL_APP}
50+ ${ANDROID_PROPERTIES_LDFLAGS}
51+ ${QTMIRSERVER_LDFLAGS}
52+ UbuntuGestures
53+ connectivity-qt1
54+ unity8-private
55+)
5156
5257if (ENABLE_TOUCH_EMULATION)
5358 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
src/DebuggingController.cpp+12−1
@@ -49,7 +49,8 @@ public:
4949};
5050
5151DebuggingController::DebuggingController(QObject *parent):
52− UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent)
52+ UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent),
53+ m_logOverlay(false)
5354{
5455}
5556
@@ -90,3 +91,13 @@ void DebuggingController::SetLoggingFilterRules(const QString &filterRules)
9091{
9192 QLoggingCategory::setFilterRules(filterRules);
9293}
94+
95+void DebuggingController::SetLogOverlay(bool logOverlay)
96+{
97+ if (logOverlay == m_logOverlay) {
98+ return;
99+ }
100+
101+ m_logOverlay = logOverlay;
102+ Q_EMIT logOverlayChanged(m_logOverlay);
103+}
src/DebuggingController.h+14
@@ -32,10 +32,14 @@ class DebuggingController: public UnityDBusObject
3232 Q_OBJECT
3333 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Debugging")
3434
35+ Q_PROPERTY(bool logOverlay READ logOverlay NOTIFY logOverlayChanged)
36+
3537public:
3638 DebuggingController(QObject *parent = nullptr);
3739 ~DebuggingController() = default;
3840
41+ bool logOverlay() const { return m_logOverlay; }
42+
3943public Q_SLOTS:
4044 /**
4145 * Set the QSG_VISUALIZE mode. This follows the vlues supported by Qt in
@@ -53,5 +57,15 @@ public Q_SLOTS:
5357 */
5458 Q_SCRIPTABLE void SetLoggingFilterRules(const QString &filterRules);
5559
60+ /**
61+ * Enable/Disable the shell console log overlay
62+ */
63+ Q_SCRIPTABLE void SetLogOverlay(bool logOverlay);
64+
65+Q_SIGNALS:
66+ void logOverlayChanged(bool logOverlay);
67+
68+private:
69+ bool m_logOverlay;
5670};
5771#endif // DEBUGGINGCONTROLLER_H
src/SecondaryWindow.cppdeleted−40
@@ -1,40 +0,0 @@
1−/*
2− * Copyright (C) 2015 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 "SecondaryWindow.h"
18−
19−// local
20−#include <paths.h>
21−
22−#include <QQmlContext>
23−
24−SecondaryWindow::SecondaryWindow(QQmlEngine *engine)
25− : QQuickView(engine, nullptr)
26−{
27− QByteArray pxpguEnv = qgetenv("GRID_UNIT_PX");
28− bool ok;
29− int pxpgu = pxpguEnv.toInt(&ok);
30− if (!ok) {
31− pxpgu = 8;
32− }
33− engine->rootContext()->setContextProperty(QStringLiteral("internalGu"), pxpgu);
34− setResizeMode(QQuickView::SizeRootObjectToView);
35− setColor("black");
36− setTitle(QStringLiteral("Unity8 Shell - Secondary Screen"));
37−
38− QUrl source(::qmlDirectory() + "/DisabledScreenNotice.qml");
39− setSource(source);
40−}
src/ShellApplication.cppdeleted−216
@@ -1,216 +0,0 @@
1−/*
2− * Copyright (C) 2015 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 "ShellApplication.h"
18−
19−// Qt
20−#include <QLibrary>
21−#include <QProcess>
22−#include <QScreen>
23−
24−#include <libintl.h>
25−
26−// libandroid-properties
27−#include <hybris/properties/properties.h>
28−
29−// local
30−#include <paths.h>
31−#include "CachingNetworkManagerFactory.h"
32−#include "UnityCommandLineParser.h"
33−#include "DebuggingController.h"
34−
35−ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
36− : QGuiApplication(argc, argv)
37−{
38− setApplicationName(QStringLiteral("unity8"));
39− setOrganizationName(QStringLiteral("Canonical"));
40−
41− connect(this, &QGuiApplication::screenAdded, this, &ShellApplication::onScreenAdded);
42−
43− setupQmlEngine(isMirServer);
44−
45− UnityCommandLineParser parser(*this);
46−
47− if (!parser.deviceName().isEmpty()) {
48− m_deviceName = parser.deviceName();
49− } else {
50− char buffer[200];
51− property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
52− m_deviceName = QString(buffer);
53− }
54− m_qmlArgs.setDeviceName(m_deviceName);
55−
56− m_qmlArgs.setMode(parser.mode());
57−
58− // The testability driver is only loaded by QApplication but not by QGuiApplication.
59− // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
60− if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
61− QLibrary testLib(QStringLiteral("qttestability"));
62− if (testLib.load()) {
63− typedef void (*TasInitialize)(void);
64− TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
65− if (initFunction) {
66− initFunction();
67− } else {
68− qCritical("Library qttestability resolve failed!");
69− }
70− } else {
71− qCritical("Library qttestability load failed!");
72− }
73− }
74−
75− bindtextdomain("unity8", translationDirectory().toUtf8().data());
76− textdomain("unity8");
77−
78− m_shellView = new ShellView(m_qmlEngine, &m_qmlArgs);
79−
80− if (parser.windowGeometry().isValid()) {
81− m_shellView->setWidth(parser.windowGeometry().width());
82− m_shellView->setHeight(parser.windowGeometry().height());
83− }
84−
85− if (parser.hasFrameless()) {
86− m_shellView->setFlags(Qt::FramelessWindowHint);
87− }
88−
89−
90− #ifdef UNITY8_ENABLE_TOUCH_EMULATION
91− // You will need this if you want to interact with touch-only components using a mouse
92− // Needed only when manually testing on a desktop.
93− if (parser.hasMouseToTouch()) {
94− m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
95− }
96− #endif
97−
98− new DebuggingController(this);
99−
100− // Some hard-coded policy for now.
101− // NB: We don't support more than two screens at the moment
102− //
103− // TODO: Support an arbitrary number of screens and different policies
104− // (eg cloned desktop, several desktops, etc)
105− if (isMirServer && screens().count() == 2) {
106− m_shellView->setScreen(screens().at(1));
107− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
108−
109− m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
110− m_secondaryWindow->setScreen(screens().at(0));
111− // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
112− m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
113− m_secondaryWindow->setVisible(true);
114− }
115−
116− if (parser.mode().compare("greeter") == 0) {
117− QSize primaryScreenSize = this->primaryScreen()->size();
118− m_shellView->setHeight(primaryScreenSize.height());
119− m_shellView->setWidth(primaryScreenSize.width());
120− m_shellView->show();
121− m_shellView->requestActivate();
122− if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
123− qDebug() << "Unable to send unity8-greeter-started event to Upstart";
124− }
125− } else if (isMirServer || parser.hasFullscreen()) {
126− m_shellView->showFullScreen();
127− } else {
128− m_shellView->show();
129− }
130−}
131−
132−ShellApplication::~ShellApplication()
133−{
134− destroyResources();
135−}
136−
137−void ShellApplication::destroyResources()
138−{
139− // Deletion order is important. Don't use QScopedPointers and the like
140− // Otherwise the process will hang on shutdown (bug somewhere I guess).
141− delete m_shellView;
142− m_shellView = nullptr;
143−
144− delete m_secondaryWindow;
145− m_secondaryWindow = nullptr;
146−
147− #ifdef UNITY8_ENABLE_TOUCH_EMULATION
148− delete m_mouseTouchAdaptor;
149− m_mouseTouchAdaptor = nullptr;
150− #endif
151−
152− delete m_qmlEngine;
153− m_qmlEngine = nullptr;
154−}
155−
156−void ShellApplication::setupQmlEngine(bool isMirServer)
157−{
158− m_qmlEngine = new QQmlEngine(this);
159−
160− m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
161−
162− prependImportPaths(m_qmlEngine, ::overrideImportPaths());
163− if (!isMirServer) {
164− prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
165− }
166− appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
167−
168− m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
169−
170− QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
171−}
172−
173−void ShellApplication::onScreenAdded(QScreen * /*screen*/)
174−{
175− // TODO: Support an arbitrary number of screens and different policies
176− // (eg cloned desktop, several desktops, etc)
177− if (screens().count() == 2) {
178− m_shellView->setScreen(screens().at(1));
179− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
180− // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
181− // its backing QPlatformWindow recreated). So lets refocus it.
182− m_shellView->requestActivate();
183− // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
184− // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
185− m_shellView->setVisible(true);
186−
187− m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
188− m_secondaryWindow->setScreen(screens().at(0));
189−
190− // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
191− m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
192− m_secondaryWindow->setVisible(true);
193− }
194−}
195−
196−void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
197−{
198− // TODO: Support an arbitrary number of screens and different policies
199− // (eg cloned desktop, several desktops, etc)
200− if (screen == m_shellView->screen()) {
201− const QList<QScreen *> allScreens = screens();
202− Q_ASSERT(allScreens.count() > 1);
203− Q_ASSERT(allScreens.at(0) != screen);
204− Q_ASSERT(m_secondaryWindow);
205− delete m_secondaryWindow;
206− m_secondaryWindow = nullptr;
207− m_shellView->setScreen(allScreens.first());
208− m_qmlArgs.setDeviceName(m_deviceName);
209− // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
210− // its backing QPlatformWindow recreated). So lets refocus it.
211− m_shellView->requestActivate();
212− // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
213− // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
214− m_shellView->setVisible(true);
215− }
216−}
src/ShellView.cppdeleted−63
@@ -1,63 +0,0 @@
1−/*
2− * Copyright (C) 2015 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 "ShellView.h"
18−
19−// Qt
20−#include <QQmlContext>
21−#include <QQuickItem>
22−
23−// local
24−#include <paths.h>
25−
26−ShellView::ShellView(QQmlEngine *engine, QObject *qmlArgs)
27− : QQuickView(engine, nullptr)
28−{
29− setResizeMode(QQuickView::SizeRootObjectToView);
30− setColor("black");
31− setTitle(QStringLiteral("Unity8"));
32−
33− rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
34−
35− QUrl source(::qmlDirectory() + "/OrientedShell.qml");
36− setSource(source);
37−
38− connect(this, &QWindow::widthChanged, this, &ShellView::onWidthChanged);
39− connect(this, &QWindow::heightChanged, this, &ShellView::onHeightChanged);
40−}
41−
42−void ShellView::onWidthChanged(int w)
43−{
44− // For good measure in case SizeRootObjectToView doesn't fulfill its promise.
45− //
46− // There's at least one situation that's know to leave the root object with an outdated size.
47− // (really looks like Qt bug)
48− // Happens when starting unity8 with an external monitor already connected.
49− // The QResizeEvent we get still has the size of the first screen and since the resize move is triggered
50− // from the resize event handler, the root item doesn't get resized.
51− // TODO: Confirm the Qt bug and submit a patch upstream
52− if (rootObject()) {
53− rootObject()->setWidth(w);
54− }
55−}
56−
57−void ShellView::onHeightChanged(int h)
58−{
59− // See comment in ShellView::onWidthChanged()
60− if (rootObject()) {
61− rootObject()->setHeight(h);
62− }
63−}
src/UnityApplication.cppnew file+131
@@ -0,0 +1,131 @@
1+/*
2+ * Copyright (C) 2015 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 "UnityApplication.h"
18+
19+// Qt
20+#include <QLibrary>
21+#include <QProcess>
22+#include <QScreen>
23+#include <QQmlContext>
24+
25+#include <libintl.h>
26+
27+// libandroid-properties
28+#include <hybris/properties/properties.h>
29+
30+// local
31+#include <paths.h>
32+#include "CachingNetworkManagerFactory.h"
33+#include "UnityCommandLineParser.h"
34+#include "DebuggingController.h"
35+#include "windowmanagementpolicy.h"
36+
37+#include <QDebug>
38+
39+
40+
41+UnityApplication::UnityApplication(int & argc, char ** argv)
42+ : qtmir::MirServerApplication(argc, argv, { qtmir::SetWindowManagementPolicy<WindowManagementPolicy>() })
43+ , m_qmlArgs(this)
44+{
45+ setApplicationName(QStringLiteral("unity8"));
46+ setOrganizationName(QStringLiteral("Canonical"));
47+
48+ setupQmlEngine();
49+
50+ if (m_qmlArgs.deviceName().isEmpty()) {
51+ char buffer[200];
52+ property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
53+ m_qmlArgs.setDeviceName(QString(buffer));
54+ }
55+
56+ // The testability driver is only loaded by QApplication but not by QGuiApplication.
57+ // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
58+ if (m_qmlArgs.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
59+ QLibrary testLib(QStringLiteral("qttestability"));
60+ if (testLib.load()) {
61+ typedef void (*TasInitialize)(void);
62+ TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
63+ if (initFunction) {
64+ initFunction();
65+ } else {
66+ qCritical("Library qttestability resolve failed!");
67+ }
68+ } else {
69+ qCritical("Library qttestability load failed!");
70+ }
71+ }
72+
73+ bindtextdomain("unity8", translationDirectory().toUtf8().data());
74+ textdomain("unity8");
75+
76+ m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("applicationArguments"), &m_qmlArgs);
77+ m_qmlEngine->rootContext()->setContextProperty("DebuggingController", new DebuggingController(this));
78+
79+ QByteArray pxpguEnv = qgetenv("GRID_UNIT_PX");
80+ bool ok;
81+ int pxpgu = pxpguEnv.toInt(&ok);
82+ if (!ok) {
83+ pxpgu = 8;
84+ }
85+ m_qmlEngine->rootContext()->setContextProperty("internalGu", pxpgu);
86+ m_qmlEngine->load(m_qmlArgs.qmlfie());
87+
88+ #ifdef UNITY8_ENABLE_TOUCH_EMULATION
89+ // You will need this if you want to interact with touch-only components using a mouse
90+ // Needed only when manually testing on a desktop.
91+ if (m_qmlArgs.hasMouseToTouch()) {
92+ m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
93+ }
94+ #endif
95+
96+ if (m_qmlArgs.mode().compare("greeter") == 0) {
97+ if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
98+ qDebug() << "Unable to send unity8-greeter-started event to Upstart";
99+ }
100+ }
101+}
102+
103+UnityApplication::~UnityApplication()
104+{
105+ destroyResources();
106+}
107+
108+void UnityApplication::destroyResources()
109+{
110+ #ifdef UNITY8_ENABLE_TOUCH_EMULATION
111+ delete m_mouseTouchAdaptor;
112+ m_mouseTouchAdaptor = nullptr;
113+ #endif
114+
115+ delete m_qmlEngine;
116+ m_qmlEngine = nullptr;
117+}
118+
119+void UnityApplication::setupQmlEngine()
120+{
121+ m_qmlEngine = new QQmlApplicationEngine(this);
122+
123+ m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
124+
125+ prependImportPaths(m_qmlEngine, ::overrideImportPaths());
126+ appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
127+
128+ m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
129+
130+ QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
131+}
src/ShellApplication.h → src/UnityApplication.hrenamed+10−20
@@ -14,11 +14,11 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef SHELLAPPLICATION_H
18−#define SHELLAPPLICATION_H
17+#ifndef UNITYAPPLICATION_H
18+#define UNITYAPPLICATION_H
1919
2020#include <QGuiApplication>
21−#include <QQmlEngine>
21+#include <QQmlApplicationEngine>
2222#include <QQuickView>
2323#include <QScopedPointer>
2424
@@ -28,36 +28,26 @@
2828#include "MouseTouchAdaptor.h"
2929#endif
3030
31−#include "SecondaryWindow.h"
32−#include "ShellView.h"
31+#include <qtmir/mirserverapplication.h>
3332
34−class ShellApplication : public QGuiApplication
33+class UnityApplication : public qtmir::MirServerApplication
3534{
3635 Q_OBJECT
3736public:
38− ShellApplication(int & argc, char ** argv, bool isMirServer);
39− virtual ~ShellApplication();
37+ UnityApplication(int & argc, char ** argv);
38+ virtual ~UnityApplication();
4039
4140 void destroyResources();
42−public Q_SLOTS:
43− // called by qtmir
44− void onScreenAboutToBeRemoved(QScreen *screen);
45−
46−private Q_SLOTS:
47− void onScreenAdded(QScreen*);
4841
4942private:
50− void setupQmlEngine(bool isMirServer);
51− QString m_deviceName;
43+ void setupQmlEngine();
5244 ApplicationArguments m_qmlArgs;
53− ShellView *m_shellView{nullptr};
54− SecondaryWindow *m_secondaryWindow{nullptr};
5545
5646 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
5747 MouseTouchAdaptor *m_mouseTouchAdaptor{nullptr};
5848 #endif
5949
60− QQmlEngine *m_qmlEngine{nullptr};
50+ QQmlApplicationEngine *m_qmlEngine{nullptr};
6151};
6252
63−#endif // SHELLAPPLICATION_H
53+#endif // UNITYAPPLICATION_H
src/UnityCommandLineParser.cpp+8
@@ -15,6 +15,7 @@
1515 */
1616
1717#include "UnityCommandLineParser.h"
18+#include <paths.h>
1819
1920#include <QDebug>
2021
@@ -60,6 +61,11 @@ UnityCommandLineParser::UnityCommandLineParser(const QCoreApplication &app)
6061 QStringLiteral("mode"), QStringLiteral("full-greeter"));
6162 parser.addOption(modeOption);
6263
64+ QCommandLineOption qmlfileOption(QStringLiteral("qmlfile"),
65+ QStringLiteral("The base qml file to load"),
66+ QStringLiteral("qmlfile"), ::qmlDirectory() + "/ShellApplication.qml");
67+ parser.addOption(qmlfileOption);
68+
6369 // Treat args with single dashes the same as arguments with two dashes
6470 // Ex: -fullscreen == --fullscreen
6571 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
@@ -85,6 +91,8 @@ UnityCommandLineParser::UnityCommandLineParser(const QCoreApplication &app)
8591 m_hasFullscreen = parser.isSet(fullscreenOption);
8692 m_deviceName = parser.value(devicenameOption);
8793 resolveMode(parser, modeOption);
94+
95+ m_qmlfile = parser.value(qmlfileOption);
8896}
8997
9098int UnityCommandLineParser::parsePixelsValue(const QString &str)
src/UnityCommandLineParser.h+4−1
@@ -36,8 +36,10 @@ public:
3636 bool hasFullscreen() const { return m_hasFullscreen; }
3737 QString deviceName() const { return m_deviceName; }
3838 QString mode() const { return m_mode; }
39−private:
4039
40+ QString qmlfie() const { return m_qmlfile; }
41+
42+protected:
4143 int parsePixelsValue(const QString &str);
4244 static float getenvFloat(const char* name, float defaultValue);
4345 void resolveMode(QCommandLineParser &parser, QCommandLineOption &modeOption);
@@ -55,6 +57,7 @@ private:
5557 bool m_hasFullscreen;
5658 QString m_deviceName;
5759 QString m_mode;
60+ QString m_qmlfile;
5861};
5962
6063#endif // UNITY_COMMAND_LINE_PARSER_H
src/libunity8-private/CMakeLists.txt+10
@@ -4,16 +4,26 @@ set(VERSION ${SOVERSION}.0.0)
44
55project(lib${LIB_NAME})
66
7+include_directories(
8+ SYSTEM
9+ ${QTMIRSERVER_INCLUDE_DIRS}
10+)
11+
712set(lib${LIB_NAME}_SRCS
813 abstractdbusservicemonitor.cpp
914 unitydbusobject.cpp
1015 unitydbusvirtualobject.cpp
16+ windowmanagementpolicy.cpp
1117 )
1218
1319add_library(${LIB_NAME} SHARED
1420 ${lib${LIB_NAME}_SRCS}
1521 )
1622
23+target_link_libraries(${LIB_NAME}
24+ ${QTMIRSERVER_LDFLAGS}
25+ )
26+
1727set_target_properties(${LIB_NAME} PROPERTIES
1828 VERSION ${VERSION}
1929 SOVERSION ${SOVERSION}
src/libunity8-private/windowmanagementpolicy.cppnew file+87
@@ -0,0 +1,87 @@
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 "windowmanagementpolicy.h"
18+
19+#include <QDebug>
20+
21+WindowManagementPolicy* WindowManagementPolicy::m_self = nullptr;
22+
23+WindowManagementPolicy::WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate &dd)
24+ : qtmir::WindowManagementPolicy(tools, dd)
25+ , m_dummyWorkspace(this->tools.create_workspace())
26+{
27+ m_self = this;
28+
29+ // we must always have a active workspace.
30+ m_activeWorkspace = m_dummyWorkspace;
31+}
32+
33+WindowManagementPolicy *WindowManagementPolicy::instance()
34+{
35+ return m_self;
36+}
37+
38+void WindowManagementPolicy::advise_new_window(miral::WindowInfo const& window_info)
39+{
40+ qtmir::WindowManagementPolicy::advise_new_window(window_info);
41+
42+ auto const parent = window_info.parent();
43+
44+ auto activeWorkspace = m_activeWorkspace.lock();
45+ if (!parent && activeWorkspace)
46+ tools.add_tree_to_workspace(window_info.window(), activeWorkspace);
47+}
48+
49+std::shared_ptr<miral::Workspace> WindowManagementPolicy::createWorkspace()
50+{
51+ auto workspace = tools.create_workspace();
52+ m_workspaces.insert(workspace);
53+
54+ if (m_activeWorkspace.lock() == m_dummyWorkspace) {
55+ moveWorkspaceContentToWorkspace(workspace, m_dummyWorkspace);
56+ m_activeWorkspace = workspace;
57+ }
58+ return workspace;
59+}
60+
61+void WindowManagementPolicy::releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
62+{
63+ auto iter = m_workspaces.find(workspace);
64+ if (iter != m_workspaces.end()) m_workspaces.erase(iter);
65+
66+ if (m_workspaces.size() == 0) {
67+ m_activeWorkspace = m_dummyWorkspace;
68+ moveWorkspaceContentToWorkspace(m_dummyWorkspace, workspace);
69+ }
70+}
71+
72+void WindowManagementPolicy::forEachWindowInWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::function<void (const miral::Window &)> &callback)
73+{
74+ tools.for_each_window_in_workspace(workspace, callback);
75+}
76+
77+void WindowManagementPolicy::moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &toWorkspace, const std::shared_ptr<miral::Workspace> &fromWorkspace)
78+{
79+ tools.move_workspace_content_to_workspace(toWorkspace, fromWorkspace);
80+}
81+
82+void WindowManagementPolicy::setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
83+{
84+ if (m_activeWorkspace.lock() == workspace)
85+ return;
86+ m_activeWorkspace = workspace ? workspace : m_dummyWorkspace;
87+}
src/libunity8-private/windowmanagementpolicy.hnew file+53
@@ -0,0 +1,53 @@
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 UNITY_WINDOWMANAGEMENTPOLICY_H
18+#define UNITY_WINDOWMANAGEMENTPOLICY_H
19+
20+#include <qtmir/windowmanagementpolicy.h>
21+
22+#include <unordered_set>
23+
24+class Q_DECL_EXPORT WindowManagementPolicy : public qtmir::WindowManagementPolicy
25+{
26+public:
27+ WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate& dd);
28+
29+ static WindowManagementPolicy *instance();
30+
31+ void advise_new_window(miral::WindowInfo const& window_info) override;
32+
33+ std::shared_ptr<miral::Workspace> createWorkspace();
34+ void releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace);
35+
36+ void forEachWindowInWorkspace(
37+ std::shared_ptr<miral::Workspace> const& workspace,
38+ std::function<void(miral::Window const& window)> const& callback);
39+
40+ void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &toWorkspace,
41+ const std::shared_ptr<miral::Workspace> &fromWorkspace);
42+
43+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace>& workspace);
44+
45+private:
46+ static WindowManagementPolicy* m_self;
47+ std::weak_ptr<miral::Workspace> m_activeWorkspace;
48+
49+ std::unordered_set<std::shared_ptr<miral::Workspace>> m_workspaces;
50+ const std::shared_ptr<miral::Workspace> m_dummyWorkspace;
51+};
52+
53+#endif // UNITY_WINDOWMANAGEMENTPOLICY_H
src/main.cpp+4−8
@@ -15,9 +15,10 @@
1515 */
1616
1717// local
18−#include "ShellApplication.h"
18+#include "UnityApplication.h"
1919#include "qmldebuggerutils.h"
2020#include "UnixSignalHandler.h"
21+#include <paths.h>
2122
2223#include <QTranslator>
2324#include <QLibraryInfo>
@@ -27,17 +28,12 @@ int main(int argc, const char *argv[])
2728{
2829 qSetMessagePattern("[%{time yyyy-MM-dd:hh:mm:ss.zzz}] %{if-category}%{category}: %{endif}%{message}");
2930
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−
3631 if (enableQmlDebugger(argc, argv)) {
3732 QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true);
3833 }
3934
40− ShellApplication *application = new ShellApplication(argc, (char**)argv, isMirServer);
35+ auto *application = new UnityApplication(argc,
36+ (char**)argv);
4137
4238 UnixSignalHandler signalHandler([]{
4339 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/Cursor/Cursor.qml+49−2
@@ -15,8 +15,11 @@
1515 */
1616
1717import QtQuick 2.4
18+import UInput 0.1
19+
20+Canvas {
21+ id: root
1822
19−Item {
2023 property int topBoundaryOffset // effectively panel height
2124 property Item confiningItem
2225
@@ -30,5 +33,49 @@ Item {
3033 signal pushStopped()
3134 signal mouseMoved()
3235
33− onMouseMoved: opacity = 1;
36+ width: units.gu(2)
37+ height: units.gu(2)
38+ antialiasing: true
39+
40+ onPaint: {
41+ var ctx = getContext("2d");
42+ ctx.save();
43+ ctx.clearRect(0,0,width, height);
44+ ctx.strokeStyle = "#000000";
45+ ctx.lineWidth = 1
46+ ctx.fillStyle = "#ffffff";
47+ ctx.globalAlpha = 1.0;
48+ ctx.lineJoin = "round";
49+ ctx.beginPath();
50+
51+ // put rectangle in the middle
52+ // draw the rectangle
53+ ctx.moveTo(width/2,height);
54+ ctx.lineTo(width, height/2);
55+ ctx.lineTo(0,0);
56+
57+ ctx.closePath();
58+ ctx.fill();
59+ ctx.stroke();
60+ ctx.restore();
61+ }
62+
63+ Connections {
64+ target: UInput
65+ onMouseMoved: {
66+ var newX = root.x;
67+ newX += dx;
68+ if (newX < 0) newX = 0;
69+ else if (newX >= parent.width) newX = parent.width-1;
70+
71+ var newY = root.y;
72+ newY += dy;
73+ if (newY < 0) newY = 0;
74+ else if (newY >= parent.height) newY = parent.height-1;
75+
76+ root.x = newX;
77+ root.y = newY;
78+ root.mouseMoved();
79+ }
80+ }
3481}
tests/mocks/GSettings.1.0/plugin.cpp+12
@@ -18,6 +18,8 @@
1818#include "fake_gsettings.h"
1919
2020#include <QtQml/qqml.h>
21+#include <QQmlEngine>
22+#include <QQmlContext>
2123
2224static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
2325{
@@ -31,3 +33,13 @@ void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
3133 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
3234 "GSettingsSchema can only be used inside of a GSettings component");
3335}
36+
37+void FakeGSettingsQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
38+{
39+ QQmlExtensionPlugin::initializeEngine(engine, uri);
40+
41+ QString usageType = qgetenv("UNITY_MOCK_DESKTOP");
42+ if (!usageType.isEmpty()) {
43+ GSettingsControllerQml::instance()->setUsageMode("Windowed");
44+ }
45+}
tests/mocks/GSettings.1.0/plugin.h+1
@@ -26,6 +26,7 @@ class FakeGSettingsQmlPlugin : public QQmlExtensionPlugin
2626
2727public:
2828 void registerTypes(const char *uri) override;
29+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
2930};
3031
3132#endif // PLUGIN_H
tests/mocks/UInput/plugin.cpp+6−1
@@ -19,8 +19,13 @@
1919
2020#include <QtQml/qqml.h>
2121
22+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
23+{
24+ return new MockUInput;
25+}
26+
2227void MockUInputPlugin::registerTypes(const char *uri)
2328{
2429 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<MockUInput>(uri, 0, 1, "UInput");
30+ qmlRegisterSingletonType<MockUInput>(uri, 0, 1, "UInput", uinputSingleton);
2631}
tests/mocks/Unity/Application/CMakeLists.txt+25−1
@@ -1,3 +1,11 @@
1+pkg_check_modules(MIRTEST mirtest>=0.26 REQUIRED)
2+
3+include_directories(
4+ SYSTEM
5+ ${MIRTEST_INCLUDE_DIRS}
6+ ${MIRAL_INCLUDE_DIRS}
7+)
8+
19set(FakeUnityApplicationQml_SOURCES
210 plugin.cpp
311 ApplicationInfo.cpp
@@ -19,11 +27,27 @@ set(FakeUnityApplicationQml_SOURCES
1927 resources/surfaces.qrc
2028)
2129
22−add_library(FakeUnityApplicationQml MODULE ${FakeUnityApplicationQml_SOURCES})
30+add_library(FakeUnityApplicationQml MODULE
31+ ${FakeUnityApplicationQml_SOURCES}
32+)
33+
34+#add_dependencies(FakeUnityApplicationQml windowmanagementpolicy)
35+
36+target_link_libraries(FakeUnityApplicationQml
37+ ${MIRTEST_LDFLAGS}
38+ ${MIRAL_LDFLAGS}
39+ mockwindowmanagmentpolicy
40+)
2341
2442add_library(NonMirUnityApplicationQml MODULE ${FakeUnityApplicationQml_SOURCES})
2543set_target_properties(NonMirUnityApplicationQml PROPERTIES OUTPUT_NAME FakeUnityApplicationQml)
2644
45+target_link_libraries(NonMirUnityApplicationQml
46+ ${MIRTEST_LDFLAGS}
47+ ${MIRAL_LDFLAGS}
48+ mockwindowmanagmentpolicy
49+)
50+
2751qt5_use_modules(FakeUnityApplicationQml Core Quick DBus)
2852qt5_use_modules(NonMirUnityApplicationQml Core Quick DBus)
2953
tests/mocks/Unity/Application/SurfaceManager.cpp+60−2
@@ -18,10 +18,12 @@
1818
1919#include "ApplicationInfo.h"
2020#include "VirtualKeyboard.h"
21+#include "../../WindowManager/windowmanagementpolicy.h"
2122
2223#include <paths.h>
24+#include <mirtest/mir/test/doubles/stub_surface.h>
2325
24−#define SURFACEMANAGER_DEBUG 0
26+#define SURFACEMANAGER_DEBUG 1
2527
2628#if SURFACEMANAGER_DEBUG
2729#define DEBUG_MSG(params) qDebug().nospace() << "SurfaceManager[" << (void*)this << "]::" << __func__ << params
@@ -31,6 +33,12 @@
3133
3234namespace unityapi = unity::shell::application;
3335
36+uint qHash(const WindowWrapper &key, uint)
37+{
38+ std::shared_ptr<mir::scene::Surface> surface = key.window;
39+ return (quintptr)surface.get();
40+}
41+
3442SurfaceManager *SurfaceManager::m_instance = nullptr;
3543
3644SurfaceManager *SurfaceManager::instance()
@@ -44,6 +52,21 @@ SurfaceManager::SurfaceManager(QObject *)
4452
4553 Q_ASSERT(m_instance == nullptr);
4654 m_instance = this;
55+
56+ connect(WindowManagementPolicy::instance(), &WindowManagementPolicy::windowAdded,
57+ this, [this](const miral::Window& window) {
58+ Q_EMIT surfaceCreated(surfaceFor(window));
59+ });
60+
61+ connect(WindowManagementPolicy::instance(), &WindowManagementPolicy::windowsAddedToWorkspace,
62+ this, [this](const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows) {
63+ Q_EMIT surfacesAddedToWorkspace(workspace, find(windows));
64+ });
65+
66+ connect(WindowManagementPolicy::instance(), &WindowManagementPolicy::windowsAboutToBeRemovedFromWorkspace,
67+ this, [this](const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows) {
68+ Q_EMIT surfacesAboutToBeRemovedFromWorkspace(workspace, find(windows));
69+ });
4770}
4871
4972SurfaceManager::~SurfaceManager()
@@ -58,6 +81,29 @@ SurfaceManager::~SurfaceManager()
5881 m_instance = nullptr;
5982}
6083
84+
85+
86+QVector<MirSurfaceInterface*> SurfaceManager::find(const std::vector<miral::Window> &windows) const
87+{
88+ QVector<unityapi::MirSurfaceInterface*> surfaces;
89+ for (size_t i = 0; i < windows.size(); i++) {
90+ auto mirSurface = surfaceFor(windows[i]);
91+ if (mirSurface) {
92+ surfaces.push_back(mirSurface);
93+ }
94+ }
95+ return surfaces;
96+}
97+
98+MirSurfaceInterface *SurfaceManager::surfaceFor(const miral::Window& window) const
99+{
100+ auto iter = m_windowToSurface.find({window});
101+ if (iter != m_windowToSurface.end()) {
102+ return *iter;
103+ }
104+ return nullptr;
105+}
106+
61107MirSurface *SurfaceManager::createSurface(const QString& name,
62108 Mir::Type type,
63109 Mir::State state,
@@ -75,7 +121,12 @@ MirSurface *SurfaceManager::createSurface(const QString& name,
75121
76122void SurfaceManager::registerSurface(MirSurface *surface)
77123{
124+ auto fakeSurface = std::make_shared<mir::test::doubles::StubSurface>();
125+ WindowWrapper window{miral::Window(nullptr, fakeSurface), fakeSurface};
126+
78127 m_surfaces.prepend(surface);
128+ m_windowToSurface.insert(window, surface);
129+ m_surfaceToWindow.insert(surface, window);
79130
80131 if (!surface->parentSurface()) {
81132 surface->setMinimumWidth(m_newSurfaceMinimumWidth);
@@ -92,6 +143,8 @@ void SurfaceManager::registerSurface(MirSurface *surface)
92143
93144 const QString persistentId = surface->persistentId();
94145 connect(surface, &QObject::destroyed, this, [=]() {
146+ WindowWrapper key = m_surfaceToWindow.take(surface);
147+ m_windowToSurface.remove(key);
95148 this->onSurfaceDestroyed(surface, persistentId);
96149 });
97150
@@ -99,7 +152,12 @@ void SurfaceManager::registerSurface(MirSurface *surface)
99152
100153void SurfaceManager::notifySurfaceCreated(unityapi::MirSurfaceInterface *surface)
101154{
102− Q_EMIT surfaceCreated(surface);
155+ if (Q_UNLIKELY(!m_surfaceToWindow.contains(surface))) {
156+ Q_EMIT surfaceCreated(surface);
157+ return;
158+ }
159+
160+ WindowManagementPolicy::instance()->addWindow(m_surfaceToWindow[surface].window);
103161}
104162
105163void SurfaceManager::setNewSurfaceMinimumWidth(int value)
tests/mocks/Unity/Application/SurfaceManager.h+14
@@ -20,12 +20,20 @@
2020#include <QObject>
2121
2222#include <unity/shell/application/SurfaceManagerInterface.h>
23+#include <miral/window.h>
2324
2425#include "MirSurface.h"
2526#include "VirtualKeyboard.h"
2627
2728class ApplicationInfo;
2829
30+struct WindowWrapper {
31+ miral::Window window;
32+ std::shared_ptr<mir::scene::Surface> session{nullptr}; // Keeps the window surface alive.
33+ bool operator==(const WindowWrapper& other) const { return window==other.window; }
34+};
35+uint qHash(const WindowWrapper &key, uint seed = 0);
36+
2937class SurfaceManager : public unity::shell::application::SurfaceManagerInterface
3038{
3139 Q_OBJECT
@@ -42,6 +50,8 @@ public:
4250
4351 static SurfaceManager *instance();
4452
53+ unity::shell::application::MirSurfaceInterface *surfaceFor(const miral::Window& window) const override;
54+
4555 // SurfaceManagerInterface
4656 void raise(unity::shell::application::MirSurfaceInterface *surface) override;
4757 void activate(unity::shell::application::MirSurfaceInterface *surface) override;
@@ -95,6 +105,7 @@ private:
95105 void doRaise(unity::shell::application::MirSurfaceInterface *surface);
96106 void focusFirstAvailableSurface();
97107 void registerSurface(MirSurface *surface);
108+ QVector<unity::shell::application::MirSurfaceInterface*> find(const std::vector<miral::Window> &windows) const;
98109
99110 static SurfaceManager *m_instance;
100111
@@ -110,6 +121,9 @@ private:
110121
111122 QList<MirSurface*> m_surfaces;
112123
124+ QHash<WindowWrapper, unity::shell::application::MirSurfaceInterface*> m_windowToSurface;
125+ QHash<unity::shell::application::MirSurfaceInterface*, WindowWrapper> m_surfaceToWindow;
126+
113127 VirtualKeyboard *m_virtualKeyboard{nullptr};
114128};
115129
tests/mocks/Unity/Application/plugin.cpp+7−1
@@ -38,6 +38,12 @@ QObject* mirSingleton(QQmlEngine*, QJSEngine*)
3838{
3939 return new MirMock;
4040}
41+
42+QObject* surfaceManagerSingleton(QQmlEngine*, QJSEngine*)
43+{
44+ return new SurfaceManager;
45+}
46+
4147} // anonymous namespace
4248
4349void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
@@ -59,7 +65,7 @@ void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
5965
6066 qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
6167 qmlRegisterSingletonType<MirMock>(uri, 0, 1, "Mir", mirSingleton);
62− qmlRegisterType<SurfaceManager>(uri, 0, 1, "SurfaceManager");
68+ qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
6369}
6470
6571void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
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/InputInfo/InputWindow.qmlnew file+68
@@ -0,0 +1,68 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import Unity.InputInfo 0.1
4+
5+Rectangle {
6+ id: rect
7+ color: "white"
8+ width: parent.width
9+ height: parent.height
10+
11+ Action {
12+ id: mouseAction
13+ text: checked ? "Remove Mouse" : "Add Mouse"
14+ onTriggered: {
15+ if (checked) {
16+ console.log("ADD")
17+ MockInputDeviceBackend.addMockDevice("/mouse0", InputInfo.Mouse);
18+ } else {
19+ console.log("REMOVE")
20+ MockInputDeviceBackend.removeDevice("/mouse0");
21+ }
22+ }
23+ iconName: "input-mouse-symbolic"
24+ checkable: true
25+ checked: false
26+ }
27+
28+ Action {
29+ id: kbAction
30+ text: checked ? "Remove Keyboard" : "Add Keyboard"
31+ onTriggered: {
32+ if (checked) {
33+ MockInputDeviceBackend.addMockDevice("/kbd0", InputInfo.Keyboard);
34+ } else {
35+ MockInputDeviceBackend.removeDevice("/kbd0");
36+ }
37+ }
38+ iconName: "input-keyboard-symbolic"
39+ checkable: true
40+ checked: false
41+ }
42+
43+ Column {
44+ anchors {
45+ fill: parent
46+ margins: units.gu(1)
47+ }
48+ spacing: units.gu(1)
49+
50+ Button {
51+ anchors {
52+ left: parent.left
53+ right: parent.right
54+ }
55+ action: mouseAction
56+ color: mouseAction.checked ? UbuntuColors.red : UbuntuColors.green
57+ }
58+
59+ Button {
60+ anchors {
61+ left: parent.left
62+ right: parent.right
63+ }
64+ action: kbAction
65+ color: kbAction.checked ? UbuntuColors.red : UbuntuColors.green
66+ }
67+ }
68+}
tests/mocks/Unity/InputInfo/mockcontroller.cpp+24−2
@@ -18,10 +18,32 @@
1818
1919#include "qinputdeviceinfo_mock_p.h"
2020
21−MockController::MockController(QObject *parent):
22− QObject(parent)
21+#include <QQuickView>
22+#include <QQmlComponent>
23+#include <QQuickItem>
24+#include <paths.h>
25+
26+MockController::MockController(QQmlEngine *engine)
2327{
28+ QQmlComponent component(engine);
29+ component.setData("import QtQuick 2.4; import Unity.InputInfo 0.1; InputWindow { }", ::qmlDirectory());
30+ QObject *myObject = component.create();
31+ QQuickItem *item = qobject_cast<QQuickItem*>(myObject);
32+ if (item) {
33+ auto window = new QQuickView();
34+ window->setTitle("Input");
35+ item->setParentItem(window->contentItem());
36+ window->setResizeMode(QQuickView::SizeRootObjectToView);
37+ window->setWidth(200);
38+ window->setHeight(100);
39+ window->show();
40+ }
41+}
2442
43+MockController *MockController::instance(QQmlEngine *engine)
44+{
45+ static MockController* controller = new MockController(engine);
46+ return controller;
2547}
2648
2749QInputDevice *MockController::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
tests/mocks/Unity/InputInfo/mockcontroller.h+5−1
@@ -20,13 +20,17 @@
2020#include <QObject>
2121#include "qinputinfo.h"
2222
23+class QQmlEngine;
24+
2325class MockController: public QObject
2426{
2527 Q_OBJECT
2628public:
27− MockController(QObject *parent = 0);
29+ MockController(QQmlEngine *engine);
2830 ~MockController() = default;
2931
32+ static MockController *instance(QQmlEngine *engine);
33+
3034 Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
3135 Q_INVOKABLE void removeDevice(const QString &devicePath);
3236};
tests/mocks/Unity/InputInfo/plugin.cpp+1−2
@@ -26,9 +26,8 @@
2626
2727static QObject *backendProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
2828{
29− Q_UNUSED(engine)
3029 Q_UNUSED(scriptEngine)
31− return new MockController(engine);
30+ return MockController::instance(engine);
3231}
3332
3433void InputInfoPlugin::registerTypes(const char *uri)
tests/mocks/Unity/InputInfo/qmldir+2
@@ -1,2 +1,4 @@
11module Unity.InputInfo
22plugin MockInputInfo
3+
4+InputWindow 0.1 InputWindow.qml
tests/mocks/Unity/Screens/CMakeLists.txtdeleted−14
@@ -1,14 +0,0 @@
1−include_directories(
2− ${CMAKE_CURRENT_SOURCE_DIR}
3−)
4−
5−set(MockScreens_SOURCES
6− plugin.cpp
7− screens.cpp
8−)
9−
10−add_library(MockScreensPlugin MODULE ${MockScreens_SOURCES})
11−
12−qt5_use_modules(MockScreensPlugin Gui Qml)
13−
14−add_unity8_mock(Unity.Screens 0.1 Unity/Screens PREFIX mocks TARGETS MockScreensPlugin)
tests/mocks/Unity/Screens/plugin.cppdeleted−29
@@ -1,29 +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−
20−#include <QScreen>
21−
22−void UnityScreensPlugin::registerTypes(const char* uri)
23−{
24− Q_ASSERT(QLatin1String(uri) == QLatin1String("Unity.Screens"));
25−
26− qRegisterMetaType<QScreen*>("QScreen*");
27−
28− qmlRegisterType<Screens>(uri, 0, 1, "Screens");
29−}
tests/mocks/Unity/Screens/qmldirdeleted−2
@@ -1,2 +0,0 @@
1−module Unity.Screens
2−plugin MockScreensPlugin
tests/mocks/Unity/Screens/screens.cppdeleted−71
@@ -1,71 +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 "screens.h"
18−
19−// Qt
20−#include <QGuiApplication>
21−#include <QScreen>
22−#include <QDebug>
23−
24−Q_DECLARE_METATYPE(QScreen*)
25−
26−Screens::Screens(QObject *parent) :
27− QAbstractListModel(parent)
28−{
29− // start with one screen attached
30− m_screenList.append(new Screen());
31−}
32−
33−Screens::~Screens() noexcept
34−{
35− qDeleteAll(m_screenList);
36− m_screenList.clear();
37−}
38−
39−QHash<int, QByteArray> Screens::roleNames() const
40−{
41− QHash<int, QByteArray> roles;
42− roles[ScreenRole] = "screen";
43− roles[OutputTypeRole] = "outputType";
44− return roles;
45−}
46−
47−QVariant Screens::data(const QModelIndex &index, int role) const
48−{
49− if (!index.isValid() || index.row() >= m_screenList.size()) {
50− return QVariant();
51− }
52−
53− switch(role) {
54− case ScreenRole:
55− return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
56− case OutputTypeRole:
57− return m_screenList.at(index.row())->outputTypes;
58− }
59−
60− return QVariant();
61−}
62−
63−int Screens::rowCount(const QModelIndex &) const
64−{
65− return count();
66−}
67−
68−int Screens::count() const
69−{
70− return m_screenList.size();
71−}
tests/mocks/WindowManager/CMakeLists.txtnew file+47
@@ -0,0 +1,47 @@
1+include_directories(
2+ SYSTEM
3+ ${QTMIRSERVER_INCLUDE_DIRS}
4+)
5+
6+include_directories(
7+ ${CMAKE_CURRENT_SOURCE_DIR}
8+ ${CMAKE_CURRENT_BINARY_DIR}
9+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager
10+)
11+
12+add_library(mockwindowmanagmentpolicy SHARED
13+ windowmanagementpolicy.cpp
14+)
15+target_link_libraries(mockwindowmanagmentpolicy
16+ ${MIRAL_LDFLAGS}
17+)
18+qt5_use_modules(mockwindowmanagmentpolicy Core)
19+
20+set(WINDOWMANAGER_SRC
21+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Screen.cpp
22+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Screens.cpp
23+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/TopLevelWindowModel.cpp
24+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Window.cpp
25+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceManager.cpp
26+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceModel.cpp
27+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
28+ MockScreens.cpp
29+ ScreenWindow.cpp
30+ WindowManagerPlugin.cpp
31+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
32+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
33+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
34+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
35+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
36+)
37+
38+add_library(MockWindowManager-qml SHARED ${WINDOWMANAGER_SRC})
39+
40+target_link_libraries(MockWindowManager-qml
41+ ${QTMIRSERVER_LDFLAGS}
42+ mockwindowmanagmentpolicy
43+)
44+
45+qt5_use_modules(MockWindowManager-qml Qml Quick Gui)
46+
47+add_unity8_mock(WindowManager 1.0 WindowManager TARGETS MockWindowManager-qml)
tests/mocks/WindowManager/MockScreens.cppnew file+140
@@ -0,0 +1,140 @@
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 "MockScreens.h"
18+
19+// qtmirserver
20+#include <qtmir/screen.h>
21+
22+namespace {
23+
24+class MockScreen : public qtmir::Screen
25+{
26+ Q_OBJECT
27+public:
28+ MockScreen()
29+ {
30+ m_sizes.append(new qtmir::ScreenMode(50, QSize(640,480)));
31+ m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
32+ m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
33+ m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
34+ m_physicalSize = QSize(800,568);
35+ }
36+
37+ qtmir::OutputId outputId() const override { return m_id; }
38+ bool used() const override { return m_used; }
39+ QString name() const override { return m_name; }
40+ float scale() const override { return m_scale; }
41+ QSizeF physicalSize() const override { return m_physicalSize; }
42+ qtmir::FormFactor formFactor() const override { return m_formFactor; }
43+ qtmir::OutputTypes outputType() const override { return m_outputType; }
44+ MirPowerMode powerMode() const override { return m_powerMode; }
45+ Qt::ScreenOrientation orientation() const override { return m_orientation; }
46+ QPoint position() const override { return m_position; }
47+ uint currentModeIndex() const override { return m_currentModeIndex; }
48+ bool isActive() const override { return m_active; }
49+
50+ QQmlListProperty<qtmir::ScreenMode> availableModes() override {
51+ return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
52+ }
53+
54+ void setActive(bool active) override {
55+ if (m_active != active) {
56+ m_active = active;
57+ Q_EMIT activeChanged(m_active);
58+ }
59+ }
60+
61+ QScreen* qscreen() const override { return nullptr; }
62+
63+ qtmir::ScreenConfiguration *beginConfiguration() const override {
64+ auto config = new qtmir::ScreenConfiguration;
65+ config->valid = true;
66+ config->id = m_id;
67+ config->used = m_used;
68+ config->topLeft = m_position;
69+ config->currentModeIndex = m_currentModeIndex;
70+ config->powerMode = m_powerMode;
71+ config->scale = m_scale;
72+ config->formFactor = m_formFactor;
73+ return config;
74+ }
75+
76+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override {
77+ m_used = configuration->used;
78+ m_position = configuration->topLeft;
79+ m_currentModeIndex = configuration->currentModeIndex;
80+ m_powerMode = configuration->powerMode;
81+ m_scale = configuration->scale;
82+ m_formFactor = configuration->formFactor;
83+ return true;
84+ }
85+
86+public:
87+ qtmir::OutputId m_id{0};
88+ bool m_active{false};
89+ bool m_used{true};
90+ QString m_name;
91+ qtmir::OutputTypes m_outputType{qtmir::Unknown};
92+ MirPowerMode m_powerMode{mir_power_mode_on};
93+ Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
94+ float m_scale{1.0};
95+ qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
96+ QPoint m_position;
97+ uint m_currentModeIndex{0};
98+ QList<qtmir::ScreenMode*> m_sizes;
99+ QSizeF m_physicalSize;
100+};
101+}
102+
103+MockScreens::MockScreens()
104+{
105+ bool ok = false;
106+ int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
107+ if (!ok) screenCount = 1;
108+ QPoint lastPoint(0,0);
109+ for (int i = 0; i < screenCount; ++i) {
110+ auto screen = new MockScreen();
111+ screen->m_id = qtmir::OutputId{i};
112+ screen->m_active = i == 0;
113+ screen->m_name = QString("Monitor %1").arg(i);
114+ screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
115+ screen->m_currentModeIndex = 3;
116+ m_mocks.append(screen);
117+
118+ lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
119+ }
120+}
121+
122+MockScreens::~MockScreens()
123+{
124+ qDeleteAll(m_mocks);
125+}
126+
127+QVector<qtmir::Screen *> MockScreens::screens() const
128+{
129+ return m_mocks;
130+}
131+
132+qtmir::Screen *MockScreens::activeScreen() const
133+{
134+ Q_FOREACH(auto screen, m_mocks) {
135+ if (screen->isActive()) return screen;
136+ }
137+ return nullptr;
138+}
139+
140+#include "MockScreens.moc"
tests/mocks/Unity/Screens/plugin.h → tests/mocks/WindowManager/MockScreens.hrenamed+27−6
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016 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,12 +14,33 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#include <QQmlExtensionPlugin>
18−#include <QtQml/qqml.h>
17+#ifndef MOCK_SCREENS_H
18+#define MOCK_SCREENS_H
1919
20−class UnityScreensPlugin : public QQmlExtensionPlugin {
20+#include <QAbstractListModel>
21+#include <QSharedPointer>
22+
23+#include <qtmir/screens.h>
24+
25+class Screen;
26+namespace qtmir
27+{
28+class Screens;
29+}
30+
31+class MockScreens : public qtmir::Screens
32+{
2133 Q_OBJECT
22− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
2334public:
24− void registerTypes(const char* uri) override;
35+ MockScreens();
36+ ~MockScreens();
37+
38+ QVector<qtmir::Screen*> screens() const override;
39+
40+ qtmir::Screen *activeScreen() const override;
41+
42+private:
43+ QVector<qtmir::Screen*> m_mocks;
2544};
45+
46+#endif // MOCK_SCREENS_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/WindowManager/WindowManagerPlugin.cppnew file+62
@@ -0,0 +1,62 @@
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 "MockScreens.h"
22+#include "ScreenWindow.h"
23+#include "TopLevelWindowModel.h"
24+#include "Window.h"
25+#include "WorkspaceManager.h"
26+#include "Workspace.h"
27+#include "WorkspaceModel.h"
28+
29+#include <QtQml>
30+
31+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
32+{
33+ Q_UNUSED(engine)
34+ Q_UNUSED(scriptEngine)
35+ return WorkspaceManager::instance();
36+}
37+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
38+ Q_UNUSED(engine);
39+ Q_UNUSED(scriptEngine);
40+ QSharedPointer<qtmir::Screens> mockScreens(new MockScreens());
41+ return new Screens(mockScreens);
42+}
43+
44+void WindowManagerPlugin::registerTypes(const char *uri)
45+{
46+ qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
47+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
48+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", "Not a creatable type");
49+ qmlRegisterSingletonType<Screens>(uri, 1, 0, "Screens", screensSingleton);
50+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", "ScreenMode is not creatable.");
51+ qmlRegisterUncreatableType<Workspace>(uri, 1, 0, "Workspace", "Workspace is not creatable.");
52+
53+ qRegisterMetaType<Screen*>("Screen*");
54+ qRegisterMetaType<ScreensProxy*>("ScreensProxy*");
55+ qRegisterMetaType<Workspace*>("Workspace*");
56+
57+ qRegisterMetaType<Window*>("Window*");
58+ qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
59+
60+ qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
61+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
62+}
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
tests/mocks/WindowManager/windowmanagementpolicy.cppnew file+98
@@ -0,0 +1,98 @@
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 "windowmanagementpolicy.h"
18+
19+WindowManagementPolicy *WindowManagementPolicy::instance()
20+{
21+ static WindowManagementPolicy* inst(new WindowManagementPolicy());
22+ return inst;
23+}
24+
25+WindowManagementPolicy::WindowManagementPolicy()
26+ : m_dummyWorkspace(std::shared_ptr<miral::Workspace>())
27+{
28+ m_activeWorkspace = m_dummyWorkspace;
29+}
30+
31+std::shared_ptr<miral::Workspace> WindowManagementPolicy::createWorkspace()
32+{
33+ auto workspace = std::make_shared<miral::Workspace>();
34+ m_workspaces.insert(workspace);
35+
36+ if (m_activeWorkspace.lock() == m_dummyWorkspace) {
37+ moveWorkspaceContentToWorkspace(workspace, m_dummyWorkspace);
38+ m_activeWorkspace = workspace;
39+ }
40+ return workspace;
41+}
42+
43+void WindowManagementPolicy::releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
44+{
45+ auto iter = m_workspaces.find(workspace);
46+ if (iter != m_workspaces.end()) m_workspaces.erase(iter);
47+
48+ if (m_workspaces.size() == 0) {
49+ m_activeWorkspace = m_dummyWorkspace;
50+ moveWorkspaceContentToWorkspace(m_dummyWorkspace, workspace);
51+ }
52+}
53+
54+void WindowManagementPolicy::forEachWindowInWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::function<void (const miral::Window &)> &callback)
55+{
56+ QMultiMap<miral::Workspace*, miral::Window>::iterator i = m_windows.find(workspace.get());
57+ while (i != m_windows.end() && i.key() == workspace.get()) {
58+ callback(i.value());
59+ ++i;
60+ }
61+}
62+
63+void WindowManagementPolicy::moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &to, const std::shared_ptr<miral::Workspace> &from)
64+{
65+ std::vector<miral::Window> windows;
66+
67+ QMultiMap<miral::Workspace*, miral::Window>::iterator i = m_windows.find(from.get());
68+ while (i != m_windows.end() && i.key() == from.get()) {
69+ windows.push_back(i.value());
70+ ++i;
71+ }
72+ Q_EMIT windowsAboutToBeRemovedFromWorkspace(from, windows);
73+ m_windows.remove(from.get());
74+
75+ Q_FOREACH(miral::Window window, windows) {
76+ m_windows.insert(to.get(), window);
77+ }
78+ Q_EMIT windowsAddedToWorkspace(to, windows);
79+}
80+
81+void WindowManagementPolicy::addWindow(const miral::Window &window)
82+{
83+ Q_EMIT windowAdded(window);
84+
85+ auto activeWorkspace = m_activeWorkspace.lock();
86+ if (activeWorkspace) {
87+ m_windows.insert(activeWorkspace.get(), window);
88+
89+ Q_EMIT windowsAddedToWorkspace(activeWorkspace, {window});
90+ }
91+}
92+
93+void WindowManagementPolicy::setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
94+{
95+ if (m_activeWorkspace.lock() == workspace)
96+ return;
97+ m_activeWorkspace = workspace ? workspace : m_dummyWorkspace;
98+}
tests/mocks/WindowManager/windowmanagementpolicy.hnew file+66
@@ -0,0 +1,66 @@
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 MOCKWINDOMANAGEMENTPOLICY_H
18+#define MOCKWINDOMANAGEMENTPOLICY_H
19+
20+#include <QObject>
21+#include <QMultiMap>
22+#include <QVector>
23+
24+#include <miral/window.h>
25+#include <memory>
26+#include <unordered_set>
27+
28+namespace miral {
29+class Workspace {};
30+}
31+
32+// A Fake window management policy for the mock.
33+class Q_DECL_EXPORT WindowManagementPolicy : public QObject
34+{
35+ Q_OBJECT
36+public:
37+ WindowManagementPolicy();
38+
39+ static WindowManagementPolicy *instance();
40+
41+ std::shared_ptr<miral::Workspace> createWorkspace();
42+ void releaseWorkspace(const std::shared_ptr<miral::Workspace>& workspace);
43+
44+ void forEachWindowInWorkspace(std::shared_ptr<miral::Workspace> const& workspace,
45+ std::function<void(miral::Window const&)> const& callback);
46+
47+ void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace>& to,
48+ const std::shared_ptr<miral::Workspace>& from);
49+
50+ void addWindow(const miral::Window& window);
51+
52+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace>& workspace);
53+
54+Q_SIGNALS:
55+ void windowAdded(const miral::Window& window);
56+ void windowsAddedToWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
57+ void windowsAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
58+
59+private:
60+ std::weak_ptr<miral::Workspace> m_activeWorkspace;
61+ std::shared_ptr<miral::Workspace> m_dummyWorkspace;
62+ std::unordered_set<std::shared_ptr<miral::Workspace>> m_workspaces;
63+
64+ QMultiMap<miral::Workspace*, miral::Window> m_windows;
65+};
66+#endif // UNITY_WINDOWMANAGEMENTPOLICY_H
tests/qmltests/ApplicationMenuDataLoader.qml+1−4
@@ -6,11 +6,8 @@ import Unity.Indicators 0.1 as Indicators
66
77Object {
88
9− property alias surfaceManager: sMgrHandler.target
10−
119 Connections {
12− id: sMgrHandler
13− target: null
10+ target: SurfaceManager
1411 onSurfaceCreated: {
1512 var fakeMenuPath = "/" + surface.persistentId.replace(/\W+/g, "");
1613
tests/qmltests/ApplicationMenus/tst_MenuBar.qml−2
@@ -42,10 +42,8 @@ Item {
4242 value: false
4343 }
4444
45− SurfaceManager { id: sMgr }
4645 ApplicationMenuDataLoader {
4746 id: appMenuData
48− surfaceManager: sMgr
4947 }
5048
5149 Rectangle {
tests/qmltests/Components/tst_VirtualTouchPad.qml+2−2
@@ -39,11 +39,11 @@ Rectangle {
3939
4040 SignalSpy {
4141 id: mouseEventSpy1
42− target: touchScreenPad.uinput
42+ target: UInput
4343 }
4444 SignalSpy {
4545 id: mouseEventSpy2
46− target: touchScreenPad.uinput
46+ target: UInput
4747 }
4848
4949 UnityTestCase {
tests/qmltests/Panel/tst_ActiveCallHint.qml−2
@@ -41,8 +41,6 @@ Item {
4141 elapsedTimerRunning: true
4242 }
4343
44− SurfaceManager {}
45−
4644 ActiveCallHint {
4745 id: callHint
4846 anchors {
tests/qmltests/Panel/tst_Panel.qml+14−14
@@ -42,10 +42,10 @@ PanelTest {
4242 value: keyboardAttached.checked
4343 }
4444
45− SurfaceManager { id: sMgr }
45+ readonly property alias panelState: panel.panelState
46+
4647 ApplicationMenuDataLoader {
4748 id: appMenuData
48− surfaceManager: sMgr
4949 }
5050
5151 Component.onCompleted: {
@@ -148,7 +148,7 @@ PanelTest {
148148 Layout.fillWidth: true
149149 CheckBox {
150150 id: windowControlsCB
151− onClicked: PanelState.decorationsVisible = checked
151+ onClicked: panelState.decorationsVisible = checked
152152 }
153153 Label {
154154 text: "Show window decorations"
@@ -159,7 +159,7 @@ PanelTest {
159159 RowLayout {
160160 Layout.fillWidth: true
161161 CheckBox {
162− onClicked: PanelState.title = checked ? "Fake window title" : ""
162+ onClicked: panelState.title = checked ? "Fake window title" : ""
163163 }
164164 Label {
165165 text: "Show fake window title"
@@ -245,7 +245,7 @@ PanelTest {
245245
246246 SignalSpy {
247247 id: windowControlButtonsSpy
248− target: PanelState
248+ target: panelState
249249 signalName: "closeClicked"
250250 }
251251
@@ -255,8 +255,8 @@ PanelTest {
255255 panel.fullscreenMode = false;
256256 callManager.foregroundCall = null;
257257
258− PanelState.title = "";
259− PanelState.decorationsVisible = false;
258+ panelState.title = "";
259+ panelState.decorationsVisible = false;
260260
261261 // Wait for the indicators to get into position.
262262 // (switches between normal and fullscreen modes are animated)
@@ -447,7 +447,7 @@ PanelTest {
447447 }
448448
449449 function test_hint(data) {
450− PanelState.title = "Fake Title"
450+ panelState.title = "Fake Title"
451451 panel.fullscreenMode = data.fullscreen;
452452 callManager.foregroundCall = data.call;
453453
@@ -489,7 +489,7 @@ PanelTest {
489489 // menus, first by running the hint animation, then after dragging down will
490490 // expose more of the panel. Releasing the touch will complete the show.
491491 function test_drag_applicationMenu_down_shows_menu(data) {
492− PanelState.title = "Fake Title";
492+ panelState.title = "Fake Title";
493493 panel.fullscreenMode = data.fullscreen;
494494 callManager.foregroundCall = data.call;
495495
@@ -580,7 +580,7 @@ PanelTest {
580580 }
581581
582582 function test_darkenedAreaEatsAllApplicationMenuEvents() {
583− PanelState.title = "Fake Title"
583+ panelState.title = "Fake Title"
584584
585585 // The center of the area not covered by the indicators menu
586586 // Ie, the visible darkened area behind the menu
@@ -701,7 +701,7 @@ PanelTest {
701701 var windowControlArea = findChild(panel, "windowControlArea");
702702 verify(windowControlArea, "Window control area should have been created in windowed mode")
703703
704− PanelState.decorationsVisible = true;
704+ panelState.decorationsVisible = true;
705705 // click in very topleft corner and verify the close button got clicked too
706706 mouseMove(panel, 0, 0);
707707 mouseClick(panel, 0, 0, undefined /*button*/, undefined /*modifiers*/, 100 /*short delay*/);
@@ -762,7 +762,7 @@ PanelTest {
762762 }
763763
764764 function test_stagedApplicationMenuBarShowOnMouseHover() {
765− PanelState.title = "Fake Title";
765+ panelState.title = "Fake Title";
766766 panel.mode = "staged";
767767 mouseEmulation.checked = false;
768768
@@ -780,7 +780,7 @@ PanelTest {
780780 }
781781
782782 function test_windowedApplicationMenuShowOnMouseHoverWhenDecorationsShown() {
783− PanelState.title = "Fake Title";
783+ panelState.title = "Fake Title";
784784 panel.mode = "windowed";
785785 mouseEmulation.checked = false;
786786
@@ -796,7 +796,7 @@ PanelTest {
796796 tryCompare(appTitle, "visible", true, undefined, "App title should still be visible on mouse hover when panel decorations are not visible");
797797 tryCompare(appMenuBar, "visible", false, undefined, "App menu bar should be visible on mouse hover when panel decorations are not visible");
798798
799− PanelState.decorationsVisible = true;
799+ panelState.decorationsVisible = true;
800800
801801 tryCompare(appTitle, "visible", false, undefined, "App title should still be visible on mouse hover when panel decorations are visible");
802802 tryCompare(appMenuBar, "visible", true, undefined, "App menu bar should be visible on mouse hover when panel decorations not visible");
tests/qmltests/Stage/tst_ApplicationWindow.qml−2
@@ -37,8 +37,6 @@ Rectangle {
3737 }
3838 property QtObject fakeApplication: null
3939
40− SurfaceManager{}
41−
4240 Loader {
4341 id: applicationWindowLoader
4442 focus: true
tests/qmltests/Stage/tst_DecoratedWindow.qml+5−3
@@ -46,10 +46,12 @@ Rectangle {
4646 value: false
4747 }
4848
49− SurfaceManager { id: sMgr }
5049 ApplicationMenuDataLoader {
5150 id: appMenuData
52− surfaceManager: sMgr
51+ }
52+
53+ PanelState {
54+ id: panelState
5355 }
5456
5557 Item {
@@ -99,7 +101,7 @@ Rectangle {
99101 surface: fakeApplication && fakeApplication.surfaceList.count > 0 ? fakeApplication.surfaceList.get(0) : null
100102
101103 Binding {
102− target: PanelState
104+ target: panelState
103105 property: "focusedPersistentSurfaceId"
104106 value: decoratedWindow.surface ? decoratedWindow.surface.persistentId : "x"
105107 }
tests/qmltests/Stage/tst_DesktopStage.qml+9−6
@@ -44,6 +44,10 @@ Item {
4444 value: false
4545 }
4646
47+ PanelState {
48+ id: panelState
49+ }
50+
4751 Component.onCompleted: {
4852 ApplicationMenusLimits.screenWidth = Qt.binding( function() { return stageLoader.width; } );
4953 ApplicationMenusLimits.screenHeight = Qt.binding( function() { return stageLoader.height; } );
@@ -63,16 +67,14 @@ Item {
6367 }
6468 }
6569
66− SurfaceManager { id: sMgr }
6770 ApplicationMenuDataLoader {
6871 id: appMenuData
69− surfaceManager: sMgr
7072 }
7173
7274 TopLevelWindowModel {
7375 id: topSurfaceList
7476 applicationManager: ApplicationManager
75− surfaceManager: sMgr
77+ surfaceManager: SurfaceManager
7678 }
7779
7880 Loader {
@@ -102,6 +104,7 @@ Item {
102104 topLevelSurfaceList: topSurfaceList
103105 interactive: true
104106 mode: "windowed"
107+ panelState: panelState
105108 }
106109 }
107110 }
@@ -631,19 +634,19 @@ Item {
631634 maximizeDelegate(facebookAppDelegate);
632635
633636 // verify the drop shadow is still not visible
634− verify(PanelState.dropShadow == false);
637+ verify(panelState.dropShadow == false);
635638
636639 // start a foreground app, not maximized
637640 var dialerAppDelegate = startApplication("dialer-app");
638641
639642 // verify the drop shadow becomes visible
640− verify(PanelState.dropShadow == true);
643+ verify(panelState.dropShadow == true);
641644
642645 // close the maximized app
643646 ApplicationManager.stopApplication("facebook-webapp");
644647
645648 // verify the drop shadow is gone
646− tryCompare(PanelState, "dropShadow", false);
649+ tryCompare(panelState, "dropShadow", false);
647650 }
648651
649652 function test_threeFingerTapShowsWindowControls_data() {
tests/qmltests/Stage/tst_PhoneStage.qml+1−3
@@ -31,10 +31,8 @@ Item {
3131
3232 property var greeter: { fullyShown: true }
3333
34− SurfaceManager { id: sMgr }
3534 ApplicationMenuDataLoader {
3635 id: appMenuData
37− surfaceManager: sMgr
3836 }
3937
4038 Stage {
@@ -50,7 +48,7 @@ Item {
5048 topLevelSurfaceList: TopLevelWindowModel {
5149 id: topLevelSurfaceList
5250 applicationManager: ApplicationManager
53− surfaceManager: sMgr
51+ surfaceManager: SurfaceManager
5452 }
5553 Component.onCompleted: {
5654 ApplicationManager.startApplication("unity8-dash");
tests/qmltests/Stage/tst_SurfaceContainer.qml−2
@@ -51,8 +51,6 @@ Rectangle {
5151 }
5252 }
5353
54− SurfaceManager {}
55−
5654 Loader {
5755 id: surfaceContainerLoader
5856 focus: true
tests/qmltests/Stage/tst_TabletStage.qml+1−3
@@ -35,10 +35,8 @@ Rectangle {
3535
3636 property var greeter: { fullyShown: true }
3737
38− SurfaceManager { id: sMgr }
3938 ApplicationMenuDataLoader {
4039 id: appMenuData
41− surfaceManager: sMgr
4240 }
4341
4442 Stage {
@@ -59,7 +57,7 @@ Rectangle {
5957 topLevelSurfaceList: TopLevelWindowModel {
6058 id: topLevelSurfaceList
6159 applicationManager: ApplicationManager
62− surfaceManager: sMgr
60+ surfaceManager: SurfaceManager
6361 }
6462 Component.onCompleted: {
6563 ApplicationManager.startApplication("unity8-dash");
tests/qmltests/Stage/tst_WindowDecoration.qml−2
@@ -47,10 +47,8 @@ Item {
4747 property string name: "webbrowser"
4848 }
4949
50− SurfaceManager { id: sMgr }
5150 ApplicationMenuDataLoader {
5251 id: appMenuData
53− surfaceManager: sMgr
5452 }
5553
5654 UnityMenuModel {
tests/qmltests/Stage/tst_WindowResizeArea.qml+1−8
@@ -19,7 +19,6 @@ import QtQuick.Layouts 1.1
1919import QtTest 1.0
2020import Unity.Test 0.1
2121import ".."
22−import "../../../qml/Components/PanelState"
2322import "../../../qml/Stage"
2423import Ubuntu.Components 1.3
2524import Ubuntu.Components.ListItems 1.3 as ListItem
@@ -31,12 +30,6 @@ Item {
3130 height: units.gu(60)
3231 width: units.gu(85)
3332
34− Binding {
35− target: PanelState
36− property: "panelHeight"
37− value: units.gu(3)
38− }
39−
4033 Component {
4134 id: fakeWindowComponent
4235
@@ -362,7 +355,7 @@ Item {
362355
363356 // Make sure it's again where we left it in normal state before destroying
364357 compare(fakeWindow.requestedX >= 0, true)
365− compare(fakeWindow.requestedY >= PanelState.panelHeight, true)
358+ compare(fakeWindow.requestedY >= 0, true)
366359 compare(fakeWindow.requestedX + fakeWindow.width <= root.width, true)
367360 compare(fakeWindow.requestedY + fakeWindow.height <= root.height, true)
368361
tests/qmltests/Tutorial/tst_Tutorial.qml+1−3
@@ -326,9 +326,7 @@ Rectangle {
326326 }
327327
328328 function ensureInputMethodSurface() {
329− var surfaceManager = findInvisibleChild(shell, "surfaceManager");
330− verify(surfaceManager);
331− surfaceManager.createInputMethodSurface();
329+ SurfaceManager.createInputMethodSurface();
332330
333331 tryCompareFunction(function() { return topLevelSurfaceList.inputMethodSurface !== null }, true);
334332 }
tests/qmltests/tst_OrientedShell.qml+19−5
@@ -30,7 +30,6 @@ import Utils 0.1
3030
3131import "../../qml"
3232import "../../qml/Components"
33−import "../../qml/Components/PanelState"
3433import "Stage"
3534
3635Rectangle {
@@ -82,6 +81,12 @@ Rectangle {
8281 deviceFilter: InputInfo.Keyboard
8382 }
8483
84+ QtObject {
85+ id: _screenWindow
86+ property bool primary: true
87+ }
88+ property alias screenWindow: _screenWindow
89+
8590 property int physicalOrientation0
8691 property int physicalOrientation90
8792 property int physicalOrientation180
@@ -446,6 +451,15 @@ Rectangle {
446451 property Item orientedShell: orientedShellLoader.status === Loader.Ready ? orientedShellLoader.item : null
447452 property Item shell
448453 property QtObject topLevelSurfaceList
454+ property var panelState: undefined
455+
456+ onOrientedShellChanged: {
457+ if (orientedShell) {
458+ panelState = findInvisibleChild(orientedShell, "panelState");
459+ } else {
460+ panelState = undefined;
461+ }
462+ }
449463
450464 SignalSpy { id: signalSpy }
451465 SignalSpy { id: signalSpy2 }
@@ -1510,13 +1524,13 @@ Rectangle {
15101524 print("exptectedAngle", expectedAngle, point.x, point.y)
15111525 switch (expectedAngle) {
15121526 case 0:
1513− return point.x === 0 && point.y === PanelState.panelHeight;
1527+ return point.x === 0 && point.y === panelState.panelHeight;
15141528 case 90:
1515− return point.x === orientedShell.width - PanelState.panelHeight && point.y === 0;
1529+ return point.x === orientedShell.width - panelState.panelHeight && point.y === 0;
15161530 case 180:
1517− return point.x === orientedShell.width && point.y === orientedShell.height - PanelState.panelHeight;
1531+ return point.x === orientedShell.width && point.y === orientedShell.height - panelState.panelHeight;
15181532 default: // 270
1519− return point.x === PanelState.panelHeight && point.y === orientedShell.height;
1533+ return point.x === panelState.panelHeight && point.y === orientedShell.height;
15201534 }
15211535 }
15221536
tests/qmltests/tst_Shell.qml+20−15
@@ -61,14 +61,21 @@ Rectangle {
6161 onShellChanged: {
6262 if (shell) {
6363 topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
64− appMenuData.surfaceManager = testCase.findInvisibleChild(shell, "surfaceManager");
64+ panelState = testCase.findInvisibleChild(shell, "panelState");
6565 } else {
6666 topLevelSurfaceList = null;
67− appMenuData.surfaceManager = null;
67+ panelState = undefined;
6868 }
6969 }
7070
7171 property var topLevelSurfaceList: null
72+ property var panelState: undefined
73+
74+ QtObject {
75+ id: _screenWindow
76+ property bool primary: false
77+ }
78+ property alias screenWindow: _screenWindow
7279
7380 Item {
7481 id: shellContainer
@@ -680,9 +687,7 @@ Rectangle {
680687 }
681688
682689 function ensureInputMethodSurface() {
683− var surfaceManager = findInvisibleChild(shell, "surfaceManager");
684− verify(surfaceManager);
685− surfaceManager.createInputMethodSurface();
690+ SurfaceManager.createInputMethodSurface();
686691
687692 tryCompareFunction(function() { return root.topLevelSurfaceList.inputMethodSurface !== null }, true);
688693 }
@@ -1868,21 +1873,21 @@ Rectangle {
18681873 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
18691874
18701875 tryCompare(appDelegate, "state", "normal");
1871− tryCompare(PanelState, "decorationsVisible", false)
1876+ tryCompare(panelState, "decorationsVisible", false)
18721877
18731878 mouseClick(maximizeButton, maximizeButton.width / 2, maximizeButton.height / 2);
18741879 tryCompare(appDelegate, "state", "maximized");
1875− tryCompare(PanelState, "decorationsVisible", true)
1880+ tryCompare(panelState, "decorationsVisible", true)
18761881
18771882 ApplicationManager.stopApplication(application.appId);
1878− tryCompare(PanelState, "decorationsVisible", false)
1883+ tryCompare(panelState, "decorationsVisible", false)
18791884
18801885 // wait until all zombie surfaces are gone. As MirSurfaceItems hold references over them.
18811886 // They won't be gone until those surface items are destroyed.
18821887 tryCompareFunction(function() { return application.surfaceList.count }, 0);
18831888
18841889 ApplicationManager.startApplication(application.appId);
1885− tryCompare(PanelState, "decorationsVisible", true)
1890+ tryCompare(panelState, "decorationsVisible", true)
18861891 }
18871892
18881893 function test_newAppHasValidGeometry() {
@@ -1939,7 +1944,7 @@ Rectangle {
19391944 mousePress(appDelegate, appDelegate.width / 2, units.gu(1))
19401945 mouseMove(appDelegate, appDelegate.width / 2, -units.gu(100))
19411946
1942− compare(appDelegate.y >= PanelState.panelHeight, true);
1947+ compare(appDelegate.y >= panelState.panelHeight, true);
19431948 }
19441949
19451950 function test_cantResizeWindowUnderPanel() {
@@ -1967,7 +1972,7 @@ Rectangle {
19671972 mouseMove(decoration, decoration.width/2, -units.gu(100));
19681973
19691974 // verify we don't go past the panel
1970− compare(appDelegate.y >= PanelState.panelHeight, true);
1975+ compare(appDelegate.y >= panelState.panelHeight, true);
19711976 }
19721977
19731978 function test_restoreWindowStateFixesIfUnderPanel() {
@@ -1991,7 +1996,7 @@ Rectangle {
19911996 tryCompareFunction(function () { return topLevelSurfaceList.applicationAt(0).appId; }, application.appId);
19921997
19931998 appDelegate = appRepeater.itemAt(0);
1994− compare(appDelegate.y >= PanelState.panelHeight, true);
1999+ compare(appDelegate.y >= panelState.panelHeight, true);
19952000 }
19962001
19972002 function test_lifecyclePolicyForNonTouchApp_data() {
@@ -2639,7 +2644,7 @@ Rectangle {
26392644 function test_oskDisplacesWindow_data() {
26402645 return [
26412646 {tag: "no need to displace", windowHeight: units.gu(10), windowY: units.gu(5), targetDisplacement: units.gu(5), oskEnabled: true},
2642− {tag: "displace to top", windowHeight: units.gu(50), windowY: units.gu(10), targetDisplacement: PanelState.panelHeight, oskEnabled: true},
2647+ {tag: "displace to top", windowHeight: units.gu(50), windowY: units.gu(10), targetDisplacement: panelState.panelHeight, oskEnabled: true},
26432648 {tag: "osk not on this screen", windowHeight: units.gu(40), windowY: units.gu(10), targetDisplacement: units.gu(10), oskEnabled: false},
26442649 ]
26452650 }
@@ -2662,8 +2667,8 @@ Rectangle {
26622667 dashAppDelegate.windowedY = data.windowY;
26632668 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, 0, 0, 0));
26642669 var initialY = dashAppDelegate.y;
2665− print("intial", initialY, "panel", PanelState.panelHeight);
2666− verify(initialY > PanelState.panelHeight);
2670+ print("intial", initialY, "panel", panelState.panelHeight);
2671+ verify(initialY > panelState.panelHeight);
26672672
26682673 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, root.height / 2, root.width, root.height / 2));
26692674 tryCompare(dashAppDelegate, "y", data.targetDisplacement);
tests/uqmlscene/main.cpp+2
@@ -479,6 +479,8 @@ int main(int argc, char ** argv)
479479 // TODO: as soon as the engine construction completes, the debug service is
480480 // listening for connections. But actually we aren't ready to debug anything.
481481 QQmlEngine engine;
482+ engine.rootContext()->setContextProperty("DebuggingController", new DebuggingController(&app));
483+
482484 QQmlComponent *component = new QQmlComponent(&engine);
483485 for (int i = 0; i < imports.size(); ++i)
484486 engine.addImportPath(imports.at(i));