on f661fa4 help sign in
144 files changed+6536−1521
since splitsnapshots
unifiedsplit
CMakeLists.txt+5−1 debian/control+7−1 debian/unity8.install+5 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/GlobalShortcut/globalshortcut.cpp−15 plugins/GlobalShortcut/globalshortcut.h−4 plugins/GlobalShortcut/globalshortcutregistry.cpp+23−15 plugins/GlobalShortcut/globalshortcutregistry.h+2−2 plugins/UInput/plugin.cpp+7−1 plugins/WindowManager/CMakeLists.txt+27−2 plugins/WindowManager/Screen.cpp+299 plugins/WindowManager/Screen.h+132 plugins/WindowManager/ScreenAttached.cpp+151 plugins/WindowManager/ScreenAttached.h+56 plugins/WindowManager/ScreenWindow.cpp+45 plugins/WindowManager/ScreenWindow.h+49 plugins/WindowManager/Screens.cpp+245 plugins/WindowManager/Screens.h+114 plugins/WindowManager/ScreensConfiguration.cpp+94 src/ShellView.h → plugins/WindowManager/ScreensConfiguration.h+10−12 plugins/WindowManager/TopLevelWindowModel.cpp+199−62 plugins/WindowManager/TopLevelWindowModel.h+21−23 plugins/WindowManager/WindowManagerObjects.cpp+47 plugins/WindowManager/WindowManagerObjects.h+66 plugins/WindowManager/WindowManagerPlugin.cpp+56−2 plugins/WindowManager/WindowManagerPlugin.h+1 plugins/WindowManager/Workspace.cpp+156 plugins/WindowManager/Workspace.h+117 plugins/WindowManager/WorkspaceManager.cpp+106 plugins/WindowManager/WorkspaceManager.h+69 plugins/WindowManager/WorkspaceModel.cpp+254 plugins/WindowManager/WorkspaceModel.h+102 qml/ApplicationMenus/ApplicationMenuItemFactory.qml+4−4 qml/ApplicationMenus/MenuBar.qml+5−1 qml/ApplicationMenus/MenuPopup.qml+3−1 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/ErrorApplication.qml+67 qml/Greeter/Greeter.qml+21−3 qml/Greeter/SecondaryGreeter.qml+75 qml/OrientedShell.qml+5−8 qml/Panel/Panel.qml+17−15 qml/Shell.qml+39−22 qml/ShellApplication.qml+60 qml/ShellNotifier.qml+30 qml/ShellScreen.qml+64 qml/Stage/ApplicationWindow.qml+14−206 qml/Stage/DecoratedWindow.qml+13−11 qml/Stage/FakeMaximizeDelegate.qml+12−11 qml/Stage/Spread/ScreensAndWorkspaces.qml+212 qml/Stage/Spread/Spread.qml+7−8 qml/Stage/Spread/SpreadDelegateInputArea.qml+36−17 qml/Stage/Spread/WorkspacePreview.qml+275 qml/Stage/Spread/Workspaces.qml+416 qml/Stage/Stage.qml+209−119 qml/Stage/SurfaceContainer.qml+2 qml/Stage/WindowDecoration.qml+2 qml/Stage/WindowResizeArea.qml+27−4 qml/Stage/WindowStateSaver.qml+4−1 qml/Stage/WorkspacePreview.qml+212 qml/Stage/WorkspaceSwitcher.qml+181 qml/Stage/graphics/multi-monitor_drop-here.png qml/Stage/graphics/multi-monitor_leave.png qml/qmldir+1 src/ApplicationArguments.cpp+11−2 src/ApplicationArguments.h+17−15 src/CMakeLists.txt+11−4 src/SecondaryWindow.cpp−40 src/ShellApplication.cpp−221 src/ShellView.cpp−85 src/UnityApplication.cpp+147 src/ShellApplication.h → src/UnityApplication.h+9−19 src/UnityCommandLineParser.cpp+8 src/UnityCommandLineParser.h+4−1 src/WindowManagementPolicy.cpp+69 src/WindowManagementPolicy.h+47 src/libunity8-private/CMakeLists.txt+1 src/SecondaryWindow.h → src/libunity8-private/wmpolicyinterface.cpp+6−12 src/libunity8-private/wmpolicyinterface.h+46 src/main.cpp+4−8 tests/CMakeLists.txt+1 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+26−1 tests/mocks/Unity/Application/MirSurfaceItem.cpp+26−7 tests/mocks/Unity/Application/SurfaceManager.cpp+95−3 tests/mocks/Unity/Application/SurfaceManager.h+21 tests/mocks/Unity/Application/plugin.cpp+7−1 tests/mocks/Unity/Application/resources/MirSurfaceItem.qml−3 tests/mocks/Unity/CMakeLists.txt−1 tests/mocks/Unity/InputInfo/mockcontroller.cpp+10 tests/mocks/Unity/InputInfo/mockcontroller.h+3−1 tests/mocks/Unity/InputInfo/plugin.cpp+1−2 tests/mocks/Unity/Screens/CMakeLists.txt−14 tests/mocks/Unity/Screens/qmldir−2 tests/mocks/Unity/Screens/screens.cpp−71 tests/mocks/Unity/Screens/screens.h−82 tests/mocks/WindowManager/CMakeLists.txt+58 tests/mocks/Unity/Screens/plugin.cpp → tests/mocks/WindowManager/MockScreenWindow.cpp+14−9 tests/mocks/Unity/Screens/plugin.h → tests/mocks/WindowManager/MockScreenWindow.h+11−6 tests/mocks/WindowManager/MockScreens.cpp+217 tests/mocks/WindowManager/MockScreens.h+54 tests/mocks/WindowManager/MockScreensConfiguration.cpp+47 tests/mocks/WindowManager/WindowManagementPolicy.cpp+114 tests/mocks/WindowManager/WindowManagementPolicy.h+73 tests/mocks/WindowManager/WindowManagerPlugin.cpp+84 tests/mocks/WindowManager/WindowManagerPlugin.h+33 tests/mocks/WindowManager/qmldir+2 tests/plugins/WindowManager/CMakeLists.txt+5−1 tests/plugins/WindowManager/UnityApplicationMocks.h+25 tests/plugins/WindowManager/tst_TopLevelWindowModel.cpp+20−8 tests/qmltests/ApplicationMenuDataLoader.qml+1−4 tests/qmltests/ApplicationMenus/tst_MenuBar.qml+2−2 tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+2 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Components/tst_VirtualTouchPad.qml+2−2 tests/qmltests/Panel/tst_ActiveCallHint.qml−2 tests/qmltests/Panel/tst_Panel.qml+18−16 tests/qmltests/Stage/tst_ApplicationWindow.qml+10−44 tests/qmltests/Stage/tst_DecoratedWindow.qml+5−3 tests/qmltests/Stage/tst_DesktopStage.qml+6−12 tests/qmltests/Stage/tst_PhoneStage.qml+6−7 tests/qmltests/Stage/tst_SurfaceContainer.qml−2 tests/qmltests/Stage/tst_TabletStage.qml+41−43 tests/qmltests/Stage/tst_WindowDecoration.qml−2 tests/qmltests/Stage/tst_WindowResizeArea.qml+1−8 tests/qmltests/Tutorial/tst_Tutorial.qml+5−23 tests/qmltests/tst_OrientedShell.qml+22−10 tests/qmltests/tst_Shell.qml+28−25 tests/qmltests/tst_ShellApplication.qml+168 tests/qmltests/tst_ShellWithPin.qml+4−16 tests/uqmlscene/main.cpp+2 tests/utils/modules/Unity/Test/StageTestCase.qml+1−1 tests/utils/modules/Unity/Test/UnityTestCase.qml+13
CMakeLists.txt+5−1
@@ -71,6 +71,7 @@ find_package(Qt5Concurrent 5.6 REQUIRED)
7171find_package(Qt5Sql 5.6 REQUIRED)
7272
7373pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=27)
74+pkg_check_modules(QTMIRSERVER REQUIRED qtmirserver>=0.6.0)
7475pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
7576pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
7677pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
@@ -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-3)
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+7−1
@@ -31,6 +31,7 @@ Build-Depends: cmake,
3131 libqmenumodel-dev (>= 0.2.12),
3232 libqt5svg5-dev,
3333 libqt5xmlpatterns5-dev,
34+ libqtmirserver-dev (>= 0.6.0),
3435 libsystemsettings-dev,
3536 libubuntu-app-launch3-dev,
3637 libubuntu-download-manager-common-dev,
@@ -38,13 +39,14 @@ Build-Depends: cmake,
3839 libubuntugestures5-private-dev (>= 1.3.2030),
3940 libudev-dev,
4041 libudm-common-dev,
41− libunity-api-dev (>= 8.6),
42+ libunity-api-dev (>= 8.7),
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],
4546 libxcb1-dev[!arm64 !armhf],
4647 libxi-dev[!arm64 !armhf],
4748# End of X11 libs
49+ mirtest-dev,
4850 pkg-config,
4951 python3-all:any,
5052 python3-setuptools,
@@ -70,6 +72,9 @@ Build-Depends: cmake,
7072 qtdeclarative5-ubuntu-settings-components (>= 0.11),
7173 ttf-ubuntu-font-family,
7274 xvfb,
75+# mirtest pkgconfig requires these, but doesn't have a deb dependency. Bug lp:1633537
76+ libboost-filesystem-dev,
77+ libboost-system-dev,
7378Standards-Version: 3.9.4
7479Homepage: http://launchpad.net/unity
7580# If you aren't a member of ~unity-team but need to upload
@@ -131,6 +136,7 @@ Depends: dmz-cursor-theme,
131136 qml-module-ubuntu-web,
132137 qtdeclarative5-qtmir-plugin (>= 0.4.8),
133138 qtdeclarative5-ubuntu-telephony0.1,
139+ qtmir-desktop (>= 0.6.0) | qtmir-android (>= 0.6.0),
134140 ubuntu-system-settings (>= 0.4),
135141 unity-launcher-impl-12,
136142 unity8-common (= ${source:Version}),
debian/unity8.install+5
@@ -16,7 +16,12 @@ usr/share/unity8/Rotation
1616usr/share/unity8/DeviceConfiguration.qml
1717usr/share/unity8/OrientedShell.qml
1818usr/share/unity8/DisabledScreenNotice.qml
19+usr/share/unity8/ErrorApplication.qml
20+usr/share/unity8/qmldir
1921usr/share/unity8/Shell.qml
22+usr/share/unity8/ShellApplication.qml
23+usr/share/unity8/ShellNotifier.qml
24+usr/share/unity8/ShellScreen.qml
2025usr/share/unity8/Stage
2126usr/share/unity8/Tutorial
2227usr/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/GlobalShortcut/globalshortcut.cpp−15
@@ -56,11 +56,6 @@ void GlobalShortcut::setActive(bool active)
5656 Q_EMIT activeChanged(active);
5757}
5858
59−void GlobalShortcut::componentComplete()
60−{
61− connect(this, &QQuickItem::windowChanged, this, &GlobalShortcut::setupFilterOnWindow);
62−}
63−
6459void GlobalShortcut::keyPressEvent(QKeyEvent * event)
6560{
6661 if (!m_active) return;
@@ -76,13 +71,3 @@ void GlobalShortcut::keyReleaseEvent(QKeyEvent * event)
7671 event->accept();
7772 Q_EMIT released(m_shortcut.toString());
7873}
79−
80−void GlobalShortcut::setupFilterOnWindow(QQuickWindow *window)
81−{
82− if (!window) {
83−// qWarning() << Q_FUNC_INFO << "Failed to setup filter on window";
84− return;
85− }
86−
87− registry->setupFilterOnWindow((qulonglong) window->winId());
88−}
plugins/GlobalShortcut/globalshortcut.h−4
@@ -53,7 +53,6 @@ public:
5353 void setActive(bool active);
5454
5555protected:
56− void componentComplete() override;
5756 void keyPressEvent(QKeyEvent * event) override;
5857 void keyReleaseEvent(QKeyEvent * event) override;
5958
@@ -69,9 +68,6 @@ Q_SIGNALS:
6968 void released(const QString &shortcut);
7069 void activeChanged(bool active);
7170
72−private Q_SLOTS:
73− void setupFilterOnWindow(QQuickWindow* window);
74−
7571private:
7672 QVariant m_shortcut;
7773 bool m_active = true;
plugins/GlobalShortcut/globalshortcutregistry.cpp+23−15
@@ -21,11 +21,25 @@
2121
2222#include "globalshortcutregistry.h"
2323
24−static qulonglong s_windowId = 0;
24+namespace {
25+QWindow* windowForShortcut(GlobalShortcut *sc) {
26+ QObject* parent= sc;
27+ while(parent) {
28+ if (auto item = qobject_cast<QQuickItem*>(parent)) {
29+ auto window = item->window();
30+ if (window) return window;
31+ }
32+ parent = parent->parent();
33+ }
34+ return nullptr;
35+}
36+} // namespace
2537
2638GlobalShortcutRegistry::GlobalShortcutRegistry(QObject *parent)
2739 : QObject(parent)
2840{
41+ connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &GlobalShortcutRegistry::setupFilterOnWindow);
42+ setupFilterOnWindow(qGuiApp->focusWindow());
2943}
3044
3145GlobalShortcutList GlobalShortcutRegistry::shortcuts() const
@@ -91,7 +105,10 @@ bool GlobalShortcutRegistry::eventFilter(QObject *obj, QEvent *event)
91105 const auto shortcuts = m_shortcuts.value(seq);
92106 Q_FOREACH(const auto &shortcut, shortcuts) {
93107 if (shortcut) {
94− qApp->sendEvent(shortcut, &eCopy);
108+ auto window = windowForShortcut(shortcut);
109+ if (!window || window == obj) { // accept shortcut if it's not attached to a window or it's window is active.
110+ qApp->sendEvent(shortcut, &eCopy);
111+ }
95112 }
96113 }
97114 }
@@ -102,24 +119,15 @@ bool GlobalShortcutRegistry::eventFilter(QObject *obj, QEvent *event)
102119 return QObject::eventFilter(obj, event);
103120}
104121
105−void GlobalShortcutRegistry::setupFilterOnWindow(qulonglong wid)
122+void GlobalShortcutRegistry::setupFilterOnWindow(QWindow* window)
106123{
107− if (wid == s_windowId) {
108− return;
109− }
110−
111124 if (m_filteredWindow) {
112125 m_filteredWindow->removeEventFilter(this);
113126 m_filteredWindow.clear();
114− s_windowId = 0;
115127 }
116128
117− Q_FOREACH(QWindow *window, qApp->allWindows()) {
118− if (window && window->winId() == wid) {
119− m_filteredWindow = window;
120− window->installEventFilter(this);
121− s_windowId = wid;
122− break;
123− }
129+ if (window) {
130+ m_filteredWindow = window;
131+ window->installEventFilter(this);
124132 }
125133}
plugins/GlobalShortcut/globalshortcutregistry.h+2−2
@@ -52,9 +52,9 @@ public:
5252 void addShortcut(const QVariant &seq, GlobalShortcut * sc);
5353
5454 /**
55− * Sets up key events filtering on window @p wid
55+ * Sets up key events filtering on window @p window
5656 */
57− void setupFilterOnWindow(qulonglong wid);
57+ void setupFilterOnWindow(QWindow* window);
5858
5959protected:
6060 bool eventFilter(QObject *obj, QEvent *event) override;
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/WindowManager/CMakeLists.txt+27−2
@@ -1,18 +1,43 @@
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+ Screen.cpp
16+ ScreenAttached.cpp
17+ Screens.cpp
18+ ScreensConfiguration.cpp
19+ ScreenWindow.cpp
20+ WindowManagerObjects.cpp
21+ Workspace.cpp
22+ WorkspaceManager.cpp
23+ WorkspaceModel.cpp
524 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
25+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
626 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
727 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
828 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
929 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
10− )
30+)
1131
1232add_definitions(-DWINDOWMANAGERQML_LIBRARY)
1333
1434add_library(windowmanager-qml SHARED ${WINDOWMANAGER_SRC})
1535
36+target_link_libraries(windowmanager-qml
37+ ${QTMIRSERVER_LDFLAGS}
38+ unity8-private
39+)
40+
1641qt5_use_modules(windowmanager-qml Qml Quick Gui)
1742
18−add_unity8_plugin(WindowManager 0.1 WindowManager TARGETS windowmanager-qml)
43+add_unity8_plugin(WindowManager 1.0 WindowManager TARGETS windowmanager-qml)
plugins/WindowManager/Screen.cppnew file+299
@@ -0,0 +1,299 @@
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 "Screens.h"
19+#include "WorkspaceManager.h"
20+#include "Workspace.h"
21+
22+Screen::Screen(QObject *parent)
23+ : QObject(parent)
24+{
25+}
26+
27+void Screen::connectToScreen(qtmir::Screen *screen)
28+{
29+ m_wrapped = screen;
30+ connect(screen, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
31+ connect(screen, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
32+ connect(screen, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
33+ connect(screen, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeNameChanged);
34+ connect(screen, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
35+ connect(screen, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
36+ connect(screen, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
37+ connect(screen, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
38+ connect(screen, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
39+ connect(screen, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
40+ connect(screen, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
41+}
42+
43+void Screen::connectToScreen(Screen *screen)
44+{
45+ connectToScreen(screen->wrapped());
46+ connect(screen, &Screen::currentWorkspaceChanged, this, &Screen::currentWorkspaceChanged);
47+}
48+
49+qtmir::OutputId Screen::outputId() const
50+{
51+ if (!m_wrapped) return qtmir::OutputId(-1);
52+ return m_wrapped->outputId();
53+}
54+
55+bool Screen::used() const
56+{
57+ if (!m_wrapped) return false;
58+ return m_wrapped->used();
59+}
60+
61+QString Screen::name() const
62+{
63+ if (!m_wrapped) return QString();
64+ return m_wrapped->name();
65+}
66+
67+float Screen::scale() const
68+{
69+ if (!m_wrapped) return 1.0;
70+ return m_wrapped->scale();
71+}
72+
73+QSizeF Screen::physicalSize() const
74+{
75+ if (!m_wrapped) return QSizeF();
76+ return m_wrapped->physicalSize();
77+}
78+
79+qtmir::FormFactor Screen::formFactor() const
80+{
81+ if (!m_wrapped) return qtmir::FormFactorUnknown;
82+ return m_wrapped->formFactor();
83+}
84+
85+qtmir::OutputTypes Screen::outputType() const
86+{
87+ if (!m_wrapped) return qtmir::Unknown;
88+ return m_wrapped->outputType();
89+}
90+
91+MirPowerMode Screen::powerMode() const
92+{
93+ if (!m_wrapped) return mir_power_mode_on;
94+ return m_wrapped->powerMode();
95+}
96+
97+Qt::ScreenOrientation Screen::orientation() const
98+{
99+ if (!m_wrapped) return Qt::PrimaryOrientation;
100+ return m_wrapped->orientation();
101+}
102+
103+QPoint Screen::position() const
104+{
105+ if (!m_wrapped) return QPoint();
106+ return m_wrapped->position();
107+}
108+
109+QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
110+{
111+ if (!m_wrapped) return QQmlListProperty<qtmir::ScreenMode>();
112+ return m_wrapped->availableModes();
113+}
114+
115+uint Screen::currentModeIndex() const
116+{
117+ if (!m_wrapped) return -1;
118+ return m_wrapped->currentModeIndex();
119+}
120+
121+bool Screen::isActive() const
122+{
123+ if (!m_wrapped) return false;
124+ return m_wrapped->isActive();
125+}
126+
127+void Screen::activate()
128+{
129+ setActive(true);
130+}
131+
132+void Screen::setActive(bool active)
133+{
134+ if (!m_wrapped) return;
135+ m_wrapped->setActive(active);
136+}
137+
138+QScreen *Screen::qscreen() const
139+{
140+ if (!m_wrapped) return nullptr;
141+ return m_wrapped->qscreen();
142+}
143+
144+qtmir::ScreenConfiguration *Screen::beginConfiguration() const
145+{
146+ if (!m_wrapped) return nullptr;
147+ return m_wrapped->beginConfiguration();
148+}
149+
150+bool Screen::applyConfiguration(qtmir::ScreenConfiguration *configuration)
151+{
152+ if (!m_wrapped) return false;
153+ return m_wrapped->applyConfiguration(configuration);
154+}
155+
156+QString Screen::outputTypeName() const
157+{
158+ switch (m_wrapped->outputType()) {
159+ case qtmir::Unknown:
160+ return tr("Unknown");
161+ case qtmir::VGA:
162+ return tr("VGA");
163+ case qtmir::DVII:
164+ case qtmir::DVID:
165+ case qtmir::DVIA:
166+ return tr("DVI");
167+ case qtmir::Composite:
168+ return tr("Composite");
169+ case qtmir::SVideo:
170+ return tr("S-Video");
171+ case qtmir::LVDS:
172+ case qtmir::NinePinDIN:
173+ case qtmir::EDP:
174+ return tr("Internal");
175+ case qtmir::Component:
176+ return tr("Component");
177+ case qtmir::DisplayPort:
178+ return tr("DisplayPort");
179+ case qtmir::HDMIA:
180+ case qtmir::HDMIB:
181+ return tr("HDMI");
182+ case qtmir::TV:
183+ return tr("TV");
184+ }
185+ return QString();
186+}
187+
188+void Screen::sync(Screen *proxy)
189+{
190+ if (!proxy) return;
191+ workspaces()->sync(proxy->workspaces());
192+}
193+
194+ConcreteScreen::ConcreteScreen(qtmir::Screen* wrapped)
195+ : m_workspaces(new WorkspaceModel)
196+{
197+ connectToScreen(wrapped);
198+
199+ // Connect the active workspace to activate the screen.
200+ connect(m_workspaces.data(), &WorkspaceModel::workspaceInserted, this, [this](int, Workspace* workspace) {
201+ connect(workspace, &Workspace::activeChanged, this, [this, workspace](bool active) {
202+ if (active) {
203+ setCurrentWorkspace(workspace);
204+ activate();
205+ }
206+ });
207+ if (workspace->isActive()) {
208+ activate();
209+ setCurrentWorkspace(workspace);
210+ }
211+ if (!m_currentWorspace) {
212+ setCurrentWorkspace(workspace);
213+ }
214+ });
215+ connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
216+ disconnect(workspace, &Workspace::activeChanged, this, 0);
217+ if (workspace == m_currentWorspace) {
218+ resetCurrentWorkspace();
219+ }
220+ });
221+ connect(this, &ConcreteScreen::activeChanged, this, [this](bool active) {
222+ if (active && m_currentWorspace) {
223+ m_currentWorspace->activate();
224+ }
225+ });
226+}
227+
228+void ConcreteScreen::resetCurrentWorkspace()
229+{
230+ auto newCurrent = m_workspaces->rowCount() > 0 ? m_workspaces->get(0) : nullptr;
231+ if (m_currentWorspace != newCurrent) {
232+ m_currentWorspace = newCurrent;
233+ Q_EMIT currentWorkspaceChanged(newCurrent);
234+ }
235+}
236+
237+
238+WorkspaceModel *ConcreteScreen::workspaces() const
239+{
240+ return m_workspaces.data();
241+}
242+
243+Workspace *ConcreteScreen::currentWorkspace() const
244+{
245+ return m_currentWorspace.data();
246+}
247+
248+void ConcreteScreen::setCurrentWorkspace(Workspace *workspace)
249+{
250+ if (m_currentWorspace != workspace) {
251+ m_currentWorspace = workspace;
252+ Q_EMIT currentWorkspaceChanged(workspace);
253+ }
254+}
255+
256+ProxyScreen::ProxyScreen(Screen *const screen, ProxyScreens* screens)
257+ : m_workspaces(new ProxyWorkspaceModel(screen->workspaces(), this))
258+ , m_original(screen)
259+ , m_screens(screens)
260+{
261+ connectToScreen(screen);
262+
263+ auto updateCurrentWorkspaceFn = [this](Workspace* realWorkspace) {
264+ Q_FOREACH(Workspace* workspace, m_workspaces->list()) {
265+ auto p = qobject_cast<ProxyWorkspace*>(workspace);
266+ if (p && p->proxyObject() == realWorkspace) {
267+ if (m_currentWorspace != p) {
268+ m_currentWorspace = p;
269+ Q_EMIT currentWorkspaceChanged(p);
270+ }
271+ }
272+ }
273+ };
274+ connect(screen, &Screen::currentWorkspaceChanged, this, updateCurrentWorkspaceFn);
275+ updateCurrentWorkspaceFn(screen->currentWorkspace());
276+}
277+
278+WorkspaceModel *ProxyScreen::workspaces() const
279+{
280+ return m_workspaces.data();
281+}
282+
283+Workspace *ProxyScreen::currentWorkspace() const
284+{
285+ return m_currentWorspace.data();
286+}
287+
288+void ProxyScreen::setCurrentWorkspace(Workspace *workspace)
289+{
290+ auto p = qobject_cast<ProxyWorkspace*>(workspace);
291+ if (p) {
292+ m_original->setCurrentWorkspace(p->proxyObject());
293+ }
294+}
295+
296+bool ProxyScreen::isSyncing() const
297+{
298+ return m_screens->isSyncing();
299+}
plugins/WindowManager/Screen.hnew file+132
@@ -0,0 +1,132 @@
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 ProxyScreen;
11+class ProxyScreens;
12+
13+class Screen: public QObject
14+{
15+ Q_OBJECT
16+
17+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
18+ Q_PROPERTY(bool used READ used NOTIFY usedChanged)
19+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
20+ Q_PROPERTY(qtmir::OutputTypes outputType READ outputType NOTIFY outputTypeChanged)
21+ Q_PROPERTY(float scale READ scale NOTIFY scaleChanged)
22+ Q_PROPERTY(qtmir::FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
23+ Q_PROPERTY(MirPowerMode powerMode READ powerMode NOTIFY powerModeChanged)
24+ Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
25+ Q_PROPERTY(QPoint position READ position NOTIFY positionChanged)
26+ Q_PROPERTY(uint currentModeIndex READ currentModeIndex NOTIFY currentModeIndexChanged)
27+ Q_PROPERTY(QQmlListProperty<qtmir::ScreenMode> availableModes READ availableModes NOTIFY availableModesChanged)
28+ Q_PROPERTY(QSizeF physicalSize READ physicalSize NOTIFY physicalSizeChanged)
29+ Q_PROPERTY(QString outputTypeName READ outputTypeName NOTIFY outputTypeChanged)
30+ Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
31+ Q_PROPERTY(Workspace* currentWorkspace READ currentWorkspace WRITE setCurrentWorkspace NOTIFY currentWorkspaceChanged)
32+public:
33+ // From qtmir::Screen
34+ qtmir::OutputId outputId() const;
35+ bool used() const;
36+ QString name() const;
37+ float scale() const;
38+ QSizeF physicalSize() const;
39+ qtmir::FormFactor formFactor() const;
40+ qtmir::OutputTypes outputType() const;
41+ MirPowerMode powerMode() const;
42+ Qt::ScreenOrientation orientation() const;
43+ QPoint position() const;
44+ QQmlListProperty<qtmir::ScreenMode> availableModes();
45+ uint currentModeIndex() const;
46+ bool isActive() const;
47+ void setActive(bool active);
48+ QScreen* qscreen() const;
49+ QString outputTypeName() const;
50+
51+ qtmir::ScreenConfiguration *beginConfiguration() const;
52+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration);
53+
54+ virtual WorkspaceModel* workspaces() const = 0;
55+ virtual Workspace *currentWorkspace() const = 0;
56+ virtual void setCurrentWorkspace(Workspace* workspace) = 0;
57+
58+ void sync(Screen* proxy);
59+
60+ qtmir::Screen* wrapped() const { return m_wrapped; }
61+
62+public Q_SLOTS:
63+ void activate();
64+
65+Q_SIGNALS:
66+ void usedChanged();
67+ void nameChanged();
68+ void outputTypeChanged();
69+ void outputTypeNameChanged();
70+ void scaleChanged();
71+ void formFactorChanged();
72+ void powerModeChanged();
73+ void orientationChanged();
74+ void positionChanged();
75+ void currentModeIndexChanged();
76+ void physicalSizeChanged();
77+ void availableModesChanged();
78+ void activeChanged(bool active);
79+ void currentWorkspaceChanged(Workspace*);
80+
81+protected:
82+ Screen(QObject* parent = 0);
83+
84+ void connectToScreen(qtmir::Screen* screen);
85+ void connectToScreen(Screen* screen);
86+
87+protected:
88+ QPointer<qtmir::Screen> m_wrapped;
89+};
90+
91+
92+class ConcreteScreen : public Screen
93+{
94+ Q_OBJECT
95+public:
96+ explicit ConcreteScreen(qtmir::Screen*const wrapped);
97+
98+ // From qtmir::Screen
99+ WorkspaceModel* workspaces() const override;
100+ Workspace *currentWorkspace() const override;
101+ void setCurrentWorkspace(Workspace* workspace) override;
102+
103+protected:
104+ void resetCurrentWorkspace();
105+
106+ const QScopedPointer<WorkspaceModel> m_workspaces;
107+ QPointer<Workspace> m_currentWorspace;
108+};
109+
110+class ProxyScreen : public Screen
111+{
112+ Q_OBJECT
113+public:
114+ explicit ProxyScreen(Screen*const screen, ProxyScreens* screens);
115+
116+ // From qtmir::Screen
117+ WorkspaceModel* workspaces() const override;
118+ Workspace *currentWorkspace() const override;
119+ void setCurrentWorkspace(Workspace* workspace) override;
120+
121+ Screen* proxyObject() const { return m_original.data(); }
122+
123+ bool isSyncing() const;
124+
125+private:
126+ const QScopedPointer<WorkspaceModel> m_workspaces;
127+ const QPointer<Screen> m_original;
128+ const ProxyScreens* m_screens;
129+ QPointer<Workspace> m_currentWorspace;
130+};
131+
132+#endif // SCREEN_H
plugins/WindowManager/ScreenAttached.cppnew file+151
@@ -0,0 +1,151 @@
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 "ScreenAttached.h"
18+#include "ScreenWindow.h"
19+#include "Screens.h"
20+
21+#include <QQuickItem>
22+#include <QScreen>
23+
24+ScreenAttached::ScreenAttached(QObject *owner)
25+ : Screen(owner)
26+ , m_window(nullptr)
27+{
28+ if (auto item = qobject_cast<QQuickItem*>(owner)) {
29+ connect(item, &QQuickItem::windowChanged, this, &ScreenAttached::windowChanged);
30+ windowChanged(item->window());
31+ } else if (auto window = qobject_cast<QQuickWindow*>(owner)) {
32+ windowChanged(window);
33+ }
34+}
35+
36+WorkspaceModel *ScreenAttached::workspaces() const
37+{
38+ if (!m_screen) return nullptr;
39+ return m_screen->workspaces();
40+}
41+
42+Workspace *ScreenAttached::currentWorkspace() const
43+{
44+ if (!m_screen) return nullptr;
45+ return m_screen->currentWorkspace();
46+}
47+
48+void ScreenAttached::setCurrentWorkspace(Workspace *workspace)
49+{
50+ if (!m_screen) return;
51+ return m_screen->setCurrentWorkspace(workspace);
52+}
53+
54+void ScreenAttached::windowChanged(QQuickWindow *window)
55+{
56+ if (m_window) {
57+ disconnect(m_window, &QWindow::screenChanged, this, &ScreenAttached::screenChanged);
58+ }
59+
60+ m_window = window;
61+ auto screenWindow = qobject_cast<ScreenWindow*>(window);
62+
63+ if (screenWindow) {
64+ screenChanged2(screenWindow->screenWrapper());
65+ connect(screenWindow, &ScreenWindow::screenWrapperChanged, this, &ScreenAttached::screenChanged2);
66+ } else {
67+ screenChanged(window ? window->screen() : NULL);
68+ if (window) {
69+ connect(window, &QWindow::screenChanged, this, &ScreenAttached::screenChanged);
70+ }
71+ }
72+}
73+
74+void ScreenAttached::screenChanged(QScreen *qscreen)
75+{
76+ // Find a screen that matches.
77+ // Should only get here in mocks if we don't have a ScreenWindow
78+ Screen* screen{nullptr};
79+ Q_FOREACH(auto s, ConcreteScreens::self()->list()) {
80+ if (s->qscreen() == qscreen) {
81+ screen = s;
82+ }
83+ }
84+ screenChanged2(screen);
85+}
86+
87+void ScreenAttached::screenChanged2(Screen* screen)
88+{
89+ if (screen == m_screen) return;
90+
91+ Screen* oldScreen = m_screen;
92+ m_screen = screen;
93+
94+ if (oldScreen)
95+ oldScreen->disconnect(this);
96+
97+ if (!screen)
98+ return; //Don't bother emitting signals, because the new values are garbage anyways
99+
100+ if (!oldScreen || screen->isActive() != oldScreen->isActive())
101+ Q_EMIT activeChanged(screen->isActive());
102+ if (!oldScreen || screen->used() != oldScreen->used())
103+ Q_EMIT usedChanged();
104+ if (!oldScreen || screen->name() != oldScreen->name())
105+ Q_EMIT nameChanged();
106+ if (!oldScreen || screen->outputType() != oldScreen->outputType())
107+ Q_EMIT outputTypeChanged();
108+ if (!oldScreen || screen->scale() != oldScreen->scale())
109+ Q_EMIT scaleChanged();
110+ if (!oldScreen || screen->formFactor() != oldScreen->formFactor())
111+ Q_EMIT formFactorChanged();
112+ if (!oldScreen || screen->powerMode() != oldScreen->powerMode())
113+ Q_EMIT powerModeChanged();
114+ if (!oldScreen || screen->orientation() != oldScreen->orientation())
115+ Q_EMIT orientationChanged();
116+ if (!oldScreen || screen->position() != oldScreen->position())
117+ Q_EMIT positionChanged();
118+ if (!oldScreen || screen->currentModeIndex() != oldScreen->currentModeIndex())
119+ Q_EMIT currentModeIndexChanged();
120+ if (!oldScreen || screen->physicalSize() != oldScreen->physicalSize())
121+ Q_EMIT physicalSizeChanged();
122+ if (!oldScreen || screen->currentWorkspace() != oldScreen->currentWorkspace())
123+ Q_EMIT currentWorkspaceChanged(currentWorkspace());
124+
125+ if (oldScreen) {
126+ QVector<qtmir::ScreenMode*> oldModes;
127+ auto oldModesQmlList = oldScreen->availableModes();
128+ for (int i = 0; i < oldModesQmlList.count(&oldModesQmlList); i++) {
129+ oldModes << oldModesQmlList.at(&oldModesQmlList, i);
130+ }
131+
132+ QVector<qtmir::ScreenMode*> newModes;
133+ auto newModesQmlList = screen->availableModes();
134+ for (int i = 0; i < newModesQmlList.count(&newModesQmlList); i++) {
135+ newModes << newModesQmlList.at(&newModesQmlList, i);
136+ }
137+
138+ if (newModes != newModes) {
139+ Q_EMIT availableModesChanged();
140+ }
141+ } else {
142+ Q_EMIT availableModesChanged();
143+ }
144+
145+ connectToScreen(screen);
146+}
147+
148+ScreenAttached *WMScreen::qmlAttachedProperties(QObject *owner)
149+{
150+ return new ScreenAttached(owner);
151+}
plugins/WindowManager/ScreenAttached.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 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 SCREENATTACHED_H
18+#define SCREENATTACHED_H
19+
20+#include "Screen.h"
21+
22+#include <QQmlEngine>
23+#include <QtQml>
24+
25+class QQuickWindow;
26+
27+class ScreenAttached : public Screen
28+{
29+ Q_OBJECT
30+public:
31+ ScreenAttached(QObject* owner);
32+
33+ WorkspaceModel* workspaces() const override;
34+ Workspace *currentWorkspace() const override;
35+ void setCurrentWorkspace(Workspace* workspace) override;
36+
37+private Q_SLOTS:
38+ void windowChanged(QQuickWindow*);
39+ void screenChanged(QScreen*);
40+ void screenChanged2(Screen* screen);
41+
42+private:
43+ QPointer<Screen> m_screen;
44+ QQuickWindow* m_window;
45+};
46+
47+class WMScreen : public QObject
48+{
49+ Q_OBJECT
50+public:
51+ static ScreenAttached *qmlAttachedProperties(QObject *owner);
52+};
53+
54+QML_DECLARE_TYPEINFO(WMScreen, QML_HAS_ATTACHED_PROPERTIES)
55+
56+#endif // SCREENATTACHED_H
plugins/WindowManager/ScreenWindow.cppnew file+45
@@ -0,0 +1,45 @@
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+}
28+
29+ScreenWindow::~ScreenWindow()
30+{
31+}
32+
33+ConcreteScreen *ScreenWindow::screenWrapper() const
34+{
35+ return m_screen.data();
36+}
37+
38+void ScreenWindow::setScreenWrapper(ConcreteScreen *screen)
39+{
40+ if (m_screen != screen) {
41+ m_screen = screen;
42+ Q_EMIT screenWrapperChanged(screen);
43+ }
44+ QQuickWindow::setScreen(screen->qscreen());
45+}
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(ConcreteScreen *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+ ConcreteScreen *screenWrapper() const;
40+ void setScreenWrapper(ConcreteScreen *screen);
41+
42+Q_SIGNALS:
43+ void screenWrapperChanged(ConcreteScreen* screen);
44+
45+private:
46+ QPointer<ConcreteScreen> m_screen;
47+};
48+
49+#endif // UNITY_SCREENWINDOW_H
plugins/WindowManager/Screens.cppnew file+245
@@ -0,0 +1,245 @@
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 "ScreensConfiguration.h"
19+#include "Screen.h"
20+#include "WorkspaceManager.h"
21+
22+// qtmirserver
23+#include <qtmir/screens.h>
24+#include <QGuiApplication>
25+#include <QQmlEngine>
26+
27+// Qt
28+#include <QScreen>
29+#include <QWindow>
30+
31+ConcreteScreens* ConcreteScreens::m_self{nullptr};
32+
33+Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
34+ : m_wrapped(model)
35+{
36+}
37+
38+Screens::~Screens()
39+{
40+ qDeleteAll(m_screens);
41+ m_screens.clear();
42+}
43+
44+QHash<int, QByteArray> Screens::roleNames() const
45+{
46+ QHash<int, QByteArray> roles;
47+ roles[ScreenRole] = "screen";
48+ return roles;
49+}
50+
51+QVariant Screens::data(const QModelIndex &index, int role) const
52+{
53+ if (!index.isValid() || index.row() >= m_screens.size()) {
54+ return QVariant();
55+ }
56+
57+ switch(role) {
58+ case ScreenRole:
59+ return QVariant::fromValue(m_screens.at(index.row()));
60+ } // switch
61+
62+ return QVariant();
63+}
64+
65+int Screens::rowCount(const QModelIndex &) const
66+{
67+ return count();
68+}
69+
70+int Screens::indexOf(Screen *screen) const
71+{
72+ return m_screens.indexOf(screen);
73+}
74+
75+Screen *Screens::get(int index) const
76+{
77+ return m_screens.at(index);
78+}
79+
80+int Screens::count() const
81+{
82+ return m_screens.size();
83+}
84+
85+QVariant Screens::activeScreen() const
86+{
87+ for (int i = 0; i < m_screens.count(); i++) {
88+ if (m_screens[i]->isActive()) return i;
89+ }
90+ return QVariant();
91+}
92+
93+void Screens::activateScreen(const QVariant& vindex)
94+{
95+ bool ok = false;
96+ int index = vindex.toInt(&ok);
97+ if (!ok || index < 0 || m_screens.count() <= index) return;
98+
99+ auto screen = m_screens.at(index);
100+ screen->setActive(true);
101+}
102+
103+
104+ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model, ScreensConfiguration* config)
105+ : Screens(model)
106+ , m_config(config)
107+{
108+ m_self = this;
109+ connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &ConcreteScreens::onScreenAdded);
110+ connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &ConcreteScreens::onScreenRemoved);
111+ connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &ConcreteScreens::activeScreenChanged);
112+
113+ Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
114+ auto screenWrapper(new ConcreteScreen(screen));
115+ m_config->load(screenWrapper);
116+
117+ QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
118+ m_screens.push_back(screenWrapper);
119+ }
120+}
121+
122+ConcreteScreens::~ConcreteScreens()
123+{
124+ Q_FOREACH(Screen* screen, m_screens) {
125+ m_config->save(screen);
126+ }
127+ delete m_config;
128+}
129+
130+ConcreteScreens *ConcreteScreens::self()
131+{
132+ return ConcreteScreens::m_self;
133+}
134+
135+ProxyScreens *ConcreteScreens::createProxy()
136+{
137+ return new ProxyScreens(this);
138+}
139+
140+void ConcreteScreens::sync(ProxyScreens *proxy)
141+{
142+ if (!proxy) return;
143+ proxy->setSyncing(true);
144+
145+ const auto& proxyList = proxy->list();
146+ for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
147+ m_screens[i]->sync(proxyList[i]);
148+ }
149+
150+ proxy->setSyncing(true);
151+}
152+
153+void ConcreteScreens::onScreenAdded(qtmir::Screen *added)
154+{
155+ Q_FOREACH(auto screenWrapper, m_screens) {
156+ if (screenWrapper->wrapped() == added) return;
157+ }
158+
159+ beginInsertRows(QModelIndex(), count(), count());
160+ auto screenWrapper(new ConcreteScreen(added));
161+ m_config->load(screenWrapper);
162+
163+ QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
164+ m_screens.push_back(screenWrapper);
165+ endInsertRows();
166+ Q_EMIT screenAdded(screenWrapper);
167+ Q_EMIT countChanged();
168+}
169+
170+void ConcreteScreens::onScreenRemoved(qtmir::Screen *removed)
171+{
172+ int index = 0;
173+ QMutableVectorIterator<Screen*> iter(m_screens);
174+ while(iter.hasNext()) {
175+ auto screenWrapper = iter.next();
176+ if (screenWrapper->wrapped() == removed) {
177+ m_config->save(screenWrapper);
178+
179+ beginRemoveRows(QModelIndex(), index, index);
180+ iter.remove();
181+ endRemoveRows();
182+
183+ Q_EMIT screenRemoved(screenWrapper);
184+ Q_EMIT countChanged();
185+
186+ screenWrapper->deleteLater();
187+ break;
188+ }
189+ index++;
190+ }
191+}
192+
193+
194+ProxyScreens::ProxyScreens(Screens * const screens)
195+ : Screens(screens->m_wrapped)
196+ , m_original(screens)
197+ , m_syncing(false)
198+{
199+ connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
200+ Q_FOREACH(auto screen, m_screens) {
201+ auto proxy = static_cast<ProxyScreen*>(screen);
202+ if (proxy->proxyObject() == added) return;
203+ }
204+
205+ beginInsertRows(QModelIndex(), count(), count());
206+ auto screenWrapper(new ProxyScreen(added, this));
207+ QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
208+ m_screens.push_back(screenWrapper);
209+ endInsertRows();
210+ Q_EMIT screenAdded(screenWrapper);
211+ Q_EMIT countChanged();
212+ });
213+
214+ connect(screens, &Screens::screenRemoved, this, [this](Screen *removed) {
215+ int index = 0;
216+ QMutableVectorIterator<Screen*> iter(m_screens);
217+ while(iter.hasNext()) {
218+ auto proxy = static_cast<ProxyScreen*>(iter.next());
219+ if (proxy->proxyObject() == removed) {
220+
221+ beginRemoveRows(QModelIndex(), index, index);
222+ iter.remove();
223+ endRemoveRows();
224+
225+ Q_EMIT screenRemoved(proxy);
226+ Q_EMIT countChanged();
227+
228+ delete proxy;
229+ break;
230+ }
231+ index++;
232+ }
233+ });
234+
235+ Q_FOREACH(Screen* screen, screens->list()) {
236+ auto screenWrapper(new ProxyScreen(screen, this));
237+ QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
238+ m_screens.push_back(screenWrapper);
239+ }
240+}
241+
242+void ProxyScreens::setSyncing(bool syncing)
243+{
244+ m_syncing = syncing;
245+}
plugins/WindowManager/Screens.hnew file+114
@@ -0,0 +1,114 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_SCREENS_H
18+#define UNITY_SCREENS_H
19+
20+#include <QAbstractListModel>
21+#include <QSharedPointer>
22+#include <QPointer>
23+
24+namespace qtmir
25+{
26+class Screen;
27+class Screens;
28+}
29+
30+class Screen;
31+class ProxyScreens;
32+class ScreensConfiguration;
33+
34+class Screens : public QAbstractListModel
35+{
36+ Q_OBJECT
37+ Q_PROPERTY(int count READ count NOTIFY countChanged)
38+ Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
39+
40+public:
41+ enum ItemRoles {
42+ ScreenRole = Qt::UserRole + 1
43+ };
44+
45+ virtual ~Screens();
46+
47+ /* QAbstractItemModel */
48+ QHash<int, QByteArray> roleNames() const override;
49+ QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
50+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
51+
52+ Q_INVOKABLE int indexOf(Screen*) const;
53+ Q_INVOKABLE Screen* get(int index) const;
54+
55+ 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);
62+
63+Q_SIGNALS:
64+ void countChanged();
65+ void activeScreenChanged();
66+
67+ void screenAdded(Screen* screen);
68+ void screenRemoved(Screen* screen);
69+
70+protected:
71+ Screens(const QSharedPointer<qtmir::Screens>& model);
72+
73+ QVector<Screen*> m_screens;
74+ const QSharedPointer<qtmir::Screens> m_wrapped;
75+
76+ friend class ProxyScreens;
77+};
78+
79+class ConcreteScreens : public Screens
80+{
81+ Q_OBJECT
82+public:
83+ explicit ConcreteScreens(const QSharedPointer<qtmir::Screens>& model, ScreensConfiguration* config);
84+ ~ConcreteScreens();
85+
86+ Q_INVOKABLE ProxyScreens *createProxy();
87+ Q_INVOKABLE void sync(ProxyScreens *proxy);
88+
89+ static ConcreteScreens *self();
90+
91+protected Q_SLOTS:
92+ void onScreenAdded(qtmir::Screen *screen);
93+ void onScreenRemoved(qtmir::Screen *screen);
94+
95+private:
96+ ScreensConfiguration* m_config;
97+
98+ static ConcreteScreens* m_self;
99+};
100+
101+class ProxyScreens : public Screens
102+{
103+public:
104+ explicit ProxyScreens(Screens*const screens);
105+
106+ void setSyncing(bool syncing);
107+ bool isSyncing() const { return m_syncing; }
108+
109+private:
110+ const QPointer<Screens> m_original;
111+ bool m_syncing;
112+};
113+
114+#endif // SCREENS_H
plugins/WindowManager/ScreensConfiguration.cppnew file+94
@@ -0,0 +1,94 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ScreensConfiguration.h"
18+#include "Screen.h"
19+#include "Workspace.h"
20+#include "WorkspaceManager.h"
21+
22+#include <QJsonObject>
23+#include <QJsonDocument>
24+#include <QJsonArray>
25+#include <QFile>
26+#include <QStandardPaths>
27+
28+namespace
29+{
30+QJsonArray jsonScreens;
31+}
32+
33+ScreensConfiguration::ScreensConfiguration()
34+{
35+ const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
36+ QFile f(dbPath + "workspaces");
37+
38+ if (f.open(QIODevice::ReadOnly)) {
39+ QByteArray saveData = f.readAll();
40+ QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
41+ QJsonObject json(loadDoc.object());
42+ jsonScreens = json["screens"].toArray();
43+ }
44+}
45+
46+ScreensConfiguration::~ScreensConfiguration()
47+{
48+ const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
49+ QFile f(dbPath + "workspaces");
50+ if (f.open(QIODevice::WriteOnly)) {
51+ QJsonObject json;
52+ json["screens"] = jsonScreens;
53+ QJsonDocument saveDoc(json);
54+ f.write(saveDoc.toJson());
55+ }
56+}
57+
58+void ScreensConfiguration::load(Screen *screen)
59+{
60+ int workspaces = 2;
61+ for (auto iter = jsonScreens.begin(); iter != jsonScreens.end(); ++iter) {
62+ QJsonObject jsonScreen = (*iter).toObject();
63+ if (jsonScreen["name"] == screen->name()) {
64+ QJsonValue jsonWorkspaces = jsonScreen["workspaces"];
65+ workspaces = qMax(jsonWorkspaces.toInt(workspaces), 1);
66+ break;
67+ }
68+ }
69+
70+ for (int i = 0; i < workspaces; i++) {
71+ WorkspaceManager::instance()->createWorkspace()->assign(screen->workspaces());
72+ }
73+}
74+
75+void ScreensConfiguration::save(Screen *screen)
76+{
77+ QJsonObject newJsonScreen;
78+ newJsonScreen["name"] = screen->name();
79+ newJsonScreen["workspaces"] = qMax(screen->workspaces()->rowCount(), 1);
80+
81+ auto iter = jsonScreens.begin();
82+ for (; iter != jsonScreens.end(); ++iter) {
83+ QJsonObject jsonScreen = (*iter).toObject();
84+ if (jsonScreen["name"] == screen->name()) {
85+ break;
86+ }
87+ }
88+
89+ if (iter == jsonScreens.end()) {
90+ jsonScreens.push_back(newJsonScreen);
91+ } else {
92+ *iter = newJsonScreen;
93+ }
94+}
src/ShellView.h → plugins/WindowManager/ScreensConfiguration.hrenamed+10−12
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2017 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 SCREENSCONFIGURATION_H
18+#define SCREENSCONFIGURATION_H
1919
20−#include <QQuickView>
20+class Screen;
2121
22−class ShellView : public QQuickView
22+class ScreensConfiguration
2323{
24− Q_OBJECT
25−
2624public:
27− ShellView(QQmlEngine *engine, QObject *qmlArgs);
25+ explicit ScreensConfiguration();
26+ ~ScreensConfiguration();
2827
29−private Q_SLOTS:
30− void onWidthChanged(int);
31− void onHeightChanged(int);
28+ void load(Screen* screen);
29+ void save(Screen* screen);
3230};
3331
34−#endif // UNITY_SHELL_VIEW_H
32+#endif // SCREENSCONFIGURATION_H
plugins/WindowManager/TopLevelWindowModel.cpp+199−62
@@ -15,6 +15,7 @@
1515 */
1616
1717#include "TopLevelWindowModel.h"
18+#include "WindowManagerObjects.h"
1819
1920// unity-api
2021#include <unity/shell/application/ApplicationInfoInterface.h>
@@ -24,11 +25,11 @@
2425#include <unity/shell/application/SurfaceManagerInterface.h>
2526
2627// Qt
27−#include <QGuiApplication>
2828#include <QDebug>
2929
3030// local
3131#include "Window.h"
32+#include "Workspace.h"
3233
3334Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
3435
@@ -37,7 +38,19 @@ Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
3738
3839namespace unityapi = unity::shell::application;
3940
40−TopLevelWindowModel::TopLevelWindowModel()
41+TopLevelWindowModel::TopLevelWindowModel(Workspace* workspace)
42+ : m_workspace(workspace)
43+{
44+ connect(WindowManagerObjects::instance(), &WindowManagerObjects::applicationManagerChanged,
45+ this, &TopLevelWindowModel::setApplicationManager);
46+ connect(WindowManagerObjects::instance(), &WindowManagerObjects::surfaceManagerChanged,
47+ this, &TopLevelWindowModel::setSurfaceManager);
48+
49+ setApplicationManager(WindowManagerObjects::instance()->applicationManager());
50+ setSurfaceManager(WindowManagerObjects::instance()->surfaceManager());
51+}
52+
53+TopLevelWindowModel::~TopLevelWindowModel()
4154{
4255}
4356
@@ -55,7 +68,6 @@ void TopLevelWindowModel::setApplicationManager(unityapi::ApplicationManagerInte
5568 beginResetModel();
5669
5770 if (m_applicationManager) {
58− m_windowModel.clear();
5971 disconnect(m_applicationManager, 0, this, 0);
6072 }
6173
@@ -64,26 +76,26 @@ void TopLevelWindowModel::setApplicationManager(unityapi::ApplicationManagerInte
6476 if (m_applicationManager) {
6577 connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
6678 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− });
79+ if (!m_workspace || !m_workspace->isActive())
80+ return;
81+
82+ for (int i = first; i <= last; ++i) {
83+ auto application = m_applicationManager->get(i);
84+ addApplication(application);
85+ }
86+ });
7287
7388 connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
7489 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− });
80−
81− for (int i = 0; i < m_applicationManager->rowCount(); ++i) {
82− auto application = m_applicationManager->get(i);
83− addApplication(application);
84− }
90+ for (int i = first; i <= last; ++i) {
91+ auto application = m_applicationManager->get(i);
92+ removeApplication(application);
93+ }
94+ });
8595 }
8696
97+ refreshWindows();
98+
8799 endResetModel();
88100 m_modelState = IdleState;
89101}
@@ -96,6 +108,11 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
96108
97109 DEBUG_MSG << "(" << surfaceManager << ")";
98110
111+ Q_ASSERT(m_modelState == IdleState);
112+ m_modelState = ResettingState;
113+
114+ beginResetModel();
115+
99116 if (m_surfaceManager) {
100117 disconnect(m_surfaceManager, 0, this, 0);
101118 }
@@ -103,13 +120,20 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
103120 m_surfaceManager = surfaceManager;
104121
105122 if (m_surfaceManager) {
106− connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfaceCreated, this, &TopLevelWindowModel::onSurfaceCreated);
107123 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
108124 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
109125 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
126+
127+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
128+ this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
129+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
130+ this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
110131 }
111132
112− Q_EMIT surfaceManagerChanged(m_surfaceManager);
133+ refreshWindows();
134+
135+ endResetModel();
136+ m_modelState = IdleState;
113137}
114138
115139void TopLevelWindowModel::addApplication(unityapi::ApplicationInfoInterface *application)
@@ -149,6 +173,7 @@ void TopLevelWindowModel::prependSurface(unityapi::MirSurfaceInterface *surface,
149173 Q_ASSERT(surface != nullptr);
150174
151175 connectSurface(surface);
176+ m_allSurfaces.insert(surface);
152177
153178 bool filledPlaceholder = false;
154179 for (int i = 0; i < m_windowModel.count() && !filledPlaceholder; ++i) {
@@ -225,15 +250,14 @@ void TopLevelWindowModel::connectWindow(Window *window)
225250
226251 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
227252 if (window->surface()) {
228− // Condense changes to the focused window
229− // eg: Do focusedWindow=A to focusedWindow=B instead of
230− // focusedWindow=A to focusedWindow=null to focusedWindow=B
231253 if (focused) {
232− Q_ASSERT(m_newlyFocusedWindow == nullptr);
233− m_focusedWindowChanged = true;
234− m_newlyFocusedWindow = window;
254+ setFocusedWindow(window);
255+ m_focusedWindowCleared = false;
235256 } else if (m_focusedWindow == window) {
236− m_focusedWindowChanged = true;
257+ // Condense changes to the focused window
258+ // eg: Do focusedWindow=A to focusedWindow=B instead of
259+ // focusedWindow=A to focusedWindow=null to focusedWindow=B
260+ m_focusedWindowCleared = true;
237261 } else {
238262 // don't clear the focused window if you were not there in the first place
239263 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
@@ -338,6 +362,7 @@ void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surf
338362 auto window = m_windowModel[i].window;
339363 window->setSurface(nullptr);
340364 window->setFocused(false);
365+ m_allSurfaces.remove(surface);
341366 INFO_MSG << " Removed surface from entry. After: " << toString();
342367 }
343368}
@@ -353,48 +378,107 @@ Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface
353378 return qmlWindow;
354379}
355380
356−void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface *surface)
381+void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
382+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
357383{
358− DEBUG_MSG << "(" << surface << ")";
384+ if (!m_workspace || !m_applicationManager) return;
385+ if (workspace != m_workspace->workspace()) return;
359386
360− if (surface->parentSurface()) {
361− // Wrap it in a Window so that we keep focusedWindow() up to date.
362− Window *window = createWindow(surface);
363− connect(surface, &QObject::destroyed, window, [=](){
364− window->setSurface(nullptr);
365− window->deleteLater();
366− });
367− } else {
368− if (surface->type() == Mir::InputMethodType) {
369− connectSurface(surface);
370− setInputMethodWindow(createWindow(surface));
387+ Q_FOREACH(auto surface, surfaces) {
388+ if (m_allSurfaces.contains(surface)) continue;
389+
390+ if (surface->parentSurface()) {
391+ // Wrap it in a Window so that we keep focusedWindow() up to date.
392+ Window *window = createWindow(surface);
393+ connect(surface, &QObject::destroyed, window, [=](){
394+ window->setSurface(nullptr);
395+ window->deleteLater();
396+ });
371397 } else {
372− auto *application = m_applicationManager->findApplicationWithSurface(surface);
373− if (application) {
374− if (surface->state() == Mir::HiddenState) {
375− // Ignore it until it's finally shown
376− connect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, [=](Mir::State newState) {
377− Q_ASSERT(newState != Mir::HiddenState);
378− disconnect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, 0);
398+ if (surface->type() == Mir::InputMethodType) {
399+ connectSurface(surface);
400+ setInputMethodWindow(createWindow(surface));
401+ } else {
402+ auto *application = m_applicationManager->findApplicationWithSurface(surface);
403+ if (application) {
404+ if (surface->state() == Mir::HiddenState) {
405+ // Ignore it until it's finally shown
406+ connect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, [=](Mir::State newState) {
407+ Q_ASSERT(newState != Mir::HiddenState);
408+ disconnect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, 0);
409+ prependSurface(surface, application);
410+ });
411+ } else {
379412 prependSurface(surface, application);
380− });
413+ }
381414 } else {
382− prependSurface(surface, application);
415+ // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
416+ // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
417+ // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
418+ Window *promptWindow = createWindow(surface);
419+ connect(surface, &QObject::destroyed, promptWindow, [=](){
420+ promptWindow->setSurface(nullptr);
421+ promptWindow->deleteLater();
422+ });
383423 }
384− } else {
385− // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
386− // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
387− // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
388− Window *promptWindow = createWindow(surface);
389− connect(surface, &QObject::destroyed, promptWindow, [=](){
390− promptWindow->setSurface(nullptr);
391− promptWindow->deleteLater();
392− });
393424 }
394425 }
395426 }
396427}
397428
429+void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
430+ const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
431+{
432+ if (!m_workspace || workspace != m_workspace->workspace()) return;
433+
434+ int start = -1;
435+ int end = -1;
436+ for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
437+ auto surface = *iter;
438+ iter++;
439+
440+ // Do removals in adjacent blocks.
441+ start = end = indexOf(surface);
442+ if (start == -1) {
443+ // probably a child surface
444+ m_allSurfaces.remove(surface);
445+ continue;
446+ }
447+ while(iter != surfaces.constEnd()) {
448+ int index = indexOf(*iter);
449+ if (index != end+1) {
450+ break;
451+ }
452+ end++;
453+ iter++;
454+ }
455+
456+ if (m_modelState == IdleState) {
457+ beginRemoveRows(QModelIndex(), start, end);
458+ m_modelState = RemovingState;
459+ } else {
460+ Q_ASSERT(m_modelState == ResettingState);
461+ // No point in signaling anything if we're resetting the whole model
462+ }
463+
464+ for (int index = start; index <= end; index++) {
465+ auto window = m_windowModel[start].window;
466+ window->setSurface(nullptr);
467+ window->setFocused(false);
468+
469+ m_windowModel.removeAt(start);
470+ m_allSurfaces.remove(surface);
471+ }
472+
473+ if (m_modelState == RemovingState) {
474+ endRemoveRows();
475+ Q_EMIT countChanged();
476+ Q_EMIT listChanged();
477+ m_modelState = IdleState;
478+ }
479+ }
480+}
481+
398482void TopLevelWindowModel::deleteAt(int index)
399483{
400484 auto window = m_windowModel[index].window;
@@ -417,12 +501,14 @@ void TopLevelWindowModel::removeAt(int index)
417501 }
418502
419503 auto window = m_windowModel[index].window;
504+ auto surface = window->surface();
420505
421506 if (!window->surface()) {
422507 window->setFocused(false);
423508 }
424509
425510 m_windowModel.removeAt(index);
511+ m_allSurfaces.remove(surface);
426512
427513 if (m_modelState == RemovingState) {
428514 endRemoveRows();
@@ -433,6 +519,7 @@ void TopLevelWindowModel::removeAt(int index)
433519
434520 if (m_focusedWindow == window) {
435521 setFocusedWindow(nullptr);
522+ m_focusedWindowCleared = false;
436523 }
437524
438525 INFO_MSG << " after " << toString();
@@ -700,12 +787,11 @@ void TopLevelWindowModel::onModificationsStarted()
700787
701788void TopLevelWindowModel::onModificationsEnded()
702789{
703− if (m_focusedWindowChanged) {
704− setFocusedWindow(m_newlyFocusedWindow);
790+ if (m_focusedWindowCleared) {
791+ setFocusedWindow(nullptr);
705792 }
706793 // reset
707− m_focusedWindowChanged = false;
708− m_newlyFocusedWindow = nullptr;
794+ m_focusedWindowCleared = false;
709795}
710796
711797void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
@@ -719,3 +805,54 @@ void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
719805 }
720806 }
721807}
808+
809+void TopLevelWindowModel::refreshWindows()
810+{
811+ DEBUG_MSG << "()";
812+ clear();
813+
814+ if (!m_workspace || !m_applicationManager || !m_surfaceManager) return;
815+
816+ m_surfaceManager->forEachSurfaceInWorkspace(m_workspace->workspace(), [this](unity::shell::application::MirSurfaceInterface* surface) {
817+ if (surface->parentSurface()) {
818+ // Wrap it in a Window so that we keep focusedWindow() up to date.
819+ Window *window = createWindow(surface);
820+ connect(surface, &QObject::destroyed, window, [=](){
821+ window->setSurface(nullptr);
822+ window->deleteLater();
823+ });
824+ } else {
825+ if (surface->type() == Mir::InputMethodType) {
826+ setInputMethodWindow(createWindow(surface));
827+ } else {
828+ auto *application = m_applicationManager->findApplicationWithSurface(surface);
829+ if (application) {
830+ prependSurface(surface, application);
831+ } else {
832+ // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
833+ // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
834+ // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
835+ Window *promptWindow = createWindow(surface);
836+ connect(surface, &QObject::destroyed, promptWindow, [=](){
837+ promptWindow->setSurface(nullptr);
838+ promptWindow->deleteLater();
839+ });
840+ }
841+ }
842+ }
843+ });
844+}
845+
846+void TopLevelWindowModel::clear()
847+{
848+ DEBUG_MSG << "()";
849+
850+ while(m_windowModel.count() > 0) {
851+ ModelEntry entry = m_windowModel.takeAt(0);
852+ disconnect(entry.window, 0, this, 0);
853+ delete entry.window;
854+ }
855+ m_allSurfaces.clear();
856+ setFocusedWindow(nullptr);
857+ m_focusedWindowCleared = false;
858+}
plugins/WindowManager/TopLevelWindowModel.h+21−23
@@ -20,11 +20,16 @@
2020#include <QAbstractListModel>
2121#include <QLoggingCategory>
2222
23+#include <memory>
24+
2325#include "WindowManagerGlobal.h"
2426
2527Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
2628
2729class Window;
30+class Workspace;
31+
32+namespace miral { class Workspace; }
2833
2934namespace unity {
3035 namespace shell {
@@ -72,16 +77,6 @@ class WINDOWMANAGERQML_EXPORT TopLevelWindowModel : public QAbstractListModel
7277 */
7378 Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
7479
75− Q_PROPERTY(unity::shell::application::SurfaceManagerInterface* surfaceManager
76− READ surfaceManager
77− WRITE setSurfaceManager
78− NOTIFY surfaceManagerChanged)
79−
80− Q_PROPERTY(unity::shell::application::ApplicationManagerInterface* applicationManager
81− READ applicationManager
82− WRITE setApplicationManager
83− NOTIFY applicationManagerChanged)
84−
8580 /**
8681 The id to be used on the next entry created
8782 Useful for tests
@@ -100,7 +95,8 @@ public:
10095 ApplicationRole = Qt::UserRole + 1,
10196 };
10297
103− TopLevelWindowModel();
98+ TopLevelWindowModel(Workspace* workspace);
99+ ~TopLevelWindowModel();
104100
105101 // From QAbstractItemModel
106102 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
@@ -111,17 +107,11 @@ public:
111107 return roleNames;
112108 }
113109
114− // Own API
110+ // Own API;
115111
116112 unity::shell::application::MirSurfaceInterface* inputMethodSurface() const;
117113 Window* focusedWindow() const;
118114
119− unity::shell::application::ApplicationManagerInterface *applicationManager() const { return m_applicationManager; }
120− void setApplicationManager(unity::shell::application::ApplicationManagerInterface*);
121−
122− unity::shell::application::SurfaceManagerInterface *surfaceManager() const { return m_surfaceManager; }
123− void setSurfaceManager(unity::shell::application::SurfaceManagerInterface*);
124−
125115 int nextId() const { return m_nextId; }
126116
127117public:
@@ -164,12 +154,13 @@ public:
164154 */
165155 Q_INVOKABLE void raiseId(int id);
166156
157+ void setApplicationManager(unity::shell::application::ApplicationManagerInterface*);
158+ void setSurfaceManager(unity::shell::application::SurfaceManagerInterface*);
159+
167160Q_SIGNALS:
168161 void countChanged();
169162 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
170163 void focusedWindowChanged(Window *focusedWindow);
171− void applicationManagerChanged(unity::shell::application::ApplicationManagerInterface*);
172− void surfaceManagerChanged(unity::shell::application::SurfaceManagerInterface*);
173164
174165 /**
175166 * @brief Emitted when the list changes
@@ -181,7 +172,10 @@ Q_SIGNALS:
181172 void nextIdChanged();
182173
183174private Q_SLOTS:
184− void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
175+ void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
176+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
177+ void onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
178+ const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
185179 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
186180
187181 void onModificationsStarted();
@@ -223,6 +217,8 @@ private:
223217 void activateEmptyWindow(Window *window);
224218
225219 void activateTopMostWindowWithoutId(int forbiddenId);
220+ void refreshWindows();
221+ void clear();
226222
227223 Window *createWindow(unity::shell::application::MirSurfaceInterface *surface);
228224
@@ -239,6 +235,9 @@ private:
239235 QVector<ModelEntry> m_windowModel;
240236 Window* m_inputMethodWindow{nullptr};
241237 Window* m_focusedWindow{nullptr};
238+ Workspace* m_workspace{nullptr};
239+ // track all the surfaces we've been told about.
240+ QSet<unity::shell::application::MirSurfaceInterface*> m_allSurfaces;
242241
243242 int m_nextId{1};
244243 // Just something big enough that we don't risk running out of unused id numbers.
@@ -259,8 +258,7 @@ private:
259258 ModelState m_modelState{IdleState};
260259
261260 // Valid between modificationsStarted and modificationsEnded
262− bool m_focusedWindowChanged{false};
263− Window *m_newlyFocusedWindow{nullptr};
261+ bool m_focusedWindowCleared{false};
264262};
265263
266264#endif // TOPLEVELWINDOWMODEL_H
plugins/WindowManager/WindowManagerObjects.cppnew file+47
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "WindowManagerObjects.h"
18+
19+WindowManagerObjects::WindowManagerObjects(QObject *parent)
20+ : QObject(parent)
21+ , m_surfaceManager(nullptr)
22+ , m_applicationManager(nullptr)
23+{
24+}
25+
26+WindowManagerObjects *WindowManagerObjects::instance()
27+{
28+ static WindowManagerObjects* objects(new WindowManagerObjects());
29+ return objects;
30+}
31+
32+
33+void WindowManagerObjects::setSurfaceManager(unity::shell::application::SurfaceManagerInterface *surfaceManager)
34+{
35+ if (m_surfaceManager == surfaceManager) return;
36+
37+ m_surfaceManager = surfaceManager;
38+ Q_EMIT surfaceManagerChanged(surfaceManager);
39+}
40+
41+void WindowManagerObjects::setApplicationManager(unity::shell::application::ApplicationManagerInterface *applicationManager)
42+{
43+ if (m_applicationManager == applicationManager) return;
44+
45+ m_applicationManager = applicationManager;
46+ Q_EMIT applicationManagerChanged(applicationManager);
47+}
plugins/WindowManager/WindowManagerObjects.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 WINDOWMANAGEROBJECTS_H
18+#define WINDOWMANAGEROBJECTS_H
19+
20+#include <QObject>
21+
22+#include "WindowManagerGlobal.h"
23+
24+namespace unity {
25+ namespace shell {
26+ namespace application {
27+ class SurfaceManagerInterface;
28+ class ApplicationManagerInterface;
29+ }
30+ }
31+}
32+
33+class WINDOWMANAGERQML_EXPORT WindowManagerObjects : public QObject
34+{
35+ Q_OBJECT
36+
37+ Q_PROPERTY(unity::shell::application::SurfaceManagerInterface* surfaceManager
38+ READ surfaceManager
39+ WRITE setSurfaceManager
40+ NOTIFY surfaceManagerChanged)
41+
42+ Q_PROPERTY(unity::shell::application::ApplicationManagerInterface* applicationManager
43+ READ applicationManager
44+ WRITE setApplicationManager
45+ NOTIFY applicationManagerChanged)
46+public:
47+ explicit WindowManagerObjects(QObject *parent = 0);
48+
49+ static WindowManagerObjects *instance();
50+
51+ unity::shell::application::SurfaceManagerInterface *surfaceManager() const { return m_surfaceManager; }
52+ void setSurfaceManager(unity::shell::application::SurfaceManagerInterface*);
53+
54+ unity::shell::application::ApplicationManagerInterface *applicationManager() const { return m_applicationManager; }
55+ void setApplicationManager(unity::shell::application::ApplicationManagerInterface*);
56+
57+Q_SIGNALS:
58+ void surfaceManagerChanged(unity::shell::application::SurfaceManagerInterface*);
59+ void applicationManagerChanged(unity::shell::application::ApplicationManagerInterface*);
60+
61+private:
62+ unity::shell::application::SurfaceManagerInterface* m_surfaceManager;
63+ unity::shell::application::ApplicationManagerInterface* m_applicationManager;
64+};
65+
66+#endif // WINDOWMANAGEROBJECTS_H
plugins/WindowManager/WindowManagerPlugin.cpp+56−2
@@ -16,16 +16,70 @@
1616
1717#include "WindowManagerPlugin.h"
1818
19+#include "Screen.h"
20+#include "ScreenAttached.h"
21+#include "Screens.h"
22+#include "ScreensConfiguration.h"
23+#include "ScreenWindow.h"
1924#include "TopLevelWindowModel.h"
2025#include "Window.h"
26+#include "WindowManagerObjects.h"
27+#include "WorkspaceManager.h"
28+#include "Workspace.h"
29+#include "WorkspaceModel.h"
2130
2231#include <QtQml>
32+#include <qtmir/qtmir.h>
33+
34+namespace {
35+
36+static const QString notInstantiatable = QStringLiteral("Not instantiatable");
37+
38+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
39+{
40+ Q_UNUSED(engine)
41+ Q_UNUSED(scriptEngine)
42+ return WorkspaceManager::instance();
43+}
44+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
45+ Q_UNUSED(engine);
46+ Q_UNUSED(scriptEngine);
47+ return ConcreteScreens::self();
48+}
49+QObject* objectsSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
50+ Q_UNUSED(engine);
51+ Q_UNUSED(scriptEngine);
52+ return WindowManagerObjects::instance();
53+}
54+
55+} // namspace
2356
2457void WindowManagerPlugin::registerTypes(const char *uri)
2558{
26− qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
59+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
60+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", notInstantiatable);
61+ qmlRegisterSingletonType<ConcreteScreens>(uri, 1, 0, "Screens", screensSingleton);
62+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", notInstantiatable);
63+ qmlRegisterSingletonType<WindowManagerObjects>(uri, 1, 0, "WindowManagerObjects", objectsSingleton);
2764
28− qRegisterMetaType<Window*>("Window*");
65+ qRegisterMetaType<ConcreteScreen*>("ConcreteScreen*");
66+ qRegisterMetaType<ProxyScreens*>("ProxyScreens*");
67+ qRegisterMetaType<Workspace*>("Workspace*");
68+ qRegisterMetaType<TopLevelWindowModel*>("TopLevelWindowModel*");
2969
70+ qRegisterMetaType<Window*>("Window*");
3071 qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
72+
73+ qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
74+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
75+
76+ qmlRegisterUncreatableType<WMScreen>(uri, 1, 0, "WMScreen", notInstantiatable);
77+}
78+
79+void WindowManagerPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
80+{
81+ QQmlExtensionPlugin::initializeEngine(engine, uri);
82+
83+ // Create Screens
84+ new ConcreteScreens(qtmir::get_screen_model(), new ScreensConfiguration());
3185}
plugins/WindowManager/WindowManagerPlugin.h+1
@@ -27,6 +27,7 @@ class WindowManagerPlugin : public QQmlExtensionPlugin
2727
2828public:
2929 void registerTypes(const char *uri) override;
30+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
3031};
3132
3233#endif // WINDOWMANAGER_PLUGIN_H
plugins/WindowManager/Workspace.cppnew file+156
@@ -0,0 +1,156 @@
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 "wmpolicyinterface.h"
23+
24+int nextWorkspace = 0;
25+
26+Workspace::Workspace(QObject *parent)
27+ : QObject(parent)
28+ , m_workspace(WMPolicyInterface::instance()->createWorkspace())
29+ , m_model(nullptr)
30+{
31+ setObjectName((QString("Wks%1").arg(nextWorkspace++)));
32+}
33+
34+Workspace::Workspace(const Workspace &other)
35+ : QObject(nullptr)
36+ , m_workspace(other.m_workspace)
37+ , m_model(nullptr)
38+{
39+ setObjectName(other.objectName());
40+
41+ connect(&other, &Workspace::activeChanged, this, &Workspace::activeChanged);
42+}
43+
44+Workspace::~Workspace()
45+{
46+ if (m_model) {
47+ m_model->remove(this);
48+ }
49+}
50+
51+void Workspace::assign(WorkspaceModel *model, const QVariant& vIndex)
52+{
53+ if (m_model == model) return;
54+
55+ if (m_model) {
56+ disconnect(m_model, 0, this, 0);
57+ m_model->remove(this);
58+ }
59+
60+ m_model = model;
61+
62+ if (model) {
63+ int index = m_model->rowCount();
64+ if (vIndex.isValid() && vIndex.canConvert(QVariant::Int)) {
65+ index = vIndex.toInt();
66+ }
67+ m_model->insert(index, this);
68+
69+ connect(m_model, &QObject::destroyed, this, [this]() {
70+ m_model = nullptr;
71+ Q_EMIT unassigned();
72+ });
73+ Q_EMIT assigned();
74+ } else {
75+ Q_EMIT unassigned();
76+ }
77+}
78+
79+void Workspace::unassign()
80+{
81+ assign(nullptr);
82+}
83+
84+bool Workspace::isAssigned() const
85+{
86+ return m_model != nullptr;
87+}
88+
89+
90+ConcreteWorkspace::ConcreteWorkspace(QObject *parent)
91+ : Workspace(parent)
92+ , m_active(false)
93+ , m_windowModel(new TopLevelWindowModel(this))
94+{
95+ connect(WorkspaceManager::instance(), &WorkspaceManager::activeWorkspaceChanged, this, [this](Workspace* activeWorkspace) {
96+ bool newActive = activeWorkspace == this;
97+ if (newActive != m_active) {
98+ m_active = newActive;
99+ Q_EMIT activeChanged(m_active);
100+
101+ if (m_active) {
102+ WMPolicyInterface::instance()->setActiveWorkspace(m_workspace);
103+ }
104+ }
105+ });
106+}
107+
108+ConcreteWorkspace::~ConcreteWorkspace()
109+{
110+ WorkspaceManager::instance()->destroyWorkspace(this);
111+ WMPolicyInterface::instance()->releaseWorkspace(m_workspace);
112+}
113+
114+TopLevelWindowModel *ConcreteWorkspace::windowModel() const
115+{
116+ return m_windowModel.data();
117+}
118+
119+void ConcreteWorkspace::activate()
120+{
121+ WorkspaceManager::instance()->setActiveWorkspace(this);
122+}
123+
124+
125+ProxyWorkspace::ProxyWorkspace(Workspace * const workspace)
126+ : Workspace(*workspace)
127+ , m_original(workspace)
128+{
129+}
130+
131+void ProxyWorkspace::assign(WorkspaceModel *model, const QVariant &index)
132+{
133+ Workspace::assign(model, index);
134+}
135+
136+void ProxyWorkspace::unassign()
137+{
138+ Workspace::unassign();
139+}
140+
141+bool ProxyWorkspace::isActive() const
142+{
143+ return m_original ? m_original->isActive() : false;
144+}
145+
146+TopLevelWindowModel *ProxyWorkspace::windowModel() const
147+{
148+ return m_original ? m_original->windowModel() : nullptr;
149+}
150+
151+void ProxyWorkspace::activate()
152+{
153+ if (m_original) {
154+ m_original->activate();
155+ }
156+}
plugins/WindowManager/Workspace.hnew file+117
@@ -0,0 +1,117 @@
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+#include <QSharedPointer>
24+
25+#include <memory>
26+#include <functional>
27+
28+#include "WindowManagerGlobal.h"
29+
30+class WorkspaceModel;
31+class TopLevelWindowModel;
32+
33+namespace miral { class Workspace; }
34+
35+namespace unity {
36+ namespace shell {
37+ namespace application {
38+ class MirSurfaceInterface;
39+ }
40+ }
41+}
42+
43+class WINDOWMANAGERQML_EXPORT Workspace : public QObject
44+{
45+ Q_OBJECT
46+ Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
47+ Q_PROPERTY(TopLevelWindowModel* windowModel READ windowModel CONSTANT)
48+public:
49+ virtual ~Workspace();
50+
51+ virtual void assign(WorkspaceModel* model, const QVariant& index = QVariant());
52+ virtual void unassign();
53+
54+ virtual bool isActive() const = 0;
55+ virtual TopLevelWindowModel *windowModel() const = 0;
56+
57+ std::shared_ptr<miral::Workspace> workspace() const { return m_workspace; }
58+ bool isAssigned() const;
59+
60+public Q_SLOTS:
61+ virtual void activate() = 0;
62+
63+Q_SIGNALS:
64+ void assigned();
65+ void unassigned();
66+
67+ void activeChanged(bool);
68+
69+protected:
70+ Workspace(QObject *parent = nullptr);
71+ Workspace(Workspace const& other);
72+
73+ std::shared_ptr<miral::Workspace> m_workspace;
74+ WorkspaceModel* m_model;
75+};
76+
77+class WINDOWMANAGERQML_EXPORT ConcreteWorkspace : public Workspace
78+{
79+public:
80+ ~ConcreteWorkspace();
81+
82+ bool isActive() const override { return m_active; }
83+ TopLevelWindowModel *windowModel() const override;
84+ void activate() override;
85+
86+private:
87+ explicit ConcreteWorkspace(QObject *parent = nullptr);
88+
89+ bool m_active;
90+ const QScopedPointer<TopLevelWindowModel> m_windowModel;
91+
92+ friend class WorkspaceManager;
93+};
94+
95+class ProxyWorkspace : public Workspace
96+{
97+ Q_OBJECT
98+public:
99+ explicit ProxyWorkspace(Workspace*const workspace);
100+ ~ProxyWorkspace() = default;
101+
102+ Q_INVOKABLE void assign(WorkspaceModel* model, const QVariant& index = QVariant()) override;
103+
104+ bool isActive() const override;
105+ TopLevelWindowModel *windowModel() const override;
106+ void activate() override;
107+
108+ Workspace* proxyObject() const { return m_original.data(); }
109+
110+public Q_SLOTS:
111+ void unassign() override;
112+
113+private:
114+ const QPointer<Workspace> m_original;
115+};
116+
117+#endif // WINDOWMANAGER_WORKSPACE_H
plugins/WindowManager/WorkspaceManager.cppnew file+106
@@ -0,0 +1,106 @@
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+#include "WindowManagerObjects.h"
21+#include <unity/shell/application/SurfaceManagerInterface.h>
22+
23+// Qt
24+#include <QGuiApplication>
25+#include <QScreen>
26+#include <QQmlEngine>
27+
28+WorkspaceManager *WorkspaceManager::instance()
29+{
30+ static WorkspaceManager* workspaceManager(new WorkspaceManager());
31+ return workspaceManager;
32+}
33+
34+WorkspaceManager::WorkspaceManager()
35+ : m_activeWorkspace(nullptr)
36+{
37+}
38+
39+Workspace *WorkspaceManager::createWorkspace()
40+{
41+ auto workspace = new ConcreteWorkspace(this);
42+ QQmlEngine::setObjectOwnership(workspace, QQmlEngine::CppOwnership);
43+ m_allWorkspaces.insert(workspace);
44+
45+ if (m_allWorkspaces.count() == 0 && m_activeWorkspace) {
46+ setActiveWorkspace(nullptr);
47+ } else if (m_allWorkspaces.count() == 1) {
48+ setActiveWorkspace(workspace);
49+ }
50+
51+ return workspace;
52+}
53+
54+void WorkspaceManager::destroyWorkspace(Workspace *workspace)
55+{
56+ if (!workspace) return;
57+
58+ if (workspace->isAssigned()) {
59+ workspace->unassign();
60+ }
61+ m_allWorkspaces.remove(workspace);
62+
63+ if (m_activeWorkspace == workspace) {
64+ setActiveWorkspace(m_allWorkspaces.count() ? *m_allWorkspaces.begin() : nullptr);
65+ }
66+ if (m_activeWorkspace) {
67+ moveWorkspaceContentToWorkspace(m_activeWorkspace, workspace);
68+ }
69+
70+ disconnect(workspace, 0, this, 0);
71+}
72+
73+void WorkspaceManager::moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface *surface, Workspace *workspace)
74+{
75+ auto surfaceManager = WindowManagerObjects::instance()->surfaceManager();
76+ if (surfaceManager) {
77+ surfaceManager->moveSurfaceToWorkspace(surface, workspace->workspace());
78+ }
79+}
80+
81+void WorkspaceManager::moveWorkspaceContentToWorkspace(Workspace *to, Workspace *from)
82+{
83+ auto surfaceManager = WindowManagerObjects::instance()->surfaceManager();
84+ if (surfaceManager) {
85+ surfaceManager->moveWorkspaceContentToWorkspace(to->workspace(), from->workspace());
86+ }
87+}
88+
89+Workspace *WorkspaceManager::activeWorkspace() const
90+{
91+ return m_activeWorkspace;
92+}
93+
94+void WorkspaceManager::setActiveWorkspace(Workspace *workspace)
95+{
96+ if (workspace != m_activeWorkspace) {
97+ m_activeWorkspace = workspace;
98+ Q_EMIT activeWorkspaceChanged(workspace);
99+ }
100+}
101+
102+void WorkspaceManager::setActiveWorkspace2(Workspace *workspace)
103+{
104+ if (!workspace) return;
105+ workspace->activate();
106+}
plugins/WindowManager/WorkspaceManager.hnew file+69
@@ -0,0 +1,69 @@
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 <QQmlListProperty>
21+
22+#include "WindowManagerGlobal.h"
23+#include "WorkspaceModel.h"
24+
25+class Workspace;
26+
27+namespace unity {
28+ namespace shell {
29+ namespace application {
30+ class MirSurfaceInterface;
31+ class SurfaceManagerInterface;
32+ }
33+ }
34+}
35+
36+class WINDOWMANAGERQML_EXPORT WorkspaceManager : public QObject
37+{
38+ Q_OBJECT
39+ Q_PROPERTY(Workspace* activeWorkspace READ activeWorkspace WRITE setActiveWorkspace2 NOTIFY activeWorkspaceChanged)
40+
41+public:
42+ WorkspaceManager();
43+ static WorkspaceManager* instance();
44+
45+ Workspace* activeWorkspace() const;
46+ void setActiveWorkspace(Workspace* workspace);
47+
48+ Workspace* createWorkspace();
49+ void destroyWorkspace(Workspace* workspace);
50+
51+ void destroyFloatingWorkspaces();
52+
53+ Q_INVOKABLE void moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface* surface,
54+ Workspace* workspace);
55+
56+ Q_INVOKABLE void moveWorkspaceContentToWorkspace(Workspace* to, Workspace* from);
57+
58+Q_SIGNALS:
59+ void activeWorkspaceChanged(Workspace*);
60+
61+private:
62+ void setActiveWorkspace2(Workspace* workspace);
63+
64+ QSet<Workspace*> m_allWorkspaces;
65+ Workspace* m_activeWorkspace;
66+ unity::shell::application::SurfaceManagerInterface* m_surfaceManager;
67+};
68+
69+#endif // WORKSPACEMANAGER_H
plugins/WindowManager/WorkspaceModel.cppnew file+254
@@ -0,0 +1,254 @@
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+#include "Screen.h"
21+
22+#include <QQmlEngine>
23+
24+Q_LOGGING_CATEGORY(WORKSPACES, "Workspaces", QtInfoMsg)
25+
26+#define DEBUG_MSG qCDebug(WORKSPACES).nospace().noquote() << __func__
27+#define INFO_MSG qCInfo(WORKSPACES).nospace().noquote() << __func__
28+
29+WorkspaceModel::WorkspaceModel(QObject *parent)
30+ : QAbstractListModel(parent)
31+{
32+}
33+
34+WorkspaceModel::~WorkspaceModel()
35+{
36+ qDeleteAll(m_workspaces.toList()); // make a copy so the list doesnt edit itself during delete.
37+ m_workspaces.clear();
38+}
39+
40+void WorkspaceModel::append(Workspace *workspace)
41+{
42+ insert(m_workspaces.count(), workspace);
43+}
44+
45+void WorkspaceModel::insert(int index, Workspace *workspace)
46+{
47+ beginInsertRows(QModelIndex(), index, index);
48+
49+ m_workspaces.insert(index, workspace);
50+
51+ endInsertRows();
52+
53+ Q_EMIT workspaceInserted(index, workspace);
54+ Q_EMIT countChanged();
55+}
56+
57+void WorkspaceModel::remove(Workspace *workspace)
58+{
59+ int index = m_workspaces.indexOf(workspace);
60+ if (index < 0) return;
61+
62+ beginRemoveRows(QModelIndex(), index, index);
63+
64+ m_workspaces.removeAt(index);
65+ insertUnassigned(workspace);
66+
67+ endRemoveRows();
68+
69+ Q_EMIT workspaceRemoved(workspace);
70+ Q_EMIT countChanged();
71+}
72+
73+void WorkspaceModel::move(int from, int to)
74+{
75+ if (from == to) return;
76+ DEBUG_MSG << " from=" << from << " to=" << to;
77+
78+ if (from >= 0 && from < m_workspaces.size() && to >= 0 && to < m_workspaces.size()) {
79+ QModelIndex parent;
80+
81+ beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
82+#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
83+ const auto &window = m_windowModel.takeAt(from);
84+ m_workspaces.insert(to, window);
85+#else
86+ m_workspaces.move(from, to);
87+#endif
88+ endMoveRows();
89+
90+ Q_EMIT workspaceMoved(from, to);
91+ }
92+}
93+
94+int WorkspaceModel::indexOf(Workspace *workspace) const
95+{
96+ return m_workspaces.indexOf(workspace);
97+}
98+
99+Workspace *WorkspaceModel::get(int index) const
100+{
101+ if (index < 0 || index >= rowCount()) return nullptr;
102+ return m_workspaces.at(index);
103+}
104+
105+int WorkspaceModel::rowCount(const QModelIndex &) const
106+{
107+ return m_workspaces.count();
108+}
109+
110+QVariant WorkspaceModel::data(const QModelIndex &index, int role) const
111+{
112+ if (index.row() < 0 || index.row() >= m_workspaces.size())
113+ return QVariant();
114+
115+ if (role == WorkspaceRole) {
116+ Workspace *workspace = m_workspaces.at(index.row());
117+ return QVariant::fromValue(workspace);
118+ } else {
119+ return QVariant();
120+ }
121+}
122+
123+void WorkspaceModel::sync(WorkspaceModel *proxy)
124+{
125+ if (!proxy) return;
126+ const auto& proxyList = proxy->list();
127+
128+ // check for removals
129+ int removedIndexWhichWasActive = -1;
130+ QVector<Workspace*> dpCpy(this->list());
131+ Q_FOREACH(auto workspace, dpCpy) {
132+
133+ bool found = false;
134+ Q_FOREACH(auto p, proxyList) {
135+ auto workspaceProxy = qobject_cast<ProxyWorkspace*>(p);
136+ if (workspaceProxy->proxyObject() == workspace) {
137+ found = true;
138+ break;
139+ }
140+ }
141+ if (!found) {
142+ if (workspace->isActive()) {
143+ removedIndexWhichWasActive = indexOf(workspace);
144+ }
145+ workspace->unassign();
146+ }
147+ }
148+
149+ // existing
150+ QSet<Workspace*> newWorkspaces;
151+ for (int i = 0; i < proxyList.count(); i++) {
152+ auto workspaceProxy = qobject_cast<ProxyWorkspace*>(proxyList[i]);
153+ auto workspace = workspaceProxy->proxyObject();
154+
155+ int oldIndex = this->indexOf(workspace);
156+
157+ if (oldIndex < 0) {
158+ workspace->assign(this, QVariant(i));
159+ } else if (oldIndex != i) {
160+ this->move(oldIndex, i);
161+ }
162+ newWorkspaces.insert(workspace);
163+ }
164+
165+ // Make sure we have at least one workspace in the model.
166+ if (rowCount() == 0) {
167+ Workspace* workspace = WorkspaceManager::instance()->createWorkspace();
168+ workspace->assign(this);
169+ (new ProxyWorkspace(workspace))->assign(proxy);
170+ }
171+
172+ if (removedIndexWhichWasActive != -1) {
173+ int newActiveIndex = qMin(removedIndexWhichWasActive, this->rowCount()-1);
174+ Workspace* newActiveWorkspace = newActiveIndex >= 0 ? this->get(newActiveIndex) : nullptr;
175+
176+ WorkspaceManager::instance()->setActiveWorkspace(newActiveWorkspace);
177+ }
178+
179+ proxy->finishSync();
180+ finishSync();
181+}
182+
183+void WorkspaceModel::finishSync()
184+{
185+ QSet<Workspace*> dpCpy(m_unassignedWorkspaces);
186+ Q_FOREACH(auto workspace, dpCpy) {
187+ delete workspace;
188+ }
189+ m_unassignedWorkspaces.clear();
190+}
191+
192+void WorkspaceModel::insertUnassigned(Workspace *workspace)
193+{
194+ m_unassignedWorkspaces.insert(workspace);
195+ connect(workspace, &Workspace::assigned, this, [=]() {
196+ m_unassignedWorkspaces.remove(workspace);
197+ disconnect(workspace, &Workspace::assigned, this, 0);
198+ });
199+ connect(workspace, &QObject::destroyed, this, [=]() {
200+ m_unassignedWorkspaces.remove(workspace);
201+ });
202+}
203+
204+
205+ProxyWorkspaceModel::ProxyWorkspaceModel(WorkspaceModel * const model, ProxyScreen* screen)
206+ : m_original(model)
207+ , m_screen(screen)
208+{
209+ Q_FOREACH(auto workspace, model->list()) {
210+ auto proxy = new ProxyWorkspace(workspace);
211+ QQmlEngine::setObjectOwnership(proxy, QQmlEngine::CppOwnership);
212+ proxy->assign(this);
213+ }
214+ connect(m_original, &WorkspaceModel::workspaceInserted, this, [this](int index, Workspace* inserted) {
215+ if (isSyncing()) return;
216+
217+ (new ProxyWorkspace(inserted))->assign(this, index);
218+ });
219+ connect(m_original, &WorkspaceModel::workspaceRemoved, this, [this](Workspace* removed) {
220+ if (isSyncing()) return;
221+
222+ for (int i = 0; i < rowCount(); i++) {
223+ auto workspaceProxy = qobject_cast<ProxyWorkspace*>(get(i));
224+ auto w = workspaceProxy->proxyObject();
225+ if (w == removed) {
226+ remove(workspaceProxy);
227+ break;
228+ }
229+ }
230+ });
231+ connect(m_original, &WorkspaceModel::workspaceMoved, this, [this](int from, int to) {
232+ if (isSyncing()) return;
233+
234+ move(from, to);
235+ });
236+}
237+
238+void ProxyWorkspaceModel::move(int from, int to)
239+{
240+ WorkspaceModel::move(from, to);
241+}
242+
243+bool ProxyWorkspaceModel::isSyncing() const
244+{
245+ return m_screen->isSyncing();
246+}
247+
248+void ProxyWorkspaceModel::addWorkspace()
249+{
250+ auto newWorkspace = WorkspaceManager::instance()->createWorkspace();
251+ m_original->insertUnassigned(newWorkspace);
252+
253+ (new ProxyWorkspace(newWorkspace))->assign(this);
254+}
plugins/WindowManager/WorkspaceModel.hnew file+102
@@ -0,0 +1,102 @@
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 ProxyWorkspaceModel;
28+class ProxyScreen;
29+
30+class WorkspaceModel : public QAbstractListModel
31+{
32+ Q_OBJECT
33+ Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
34+public:
35+ /**
36+ * @brief The Roles supported by the model
37+ *
38+ * WorkspaceRole - A workspace.
39+ */
40+ enum Roles {
41+ WorkspaceRole = Qt::UserRole
42+ };
43+
44+ explicit WorkspaceModel(QObject *parent = 0);
45+ ~WorkspaceModel();
46+
47+ void append(Workspace *workspace);
48+ void insert(int index, Workspace *workspace);
49+ void remove(Workspace* workspace);
50+ virtual void move(int from, int to);
51+
52+ Q_INVOKABLE int indexOf(Workspace *workspace) const;
53+ Q_INVOKABLE Workspace* get(int index) const;
54+
55+ // From QAbstractItemModel
56+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
57+ QVariant data(const QModelIndex& index, int role) const override;
58+ QHash<int, QByteArray> roleNames() const override {
59+ QHash<int, QByteArray> roleNames { {WorkspaceRole, "workspace"} };
60+ return roleNames;
61+ }
62+
63+ const QVector<Workspace*>& list() const { return m_workspaces; }
64+
65+ void sync(WorkspaceModel* proxy);
66+ void finishSync();
67+
68+Q_SIGNALS:
69+ void countChanged();
70+
71+ void workspaceInserted(int index, Workspace *workspace);
72+ void workspaceRemoved(Workspace *workspace);
73+ void workspaceMoved(int from, int to);
74+
75+protected:
76+ void insertUnassigned(Workspace* workspace);
77+
78+ QVector<Workspace*> m_workspaces;
79+ QSet<Workspace*> m_unassignedWorkspaces;
80+
81+ friend class ProxyWorkspaceModel;
82+};
83+
84+class ProxyWorkspaceModel : public WorkspaceModel
85+{
86+ Q_OBJECT
87+public:
88+ explicit ProxyWorkspaceModel(WorkspaceModel*const model, ProxyScreen* screen);
89+
90+ Q_INVOKABLE void move(int from, int to) override;
91+
92+ bool isSyncing() const;
93+
94+public Q_SLOTS:
95+ void addWorkspace();
96+
97+protected:
98+ const QPointer<WorkspaceModel> m_original;
99+ const ProxyScreen* m_screen;
100+};
101+
102+#endif // WORKSPACEMODEL_H
qml/ApplicationMenus/ApplicationMenuItemFactory.qml+4−4
@@ -45,7 +45,7 @@ Object {
4545
4646 Action {
4747 id: action
48− text: menuData.label.replace("_", "&")
48+ text: menuData && menuData.label.replace("_", "&") || ""
4949 }
5050
5151 ListItemLayout {
@@ -59,8 +59,8 @@ Object {
5959 }
6060
6161 Label {
62− text: menuData.shortcut
63− visible: menuData.shortcut && QuickUtils.keyboardAttached
62+ text: menuData && menuData.shortcut || ""
63+ visible: menuData && menuData.shortcut && QuickUtils.keyboardAttached
6464 SlotsLayout.position: SlotsLayout.Trailing
6565 color: enabled ? theme.palette.normal.backgroundSecondaryText :
6666 theme.palette.disabled.backgroundSecondaryText
@@ -86,7 +86,7 @@ Object {
8686
8787 Action {
8888 id: action
89− text: menuData.label.replace("_", "&")
89+ text: menuData && menuData.label.replace("_", "&") || ""
9090 }
9191
9292 ListItemLayout {
qml/ApplicationMenus/MenuBar.qml+5−1
@@ -19,6 +19,7 @@ import QtQuick.Layouts 1.1
1919import Utils 0.1
2020import Ubuntu.Components 1.3
2121import GlobalShortcut 1.0
22+import "../Components/PanelState"
2223
2324Item {
2425 id: root
@@ -29,6 +30,7 @@ Item {
2930 property bool enableKeyFilter: false
3031 property real overflowWidth: width
3132 property bool windowMoving: false
33+ property PanelState panelState
3234
3335 // read from outside
3436 readonly property bool valid: rowRepeater.count > 0
@@ -106,7 +108,9 @@ Item {
106108
107109 Component {
108110 id: menuComponent
109− MenuPopup { }
111+ MenuPopup {
112+ panelState: root.panelState
113+ }
110114 }
111115
112116 Repeater {
qml/ApplicationMenus/MenuPopup.qml+3−1
@@ -64,6 +64,7 @@ UbuntuShape {
6464 }
6565
6666 property alias unityMenuModel: repeater.model
67+ property PanelState panelState
6768
6869 function show() {
6970 visible = true;
@@ -103,7 +104,7 @@ UbuntuShape {
103104 property real __minimumWidth: units.gu(20)
104105 property real __maximumWidth: ApplicationMenusLimits.screenWidth * 0.7
105106 property real __minimumHeight: units.gu(2)
106− property real __maximumHeight: ApplicationMenusLimits.screenHeight - PanelState.panelHeight
107+ property real __maximumHeight: ApplicationMenusLimits.screenHeight - panelState.panelHeight
107108
108109 signal dismissAll()
109110
@@ -483,6 +484,7 @@ UbuntuShape {
483484
484485 onLoaded: {
485486 item.unityMenuModel = Qt.binding(function() { return submenuLoader.unityMenuModel; });
487+ item.panelState = Qt.binding(function() { return root.panelState; });
486488 item.objectName = Qt.binding(function() { return submenuLoader.objectName + "menu"; });
487489 item.desiredX = Qt.binding(function() { return submenuLoader.desiredX; });
488490 item.desiredY = Qt.binding(function() { return submenuLoader.desiredY; });
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/ErrorApplication.qmlnew file+67
@@ -0,0 +1,67 @@
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+import QtQuick 2.4
18+import QtQuick.Window 2.2
19+import Ubuntu.Components 1.3
20+import WindowManager 1.0
21+
22+Instantiator {
23+ id: root
24+ model: Screens
25+
26+ ScreenWindow {
27+ id: window
28+ objectName: "screen"+index
29+ screen: model.screen
30+ visibility: applicationArguments.hasFullscreen ? Window.FullScreen : Window.Windowed
31+ flags: applicationArguments.hasFrameless ? Qt.FramelessWindowHint : 0
32+
33+ Binding {
34+ when: applicationArguments.hasGeometry
35+ target: window
36+ property: "width"
37+ value: applicationArguments.windowGeometry.width
38+ }
39+ Binding {
40+ when: applicationArguments.hasGeometry
41+ target: window
42+ property: "height"
43+ value: applicationArguments.windowGeometry.height
44+ }
45+
46+ Loader {
47+ width: window.width
48+ height: window.height
49+
50+ Rectangle {
51+ color: "white"
52+ Column {
53+ spacing: units.gu(1)
54+
55+ Label {
56+ text: "Unity encountered an unrecoverable error while loading:"
57+ fontSize: "large"
58+ }
59+
60+ Label {
61+ text: errorString
62+ }
63+ }
64+ }
65+ }
66+ }
67+}
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+5−8
@@ -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) {
qml/Panel/Panel.qml+17−15
@@ -48,6 +48,7 @@ Item {
4848 property bool hasKeyboard: false
4949
5050 property string mode: "staged"
51+ property PanelState panelState
5152
5253 MouseArea {
5354 id: backMouseEater
@@ -64,14 +65,14 @@ Item {
6465 }
6566
6667 Binding {
67− target: PanelState
68+ target: panelState
6869 property: "panelHeight"
6970 value: minimizedPanelHeight
7071 }
7172
7273 RegisteredApplicationMenuModel {
7374 id: registeredMenuModel
74− persistentSurfaceId: PanelState.focusedPersistentSurfaceId
75+ persistentSurfaceId: panelState.focusedPersistentSurfaceId
7576 }
7677
7778 QtObject {
@@ -82,11 +83,11 @@ Item {
8283 !indicators.shown &&
8384 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
8485
85− property bool showWindowDecorationControls: (revealControls && PanelState.decorationsVisible) ||
86− PanelState.decorationsAlwaysVisible
86+ property bool showWindowDecorationControls: (revealControls && panelState.decorationsVisible) ||
87+ panelState.decorationsAlwaysVisible
8788
8889 property bool showPointerMenu: revealControls &&
89− (PanelState.decorationsVisible || mode == "staged")
90+ (panelState.decorationsVisible || mode == "staged")
9091
9192 property bool enablePointerMenu: revealControls &&
9293 applicationMenus.available &&
@@ -138,7 +139,7 @@ Item {
138139 fill: panelAreaBackground
139140 bottomMargin: -units.gu(1)
140141 }
141− visible: PanelState.dropShadow
142+ visible: panelState.dropShadow
142143 source: "graphics/rectangular_dropshadow.sci"
143144 }
144145
@@ -195,12 +196,12 @@ Item {
195196 visible: opacity != 0
196197 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
197198
198− active: PanelState.decorationsVisible || PanelState.decorationsAlwaysVisible
199+ active: panelState.decorationsVisible || panelState.decorationsAlwaysVisible
199200 windowIsMaximized: true
200− onCloseClicked: PanelState.closeClicked()
201− onMinimizeClicked: PanelState.minimizeClicked()
202− onMaximizeClicked: PanelState.restoreClicked()
203− closeButtonShown: PanelState.closeButtonShown
201+ onCloseClicked: panelState.closeClicked()
202+ onMinimizeClicked: panelState.minimizeClicked()
203+ onMaximizeClicked: panelState.restoreClicked()
204+ closeButtonShown: panelState.closeButtonShown
204205 }
205206
206207 Loader {
@@ -220,11 +221,12 @@ Item {
220221 sourceComponent: MenuBar {
221222 id: bar
222223 objectName: "menuBar"
223− anchors.left: parent.left
224+ anchors.left: menuBarLoader.left
224225 anchors.margins: units.gu(1)
225226 height: menuBarLoader.height
226− enableKeyFilter: valid && PanelState.decorationsVisible
227+ enableKeyFilter: valid && panelState.decorationsVisible
227228 unityMenuModel: __applicationMenus.model
229+ panelState: root.panelState
228230
229231 Connections {
230232 target: __applicationMenus
@@ -236,7 +238,7 @@ Item {
236238 onShownChanged: bar.dismiss();
237239 }
238240
239− onDoubleClicked: PanelState.restoreClicked()
241+ onDoubleClicked: panelState.restoreClicked()
240242 onPressed: mouse.accepted = false // let the parent mouse area handle this, so it can both unsnap window and show menu
241243 }
242244 }
@@ -343,7 +345,7 @@ Item {
343345 opacity: __applicationMenus.visible && !__applicationMenus.expanded ? 1 : 0
344346 visible: opacity != 0
345347 Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
346− text: PanelState.title
348+ text: panelState.title
347349 }
348350
349351 PanelMenu {
qml/Shell.qml+39−22
@@ -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,6 +38,7 @@ 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
@@ -96,6 +97,11 @@ StyledItem {
9697
9798 readonly property var mainApp: stage.mainApp
9899
100+ readonly property var topLevelSurfaceList: {
101+ if (!WMScreen.currentWorkspace) return null;
102+ return WMScreen.currentWorkspace.windowModel
103+ }
104+
99105 onMainAppChanged: {
100106 if (mainApp) {
101107 _onMainAppChanged(mainApp.appId);
@@ -186,6 +192,7 @@ StyledItem {
186192 if (ApplicationManager.findApplication(appId)) {
187193 ApplicationManager.requestFocusApplication(appId);
188194 } else {
195+ print("calling startApplication. active workspace is", WorkspaceManager.activeWorkspace)
189196 ApplicationManager.startApplication(appId);
190197 }
191198 }
@@ -260,23 +267,17 @@ StyledItem {
260267 schema.id: "com.canonical.Unity8"
261268 }
262269
270+ PanelState {
271+ id: panelState
272+ objectName: "panelState"
273+ }
274+
263275 Item {
264276 id: stages
265277 objectName: "stages"
266278 width: parent.width
267279 height: parent.height
268280
269− SurfaceManager {
270− id: surfaceMan
271− objectName: "surfaceManager"
272− }
273− TopLevelWindowModel {
274− id: topLevelSurfaceList
275− objectName: "topLevelSurfaceList"
276− applicationManager: ApplicationManager // it's a singleton
277− surfaceManager: surfaceMan
278− }
279−
280281 Stage {
281282 id: stage
282283 objectName: "stage"
@@ -287,7 +288,7 @@ StyledItem {
287288 background: wallpaperResolver.background
288289
289290 applicationManager: ApplicationManager
290− topLevelSurfaceList: topLevelSurfaceList
291+ topLevelSurfaceList: shell.topLevelSurfaceList
291292 inputMethodRect: inputMethod.visibleRect
292293 rightEdgePushProgress: rightEdgeBarrier.progress
293294
@@ -316,6 +317,7 @@ StyledItem {
316317 altTabPressed: physicalKeysMapper.altTabPressed
317318 oskEnabled: shell.oskEnabled
318319 spreadEnabled: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
320+ panelState: panelState
319321
320322 onSpreadShownChanged: {
321323 panel.indicators.hide();
@@ -356,7 +358,7 @@ StyledItem {
356358 InputMethod {
357359 id: inputMethod
358360 objectName: "inputMethod"
359− surface: topLevelSurfaceList.inputMethodSurface
361+ surface: shell.topLevelSurfaceList.inputMethodSurface
360362 anchors {
361363 fill: parent
362364 topMargin: panel.panelHeight
@@ -370,8 +372,13 @@ StyledItem {
370372 objectName: "greeterLoader"
371373 anchors.fill: parent
372374 anchors.topMargin: panel.panelHeight
373− sourceComponent: shell.mode != "shell" ? integratedGreeter :
374− Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
375+ sourceComponent: {
376+ if (shell.mode != "shell") {
377+ if (screenWindow.primary) return integratedGreeter;
378+ return secondaryGreeter;
379+ }
380+ return Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
381+ }
375382 onLoaded: {
376383 item.objectName = "greeter"
377384 }
@@ -421,6 +428,13 @@ StyledItem {
421428 }
422429 }
423430
431+ Component {
432+ id: secondaryGreeter
433+ SecondaryGreeter {
434+ hides: [launcher, panel.indicators]
435+ }
436+ }
437+
424438 Timer {
425439 // See powerConnection for why this is useful
426440 id: showGreeterDelayed
@@ -531,13 +545,14 @@ StyledItem {
531545 && !stage.spreadShown
532546 }
533547
534− readonly property bool focusedSurfaceIsFullscreen: topLevelSurfaceList.focusedWindow
535− ? topLevelSurfaceList.focusedWindow.state === Mir.FullscreenState
548+ readonly property bool focusedSurfaceIsFullscreen: shell.topLevelSurfaceList.focusedWindow
549+ ? shell.topLevelSurfaceList.focusedWindow.state === Mir.FullscreenState
536550 : false
537551 fullscreenMode: (focusedSurfaceIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0 && !stage.spreadShown)
538552 || greeter.hasLockedApp
539553 greeterShown: greeter && greeter.shown
540554 hasKeyboard: shell.hasKeyboard
555+ panelState: panelState
541556 }
542557
543558 Launcher {
@@ -786,11 +801,11 @@ StyledItem {
786801 Cursor {
787802 id: cursor
788803 objectName: "cursor"
789− visible: shell.hasMouse
804+
790805 z: itemGrabber.z + 1
791806 topBoundaryOffset: panel.panelHeight
792−
793− confiningItem: stage.itemConfiningMouseCursor
807+ enabled: shell.hasMouse && screenWindow.active
808+ visible: enabled
794809
795810 property bool mouseNeverMoved: true
796811 Binding {
@@ -802,6 +817,8 @@ StyledItem {
802817 when: cursor.mouseNeverMoved && cursor.visible
803818 }
804819
820+ confiningItem: stage.itemConfiningMouseCursor
821+
805822 height: units.gu(3)
806823
807824 readonly property var previewRectangle: stage.previewRectangle.target &&
@@ -865,7 +882,7 @@ StyledItem {
865882
866883 // non-visual objects
867884 KeymapSwitcher {
868− focusedSurface: topLevelSurfaceList.focusedWindow ? topLevelSurfaceList.focusedWindow.surface : null
885+ focusedSurface: shell.topLevelSurfaceList.focusedWindow ? shell.topLevelSurfaceList.focusedWindow.surface : null
869886 }
870887 BrightnessControl {}
871888
qml/ShellApplication.qmlnew file+60
@@ -0,0 +1,60 @@
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+import Unity.Application 0.1
21+
22+Instantiator {
23+ id: root
24+ model: Screens
25+
26+ ShellScreen {
27+ id: window
28+ objectName: "screen"+index
29+ screen: model.screen
30+ visibility: applicationArguments.hasFullscreen ? Window.FullScreen : Window.Windowed
31+ flags: applicationArguments.hasFrameless ? Qt.FramelessWindowHint : 0
32+
33+ Binding {
34+ when: applicationArguments.hasGeometry
35+ target: window
36+ property: "width"
37+ value: applicationArguments.windowGeometry.width
38+ }
39+ Binding {
40+ when: applicationArguments.hasGeometry
41+ target: window
42+ property: "height"
43+ value: applicationArguments.windowGeometry.height
44+ }
45+
46+ Component.onCompleted: screen.active = primary
47+ primary: index == 0
48+ }
49+
50+ property var windowManagerSurfaceManagerBinding: Binding {
51+ target: WindowManagerObjects
52+ property: "surfaceManager"
53+ value: SurfaceManager
54+ }
55+ property var windowManagerApplicationManagerBinding: Binding {
56+ target: WindowManagerObjects
57+ property: "applicationManager"
58+ value: ApplicationManager
59+ }
60+}
qml/ShellNotifier.qmlnew file+30
@@ -0,0 +1,30 @@
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+/*
18+ Shared signals & properties on multi-window desktop
19+ */
20+
21+pragma Singleton
22+import QtQuick 2.4
23+
24+QtObject {
25+ property var greeter: QtObject {
26+ signal hide(bool now)
27+
28+ property bool shown: true
29+ }
30+}
qml/ShellScreen.qmlnew file+64
@@ -0,0 +1,64 @@
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+ id: loader
37+ width: screenWindow.width
38+ height: screenWindow.height
39+
40+ sourceComponent: {
41+ if (Screens.count > 1 && primary && deviceConfiguration.category !== "desktop") {
42+ return disabledScreenComponent;
43+ }
44+ return shellComponent;
45+ }
46+ }
47+
48+ Component {
49+ id: shellComponent
50+ OrientedShell {
51+ implicitWidth: screenWindow.width
52+ implicitHeight: screenWindow.height
53+
54+ deviceConfiguration {
55+ name: Screens.count > 1 ? "desktop" : applicationArguments.deviceName
56+ }
57+ }
58+ }
59+
60+ Component {
61+ id: disabledScreenComponent
62+ DisabledScreenNotice {}
63+ }
64+}
qml/Stage/ApplicationWindow.qml+14−206
@@ -50,37 +50,22 @@ FocusScope {
5050 // transitions in stateGroup take place.
5151 // More specifically, the moment surfaceContainer.surface gets updated relative to the
5252 // other instructions.
53+ print("AAA surface changed,", surface)
5354 if (surface) {
5455 surfaceContainer.surface = surface;
55− d.liveSurface = surface.live;
56− d.hadSurface = false;
5756 surfaceInitTimer.start();
5857 } else {
59− if (d.surfaceInitialized) {
60− d.hadSurface = true;
61− }
6258 d.surfaceInitialized = false;
6359 surfaceContainer.surface = null;
6460 }
6561 }
6662
63+ Component.onCompleted: print("AAA completed")
6764 QtObject {
6865 id: d
6966
70− property bool liveSurface: false;
71− property var con: Connections {
72− target: root.surface
73− onLiveChanged: d.liveSurface = root.surface.live
74− }
75− // using liveSurface instead of root.surface.live because with the latter
76− // this expression is not reevaluated when root.surface changes
77− readonly property bool needToTakeScreenshot: root.surface && d.surfaceInitialized && !d.liveSurface
78− && applicationState !== ApplicationInfoInterface.Running
79− onNeedToTakeScreenshotChanged: {
80− if (needToTakeScreenshot && screenshotImage.status === Image.Null) {
81− screenshotImage.take();
82− }
83− }
67+ onHadSurfaceChanged: print("AAA had surface changed,", hadSurface)
68+ onSurfaceInitializedChanged: print("AAA surface initialized changed", surfaceInitialized)
8469
8570 // helpers so that we don't have to check for the existence of an application everywhere
8671 // (in order to avoid breaking qml binding due to a javascript exception)
@@ -131,34 +116,10 @@ FocusScope {
131116 id: surfaceInitTimer
132117 interval: 100
133118 onTriggered: {
134− if (root.surface && root.surface.live) {d.surfaceInitialized = true;}
135− }
136− }
137−
138− Timer {
139− id: surfaceIsOldTimer
140− interval: 1000
141− onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
142− }
143−
144− Image {
145− id: screenshotImage
146− objectName: "screenshotImage"
147− anchors.fill: parent
148− fillMode: Image.PreserveAspectCrop
149− horizontalAlignment: Image.AlignLeft
150− verticalAlignment: Image.AlignTop
151− antialiasing: !root.interactive
152− z: 1
153−
154− function take() {
155− // Save memory by using a half-resolution (thus quarter size) screenshot.
156− // Do not make this a binding, we can only take the screenshot once!
157− surfaceContainer.grabToImage(
158− function(result) {
159− screenshotImage.source = result.url;
160− },
161− Qt.size(root.width / 2, root.height / 2));
119+ if (root.surface && root.surface.live) {
120+ d.surfaceInitialized = true;
121+ d.hadSurface = true;
122+ }
162123 }
163124 }
164125
@@ -167,7 +128,7 @@ FocusScope {
167128 visible: active
168129 active: false
169130 anchors.fill: parent
170− z: screenshotImage.z + 1
131+ z: 1
171132 sourceComponent: Component {
172133 Splash {
173134 id: splash
@@ -238,167 +199,14 @@ FocusScope {
238199 id: stateGroup
239200 objectName: "applicationWindowStateGroup"
240201 states: [
241− State {
242− name: "void"
243− when:
244− d.hadSurface && (!root.surface || !d.surfaceInitialized)
245− &&
246− screenshotImage.status !== Image.Ready
247− },
248− State {
249− name: "splashScreen"
250− when:
251− !d.hadSurface && (!root.surface || !d.surfaceInitialized)
252− &&
253− screenshotImage.status !== Image.Ready
254− },
255− State {
202+ State{
256203 name: "surface"
257− when:
258− (root.surface && d.surfaceInitialized)
259− &&
260− (d.liveSurface ||
261− (d.applicationState !== ApplicationInfoInterface.Running
262− && screenshotImage.status !== Image.Ready))
263− PropertyChanges {
264− target: root
265− implicitWidth: surfaceContainer.implicitWidth
266− implicitHeight: surfaceContainer.implicitHeight
267− }
268− },
269− State {
270− name: "screenshot"
271− when:
272− screenshotImage.status === Image.Ready
273− &&
274− (d.applicationState !== ApplicationInfoInterface.Running
275− || !root.surface || !d.surfaceInitialized)
204+ when: (root.surface && d.surfaceInitialized) || d.hadSurface
276205 },
277206 State {
278− // This is a dead end. From here we expect the surface to be removed from the model
279− // shortly after we stop referencing to it in our SurfaceContainer.
280− name: "closed"
281− when:
282− // The surface died while the application is running. It must have been closed
283− // by the shell or the application decided to destroy it by itself
284− root.surface && d.surfaceInitialized && !d.liveSurface
285− && d.applicationState === ApplicationInfoInterface.Running
286− }
287− ]
288−
289− transitions: [
290− Transition {
291− from: ""; to: "splashScreen"
292− PropertyAction { target: splashLoader; property: "active"; value: true }
293− PropertyAction { target: surfaceContainer
294− property: "visible"; value: false }
295− },
296− Transition {
297− from: "splashScreen"; to: "surface"
298− SequentialAnimation {
299− PropertyAction { target: surfaceContainer
300− property: "opacity"; value: 0.0 }
301− PropertyAction { target: surfaceContainer
302− property: "visible"; value: true }
303− UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
304− from: 0.0; to: 1.0
305− duration: UbuntuAnimation.BriskDuration }
306− ScriptAction { script: {
307− splashLoader.active = false;
308− surfaceIsOldTimer.start();
309− } }
310− }
311− },
312− Transition {
313− from: "surface"; to: "splashScreen"
314− SequentialAnimation {
315− ScriptAction { script: {
316− surfaceIsOldTimer.stop();
317− d.surfaceOldEnoughToBeResized = false;
318− splashLoader.active = true;
319− surfaceContainer.visible = true;
320− } }
321− UbuntuNumberAnimation { target: splashLoader; property: "opacity";
322− from: 0.0; to: 1.0
323− duration: UbuntuAnimation.BriskDuration }
324− PropertyAction { target: surfaceContainer
325− property: "visible"; value: false }
326− }
327− },
328− Transition {
329− from: "surface"; to: "screenshot"
330− SequentialAnimation {
331− ScriptAction { script: {
332− surfaceIsOldTimer.stop();
333− d.surfaceOldEnoughToBeResized = false;
334− screenshotImage.visible = true;
335− } }
336− UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
337− from: 0.0; to: 1.0
338− duration: UbuntuAnimation.BriskDuration }
339− ScriptAction { script: {
340− surfaceContainer.visible = false;
341− surfaceContainer.surface = null;
342− d.hadSurface = true;
343− } }
344− }
345− },
346− Transition {
347− from: "screenshot"; to: "surface"
348− SequentialAnimation {
349− PropertyAction { target: surfaceContainer
350− property: "visible"; value: true }
351− UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
352− from: 1.0; to: 0.0
353− duration: UbuntuAnimation.BriskDuration }
354− ScriptAction { script: {
355− screenshotImage.visible = false;
356− screenshotImage.source = "";
357− surfaceIsOldTimer.start();
358− } }
359− }
360− },
361− Transition {
362− from: "splashScreen"; to: "screenshot"
363− SequentialAnimation {
364− PropertyAction { target: screenshotImage
365− property: "visible"; value: true }
366− UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
367− from: 0.0; to: 1.0
368− duration: UbuntuAnimation.BriskDuration }
369− PropertyAction { target: splashLoader; property: "active"; value: false }
370− }
371− },
372− Transition {
373− from: "surface"; to: "void"
374− ScriptAction { script: {
375− surfaceIsOldTimer.stop();
376− d.surfaceOldEnoughToBeResized = false;
377− surfaceContainer.visible = false;
378− } }
379− },
380− Transition {
381− from: "void"; to: "surface"
382− SequentialAnimation {
383− PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
384− PropertyAction { target: surfaceContainer; property: "visible"; value: true }
385− UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
386− from: 0.0; to: 1.0
387− duration: UbuntuAnimation.BriskDuration }
388− ScriptAction { script: {
389− surfaceIsOldTimer.start();
390− } }
391− }
392− },
393− Transition {
394− to: "closed"
395− SequentialAnimation {
396− ScriptAction { script: {
397− surfaceContainer.visible = false;
398− surfaceContainer.surface = null;
399− d.hadSurface = true;
400− } }
401− }
207+ name: "splash"
208+ when: !root.surface && !d.surfaceInitialized && !d.hadSurface
209+ PropertyChanges { target: splashLoader; active: true }
402210 }
403211 ]
404212 }
qml/Stage/DecoratedWindow.qml+13−11
@@ -38,6 +38,7 @@ FocusScope {
3838 property alias maximizeButtonShown: decoration.maximizeButtonShown
3939 property alias interactive: applicationWindow.interactive
4040 readonly property alias orientationChangesEnabled: applicationWindow.orientationChangesEnabled
41+ property PanelState panelState
4142
4243 // Changing this will actually add/remove a decoration, meaning, requestedHeight will take the decoration into account.
4344 property bool hasDecoration: true
@@ -118,15 +119,15 @@ FocusScope {
118119 name: "preview"; when: root.scaleToPreviewProgress > 0
119120 PropertyChanges {
120121 target: root
121− implicitWidth: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedWidth, root.scaleToPreviewSize, root.scaleToPreviewProgress)
122− implicitHeight: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedHeight, root.scaleToPreviewSize, root.scaleToPreviewProgress)
122+ implicitWidth: MathUtils.linearAnimation(0, 1, applicationWindow.requestedWidth, root.scaleToPreviewSize, root.scaleToPreviewProgress)
123+ implicitHeight: MathUtils.linearAnimation(0, 1, applicationWindow.requestedHeight, root.scaleToPreviewSize, root.scaleToPreviewProgress)
123124 }
124125 PropertyChanges {
125126 target: applicationWindow;
126− requestedWidth: applicationWindow.oldRequestedWidth
127− requestedHeight: applicationWindow.oldRequestedHeight
128− width: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedWidth, applicationWindow.minSize, root.scaleToPreviewProgress)
129− height: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedHeight, applicationWindow.minSize, root.scaleToPreviewProgress)
127+// requestedWidth: applicationWindow.oldRequestedWidth
128+// requestedHeight: applicationWindow.oldRequestedHeight
129+ width: MathUtils.linearAnimation(0, 1, applicationWindow.requestedWidth, applicationWindow.minSize, root.scaleToPreviewProgress)
130+ height: MathUtils.linearAnimation(0, 1, applicationWindow.requestedHeight, applicationWindow.minSize, root.scaleToPreviewProgress)
130131 itemScale: root.implicitWidth / width
131132 }
132133 }
@@ -165,10 +166,10 @@ FocusScope {
165166 height: implicitHeight
166167 requestedHeight: !counterRotate ? root.requestedHeight - d.requestedDecorationHeight : root.requestedWidth
167168 requestedWidth: !counterRotate ? root.requestedWidth : root.requestedHeight - d.requestedDecorationHeight
168− property int oldRequestedWidth: requestedWidth
169− property int oldRequestedHeight: requestedHeight
170− onRequestedWidthChanged: oldRequestedWidth = requestedWidth
171− onRequestedHeightChanged: oldRequestedHeight = requestedHeight
169+// property int oldRequestedWidth: requestedWidth
170+// property int oldRequestedHeight: requestedHeight
171+// onRequestedWidthChanged: oldRequestedWidth = requestedWidth
172+// onRequestedHeightChanged: oldRequestedHeight = requestedHeight
172173 focus: true
173174
174175 property real itemScale: 1
@@ -211,6 +212,7 @@ FocusScope {
211212
212213 title: applicationWindow.title
213214 windowMoving: moveHandler.moving && !altDragHandler.dragging
215+ panelState: root.panelState
214216
215217 opacity: root.hasDecoration ? Math.min(1, root.showDecoration) : 0
216218 Behavior on opacity { UbuntuNumberAnimation { } }
@@ -234,7 +236,7 @@ FocusScope {
234236 enableMenus: {
235237 return active &&
236238 surface &&
237− (PanelState.focusedPersistentSurfaceId === surface.persistentId && !PanelState.decorationsVisible)
239+ (panelState.focusedPersistentSurfaceId === surface.persistentId && !panelState.decorationsVisible)
238240 }
239241 menu: sharedAppModel.model
240242
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/Spread/ScreensAndWorkspaces.qmlnew file+212
@@ -0,0 +1,212 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import Ubuntu.Components.Popups 1.3
4+import WindowManager 1.0
5+import Unity.Application 0.1
6+import ".."
7+
8+Item {
9+ id: root
10+
11+ property string background
12+
13+ property var screensProxy: Screens.createProxy();
14+
15+ signal closeSpread();
16+
17+ Row {
18+ id: row
19+ anchors.bottom: parent.bottom
20+ anchors.horizontalCenter: parent.horizontalCenter
21+ Behavior on anchors.horizontalCenterOffset { NumberAnimation { duration: UbuntuAnimation.SlowDuration } }
22+// anchors.left: parent.left
23+ spacing: units.gu(1)
24+
25+ Repeater {
26+ model: screensProxy
27+
28+ delegate: Item {
29+ height: root.height - units.gu(6)
30+ width: workspaces.width
31+
32+ UbuntuShape {
33+ id: header
34+ anchors { left: parent.left; top: parent.top; right: parent.right }
35+ height: units.gu(7)
36+ backgroundColor: "white"
37+ z: 1
38+
39+ DropArea {
40+ anchors.fill: parent
41+ keys: ["workspace"]
42+
43+ onEntered: {
44+ workspaces.workspaceModel.insert(workspaces.workspaceModel.count, {text: drag.source.text})
45+ drag.source.inDropArea = true;
46+ }
47+
48+ onExited: {
49+ workspaces.workspaceModel.remove(workspaces.workspaceModel.count - 1, 1)
50+ drag.source.inDropArea = false;
51+ }
52+
53+ onDropped: {
54+ drag.source.inDropArea = false;
55+ }
56+ }
57+
58+ Column {
59+ anchors.fill: parent
60+ anchors.margins: units.gu(1)
61+
62+ Label {
63+ text: model.screen.name
64+ color: "black"
65+ }
66+
67+ Label {
68+ text: model.screen.outputTypeName
69+ color: "black"
70+ fontSize: "x-small"
71+ }
72+
73+ Label {
74+ text: screen.availableModes[screen.currentModeIndex].size.width + "x" + screen.availableModes[screen.currentModeIndex].size.height
75+ color: "black"
76+ fontSize: "x-small"
77+ }
78+ }
79+
80+ MouseArea {
81+ anchors.fill: parent
82+
83+ onClicked: {
84+ var obj = screensMenuComponent.createObject(header)
85+ obj.open(mouseX, mouseY)
86+ }
87+ }
88+
89+ Component {
90+ id: screensMenuComponent
91+ UbuntuShape {
92+ id: screensMenu
93+ width: units.gu(20)
94+ height: contentColumn.childrenRect.height
95+ backgroundColor: "white"
96+
97+ function open(mouseX, mouseY) {
98+ x = Math.max(0, Math.min(mouseX - width / 2, parent.width - width))
99+ y = mouseY + units.gu(1)
100+ }
101+
102+ InverseMouseArea {
103+ anchors.fill: parent
104+ onClicked: {
105+ screensMenu.destroy()
106+ }
107+ }
108+
109+ Column {
110+ id: contentColumn
111+ width: parent.width
112+ ListItem {
113+ height: layout.height
114+ highlightColor: "transparent"
115+ ListItemLayout {
116+ id: layout
117+ title.text: qsTr("Add workspace")
118+ title.color: "black"
119+ }
120+ onClicked: {
121+ screen.workspaces.addWorkspace();
122+ Screens.sync(root.screensProxy);
123+ screensMenu.destroy();
124+ }
125+ }
126+ }
127+ }
128+ }
129+ }
130+
131+ Workspaces {
132+ id: workspaces
133+ height: parent.height - header.height - units.gu(2)
134+ width: {
135+ var width = 0;
136+ if (screensProxy.count == 1) {
137+ width = Math.min(implicitWidth, root.width - units.gu(8));
138+ } else {
139+ width = Math.min(implicitWidth, model.screen.active ? root.width - units.gu(48) : units.gu(40))
140+ }
141+ return Math.max(workspaces.minimumWidth, width);
142+ }
143+
144+ Behavior on width { UbuntuNumberAnimation {} }
145+ anchors.bottom: parent.bottom
146+ anchors.bottomMargin: units.gu(1)
147+ anchors.horizontalCenter: parent.horizontalCenter
148+ screen: model.screen
149+ background: root.background
150+
151+ workspaceModel: model.screen.workspaces
152+ readOnly: false
153+
154+ onCommitScreenSetup: Screens.sync(root.screensProxy)
155+ onCloseSpread: root.closeSpread();
156+ }
157+ }
158+ }
159+ }
160+
161+ Rectangle {
162+ anchors { left: parent.left; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
163+ width: units.gu(5)
164+ color: "#33000000"
165+ visible: (row.width - root.width + units.gu(10)) / 2 - row.anchors.horizontalCenterOffset > units.gu(5)
166+ MouseArea {
167+ id: leftScrollArea
168+ anchors.fill: parent
169+ hoverEnabled: true
170+ onPressed: mouse.accepted = false;
171+ }
172+ DropArea {
173+ id: leftFakeDropArea
174+ anchors.fill: parent
175+ keys: ["application", "workspace"]
176+ }
177+ }
178+ Rectangle {
179+ anchors { right: parent.right; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
180+ width: units.gu(5)
181+ color: "#33000000"
182+ visible: (row.width - root.width + units.gu(10)) / 2 + row.anchors.horizontalCenterOffset > units.gu(5)
183+ MouseArea {
184+ id: rightScrollArea
185+ anchors.fill: parent
186+ hoverEnabled: true
187+ onPressed: mouse.accepted = false;
188+ }
189+ DropArea {
190+ id: rightFakeDropArea
191+ anchors.fill: parent
192+ keys: ["application", "workspace"]
193+ }
194+ }
195+ Timer {
196+ repeat: true
197+ running: leftScrollArea.containsMouse || rightScrollArea.containsMouse || leftFakeDropArea.containsDrag || rightFakeDropArea.containsDrag
198+ interval: UbuntuAnimation.SlowDuration
199+ triggeredOnStart: true
200+ onTriggered: {
201+ var newOffset = row.anchors.horizontalCenterOffset;
202+ var maxOffset = Math.max((row.width - root.width + units.gu(10)) / 2, 0);
203+ if (leftScrollArea.containsMouse || leftFakeDropArea.containsDrag) {
204+ newOffset += units.gu(20)
205+ } else {
206+ newOffset -= units.gu(20)
207+ }
208+ newOffset = Math.max(-maxOffset, Math.min(maxOffset, newOffset));
209+ row.anchors.horizontalCenterOffset = newOffset;
210+ }
211+ }
212+}
qml/Stage/Spread/Spread.qml+7−8
@@ -28,10 +28,10 @@ Item {
2828 property var spreadFlickable
2929
3030 // some config options
31− property real contentMargin: 0.16 * root.height
32− property real contentTopMargin: contentMargin
33− property real contentBottomMargin: 0.35 * contentMargin
34− property real windowTitleTopMargin: 3/4 * (contentTopMargin - windowTitle.height)
31+ property real contentMargin: 0.1 * root.height
32+ property real contentTopMargin: contentMargin + root.y + windowTitle.height
33+ property real contentBottomMargin: contentMargin
34+ property real windowTitleTopMargin: contentMargin - windowTitle.height
3535 property int stackItemCount: 3
3636 property real leftRotationAngle: 22
3737 property real rightRotationAngle: 32
@@ -52,7 +52,7 @@ Item {
5252
5353 readonly property real spreadWidth: rightStackXPos - leftStackXPos
5454 readonly property real spreadHeight: root.height
55− readonly property real spreadItemHeight: spreadHeight - contentTopMargin - contentBottomMargin
55+ readonly property real spreadItemHeight: spreadHeight - contentMargin * 2
5656 readonly property real spreadItemWidth: stackHeight
5757
5858 readonly property real dynamicLeftRotationAngle: leftRotationAngle * rotationAngleFactor
@@ -92,10 +92,9 @@ Item {
9292
9393 readonly property real visibleItemCount: (spreadWidth / spreadItemWidth) / (1 - itemOverlap)
9494
95− readonly property real spreadTotalWidth: Math.max(2,totalItemCount) * spreadWidth / visibleItemCount
96−
97− readonly property real centeringOffset: Math.max(spreadWidth - spreadTotalWidth ,0) / (2 * spreadWidth)
95+ readonly property real spreadTotalWidth: totalItemCount * spreadWidth / visibleItemCount
9896
97+ readonly property real centeringOffset: Math.max(spreadWidth - spreadTotalWidth + (leftStackXPos - leftMargin) * 2, 0) / (2 * spreadWidth)
9998
10099 readonly property var curve: BezierCurve {
101100 controlPoint2: {'x': 0.19, 'y': 0.00}
qml/Stage/Spread/SpreadDelegateInputArea.qml+36−17
@@ -28,6 +28,9 @@ Item {
2828
2929 readonly property alias distance: d.distance
3030
31+ property var stage: null
32+ property var dragDelegate: null
33+
3134 signal clicked()
3235 signal close()
3336
@@ -84,33 +87,27 @@ Item {
8487 }
8588 }
8689
87− // Event eater
88− MouseArea {
89− anchors.fill: parent
90− onClicked: root.clicked()
91− onWheel: wheel.accepted = true
92− }
93−
9490 MultiPointTouchArea {
9591 anchors.fill: parent
96− mouseEnabled: false
9792 maximumTouchPoints: 1
9893 property int offset: 0
9994
95+ // tp.startY seems to be broken for mouse interaction... lets track it ourselves
96+ property int startY: 0
97+
10098 touchPoints: [
10199 TouchPoint {
102100 id: tp
103101 }
104102 ]
105103
106− onCanceled: {
107− d.moving = false
108− animation.animate("center");
104+ onPressed: {
105+ startY = tp.y
109106 }
110107
111108 onTouchUpdated: {
112− if (!d.moving) {
113− if (Math.abs(tp.startY - tp.y) > d.threshold) {
109+ if (!d.moving || !tp.pressed) {
110+ if (Math.abs(startY - tp.y) > d.threshold) {
114111 d.moving = true;
115112 d.dragEvents = []
116113 offset = tp.y - tp.startY;
@@ -119,17 +116,32 @@ Item {
119116 }
120117 }
121118
122− if (root.closeable) {
123− d.distance = tp.y - tp.startY - offset
119+
120+ var value = tp.y - tp.startY - offset;
121+ if (value < 0) {
122+ var coords = mapToItem(stage, tp.x, tp.y);
123+ dragDelegate.Drag.hotSpot.x = dragDelegate.width / 2
124+ dragDelegate.Drag.hotSpot.y = units.gu(2)
125+ dragDelegate.x = coords.x - dragDelegate.Drag.hotSpot.x
126+ dragDelegate.y = coords.y - dragDelegate.Drag.hotSpot.y
127+ dragDelegate.Drag.active = true;
128+ dragDelegate.surface = model.window.surface;
129+
124130 } else {
125− var value = tp.y - tp.startY - offset;
126− d.distance = Math.sqrt(Math.abs(value)) * (value < 0 ? -1 : 1) * 3
131+ if (root.closeable) {
132+ d.distance = value
133+ } else {
134+ d.distance = Math.sqrt(Math.abs(value)) * (value < 0 ? -1 : 1) * 3
135+ }
127136 }
128137
129138 d.pushDragEvent(tp);
130139 }
131140
132141 onReleased: {
142+ var result = dragDelegate.Drag.drop();
143+ dragDelegate.surface = null;
144+
133145 if (!d.moving) {
134146 root.clicked()
135147 }
@@ -149,6 +161,13 @@ Item {
149161 animation.animate("center")
150162 }
151163 }
164+
165+ onCanceled: {
166+ dragDelegate.Drag.active = false;
167+ dragDelegate.surface = null;
168+ d.moving = false
169+ animation.animate("center");
170+ }
152171 }
153172
154173 UbuntuNumberAnimation {
qml/Stage/Spread/WorkspacePreview.qmlnew file+275
@@ -0,0 +1,275 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import Unity.Application 0.1
4+import WindowManager 1.0
5+import ".."
6+import "../../Components"
7+
8+Item {
9+ id: previewSpace
10+ clip: true
11+
12+ property var workspace
13+
14+ property string background
15+ property int screenHeight
16+
17+ property real previewScale: previewSpace.height / previewSpace.screenHeight
18+
19+ property bool containsDragLeft: false
20+ property bool containsDragRight: false
21+ property bool isActive: false
22+ property bool isSelected: false
23+
24+ Image {
25+ source: previewSpace.background
26+ anchors.fill: parent
27+ sourceSize.width: width
28+ sourceSize.height: height
29+
30+ Repeater {
31+ id: topLevelSurfaceRepeater
32+ model: visible ? workspace.windowModel : null
33+ delegate: Rectangle {
34+ width: surfaceItem.width
35+ height: surfaceItem.height + decorationHeight * previewScale
36+ x: model.window.position.x * previewScale
37+ y: (model.window.position.y - decorationHeight) * previewScale
38+ color: "blue"
39+ z: topLevelSurfaceRepeater.count - index
40+
41+ property int decorationHeight: units.gu(3)
42+
43+ WindowDecoration {
44+ width: surfaceItem.implicitWidth
45+ height: parent.decorationHeight
46+ transform: Scale {
47+ origin.x: 0
48+ origin.y: 0
49+ xScale: previewScale
50+ yScale: previewScale
51+ }
52+ title: model.window && model.window.surface ? model.window.surface.name : ""
53+ z: 3
54+ }
55+
56+ MirSurfaceItem {
57+ id: surfaceItem
58+ y: parent.decorationHeight * previewScale
59+ width: implicitWidth * previewScale
60+ height: implicitHeight * previewScale
61+ surfaceWidth: -1
62+ surfaceHeight: -1
63+ onImplicitHeightChanged: print("item", surfaceItem, "height changed", implicitHeight)
64+ surface: model.window.surface
65+ }
66+ }
67+ }
68+
69+ }
70+
71+ Rectangle {
72+ anchors.fill: parent
73+ border.color: UbuntuColors.ash
74+ border.width: units.gu(.5)
75+ color: "transparent"
76+ visible: previewSpace.isActive
77+ }
78+
79+ Rectangle {
80+ anchors.fill: parent
81+ border.color: UbuntuColors.blue
82+ border.width: units.gu(.5)
83+ color: "transparent"
84+ visible: previewSpace.isSelected
85+ }
86+
87+ Rectangle {
88+ anchors.fill: parent
89+ anchors.rightMargin: parent.width / 2
90+ color: "#55000000"
91+ visible: previewSpace.containsDragLeft
92+
93+ Column {
94+ anchors.centerIn: parent
95+ spacing: units.gu(1)
96+ Icon {
97+ source: "../graphics/multi-monitor_drop-here.png"
98+ height: units.gu(4)
99+ width: height
100+ anchors.horizontalCenter: parent.horizontalCenter
101+ }
102+ Label {
103+ text: qsTr("Drop here")
104+ }
105+ }
106+ }
107+
108+ Rectangle {
109+ anchors.fill: parent
110+ anchors.leftMargin: parent.width / 2
111+ color: "#55000000"
112+ visible: previewSpace.containsDragRight
113+
114+ Column {
115+ anchors.centerIn: parent
116+ spacing: units.gu(1)
117+ Icon {
118+ source: "../graphics/multi-monitor_leave.png"
119+ height: units.gu(4)
120+ width: height
121+ anchors.horizontalCenter: parent.horizontalCenter
122+ }
123+ Label {
124+ text: qsTr("Drop and go")
125+ }
126+ }
127+ }
128+}
129+
130+ // Repeater {
131+ // id: topLevelSurfaceRepeater
132+ // model: visible ? topLevelSurfaceList : null
133+ // delegate: Rectangle {
134+ // width: surfaceItem.width
135+ // height: surfaceItem.height + decorationHeight * previewScale
136+ // x: model.window.position.x * previewScale
137+ // y: (model.window.position.y - decorationHeight) * previewScale
138+ // color: "blue"
139+ // z: topLevelSurfaceRepeater.count - index
140+
141+ // property int decorationHeight: units.gu(3)
142+
143+ // WindowDecoration {
144+ // width: surfaceItem.implicitWidth
145+ // height: parent.decorationHeight
146+ // transform: Scale {
147+ // origin.x: 0
148+ // origin.y: 0
149+ // xScale: previewScale
150+ // yScale: previewScale
151+ // }
152+ // title: model.window && model.window.surface ? model.window.surface.name : ""
153+ // z: 3
154+ // }
155+
156+ // MirSurfaceItem {
157+ // id: surfaceItem
158+ // y: parent.decorationHeight * previewScale
159+ // width: implicitWidth * previewScale
160+ // height: implicitHeight * previewScale
161+ // surfaceWidth: -1
162+ // surfaceHeight: -1
163+ // onImplicitHeightChanged: print("item", surfaceItem, "height changed", implicitHeight)
164+ // surface: model.window.surface
165+ // }
166+ // }
167+ // }
168+// }
169+// }
170+
171+
172+// MouseArea {
173+// id: mouseArea
174+// anchors.centerIn: parent
175+// anchors.verticalCenterOffset: header.height / 2
176+// width: units.gu(8)
177+// height: width
178+// hoverEnabled: true
179+// opacity: containsMouse ? 1 : 0
180+
181+// Rectangle {
182+// anchors.fill: parent
183+// color: "#80000000"
184+// radius: height / 2
185+// }
186+
187+// NumberAnimation {
188+// target: canvas
189+// property: "progress"
190+// duration: 2000
191+// running: mouseArea.containsMouse
192+// from: 0
193+// to: 1
194+// }
195+
196+// Canvas {
197+// id: canvas
198+// height: parent.height
199+// width: height
200+// anchors.centerIn: parent
201+
202+// property real progress: 0.5
203+// property int lineWidth: units.dp(4)
204+// onProgressChanged: {
205+// requestPaint();
206+// if (progress == 1) {
207+// Screens.activateScreen(index);
208+// }
209+// }
210+
211+// rotation: -90
212+
213+// onPaint: {
214+// var ctx = canvas.getContext("2d");
215+// ctx.save();
216+// ctx.reset();
217+
218+// ctx.lineWidth = lineWidth;
219+
220+// ctx.strokeStyle = "#3bffffff"
221+// ctx.beginPath();
222+// ctx.arc(canvas.width/2,canvas.height/2, (canvas.height - ctx.lineWidth) / 2, 0, (Math.PI*2),false);
223+// ctx.stroke();
224+// ctx.closePath();
225+
226+// ctx.strokeStyle = "white"
227+// ctx.beginPath();
228+// ctx.arc(canvas.width/2,canvas.height/2, (canvas.height - ctx.lineWidth) / 2, 0, (Math.PI*2*(progress)),false);
229+// ctx.stroke();
230+// ctx.closePath();
231+
232+// ctx.restore();
233+// }
234+// }
235+
236+// Icon {
237+// source: "graphics/multi-monitor_leave.png"
238+// height: units.gu(4)
239+// width: height
240+// anchors.centerIn: parent
241+// }
242+// }
243+// }
244+
245+// FloatingFlickable {
246+// id: flickable
247+// anchors.fill: parent
248+// contentWidth: workspaceRepeater.count * previewSpace.screenWidth * previewScale
249+// property real progress: contentX / contentWidth
250+// onContentXChanged: print("contentX:", contentX, "progress:", progress)
251+// }
252+
253+// MouseArea {
254+// anchors.fill: parent
255+// hoverEnabled: true
256+// property int scrollAreaWidth: width / 3
257+
258+// onMouseXChanged: {
259+// var margins = flickable.width * 0.05;
260+
261+// // do we need to scroll?
262+// if (mouseX < scrollAreaWidth + margins) {
263+// var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
264+// var contentX = (1 - progress) * (flickable.contentWidth - flickable.width)
265+// flickable.contentX = Math.max(0, Math.min(flickable.contentX, contentX))
266+// }
267+// if (mouseX > flickable.width - scrollAreaWidth) {
268+// var progress = Math.min(1, (mouseX - (flickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
269+// var contentX = progress * (flickable.contentWidth - flickable.width)
270+// flickable.contentX = Math.min(flickable.contentWidth - flickable.width, Math.max(flickable.contentX, contentX))
271+// }
272+// }
273+// }
274+// }
275+//}
qml/Stage/Spread/Workspaces.qmlnew file+416
@@ -0,0 +1,416 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import WindowManager 1.0
4+import "MathUtils.js" as MathUtils
5+import "../../Components"
6+
7+Item {
8+ id: root
9+ implicitWidth: listView.contentWidth
10+ readonly property int minimumWidth: {
11+ var count = Math.min(3, listView.count);
12+ return listView.itemWidth * count + listView.spacing * (count - 1)
13+ }
14+
15+ property QtObject screen: null
16+ property alias workspaceModel: listView.model
17+ property var background // TODO: should be stored in the workspace data
18+ property int selectedIndex: -1
19+ property bool readOnly: true
20+
21+ signal commitScreenSetup();
22+ signal closeSpread();
23+
24+ DropArea {
25+ anchors.fill: root
26+
27+ keys: ['workspace']
28+
29+ onEntered: {
30+ var index = listView.getDropIndex(drag);
31+ drag.source.workspace.assign(workspaceModel, index)
32+ drag.source.inDropArea = true;
33+ }
34+
35+ onPositionChanged: {
36+ var index = listView.getDropIndex(drag);
37+ if (listView.dropItemIndex == index) return;
38+ listView.model.move(listView.dropItemIndex, index, 1);
39+ listView.dropItemIndex = index;
40+ }
41+
42+ onExited: {
43+ drag.source.workspace.unassign()
44+ listView.dropItemIndex = -1;
45+ listView.hoveredWorkspaceIndex = -1;
46+ drag.source.inDropArea = false;
47+ }
48+
49+ onDropped: {
50+ drop.accept(Qt.MoveAction);
51+ listView.dropItemIndex = -1;
52+ drag.source.inDropArea = false;
53+ }
54+ }
55+ DropArea {
56+ anchors.fill: parent
57+ keys: ["application"]
58+
59+ onPositionChanged: {
60+ listView.progressiveScroll(drag.x)
61+ listView.updateDropProperties(drag)
62+ }
63+ onExited: {
64+ listView.hoveredWorkspaceIndex = -1
65+ }
66+ onDropped: {
67+ var surface = drag.source.surface;
68+ drag.source.surface = null;
69+ var workspace = listView.model.get(listView.hoveredWorkspaceIndex);
70+ WorkspaceManager.moveSurfaceToWorkspace(surface, workspace);
71+ drop.accept(Qt.MoveAction)
72+ if (listView.hoveredHalf == "right") {
73+ root.closeSpread();
74+ workspace.activate();
75+ }
76+ surface.activate();
77+ listView.hoveredWorkspaceIndex = -1
78+ }
79+ }
80+
81+ Item {
82+ // We need to clip the listview as it has left/right margins and it would
83+ // overlap with items next to it and eat mouse input. However, we can't
84+ // just clip at the actual bounds as the delegates have the close button
85+ // on hover which reaches a bit outside, so lets some margins for the clipping
86+ anchors.fill: parent
87+ anchors.margins: -units.gu(2)
88+ clip: true
89+
90+ ListView {
91+ id: listView
92+ anchors {
93+ fill: parent
94+ topMargin: -parent.anchors.margins
95+ bottomMargin: -parent.anchors.margins
96+ leftMargin: -itemWidth - parent.anchors.margins
97+ rightMargin: -itemWidth - parent.anchors.margins
98+ }
99+ boundsBehavior: Flickable.StopAtBounds
100+
101+ Behavior on contentX {
102+ SmoothedAnimation { duration: 200 }
103+ }
104+
105+ orientation: ListView.Horizontal
106+ spacing: units.gu(1)
107+ leftMargin: itemWidth
108+ rightMargin: itemWidth
109+
110+ Connections {
111+ target: screen
112+ onAvailableModesChanged: {
113+ print("blabla", screen.availableModes[screen.currentModeIndex].size.width, screen.availableModes[screen.currentModeIndex].size.height)
114+ }
115+ }
116+
117+ property int screenWidth: screen.availableModes[screen.currentModeIndex].size.width
118+ property int screenHeight: screen.availableModes[screen.currentModeIndex].size.height
119+ property int itemWidth: height * screenWidth / screenHeight
120+ property int foldingAreaWidth: itemWidth / 2
121+ property int maxAngle: 40
122+
123+ property real realContentX: contentX - originX + leftMargin
124+ property int dropItemIndex: -1
125+ property int hoveredWorkspaceIndex: -1
126+ property string hoveredHalf: "" // left or right
127+
128+ function getDropIndex(drag) {
129+ var coords = mapToItem(listView.contentItem, drag.x, drag.y)
130+ var index = Math.floor((drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing));
131+ if (index < 0) index = 0;
132+ var upperLimit = dropItemIndex == -1 ? listView.count : listView.count - 1
133+ if (index > upperLimit) index = upperLimit;
134+ return index;
135+ }
136+
137+ function updateDropProperties(drag) {
138+ var coords = mapToItem(listView.contentItem, drag.x, drag.y)
139+ var index = Math.floor(drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing);
140+ if (index < 0) {
141+ listView.hoveredWorkspaceIndex = -1;
142+ listView.hoveredHalf = "";
143+ return;
144+ }
145+
146+ var upperLimit = dropItemIndex == -1 ? listView.count : listView.count - 1
147+ if (index > upperLimit) index = upperLimit;
148+ listView.hoveredWorkspaceIndex = index;
149+ print("updating drag:", (drag.x + listView.realContentX) % (listView.itemWidth + listView.spacing))
150+ var pixelsInTile = (drag.x + listView.realContentX) % (listView.itemWidth + listView.spacing);
151+ listView.hoveredHalf = (pixelsInTile / listView.itemWidth) < .5 ? "left" : "right";
152+ }
153+
154+ function progressiveScroll(mouseX) {
155+ var progress = Math.max(0, Math.min(1, (mouseX - listView.itemWidth) / (width - listView.leftMargin * 2 - listView.itemWidth * 2)))
156+ listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
157+ }
158+
159+ displaced: Transition { UbuntuNumberAnimation { properties: "x" } }
160+
161+ delegate: Item {
162+ id: workspaceDelegate
163+ objectName: "delegate" + index
164+ height: parent.height
165+ width: listView.itemWidth
166+ Behavior on width { UbuntuNumberAnimation {} }
167+ visible: listView.dropItemIndex !== index
168+
169+ property int itemX: -listView.realContentX + index * (listView.itemWidth + listView.spacing)
170+ property int distanceFromLeft: itemX //- listView.leftMargin
171+ property int distanceFromRight: listView.width - listView.leftMargin - listView.rightMargin - itemX - listView.itemWidth
172+
173+ property int itemAngle: {
174+ if (index == 0) {
175+ if (distanceFromLeft < 0) {
176+ var progress = (distanceFromLeft + listView.foldingAreaWidth) / listView.foldingAreaWidth
177+ return MathUtils.linearAnimation(1, -1, 0, listView.maxAngle, Math.max(-1, Math.min(1, progress)));
178+ }
179+ return 0
180+ }
181+ if (index == listView.count - 1) {
182+ if (distanceFromRight < 0) {
183+ var progress = (distanceFromRight + listView.foldingAreaWidth) / listView.foldingAreaWidth
184+ return MathUtils.linearAnimation(1, -1, 0, -listView.maxAngle, Math.max(-1, Math.min(1, progress)));
185+ }
186+ return 0
187+ }
188+
189+ if (distanceFromLeft < listView.foldingAreaWidth) {
190+ // itemX : 10gu = p : 100
191+ var progress = distanceFromLeft / listView.foldingAreaWidth
192+ return MathUtils.linearAnimation(1, -1, 0, listView.maxAngle, Math.max(-1, Math.min(1, progress)));
193+ }
194+ if (distanceFromRight < listView.foldingAreaWidth) {
195+ var progress = distanceFromRight / listView.foldingAreaWidth
196+ return MathUtils.linearAnimation(1, -1, 0, -listView.maxAngle, Math.max(-1, Math.min(1, progress)));
197+ }
198+ return 0
199+ }
200+
201+ property int itemOffset: {
202+ if (index == 0) {
203+ if (distanceFromLeft < 0) {
204+ return -distanceFromLeft
205+ }
206+ return 0
207+ }
208+ if (index == listView.count - 1) {
209+ if (distanceFromRight < 0) {
210+ return distanceFromRight
211+ }
212+ return 0
213+ }
214+
215+ if (itemX < -listView.foldingAreaWidth) {
216+ return -itemX
217+ }
218+ if (distanceFromLeft < listView.foldingAreaWidth) {
219+ return (listView.foldingAreaWidth - distanceFromLeft) / 2
220+ }
221+
222+ if (distanceFromRight < -listView.foldingAreaWidth) {
223+ return distanceFromRight
224+ }
225+
226+ if (distanceFromRight < listView.foldingAreaWidth) {
227+ return -(listView.foldingAreaWidth - distanceFromRight) / 2
228+ }
229+
230+ return 0
231+ }
232+
233+ // onItemXChanged: if (index == 1) print("x", itemX, listView.contentX)
234+
235+ z: itemOffset < 0 ? itemOffset : -itemOffset
236+ transform: [
237+ Rotation {
238+ angle: itemAngle
239+ axis { x: 0; y: 1; z: 0 }
240+ origin { x: itemAngle < 0 ? listView.itemWidth : 0; y: height / 2 }
241+ },
242+ Translate {
243+ x: itemOffset
244+ }
245+ ]
246+
247+ WorkspacePreview {
248+ id: workspacePreview
249+ height: listView.height
250+ width: listView.itemWidth
251+ background: root.background
252+ screenHeight: listView.screenHeight
253+ containsDragLeft: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "left"
254+ containsDragRight: listView.hoveredWorkspaceIndex == index && listView.hoveredHalf == "right"
255+ isActive: model.workspace.active
256+ isSelected: index === root.selectedIndex
257+ workspace: model.workspace
258+ }
259+ MouseArea {
260+ anchors.fill: parent
261+ onClicked: {
262+ model.workspace.activate();
263+ }
264+ onDoubleClicked: {
265+ model.workspace.activate();
266+ root.closeSpread();
267+ }
268+ }
269+
270+ MouseArea {
271+ id: closeMouseArea
272+ objectName: "closeMouseArea"
273+ anchors { left: parent.left; top: parent.top; leftMargin: -height / 2; topMargin: -height / 2 }
274+ hoverEnabled: true
275+ height: units.gu(4)
276+ width: height
277+ visible: !root.readOnly && listView.count > 1
278+
279+ onClicked: {
280+ model.workspace.unassign();
281+ root.commitScreenSetup();
282+ }
283+ Image {
284+ id: closeImage
285+ source: "../graphics/window-close.svg"
286+ anchors.fill: closeMouseArea
287+ anchors.margins: units.gu(1)
288+ sourceSize.width: width
289+ sourceSize.height: height
290+ readonly property var mousePos: hoverMouseArea.mapToItem(workspaceDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
291+ readonly property bool shown: (hoverMouseArea.containsMouse || parent.containsMouse)
292+ && mousePos.y < workspaceDelegate.width / 4
293+ && mousePos.y > -units.gu(2)
294+ && mousePos.x > -units.gu(2)
295+ && mousePos.x < workspaceDelegate.height / 4
296+ opacity: shown ? 1 : 0
297+ visible: opacity > 0
298+ Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
299+
300+ }
301+ }
302+ }
303+
304+ MouseArea {
305+ id: hoverMouseArea
306+ anchors.fill: parent
307+ hoverEnabled: true
308+ propagateComposedEvents: true
309+ anchors.leftMargin: listView.leftMargin
310+ anchors.rightMargin: listView.rightMargin
311+ enabled: !root.readOnly
312+
313+ property int draggedIndex: -1
314+
315+ property int startX: 0
316+ property int startY: 0
317+
318+ onMouseXChanged: {
319+ if (!pressed || dragging) {
320+ listView.progressiveScroll(mouseX)
321+ }
322+ }
323+ onMouseYChanged: {
324+ if (Math.abs(mouseY - startY) > units.gu(3)) {
325+ drag.axis = Drag.XAndYAxis;
326+ }
327+ }
328+
329+ onReleased: {
330+ var result = fakeDragItem.Drag.drop();
331+ // if (result == Qt.IgnoreAction) {
332+ // WorkspaceManager.destroyWorkspace(fakeDragItem.workspace);
333+ // }
334+ root.commitScreenSetup();
335+ drag.target = null;
336+ }
337+
338+ property bool dragging: drag.active
339+ onDraggingChanged: {
340+ if (drag.active) {
341+ print("drai", draggedIndex)
342+ var ws = listView.model.get(draggedIndex);
343+ print("ws:", ws)
344+ ws.unassign();
345+ // listView.model.remove(draggedIndex, 1)
346+ }
347+ }
348+
349+ onPressed: {
350+ startX = mouseX;
351+ startY = mouseY;
352+ if (listView.model.count < 2) return;
353+
354+ var coords = mapToItem(listView.contentItem, mouseX, mouseY)
355+ draggedIndex = listView.indexAt(coords.x, coords.y)
356+ var clickedItem = listView.itemAt(coords.x, coords.y)
357+
358+ var itemCoords = clickedItem.mapToItem(listView, -listView.leftMargin, 0);
359+ fakeDragItem.x = itemCoords.x
360+ fakeDragItem.y = itemCoords.y
361+ fakeDragItem.workspace = listView.model.get(draggedIndex)
362+
363+ var mouseCoordsInItem = mapToItem(clickedItem, mouseX, mouseY);
364+ fakeDragItem.Drag.hotSpot.x = mouseCoordsInItem.x
365+ fakeDragItem.Drag.hotSpot.y = mouseCoordsInItem.y
366+
367+ drag.axis = Drag.YAxis;
368+ drag.target = fakeDragItem;
369+ }
370+
371+ WorkspacePreview {
372+ id: fakeDragItem
373+ height: listView.height
374+ width: listView.itemWidth
375+ background: root.background
376+ screenHeight: screen.availableModes[screen.currentModeIndex].size.height
377+ visible: Drag.active
378+
379+ Drag.active: hoverMouseArea.drag.active
380+ Drag.keys: ['workspace']
381+
382+ property bool inDropArea: false
383+
384+ Rectangle {
385+ anchors.fill: parent
386+ color: "#33000000"
387+ opacity: parent.inDropArea ? 0 : 1
388+ Behavior on opacity { UbuntuNumberAnimation { } }
389+ Rectangle {
390+ anchors.centerIn: parent
391+ width: units.gu(6)
392+ height: units.gu(6)
393+ radius: width / 2
394+ color: "#aa000000"
395+ }
396+
397+ Icon {
398+ height: units.gu(3)
399+ width: height
400+ anchors.centerIn: parent
401+ name: "edit-delete"
402+ color: "white"
403+ }
404+ }
405+
406+ states: [
407+ State {
408+ when: fakeDragItem.Drag.active
409+ ParentChange { target: fakeDragItem; parent: shell }
410+ }
411+ ]
412+ }
413+ }
414+ }
415+ }
416+}
qml/Stage/Stage.qml+209−119
@@ -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"
@@ -224,6 +225,25 @@ FocusScope {
224225 active: priv.focusedAppDelegate !== null
225226 }
226227
228+ GlobalShortcut {
229+ id: showWorkspaceSwitcherShortcutLeft
230+ shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Left
231+ active: !workspaceSwitcher.active
232+ onTriggered: {
233+ root.focus = true;
234+ workspaceSwitcher.showLeft()
235+ }
236+ }
237+ GlobalShortcut {
238+ id: showWorkspaceSwitcherShortcutRight
239+ shortcut: Qt.AltModifier|Qt.ControlModifier|Qt.Key_Right
240+ active: !workspaceSwitcher.active
241+ onTriggered: {
242+ root.focus = true;
243+ workspaceSwitcher.showRight()
244+ }
245+ }
246+
227247 QtObject {
228248 id: priv
229249 objectName: "DesktopStagePrivate"
@@ -349,23 +369,23 @@ FocusScope {
349369 readonly property real virtualKeyboardHeight: root.inputMethodRect.height
350370 }
351371
352− Component.onCompleted: priv.updateMainAndSideStageIndexes();
372+ Component.onCompleted: priv.updateMainAndSideStageIndexes()
353373
354374 Connections {
355− target: PanelState
375+ target: panelState
356376 onCloseClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
357377 onMinimizeClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestMinimize(); } }
358378 onRestoreClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestRestore(); } }
359379 }
360380
361381 Binding {
362− target: PanelState
382+ target: panelState
363383 property: "decorationsVisible"
364384 value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.maximized // FIXME for Locally integrated menus
365385 }
366386
367387 Binding {
368− target: PanelState
388+ target: panelState
369389 property: "title"
370390 value: {
371391 if (priv.focusedAppDelegate !== null) {
@@ -380,7 +400,7 @@ FocusScope {
380400 }
381401
382402 Binding {
383− target: PanelState
403+ target: panelState
384404 property: "focusedPersistentSurfaceId"
385405 value: {
386406 if (priv.focusedAppDelegate !== null) {
@@ -394,21 +414,21 @@ FocusScope {
394414 }
395415
396416 Binding {
397− target: PanelState
417+ target: panelState
398418 property: "dropShadow"
399419 value: priv.focusedAppDelegate && !priv.focusedAppDelegate.maximized && priv.foregroundMaximizedAppDelegate !== null && mode == "windowed"
400420 }
401421
402422 Binding {
403− target: PanelState
423+ target: panelState
404424 property: "closeButtonShown"
405425 value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized && !priv.focusedAppDelegate.isDash
406426 }
407427
408428 Component.onDestruction: {
409− PanelState.title = "";
410− PanelState.decorationsVisible = false;
411− PanelState.dropShadow = false;
429+ panelState.title = "";
430+ panelState.decorationsVisible = false;
431+ panelState.dropShadow = false;
412432 }
413433
414434 Instantiator {
@@ -454,6 +474,7 @@ FocusScope {
454474 PropertyChanges { target: cancelSpreadMouseArea; enabled: true }
455475 PropertyChanges { target: blurLayer; visible: true; blurRadius: 32; brightness: .65; opacity: 1 }
456476 PropertyChanges { target: wallpaper; visible: false }
477+ PropertyChanges { target: screensAndWorkspaces; opacity: 1 }
457478 },
458479 State {
459480 name: "stagedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "staged"
@@ -502,10 +523,13 @@ FocusScope {
502523 from: "stagedRightEdge,sideStagedRightEdge,windowedRightEdge"; to: "spread"
503524 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
504525 PropertyAnimation { target: blurLayer; properties: "brightness,blurRadius"; duration: priv.animationDuration }
526+ UbuntuNumberAnimation { target: screensAndWorkspaces; property: "opacity"; duration: priv.animationDuration }
505527 },
506528 Transition {
507529 to: "spread"
508530 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: appRepeater.count > 1 ? 1 : 0 }
531+ PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
532+ UbuntuNumberAnimation { target: screensAndWorkspaces; property: "opacity"; duration: priv.animationDuration }
509533 },
510534 Transition {
511535 from: "spread"
@@ -563,10 +587,21 @@ FocusScope {
563587 visible: false
564588 }
565589
590+ ScreensAndWorkspaces {
591+ id: screensAndWorkspaces
592+ anchors { left: parent.left; top: parent.top; right: parent.right; leftMargin: root.leftMargin }
593+ height: Math.max(units.gu(30), parent.height * .3)
594+ background: root.background
595+ opacity: 0
596+ visible: opacity > 0
597+
598+ onCloseSpread: priv.goneToSpread = false;
599+ }
600+
566601 Spread {
567602 id: spreadItem
568603 objectName: "spreadItem"
569− anchors.fill: appContainer
604+ anchors { left: parent.left; bottom: parent.bottom; right: parent.right; top: screensAndWorkspaces.bottom }
570605 leftMargin: root.leftMargin
571606 model: root.topLevelSurfaceList
572607 spreadFlickable: floatingFlickable
@@ -581,6 +616,83 @@ FocusScope {
581616 appRepeater.itemAt(highlightedIndex).close();
582617 }
583618 }
619+
620+ FloatingFlickable {
621+ id: floatingFlickable
622+ objectName: "spreadFlickable"
623+ anchors.fill: parent
624+ enabled: false
625+ contentWidth: spreadItem.spreadTotalWidth
626+
627+ function snap(toIndex) {
628+ var delegate = appRepeater.itemAt(toIndex)
629+ var targetContentX = floatingFlickable.contentWidth / spreadItem.totalItemCount * toIndex;
630+ if (targetContentX - floatingFlickable.contentX > spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) {
631+ var offset = (spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) - (targetContentX - floatingFlickable.contentX)
632+ snapAnimation.to = floatingFlickable.contentX - offset;
633+ snapAnimation.start();
634+ } else if (targetContentX - floatingFlickable.contentX < spreadItem.leftStackXPos + units.gu(1)) {
635+ var offset = (spreadItem.leftStackXPos + units.gu(1)) - (targetContentX - floatingFlickable.contentX);
636+ snapAnimation.to = floatingFlickable.contentX - offset;
637+ snapAnimation.start();
638+ }
639+ }
640+ UbuntuNumberAnimation {id: snapAnimation; target: floatingFlickable; property: "contentX"}
641+ }
642+
643+ MouseArea {
644+ id: hoverMouseArea
645+ objectName: "hoverMouseArea"
646+ anchors.fill: parent
647+ propagateComposedEvents: true
648+ hoverEnabled: true
649+ enabled: false
650+ visible: enabled
651+
652+ property int scrollAreaWidth: width / 3
653+ property bool progressiveScrollingEnabled: false
654+
655+ onPressed: mouse.accepted = false
656+
657+ onMouseXChanged: {
658+ mouse.accepted = false
659+
660+ if (hoverMouseArea.pressed) {
661+ return;
662+ }
663+
664+ // Find the hovered item and mark it active
665+ for (var i = appRepeater.count - 1; i >= 0; i--) {
666+ var appDelegate = appRepeater.itemAt(i);
667+ var mapped = mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
668+ var itemUnder = appDelegate.childAt(mapped.x, mapped.y);
669+ if (itemUnder && (itemUnder.objectName === "dragArea" || itemUnder.objectName === "windowInfoItem" || itemUnder.objectName == "closeMouseArea")) {
670+ spreadItem.highlightedIndex = i;
671+ break;
672+ }
673+ }
674+
675+ if (floatingFlickable.contentWidth > floatingFlickable.width) {
676+ var margins = floatingFlickable.width * 0.05;
677+
678+ if (!progressiveScrollingEnabled && mouseX < floatingFlickable.width - scrollAreaWidth) {
679+ progressiveScrollingEnabled = true
680+ }
681+
682+ // do we need to scroll?
683+ if (mouseX < scrollAreaWidth + margins) {
684+ var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
685+ var contentX = (1 - progress) * (floatingFlickable.contentWidth - floatingFlickable.width)
686+ floatingFlickable.contentX = Math.max(0, Math.min(floatingFlickable.contentX, contentX))
687+ }
688+ if (mouseX > floatingFlickable.width - scrollAreaWidth && progressiveScrollingEnabled) {
689+ var progress = Math.min(1, (mouseX - (floatingFlickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
690+ var contentX = progress * (floatingFlickable.contentWidth - floatingFlickable.width)
691+ floatingFlickable.contentX = Math.min(floatingFlickable.contentWidth - floatingFlickable.width, Math.max(floatingFlickable.contentX, contentX))
692+ }
693+ }
694+ }
695+ }
584696 }
585697
586698 Connections {
@@ -675,10 +787,28 @@ FocusScope {
675787 }
676788 }
677789
790+ MirSurfaceItem {
791+ id: fakeDragItem
792+ property real previewScale: .5
793+ height: (screensAndWorkspaces.height - units.gu(8)) / 2
794+ // w : h = iw : ih
795+ width: implicitWidth * height / implicitHeight
796+ surfaceWidth: -1
797+ surfaceHeight: -1
798+ opacity: surface != null ? 1 : 0
799+ Behavior on opacity { UbuntuNumberAnimation {} }
800+ visible: opacity > 0
801+
802+ Drag.active: surface != null
803+ Drag.keys: ["application"]
804+
805+ z: 1000
806+ }
807+
678808 Item {
679809 id: boundariesForWindowPlacement
680810 anchors.fill: parent
681− anchors.topMargin: PanelState.panelHeight
811+ anchors.topMargin: panelState.panelHeight
682812 visible: false
683813 }
684814
@@ -710,6 +840,9 @@ FocusScope {
710840 }
711841 z: normalZ
712842
843+ opacity: fakeDragItem.surface == model.window.surface && fakeDragItem.Drag.active ? 0 : 1
844+ Behavior on opacity { UbuntuNumberAnimation {} }
845+
713846 // Normally we want x/y where the surface thinks it is. Width/height of our delegate will
714847 // match what the actual surface size is.
715848 // Don't write to those, they will be set by states
@@ -779,7 +912,7 @@ FocusScope {
779912 target: appDelegate
780913 property: "y"
781914 value: appDelegate.requestedY -
782− Math.min(appDelegate.requestedY - PanelState.panelHeight,
915+ Math.min(appDelegate.requestedY - panelState.panelHeight,
783916 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
784917 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
785918 && root.inputMethodRect.height > 0
@@ -890,7 +1023,6 @@ FocusScope {
8901023 function claimFocus() {
8911024 if (root.state == "spread") {
8921025 spreadItem.highlightedIndex = index
893− priv.goneToSpread = false;
8941026 }
8951027 if (root.mode == "stagedWithSideStage") {
8961028 if (appDelegate.stage == ApplicationInfoInterface.SideStage && !sideStage.shown) {
@@ -1177,7 +1309,7 @@ FocusScope {
11771309 progress: 0
11781310 targetHeight: spreadItem.stackHeight
11791311 targetX: spreadMaths.targetX
1180− startY: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1312+ startY: appDelegate.fullscreen ? 0 : panelState.panelHeight
11811313 targetY: spreadMaths.targetY
11821314 targetAngle: spreadMaths.targetAngle
11831315 targetScale: spreadMaths.targetScale
@@ -1223,8 +1355,6 @@ FocusScope {
12231355 y: spreadMaths.targetY
12241356 z: index
12251357 height: spreadItem.spreadItemHeight
1226− requestedWidth: decoratedWindow.oldRequestedWidth
1227− requestedHeight: decoratedWindow.oldRequestedHeight
12281358 visible: spreadMaths.itemVisible
12291359 }
12301360 PropertyChanges { target: dragArea; enabled: true }
@@ -1244,8 +1374,6 @@ FocusScope {
12441374 y: stagedRightEdgeMaths.animatedY
12451375 z: stagedRightEdgeMaths.animatedZ
12461376 height: stagedRightEdgeMaths.animatedHeight
1247− requestedWidth: decoratedWindow.oldRequestedWidth
1248− requestedHeight: decoratedWindow.oldRequestedHeight
12491377 visible: appDelegate.x < root.width
12501378 }
12511379 PropertyChanges {
@@ -1275,8 +1403,6 @@ FocusScope {
12751403 y: windowedRightEdgeMaths.animatedY
12761404 z: windowedRightEdgeMaths.animatedZ
12771405 height: stagedRightEdgeMaths.animatedHeight
1278− requestedWidth: decoratedWindow.oldRequestedWidth
1279− requestedHeight: decoratedWindow.oldRequestedHeight
12801406 }
12811407 PropertyChanges {
12821408 target: decoratedWindow
@@ -1298,12 +1424,16 @@ FocusScope {
12981424 PropertyChanges {
12991425 target: appDelegate
13001426 x: stageMaths.itemX
1301− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1302− requestedWidth: appContainer.width
1303− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1427+ y: appDelegate.fullscreen ? 0 : panelState.panelHeight
13041428 visuallyMaximized: true
13051429 visible: appDelegate.x < root.width
13061430 }
1431+ PropertyChanges {
1432+ target: appDelegate
1433+ requestedWidth: appContainer.width
1434+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
1435+ restoreEntryValues: false
1436+ }
13071437 PropertyChanges {
13081438 target: decoratedWindow
13091439 hasDecoration: false
@@ -1330,13 +1460,17 @@ FocusScope {
13301460 PropertyChanges {
13311461 target: appDelegate
13321462 x: stageMaths.itemX
1333− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1463+ y: appDelegate.fullscreen ? 0 : panelState.panelHeight
13341464 z: stageMaths.itemZ
1335− requestedWidth: stageMaths.itemWidth
1336− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
13371465 visuallyMaximized: true
13381466 visible: appDelegate.x < root.width
13391467 }
1468+ PropertyChanges {
1469+ target: appDelegate
1470+ requestedWidth: stageMaths.itemWidth
1471+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
1472+ restoreEntryValues: false
1473+ }
13401474 PropertyChanges {
13411475 target: decoratedWindow
13421476 hasDecoration: false
@@ -1358,8 +1492,12 @@ FocusScope {
13581492 requestedY: 0;
13591493 visuallyMinimized: false;
13601494 visuallyMaximized: true
1361− requestedWidth: appContainer.width - root.leftMargin;
1362− requestedHeight: appContainer.height;
1495+ }
1496+ PropertyChanges {
1497+ target: appDelegate
1498+ requestedWidth: appContainer.width - root.leftMargin
1499+ requestedHeight: appContainer.height
1500+ restoreEntryValues: false
13631501 }
13641502 PropertyChanges { target: touchControls; enabled: true }
13651503 },
@@ -1369,8 +1507,12 @@ FocusScope {
13691507 target: appDelegate;
13701508 requestedX: 0
13711509 requestedY: 0
1372− requestedWidth: appContainer.width;
1373− requestedHeight: appContainer.height;
1510+ }
1511+ PropertyChanges {
1512+ target: appDelegate
1513+ requestedWidth: appContainer.width
1514+ requestedHeight: appContainer.height
1515+ restoreEntryValues: false
13741516 }
13751517 PropertyChanges { target: decoratedWindow; hasDecoration: false }
13761518 },
@@ -1385,6 +1527,12 @@ FocusScope {
13851527 PropertyChanges { target: touchControls; enabled: true }
13861528 PropertyChanges { target: resizeArea; enabled: true }
13871529 PropertyChanges { target: decoratedWindow; shadowOpacity: .3}
1530+ PropertyChanges {
1531+ target: appDelegate
1532+ requestedWidth: windowedWidth
1533+ requestedHeight: windowedHeight
1534+ restoreEntryValues: false
1535+ }
13881536 },
13891537 State {
13901538 name: "restored";
@@ -1402,9 +1550,9 @@ FocusScope {
14021550 PropertyChanges {
14031551 target: appDelegate
14041552 windowedX: root.leftMargin
1405− windowedY: PanelState.panelHeight
1553+ windowedY: panelState.panelHeight
14061554 windowedWidth: (appContainer.width - root.leftMargin)/2
1407− windowedHeight: appContainer.height - PanelState.panelHeight
1555+ windowedHeight: appContainer.height - panelState.panelHeight
14081556 }
14091557 },
14101558 State {
@@ -1421,9 +1569,9 @@ FocusScope {
14211569 PropertyChanges {
14221570 target: appDelegate
14231571 windowedX: root.leftMargin
1424− windowedY: PanelState.panelHeight
1572+ windowedY: panelState.panelHeight
14251573 windowedWidth: (appContainer.width - root.leftMargin)/2
1426− windowedHeight: (appContainer.height - PanelState.panelHeight)/2
1574+ windowedHeight: (appContainer.height - panelState.panelHeight)/2
14271575 }
14281576 },
14291577 State {
@@ -1440,7 +1588,7 @@ FocusScope {
14401588 PropertyChanges {
14411589 target: appDelegate
14421590 windowedX: root.leftMargin
1443− windowedY: (appContainer.height + PanelState.panelHeight)/2
1591+ windowedY: (appContainer.height + panelState.panelHeight)/2
14441592 windowedWidth: (appContainer.width - root.leftMargin)/2
14451593 windowedHeight: appContainer.height/2
14461594 }
@@ -1462,8 +1610,8 @@ FocusScope {
14621610 State {
14631611 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
14641612 extend: "normal"
1465− PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: PanelState.panelHeight;
1466− windowedWidth: windowedWidth; windowedHeight: appContainer.height - PanelState.panelHeight }
1613+ PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: panelState.panelHeight;
1614+ windowedWidth: windowedWidth; windowedHeight: appContainer.height - panelState.panelHeight }
14671615 },
14681616 State {
14691617 name: "minimized"; when: appDelegate.minimized
@@ -1478,6 +1626,10 @@ FocusScope {
14781626 }
14791627 }
14801628 ]
1629+ onStateChanged: {
1630+ print("item", index, "state changed", state)
1631+ }
1632+
14811633 transitions: [
14821634 Transition {
14831635 from: "staged,stagedWithSideStage"
@@ -1491,6 +1643,7 @@ FocusScope {
14911643 UbuntuNumberAnimation { target: appDelegate; properties: "x,y,requestedX,requestedY,requestedWidth,requestedHeight"; duration: priv.animationDuration}
14921644 },
14931645 Transition {
1646+ from: "normal,restored,maximized,maximizedHorizontally,maximizedVertically,maximizedLeft,maximizedRight,maximizedTopLeft,maximizedBottomLeft,maximizedTopRight,maximizedBottomRight,staged,stagedWithSideStage,windowedRightEdge,stagedRightEdge";
14941647 to: "spread"
14951648 // DecoratedWindow wants the scaleToPreviewSize set before enabling scaleToPreview
14961649 PropertyAction { target: appDelegate; properties: "z,visible" }
@@ -1576,7 +1729,7 @@ FocusScope {
15761729 ]
15771730
15781731 Binding {
1579− target: PanelState
1732+ target: panelState
15801733 property: "decorationsAlwaysVisible"
15811734 value: appDelegate && appDelegate.maximized && touchControls.overlayShown
15821735 }
@@ -1597,6 +1750,7 @@ FocusScope {
15971750 borderThickness: units.gu(2)
15981751 enabled: false
15991752 visible: enabled
1753+ readyToAssesBounds: !appDelegate._constructing
16001754
16011755 onPressed: {
16021756 appDelegate.activate();
@@ -1620,17 +1774,12 @@ FocusScope {
16201774 height: implicitHeight
16211775 highlightSize: windowInfoItem.iconMargin / 2
16221776 boundsItem: boundariesForWindowPlacement
1777+ panelState: root.panelState
16231778 altDragEnabled: root.mode == "windowed"
16241779
16251780 requestedWidth: appDelegate.requestedWidth
16261781 requestedHeight: appDelegate.requestedHeight
16271782
1628− property int oldRequestedWidth: -1
1629− property int oldRequestedHeight: -1
1630−
1631− onRequestedWidthChanged: oldRequestedWidth = requestedWidth
1632− onRequestedHeightChanged: oldRequestedHeight = requestedHeight
1633−
16341783 onCloseClicked: { appDelegate.close(); }
16351784 onMaximizeClicked: {
16361785 if (appDelegate.canBeMaximized) {
@@ -1711,6 +1860,8 @@ FocusScope {
17111860 anchors.fill: decoratedWindow
17121861 enabled: false
17131862 closeable: !appDelegate.isDash
1863+ stage: root
1864+ dragDelegate: fakeDragItem
17141865
17151866 onClicked: {
17161867 spreadItem.highlightedIndex = index;
@@ -1753,12 +1904,15 @@ FocusScope {
17531904 objectName: "closeMouseArea"
17541905 anchors { left: parent.left; top: parent.top; leftMargin: -height / 2; topMargin: -height / 2 + spreadMaths.closeIconOffset }
17551906 readonly property var mousePos: hoverMouseArea.mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
1756− visible: !appDelegate.isDash && dragArea.distance == 0
1907+ readonly property bool shown: !appDelegate.isDash && dragArea.distance == 0
17571908 && index == spreadItem.highlightedIndex
17581909 && mousePos.y < (decoratedWindow.height / 3)
17591910 && mousePos.y > -units.gu(4)
17601911 && mousePos.x > -units.gu(4)
17611912 && mousePos.x < (decoratedWindow.width * 2 / 3)
1913+ opacity: shown ? 1 : 0
1914+ visible: opacity > 0
1915+ Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
17621916 height: units.gu(6)
17631917 width: height
17641918
@@ -1820,83 +1974,19 @@ FocusScope {
18201974 leftMargin: root.leftMargin
18211975 appContainerWidth: appContainer.width
18221976 appContainerHeight: appContainer.height
1977+ panelState: root.panelState
18231978 }
18241979
1825− MouseArea {
1826− id: hoverMouseArea
1827− objectName: "hoverMouseArea"
1828− anchors.fill: appContainer
1829− propagateComposedEvents: true
1830− hoverEnabled: true
1831− enabled: false
1832− visible: enabled
1833−
1834− property int scrollAreaWidth: width / 3
1835− property bool progressiveScrollingEnabled: false
1836−
1837− onMouseXChanged: {
1838− mouse.accepted = false
1839−
1840− if (hoverMouseArea.pressed) {
1841− return;
1842− }
1843−
1844− // Find the hovered item and mark it active
1845− for (var i = appRepeater.count - 1; i >= 0; i--) {
1846− var appDelegate = appRepeater.itemAt(i);
1847− var mapped = mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
1848− var itemUnder = appDelegate.childAt(mapped.x, mapped.y);
1849− if (itemUnder && (itemUnder.objectName === "dragArea" || itemUnder.objectName === "windowInfoItem" || itemUnder.objectName == "closeMouseArea")) {
1850− spreadItem.highlightedIndex = i;
1851− break;
1852− }
1853− }
1854−
1855− if (floatingFlickable.contentWidth > floatingFlickable.width) {
1856− var margins = floatingFlickable.width * 0.05;
1857−
1858− if (!progressiveScrollingEnabled && mouseX < floatingFlickable.width - scrollAreaWidth) {
1859− progressiveScrollingEnabled = true
1860− }
1861−
1862− // do we need to scroll?
1863− if (mouseX < scrollAreaWidth + margins) {
1864− var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
1865− var contentX = (1 - progress) * (floatingFlickable.contentWidth - floatingFlickable.width)
1866− floatingFlickable.contentX = Math.max(0, Math.min(floatingFlickable.contentX, contentX))
1867− }
1868− if (mouseX > floatingFlickable.width - scrollAreaWidth && progressiveScrollingEnabled) {
1869− var progress = Math.min(1, (mouseX - (floatingFlickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
1870− var contentX = progress * (floatingFlickable.contentWidth - floatingFlickable.width)
1871− floatingFlickable.contentX = Math.min(floatingFlickable.contentWidth - floatingFlickable.width, Math.max(floatingFlickable.contentX, contentX))
1872− }
1873− }
1874− }
1875−
1876− onPressed: mouse.accepted = false
1877− }
1878−
1879− FloatingFlickable {
1880− id: floatingFlickable
1881− objectName: "spreadFlickable"
1882− anchors.fill: appContainer
1883− enabled: false
1884− contentWidth: spreadItem.spreadTotalWidth
1885−
1886− function snap(toIndex) {
1887− var delegate = appRepeater.itemAt(toIndex)
1888− var targetContentX = floatingFlickable.contentWidth / spreadItem.totalItemCount * toIndex;
1889− if (targetContentX - floatingFlickable.contentX > spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) {
1890− var offset = (spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) - (targetContentX - floatingFlickable.contentX)
1891− snapAnimation.to = Math.max(0, floatingFlickable.contentX - offset);
1892− snapAnimation.start();
1893− } else if (targetContentX - floatingFlickable.contentX < spreadItem.leftStackXPos + units.gu(1)) {
1894− var offset = (spreadItem.leftStackXPos + units.gu(1)) - (targetContentX - floatingFlickable.contentX);
1895− snapAnimation.to = Math.max(0, floatingFlickable.contentX - offset);
1896− snapAnimation.start();
1980+ WorkspaceSwitcher {
1981+ id: workspaceSwitcher
1982+ anchors.centerIn: parent
1983+ height: units.gu(20)
1984+ background: root.background
1985+ onActiveChanged: {
1986+ if (!active) {
1987+ appContainer.focus = true;
18971988 }
18981989 }
1899− UbuntuNumberAnimation {id: snapAnimation; target: floatingFlickable; property: "contentX"}
19001990 }
19011991
19021992 PropertyAnimation {
qml/Stage/SurfaceContainer.qml+2
@@ -66,6 +66,8 @@ FocusScope {
6666 fillMode: MirSurfaceItem.PadOrCrop
6767 consumesInput: true
6868
69+ onSurfaceChanged: print("surface changed", surface, implicitWidth, implicitHeight)
70+
6971 surfaceWidth: root.requestedWidth
7072 surfaceHeight: root.requestedHeight
7173
qml/Stage/WindowDecoration.qml+2
@@ -34,6 +34,7 @@ MouseArea {
3434 property var menu: undefined
3535 property bool enableMenus: true
3636 property bool windowMoving: false
37+ property PanelState panelState
3738
3839 readonly property real buttonsWidth: buttons.width + row.spacing
3940
@@ -146,6 +147,7 @@ MouseArea {
146147 enableKeyFilter: valid && root.active && root.enableMenus
147148 unityMenuModel: root.menu
148149 windowMoving: root.windowMoving
150+ panelState: root.panelState
149151
150152 onPressed: root.onPressed(mouse)
151153 onPressedChangedEx: root.pressedChangedEx(pressed, pressedButtons, mouseX, mouseY)
qml/Stage/WindowResizeArea.qml+27−4
@@ -36,35 +36,58 @@ MouseArea {
3636 property int minWidth: 0
3737 property int minHeight: 0
3838
39+ property bool readyToAssesBounds: false
40+ onReadyToAssesBoundsChanged: d.reassesBounds()
41+
3942 QtObject {
4043 id: d
4144
4245 readonly property int maxSafeInt: 2147483647
4346 readonly property int maxSizeIncrement: units.gu(40)
4447
48+ function reassesBounds() {
49+ if (!readyToAssesBounds) return;
50+
51+ if (target.windowedWidth < minimumWidth) {
52+ target.windowedWidth = minimumWidth;
53+ }
54+ if (target.windowedHeight < minimumHeight) {
55+ target.windowedHeight = minimumHeight;
56+ }
57+ if (target.windowedHeight < minimumHeight) {
58+ target.windowedHeight = minimumHeight;
59+ }
60+ if (target.windowedWidth > maximumWidth) {
61+ target.windowedWidth = maximumWidth;
62+ }
63+ if (target.windowedHeight > maximumHeight) {
64+ target.windowedHeight = maximumHeight;
65+ }
66+ }
67+
4568 readonly property int minimumWidth: root.target ? Math.max(root.minWidth, root.target.minimumWidth) : root.minWidth
4669 onMinimumWidthChanged: {
47− if (target.windowedWidth < minimumWidth) {
70+ if (readyToAssesBounds && target.windowedWidth < minimumWidth) {
4871 target.windowedWidth = minimumWidth;
4972 }
5073 }
5174 readonly property int minimumHeight: root.target ? Math.max(root.minHeight, root.target.minimumHeight) : root.minHeight
5275 onMinimumHeightChanged: {
53− if (target.windowedHeight < minimumHeight) {
76+ if (readyToAssesBounds && target.windowedHeight < minimumHeight) {
5477 target.windowedHeight = minimumHeight;
5578 }
5679 }
5780 readonly property int maximumWidth: root.target && root.target.maximumWidth >= minimumWidth && root.target.maximumWidth > 0
5881 ? root.target.maximumWidth : maxSafeInt
5982 onMaximumWidthChanged: {
60− if (target.windowedWidth > maximumWidth) {
83+ if (readyToAssesBounds && target.windowedWidth > maximumWidth) {
6184 target.windowedWidth = maximumWidth;
6285 }
6386 }
6487 readonly property int maximumHeight: root.target && root.target.maximumHeight >= minimumHeight && root.target.maximumHeight > 0
6588 ? root.target.maximumHeight : maxSafeInt
6689 onMaximumHeightChanged: {
67− if (target.windowedHeight > maximumHeight) {
90+ if (readyToAssesBounds && target.windowedHeight > maximumHeight) {
6891 target.windowedHeight = maximumHeight;
6992 }
7093 }
qml/Stage/WindowStateSaver.qml+4−1
@@ -43,7 +43,10 @@ QtObject {
4343 (target.fullscreen ? 0 : root.leftMargin)); });
4444 target.windowedY = Qt.binding(function() { return Math.max(Math.min(windowGeometry.y, screenHeight - target.windowedHeight), minimumY); });
4545
46− target.updateNormalGeometry();
46+ target.normalWidth = target.windowedWidth;
47+ target.normalHeight = target.windowedHeight;
48+ target.normalX = target.windowedX;
49+ target.normalY = target.windowedY;
4750
4851 // initialize the x/y to restore to
4952 target.restoredX = target.normalX;
qml/Stage/WorkspacePreview.qmlnew file+212
@@ -0,0 +1,212 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import Unity.Screens 0.1
4+import Unity.Application 0.1
5+import "../Components"
6+
7+UbuntuShape {
8+ id: previewSpace
9+
10+ // Set the height. this preview will then automatically adjust the width, keeping aspect ratio of the screen
11+ width: model.geometry.width * previewScale * 4
12+ color: "white"
13+ property string background
14+
15+ property int screenWidth: model.geometry.width
16+ property int screenHeight: model.geometry.height
17+ property real previewScale: (previewSpace.height - header.height) / previewSpace.screenHeight
18+
19+ Item {
20+ id: header
21+ anchors { left: parent.left; top: parent.top; right: parent.right }
22+ height: units.gu(7)
23+
24+ Column {
25+ anchors.fill: parent
26+ anchors.margins: units.gu(1)
27+
28+ Label {
29+ text: model.name
30+ color: "black"
31+ }
32+
33+ Label {
34+ text: model.outputType === Screens.LVDS ? "Built-in" : "Clone"
35+ color: "black"
36+ fontSize: "x-small"
37+ }
38+
39+ Label {
40+ text: model.geometry.width + "x" + model.geometry.height
41+ color: "black"
42+ fontSize: "x-small"
43+ }
44+ }
45+ }
46+
47+
48+ Rectangle {
49+ anchors.fill: parent
50+ anchors.topMargin: header.height
51+ color: "blue"
52+
53+ Repeater {
54+ id: workspaceRepeater
55+ model: 15
56+
57+ delegate: Item {
58+ x: index * previewSpace.screenWidth * previewScale
59+ height: previewSpace.screenHeight * previewScale
60+ width: previewSpace.screenWidth * previewScale
61+ clip: true
62+
63+ Wallpaper {
64+ source: previewSpace.background
65+ anchors.fill: parent
66+
67+ // Repeater {
68+ // id: topLevelSurfaceRepeater
69+ // model: visible ? topLevelSurfaceList : null
70+ // delegate: Rectangle {
71+ // width: surfaceItem.width
72+ // height: surfaceItem.height + decorationHeight * previewScale
73+ // x: model.window.position.x * previewScale
74+ // y: (model.window.position.y - decorationHeight) * previewScale
75+ // color: "blue"
76+ // z: topLevelSurfaceRepeater.count - index
77+
78+ // property int decorationHeight: units.gu(3)
79+
80+ // WindowDecoration {
81+ // width: surfaceItem.implicitWidth
82+ // height: parent.decorationHeight
83+ // transform: Scale {
84+ // origin.x: 0
85+ // origin.y: 0
86+ // xScale: previewScale
87+ // yScale: previewScale
88+ // }
89+ // title: model.window && model.window.surface ? model.window.surface.name : ""
90+ // z: 3
91+ // }
92+
93+ // MirSurfaceItem {
94+ // id: surfaceItem
95+ // y: parent.decorationHeight * previewScale
96+ // width: implicitWidth * previewScale
97+ // height: implicitHeight * previewScale
98+ // surfaceWidth: -1
99+ // surfaceHeight: -1
100+ // onImplicitHeightChanged: print("item", surfaceItem, "height changed", implicitHeight)
101+ // surface: model.window.surface
102+ // }
103+ // }
104+ // }
105+ }
106+ }
107+
108+
109+// MouseArea {
110+// id: mouseArea
111+// anchors.centerIn: parent
112+// anchors.verticalCenterOffset: header.height / 2
113+// width: units.gu(8)
114+// height: width
115+// hoverEnabled: true
116+// opacity: containsMouse ? 1 : 0
117+
118+// Rectangle {
119+// anchors.fill: parent
120+// color: "#80000000"
121+// radius: height / 2
122+// }
123+
124+// NumberAnimation {
125+// target: canvas
126+// property: "progress"
127+// duration: 2000
128+// running: mouseArea.containsMouse
129+// from: 0
130+// to: 1
131+// }
132+
133+// Canvas {
134+// id: canvas
135+// height: parent.height
136+// width: height
137+// anchors.centerIn: parent
138+
139+// property real progress: 0.5
140+// property int lineWidth: units.dp(4)
141+// onProgressChanged: {
142+// requestPaint();
143+// if (progress == 1) {
144+// Screens.activateScreen(index);
145+// }
146+// }
147+
148+// rotation: -90
149+
150+// onPaint: {
151+// var ctx = canvas.getContext("2d");
152+// ctx.save();
153+// ctx.reset();
154+
155+// ctx.lineWidth = lineWidth;
156+
157+// ctx.strokeStyle = "#3bffffff"
158+// ctx.beginPath();
159+// ctx.arc(canvas.width/2,canvas.height/2, (canvas.height - ctx.lineWidth) / 2, 0, (Math.PI*2),false);
160+// ctx.stroke();
161+// ctx.closePath();
162+
163+// ctx.strokeStyle = "white"
164+// ctx.beginPath();
165+// ctx.arc(canvas.width/2,canvas.height/2, (canvas.height - ctx.lineWidth) / 2, 0, (Math.PI*2*(progress)),false);
166+// ctx.stroke();
167+// ctx.closePath();
168+
169+// ctx.restore();
170+// }
171+// }
172+
173+// Icon {
174+// source: "graphics/multi-monitor_leave.png"
175+// height: units.gu(4)
176+// width: height
177+// anchors.centerIn: parent
178+// }
179+// }
180+ }
181+
182+ FloatingFlickable {
183+ id: flickable
184+ anchors.fill: parent
185+ contentWidth: workspaceRepeater.count * previewSpace.screenWidth * previewScale
186+ property real progress: contentX / contentWidth
187+ onContentXChanged: print("contentX:", contentX, "progress:", progress)
188+ }
189+
190+ MouseArea {
191+ anchors.fill: parent
192+ hoverEnabled: true
193+ property int scrollAreaWidth: width / 3
194+
195+ onMouseXChanged: {
196+ var margins = flickable.width * 0.05;
197+
198+ // do we need to scroll?
199+ if (mouseX < scrollAreaWidth + margins) {
200+ var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
201+ var contentX = (1 - progress) * (flickable.contentWidth - flickable.width)
202+ flickable.contentX = Math.max(0, Math.min(flickable.contentX, contentX))
203+ }
204+ if (mouseX > flickable.width - scrollAreaWidth) {
205+ var progress = Math.min(1, (mouseX - (flickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
206+ var contentX = progress * (flickable.contentWidth - flickable.width)
207+ flickable.contentX = Math.min(flickable.contentWidth - flickable.width, Math.max(flickable.contentX, contentX))
208+ }
209+ }
210+ }
211+ }
212+}
qml/Stage/WorkspaceSwitcher.qmlnew file+181
@@ -0,0 +1,181 @@
1+/*
2+ * Copyright (C) 2014-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 "Spread"
20+import WindowManager 1.0
21+import Unity.Application 0.1
22+
23+UbuntuShape {
24+ id: root
25+
26+ backgroundColor: "#F2111111"
27+ width: screensRow.childrenRect.width + units.gu(4)
28+ opacity: d.shown ? 1 : 0
29+ visible: opacity > 0
30+ Behavior on opacity { UbuntuNumberAnimation {} }
31+
32+ property var screensProxy: Screens.createProxy();
33+ property string background
34+
35+ readonly property alias active: d.active
36+
37+ function showLeft() {
38+ show();
39+ d.decreaseHighlight();
40+ }
41+ function showRight() {
42+ show();
43+ d.increaseHighlight();
44+ }
45+
46+ function show() {
47+ hideTimer.stop();
48+ d.altPressed = true;
49+ d.ctrlPressed = true;
50+ d.active = true;
51+ d.shown = true;
52+ focus = true;
53+
54+ d.highlightedScreenIndex = screensProxy.activeScreen;
55+ var activeScreen = screensProxy.get(screensProxy.activeScreen);
56+ d.highlightedWorkspaceIndex = activeScreen.workspaces.indexOf(activeScreen.currentWorkspace)
57+ }
58+
59+ QtObject {
60+ id: d
61+
62+ property bool active: false
63+ property bool shown: false
64+ property bool altPressed: false
65+ property bool ctrlPressed: false
66+
67+ property int highlightedScreenIndex: -1
68+ property int highlightedWorkspaceIndex: -1
69+
70+ function increaseHighlight() {
71+ var screen = screensProxy.get(highlightedScreenIndex);
72+ highlightedWorkspaceIndex++
73+ if (highlightedWorkspaceIndex >= screen.workspaces.count) {
74+ highlightedScreenIndex = (highlightedScreenIndex + 1) % screensProxy.count;
75+ highlightedWorkspaceIndex = 0;
76+ }
77+ }
78+ function decreaseHighlight() {
79+ highlightedWorkspaceIndex--;
80+ if (highlightedWorkspaceIndex < 0) {
81+ highlightedScreenIndex--;
82+ if (highlightedScreenIndex < 0) {
83+ highlightedScreenIndex = screensProxy.count - 1
84+ }
85+ var screen = screensProxy.get(highlightedScreenIndex);
86+ highlightedWorkspaceIndex = screen.workspaces.count -1;
87+ }
88+ }
89+ }
90+
91+ Timer {
92+ id: hideTimer
93+ interval: 300
94+ onTriggered: d.shown = false;
95+ }
96+
97+ Keys.onPressed: {
98+ hideTimer.restart();
99+ switch (event.key) {
100+ case Qt.Key_Left:
101+ d.decreaseHighlight();
102+ break;
103+ case Qt.Key_Right:
104+ d.increaseHighlight();
105+ break;
106+ }
107+ }
108+ Keys.onReleased: {
109+ switch (event.key) {
110+ case Qt.Key_Alt:
111+ d.altPressed = false;
112+ break;
113+ case Qt.Key_Control:
114+ d.ctrlPressed = false;
115+ break;
116+ }
117+
118+ if (!d.altPressed && !d.ctrlPressed) {
119+ print("starting hidetimer")
120+ d.active = false;
121+ hideTimer.start();
122+ focus = false;
123+ screensProxy.get(d.highlightedScreenIndex).workspaces.get(d.highlightedWorkspaceIndex).activate();
124+ }
125+ }
126+
127+ Row {
128+ id: screensRow
129+ anchors {
130+ top: parent.top; topMargin: units.gu(2)
131+ left: parent.left; leftMargin: units.gu(2)
132+ }
133+ spacing: units.gu(2)
134+
135+ Repeater {
136+ model: screensProxy
137+
138+ delegate: Item {
139+ height: root.height - units.gu(4)
140+ width: workspaces.width
141+
142+ UbuntuShape {
143+ id: header
144+ anchors { left: parent.left; top: parent.top; right: parent.right }
145+ height: units.gu(4)
146+ backgroundColor: "white"
147+
148+ Label {
149+ anchors { left: parent.left; top: parent.top; right: parent.right; margins: units.gu(1) }
150+ text: model.screen.name
151+ color: UbuntuColors.ash
152+ }
153+ }
154+
155+ Workspaces {
156+ id: workspaces
157+ height: parent.height - header.height - units.gu(2)
158+ width: {
159+ var width = 0;
160+ if (screensProxy.count == 1) {
161+ width = Math.min(implicitWidth, root.width - units.gu(8));
162+ } else {
163+ width = Math.min(implicitWidth, model.screen.active ? root.width - units.gu(48) : units.gu(40))
164+ }
165+ return Math.max(workspaces.minimumWidth, width);
166+ }
167+
168+ Behavior on width { UbuntuNumberAnimation {} }
169+ anchors.bottom: parent.bottom
170+ anchors.bottomMargin: units.gu(1)
171+ anchors.horizontalCenter: parent.horizontalCenter
172+ screen: model.screen
173+ background: root.background
174+ selectedIndex: d.highlightedScreenIndex == index ? d.highlightedWorkspaceIndex : -1
175+
176+ workspaceModel: model.screen.workspaces
177+ }
178+ }
179+ }
180+ }
181+}
qml/Stage/graphics/multi-monitor_drop-here.pngnew file

Binary file not shown.

qml/Stage/graphics/multi-monitor_leave.pngnew file

Binary file not shown.

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+11−4
@@ -9,6 +9,7 @@ include_directories(
99 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
1010 ${GSETTINGS_QT_INCLUDE_DIRS}
1111 ${CONNECTIVITY_INCLUDE_DIRS}
12+ ${QTMIRSERVER_INCLUDE_DIRS}
1213)
1314
1415include_directories(
@@ -29,12 +30,11 @@ set(SOURCE_FILES
2930 ApplicationArguments.cpp
3031 main.cpp
3132 CachingNetworkManagerFactory.cpp
32− SecondaryWindow.cpp
33− ShellApplication.cpp
34− ShellView.cpp
33+ UnityApplication.cpp
3534 UnityCommandLineParser.cpp
3635 UnixSignalHandler.cpp
3736 DebuggingController.cpp
37+ WindowManagementPolicy.cpp
3838 ${QML_FILES} # This is to make qml and image files appear in the IDE's project tree
3939)
4040
@@ -49,7 +49,14 @@ qt5_use_modules(${SHELL_APP} DBus Gui Qml Quick Test)
4949if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
5050 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
5151endif()
52−target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} ${GSETTINGS_QT_LDFLAGS} UbuntuGestures connectivity-qt1 unity8-private)
52+target_link_libraries(${SHELL_APP}
53+ ${ANDROID_PROPERTIES_LDFLAGS}
54+ ${GSETTINGS_QT_LDFLAGS}
55+ ${QTMIRSERVER_LDFLAGS}
56+ UbuntuGestures
57+ connectivity-qt1
58+ unity8-private
59+)
5360
5461if (ENABLE_TOUCH_EMULATION)
5562 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
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−221
@@ -1,221 +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 <QGSettings>
25−
26−#include <libintl.h>
27−
28−// libandroid-properties
29−#include <hybris/properties/properties.h>
30−
31−// local
32−#include <paths.h>
33−#include "CachingNetworkManagerFactory.h"
34−#include "UnityCommandLineParser.h"
35−#include "DebuggingController.h"
36−
37−ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
38− : QGuiApplication(argc, argv)
39−{
40− setApplicationName(QStringLiteral("unity8"));
41− setOrganizationName(QStringLiteral("Canonical"));
42−
43− connect(this, &QGuiApplication::screenAdded, this, &ShellApplication::onScreenAdded);
44−
45− setupQmlEngine(isMirServer);
46−
47− UnityCommandLineParser parser(*this);
48−
49− if (!parser.deviceName().isEmpty()) {
50− m_deviceName = parser.deviceName();
51− } else {
52− char buffer[200];
53− property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
54− m_deviceName = QString(buffer);
55− }
56− m_qmlArgs.setDeviceName(m_deviceName);
57−
58− m_qmlArgs.setMode(parser.mode());
59−
60− // The testability driver is only loaded by QApplication but not by QGuiApplication.
61− // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
62− if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
63− QLibrary testLib(QStringLiteral("qttestability"));
64− if (testLib.load()) {
65− typedef void (*TasInitialize)(void);
66− TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
67− if (initFunction) {
68− initFunction();
69− } else {
70− qCritical("Library qttestability resolve failed!");
71− }
72− } else {
73− qCritical("Library qttestability load failed!");
74− }
75− }
76−
77− bindtextdomain("unity8", translationDirectory().toUtf8().data());
78− textdomain("unity8");
79−
80− QScopedPointer<QGSettings> gSettings(new QGSettings("com.canonical.Unity8"));
81− gSettings->reset(QStringLiteral("alwaysShowOsk"));
82−
83− m_shellView = new ShellView(m_qmlEngine, &m_qmlArgs);
84−
85− if (parser.windowGeometry().isValid()) {
86− m_shellView->setWidth(parser.windowGeometry().width());
87− m_shellView->setHeight(parser.windowGeometry().height());
88− }
89−
90− if (parser.hasFrameless()) {
91− m_shellView->setFlags(Qt::FramelessWindowHint);
92− }
93−
94−
95− #ifdef UNITY8_ENABLE_TOUCH_EMULATION
96− // You will need this if you want to interact with touch-only components using a mouse
97− // Needed only when manually testing on a desktop.
98− if (parser.hasMouseToTouch()) {
99− m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
100− }
101− #endif
102−
103− new DebuggingController(this);
104−
105− // Some hard-coded policy for now.
106− // NB: We don't support more than two screens at the moment
107− //
108− // TODO: Support an arbitrary number of screens and different policies
109− // (eg cloned desktop, several desktops, etc)
110− if (isMirServer && screens().count() == 2) {
111− m_shellView->setScreen(screens().at(1));
112− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
113−
114− m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
115− m_secondaryWindow->setScreen(screens().at(0));
116− // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
117− m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
118− m_secondaryWindow->setVisible(true);
119− }
120−
121− if (parser.mode().compare("greeter") == 0) {
122− QSize primaryScreenSize = this->primaryScreen()->size();
123− m_shellView->setHeight(primaryScreenSize.height());
124− m_shellView->setWidth(primaryScreenSize.width());
125− m_shellView->show();
126− m_shellView->requestActivate();
127− if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
128− qDebug() << "Unable to send unity8-greeter-started event to Upstart";
129− }
130− } else if (isMirServer || parser.hasFullscreen()) {
131− m_shellView->showFullScreen();
132− } else {
133− m_shellView->show();
134− }
135−}
136−
137−ShellApplication::~ShellApplication()
138−{
139− destroyResources();
140−}
141−
142−void ShellApplication::destroyResources()
143−{
144− // Deletion order is important. Don't use QScopedPointers and the like
145− // Otherwise the process will hang on shutdown (bug somewhere I guess).
146− delete m_shellView;
147− m_shellView = nullptr;
148−
149− delete m_secondaryWindow;
150− m_secondaryWindow = nullptr;
151−
152− #ifdef UNITY8_ENABLE_TOUCH_EMULATION
153− delete m_mouseTouchAdaptor;
154− m_mouseTouchAdaptor = nullptr;
155− #endif
156−
157− delete m_qmlEngine;
158− m_qmlEngine = nullptr;
159−}
160−
161−void ShellApplication::setupQmlEngine(bool isMirServer)
162−{
163− m_qmlEngine = new QQmlEngine(this);
164−
165− m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
166−
167− prependImportPaths(m_qmlEngine, ::overrideImportPaths());
168− if (!isMirServer) {
169− prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
170− }
171− appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
172−
173− m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
174−
175− QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
176−}
177−
178−void ShellApplication::onScreenAdded(QScreen * /*screen*/)
179−{
180− // TODO: Support an arbitrary number of screens and different policies
181− // (eg cloned desktop, several desktops, etc)
182− if (screens().count() == 2) {
183− m_shellView->setScreen(screens().at(1));
184− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
185− // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
186− // its backing QPlatformWindow recreated). So lets refocus it.
187− m_shellView->requestActivate();
188− // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
189− // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
190− m_shellView->setVisible(true);
191−
192− m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
193− m_secondaryWindow->setScreen(screens().at(0));
194−
195− // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
196− m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
197− m_secondaryWindow->setVisible(true);
198− }
199−}
200−
201−void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
202−{
203− // TODO: Support an arbitrary number of screens and different policies
204− // (eg cloned desktop, several desktops, etc)
205− if (screen == m_shellView->screen()) {
206− const QList<QScreen *> allScreens = screens();
207− Q_ASSERT(allScreens.count() > 1);
208− Q_ASSERT(allScreens.at(0) != screen);
209− Q_ASSERT(m_secondaryWindow);
210− delete m_secondaryWindow;
211− m_secondaryWindow = nullptr;
212− m_shellView->setScreen(allScreens.first());
213− m_qmlArgs.setDeviceName(m_deviceName);
214− // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
215− // its backing QPlatformWindow recreated). So lets refocus it.
216− m_shellView->requestActivate();
217− // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
218− // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
219− m_shellView->setVisible(true);
220− }
221−}
src/ShellView.cppdeleted−85
@@ -1,85 +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−#include <QtQuick/private/qquickitem_p.h>
23−#include <QtQuick/private/qquickrectangle_p.h>
24−#include <QtQuick/private/qquicktext_p.h>
25−
26−// local
27−#include <paths.h>
28−
29−ShellView::ShellView(QQmlEngine *engine, QObject *qmlArgs)
30− : QQuickView(engine, nullptr)
31−{
32− setResizeMode(QQuickView::SizeRootObjectToView);
33− setColor("black");
34− setTitle(QStringLiteral("Unity8"));
35−
36− rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
37−
38− connect(this, &QQuickView::statusChanged, this, [this] {
39− if (status() == QQuickView::Error) {
40− QQuickRectangle *rect = new QQuickRectangle(contentItem());
41− rect->setColor(Qt::white);
42− QQuickItemPrivate::get(rect)->anchors()->setFill(contentItem());
43−
44− QString errorsString;
45− for(const QQmlError &e: errors()) {
46− errorsString += e.toString() + "\n";
47− }
48− QQuickText *text = new QQuickText(rect);
49− text->setColor(Qt::black);
50− text->setWrapMode(QQuickText::Wrap);
51− text->setText(QString("There was an error loading Unity8:\n%1").arg(errorsString));
52− QQuickItemPrivate::get(text)->anchors()->setFill(rect);
53− }
54− }
55− );
56−
57− QUrl source(::qmlDirectory() + "/OrientedShell.qml");
58− setSource(source);
59−
60− connect(this, &QWindow::widthChanged, this, &ShellView::onWidthChanged);
61− connect(this, &QWindow::heightChanged, this, &ShellView::onHeightChanged);
62−}
63−
64−void ShellView::onWidthChanged(int w)
65−{
66− // For good measure in case SizeRootObjectToView doesn't fulfill its promise.
67− //
68− // There's at least one situation that's know to leave the root object with an outdated size.
69− // (really looks like Qt bug)
70− // Happens when starting unity8 with an external monitor already connected.
71− // The QResizeEvent we get still has the size of the first screen and since the resize move is triggered
72− // from the resize event handler, the root item doesn't get resized.
73− // TODO: Confirm the Qt bug and submit a patch upstream
74− if (rootObject()) {
75− rootObject()->setWidth(w);
76− }
77−}
78−
79−void ShellView::onHeightChanged(int h)
80−{
81− // See comment in ShellView::onWidthChanged()
82− if (rootObject()) {
83− rootObject()->setHeight(h);
84− }
85−}
src/UnityApplication.cppnew file+147
@@ -0,0 +1,147 @@
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+#include <QQmlComponent>
25+
26+#include <QGSettings>
27+
28+#include <libintl.h>
29+
30+// libandroid-properties
31+#include <hybris/properties/properties.h>
32+
33+// local
34+#include <paths.h>
35+#include "CachingNetworkManagerFactory.h"
36+#include "UnityCommandLineParser.h"
37+#include "DebuggingController.h"
38+#include "WindowManagementPolicy.h"
39+
40+#include <QDebug>
41+
42+
43+
44+UnityApplication::UnityApplication(int & argc, char ** argv)
45+ : qtmir::MirServerApplication(argc, argv, { qtmir::SetWindowManagementPolicy<WindowManagementPolicy>() })
46+ , m_qmlArgs(this)
47+{
48+ setApplicationName(QStringLiteral("unity8"));
49+ setOrganizationName(QStringLiteral("Canonical"));
50+
51+ setupQmlEngine();
52+
53+ if (m_qmlArgs.deviceName().isEmpty()) {
54+ char buffer[200];
55+ property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
56+ m_qmlArgs.setDeviceName(QString(buffer));
57+ }
58+
59+ // The testability driver is only loaded by QApplication but not by QGuiApplication.
60+ // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
61+ if (m_qmlArgs.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
62+ QLibrary testLib(QStringLiteral("qttestability"));
63+ if (testLib.load()) {
64+ typedef void (*TasInitialize)(void);
65+ TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
66+ if (initFunction) {
67+ initFunction();
68+ } else {
69+ qCritical("Library qttestability resolve failed!");
70+ }
71+ } else {
72+ qCritical("Library qttestability load failed!");
73+ }
74+ }
75+
76+ bindtextdomain("unity8", translationDirectory().toUtf8().data());
77+ textdomain("unity8");
78+
79+ QScopedPointer<QGSettings> gSettings(new QGSettings("com.canonical.Unity8"));
80+ gSettings->reset(QStringLiteral("alwaysShowOsk"));
81+
82+
83+ QByteArray pxpguEnv = qgetenv("GRID_UNIT_PX");
84+ bool ok;
85+ int pxpgu = pxpguEnv.toInt(&ok);
86+ if (!ok) {
87+ pxpgu = 8;
88+ }
89+ m_qmlEngine->rootContext()->setContextProperty("internalGu", pxpgu);
90+ m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("applicationArguments"), &m_qmlArgs);
91+ m_qmlEngine->rootContext()->setContextProperty("DebuggingController", new DebuggingController(this));
92+
93+ auto component(new QQmlComponent(m_qmlEngine, m_qmlArgs.qmlfie()));
94+ component->create();
95+ if (component->status() == QQmlComponent::Error) {
96+ m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("errorString"), component->errorString());
97+ auto errorComponent(new QQmlComponent(m_qmlEngine,
98+ QUrl::fromLocalFile(::qmlDirectory() + "/ErrorApplication.qml")));
99+ errorComponent->create();
100+ qDebug() << errorComponent->errorString();
101+ return;
102+ }
103+
104+ #ifdef UNITY8_ENABLE_TOUCH_EMULATION
105+ // You will need this if you want to interact with touch-only components using a mouse
106+ // Needed only when manually testing on a desktop.
107+ if (m_qmlArgs.hasMouseToTouch()) {
108+ m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
109+ }
110+ #endif
111+
112+ if (m_qmlArgs.mode().compare("greeter") == 0) {
113+ if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
114+ qDebug() << "Unable to send unity8-greeter-started event to Upstart";
115+ }
116+ }
117+}
118+
119+UnityApplication::~UnityApplication()
120+{
121+ destroyResources();
122+}
123+
124+void UnityApplication::destroyResources()
125+{
126+ #ifdef UNITY8_ENABLE_TOUCH_EMULATION
127+ delete m_mouseTouchAdaptor;
128+ m_mouseTouchAdaptor = nullptr;
129+ #endif
130+
131+ delete m_qmlEngine;
132+ m_qmlEngine = nullptr;
133+}
134+
135+void UnityApplication::setupQmlEngine()
136+{
137+ m_qmlEngine = new QQmlEngine(this);
138+
139+ m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
140+
141+ prependImportPaths(m_qmlEngine, ::overrideImportPaths());
142+ appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
143+
144+ m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
145+
146+ QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
147+}
src/ShellApplication.h → src/UnityApplication.hrenamed+9−19
@@ -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,30 +28,20 @@
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};
@@ -60,4 +50,4 @@ private:
6050 QQmlEngine *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/WindowManagementPolicy.cppnew file+69
@@ -0,0 +1,69 @@
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(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate &dd)
20+ : qtmir::WindowManagementPolicy(tools, dd)
21+ , m_dummyWorkspace(this->tools.create_workspace())
22+{
23+ wmPolicyInterface = this;
24+
25+ // we must always have a active workspace.
26+ m_activeWorkspace = m_dummyWorkspace;
27+}
28+
29+void WindowManagementPolicy::advise_new_window(miral::WindowInfo const& window_info)
30+{
31+ qtmir::WindowManagementPolicy::advise_new_window(window_info);
32+
33+ auto const parent = window_info.parent();
34+
35+ auto activeWorkspace = m_activeWorkspace.lock();
36+ if (!parent && activeWorkspace) {
37+ tools.add_tree_to_workspace(window_info.window(), activeWorkspace);
38+ }
39+}
40+
41+std::shared_ptr<miral::Workspace> WindowManagementPolicy::createWorkspace()
42+{
43+ auto workspace = tools.create_workspace();
44+ m_workspaces.insert(workspace);
45+
46+ if (m_activeWorkspace.lock() == m_dummyWorkspace) {
47+ tools.move_workspace_content_to_workspace(workspace, m_dummyWorkspace);
48+ m_activeWorkspace = workspace;
49+ }
50+ return workspace;
51+}
52+
53+void WindowManagementPolicy::releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
54+{
55+ auto iter = m_workspaces.find(workspace);
56+ if (iter != m_workspaces.end()) m_workspaces.erase(iter);
57+
58+ if (m_workspaces.size() == 0) {
59+ m_activeWorkspace = m_dummyWorkspace;
60+ tools.move_workspace_content_to_workspace(m_dummyWorkspace, workspace);
61+ }
62+}
63+
64+void WindowManagementPolicy::setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
65+{
66+ if (m_activeWorkspace.lock() == workspace)
67+ return;
68+ m_activeWorkspace = workspace ? workspace : m_dummyWorkspace;
69+}
src/WindowManagementPolicy.hnew file+47
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_WINDOWMANAGEMENTPOLICY_H
18+#define UNITY_WINDOWMANAGEMENTPOLICY_H
19+
20+#include <qtmir/windowmanagementpolicy.h>
21+#include "wmpolicyinterface.h"
22+
23+#include <unordered_set>
24+
25+class Q_DECL_EXPORT WindowManagementPolicy : public qtmir::WindowManagementPolicy,
26+ public WMPolicyInterface
27+{
28+public:
29+ WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate& dd);
30+
31+ void advise_new_window(miral::WindowInfo const& window_info) override;
32+
33+ // From WMPolicyInterface
34+ std::shared_ptr<miral::Workspace> createWorkspace() override;
35+
36+ void releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
37+
38+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
39+
40+private:
41+ std::weak_ptr<miral::Workspace> m_activeWorkspace;
42+
43+ std::unordered_set<std::shared_ptr<miral::Workspace>> m_workspaces;
44+ const std::shared_ptr<miral::Workspace> m_dummyWorkspace;
45+};
46+
47+#endif // UNITY_WINDOWMANAGEMENTPOLICY_H
src/libunity8-private/CMakeLists.txt+1
@@ -8,6 +8,7 @@ set(lib${LIB_NAME}_SRCS
88 abstractdbusservicemonitor.cpp
99 unitydbusobject.cpp
1010 unitydbusvirtualobject.cpp
11+ wmpolicyinterface.cpp
1112 )
1213
1314add_library(${LIB_NAME} SHARED
src/SecondaryWindow.h → src/libunity8-private/wmpolicyinterface.cpprenamed+6−12
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2017 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,11 @@
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
17+#include "wmpolicyinterface.h"
1918
20−#include <QQuickView>
19+WMPolicyInterface* wmPolicyInterface = nullptr;
2120
22−class SecondaryWindow : public QQuickView
21+WMPolicyInterface *WMPolicyInterface::instance()
2322{
24− Q_OBJECT
25−
26−public:
27− SecondaryWindow(QQmlEngine *engine);
28−};
29−
30−#endif // UNITY_SECONDARY_WINDOW_H
23+ return wmPolicyInterface;
24+}
src/libunity8-private/wmpolicyinterface.hnew file+46
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef WMPOLICYINTERFACE_H
18+#define WMPOLICYINTERFACE_H
19+
20+#include <memory>
21+#include <functional>
22+
23+#include <qglobal.h>
24+
25+namespace miral {
26+class Workspace;
27+class Window;
28+}
29+
30+class Q_DECL_EXPORT WMPolicyInterface
31+{
32+public:
33+ virtual ~WMPolicyInterface() {}
34+
35+ static WMPolicyInterface *instance();
36+
37+ virtual std::shared_ptr<miral::Workspace> createWorkspace() = 0;
38+
39+ virtual void releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace) = 0;
40+
41+ virtual void setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace) = 0;
42+};
43+
44+extern Q_DECL_EXPORT WMPolicyInterface* wmPolicyInterface;
45+
46+#endif // WMPOLICYINTERFACE_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/CMakeLists.txt+1
@@ -46,6 +46,7 @@ macro(unity8_parse_arguments)
4646 list(APPEND ld_paths
4747 ${UNITY_MOCKPATH}/liblightdm
4848 ${UNITY_MOCKPATH}/libusermetrics
49+ ${UNITY_MOCKPATH}/WindowManager
4950 )
5051
5152 string(REPLACE ";" ":" ld_library_path "${ld_paths}")
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+26−1
@@ -1,3 +1,12 @@
1+pkg_check_modules(MIRTEST mirtest>=0.26 REQUIRED)
2+
3+include_directories(
4+ SYSTEM
5+ ${MIRTEST_INCLUDE_DIRS}
6+ ${MIRAL_INCLUDE_DIRS}
7+ ${libunity8-private_SOURCE_DIR}
8+)
9+
110set(FakeUnityApplicationQml_SOURCES
211 plugin.cpp
312 ApplicationInfo.cpp
@@ -19,11 +28,27 @@ set(FakeUnityApplicationQml_SOURCES
1928 resources/surfaces.qrc
2029)
2130
22−add_library(FakeUnityApplicationQml MODULE ${FakeUnityApplicationQml_SOURCES})
31+add_library(FakeUnityApplicationQml MODULE
32+ ${FakeUnityApplicationQml_SOURCES}
33+)
34+
35+#add_dependencies(FakeUnityApplicationQml windowmanagementpolicy)
36+
37+target_link_libraries(FakeUnityApplicationQml
38+ ${MIRTEST_LDFLAGS}
39+ ${MIRAL_LDFLAGS}
40+ mockwindowmanagmentpolicy
41+)
2342
2443add_library(NonMirUnityApplicationQml MODULE ${FakeUnityApplicationQml_SOURCES})
2544set_target_properties(NonMirUnityApplicationQml PROPERTIES OUTPUT_NAME FakeUnityApplicationQml)
2645
46+target_link_libraries(NonMirUnityApplicationQml
47+ ${MIRTEST_LDFLAGS}
48+ ${MIRAL_LDFLAGS}
49+ mockwindowmanagmentpolicy
50+)
51+
2752qt5_use_modules(FakeUnityApplicationQml Core Quick DBus)
2853qt5_use_modules(NonMirUnityApplicationQml Core Quick DBus)
2954
tests/mocks/Unity/Application/MirSurfaceItem.cpp+26−7
@@ -189,11 +189,13 @@ void MirSurfaceItem::createQmlContentItem()
189189 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
190190 m_qmlItem->setParentItem(this);
191191
192− m_qmlItem->setWidth(m_surfaceWidth);
193− m_qmlItem->setHeight(m_surfaceHeight);
194−
195− setImplicitWidth(m_qmlItem->implicitWidth());
196− setImplicitHeight(m_qmlItem->implicitHeight());
192+ if (m_fillMode == FillMode::Stretch && width() != 0 && height() != 0) {
193+ m_qmlItem->setSize(QSize(this->width(), this->height()));
194+ } else {
195+ m_qmlItem->setSize(m_qmlSurface->size());
196+ }
197+ setImplicitWidth(m_qmlItem->width());
198+ setImplicitHeight(m_qmlItem->height());
197199
198200 {
199201 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
@@ -308,6 +310,16 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
308310 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
309311 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
310312 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
313+ connect(m_qmlSurface, &MirSurface::sizeChanged, this, [this] () {
314+ setImplicitSize(m_qmlSurface->width(), m_qmlSurface->height());
315+ if (m_fillMode == FillMode::Stretch) {
316+ m_qmlItem->setSize(QSize(this->width(), this->height()));
317+ } else {
318+ m_qmlItem->setSize(m_qmlSurface->size());
319+ }
320+ });
321+ m_surfaceWidth = surface->size().width();
322+ m_surfaceHeight = surface->size().height();
311323
312324 QUrl qmlComponentFilePath;
313325 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
@@ -321,6 +333,7 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
321333 switch (m_qmlContentComponent->status()) {
322334 case QQmlComponent::Ready:
323335 createQmlContentItem();
336+ qDebug() << "content created" << m_surfaceWidth << implicitWidth() << width();
324337 break;
325338 case QQmlComponent::Loading:
326339 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
@@ -399,9 +412,15 @@ void MirSurfaceItem::updateSurfaceSize()
399412 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
400413 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
401414 if (m_qmlItem) {
402− m_qmlItem->setWidth(m_surfaceWidth);
403− m_qmlItem->setHeight(m_surfaceHeight);
415+ if (m_fillMode == FillMode::Stretch) {
416+ m_qmlItem->setWidth(width());
417+ m_qmlItem->setHeight(height());
418+ } else {
419+ m_qmlItem->setWidth(m_surfaceWidth);
420+ m_qmlItem->setHeight(m_surfaceHeight);
421+ }
404422 }
423+ qDebug() << this << "setting implicitsize" << m_surfaceWidth << m_surfaceHeight;
405424 setImplicitSize(m_surfaceWidth, m_surfaceHeight);
406425 }
407426}
tests/mocks/Unity/Application/SurfaceManager.cpp+95−3
@@ -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, surfacesFor(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, surfacesFor(windows));
69+ });
4770}
4871
4972SurfaceManager::~SurfaceManager()
@@ -58,6 +81,36 @@ SurfaceManager::~SurfaceManager()
5881 m_instance = nullptr;
5982}
6083
84+MirSurfaceInterface *SurfaceManager::surfaceFor(const miral::Window& window) const
85+{
86+ auto iter = m_windowToSurface.find({window});
87+ if (iter != m_windowToSurface.end()) {
88+ return *iter;
89+ }
90+ return nullptr;
91+}
92+
93+QVector<MirSurfaceInterface*> SurfaceManager::surfacesFor(const std::vector<miral::Window> &windows) const
94+{
95+ QVector<unityapi::MirSurfaceInterface*> surfaces;
96+ for (size_t i = 0; i < windows.size(); i++) {
97+ auto mirSurface = surfaceFor(windows[i]);
98+ if (mirSurface) {
99+ surfaces.push_back(mirSurface);
100+ }
101+ }
102+ return surfaces;
103+}
104+
105+miral::Window SurfaceManager::windowFor(MirSurfaceInterface *surface) const
106+{
107+ auto iter = m_surfaceToWindow.find(surface);
108+ if (iter != m_surfaceToWindow.end()) {
109+ return iter->window;
110+ }
111+ return miral::Window();
112+}
113+
61114MirSurface *SurfaceManager::createSurface(const QString& name,
62115 Mir::Type type,
63116 Mir::State state,
@@ -75,7 +128,12 @@ MirSurface *SurfaceManager::createSurface(const QString& name,
75128
76129void SurfaceManager::registerSurface(MirSurface *surface)
77130{
131+ auto fakeSurface = std::make_shared<mir::test::doubles::StubSurface>();
132+ WindowWrapper window{miral::Window(nullptr, fakeSurface), fakeSurface};
133+
78134 m_surfaces.prepend(surface);
135+ m_windowToSurface.insert(window, surface);
136+ m_surfaceToWindow.insert(surface, window);
79137
80138 if (!surface->parentSurface()) {
81139 surface->setMinimumWidth(m_newSurfaceMinimumWidth);
@@ -92,6 +150,8 @@ void SurfaceManager::registerSurface(MirSurface *surface)
92150
93151 const QString persistentId = surface->persistentId();
94152 connect(surface, &QObject::destroyed, this, [=]() {
153+ WindowWrapper key = m_surfaceToWindow.take(surface);
154+ m_windowToSurface.remove(key);
95155 this->onSurfaceDestroyed(surface, persistentId);
96156 });
97157
@@ -99,7 +159,12 @@ void SurfaceManager::registerSurface(MirSurface *surface)
99159
100160void SurfaceManager::notifySurfaceCreated(unityapi::MirSurfaceInterface *surface)
101161{
102− Q_EMIT surfaceCreated(surface);
162+ if (Q_UNLIKELY(!m_surfaceToWindow.contains(surface))) {
163+ Q_EMIT surfaceCreated(surface);
164+ return;
165+ }
166+
167+ WindowManagementPolicy::instance()->addWindow(m_surfaceToWindow[surface].window);
103168}
104169
105170void SurfaceManager::setNewSurfaceMinimumWidth(int value)
@@ -209,6 +274,32 @@ void SurfaceManager::activate(unityapi::MirSurfaceInterface *apiSurface)
209274 DEBUG_MSG("("<<surface<<") ended");
210275}
211276
277+void SurfaceManager::forEachSurfaceInWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
278+ const std::function<void(unity::shell::application::MirSurfaceInterface*)> &callback)
279+{
280+ WindowManagementPolicy::instance()->forEachWindowInWorkspace(workspace, [&](const miral::Window &window) {
281+ auto surface = surfaceFor(window);
282+ if (surface) {
283+ callback(surface);
284+ }
285+ });
286+}
287+
288+void SurfaceManager::moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface* surface,
289+ const std::shared_ptr<miral::Workspace> &workspace)
290+{
291+ auto window = windowFor(surface);
292+ if (window) {
293+ WindowManagementPolicy::instance()->moveWindowToWorkspace(window, workspace);
294+ }
295+}
296+
297+void SurfaceManager::moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &to,
298+ const std::shared_ptr<miral::Workspace> &from)
299+{
300+ WindowManagementPolicy::instance()->moveWorkspaceContentToWorkspace(to, from);
301+}
302+
212303void SurfaceManager::onStateRequested(MirSurface *surface, Mir::State state)
213304{
214305 DEBUG_MSG("("<<surface<<","<<state<<") started");
@@ -276,6 +367,7 @@ void SurfaceManager::createInputMethodSurface()
276367 if (!m_virtualKeyboard) {
277368 m_virtualKeyboard = new VirtualKeyboard;
278369 registerSurface(m_virtualKeyboard);
279− Q_EMIT surfaceCreated(m_virtualKeyboard);
370+
371+ WindowManagementPolicy::instance()->addWindow(m_surfaceToWindow[m_virtualKeyboard].window);
280372 }
281373}
tests/mocks/Unity/Application/SurfaceManager.h+21
@@ -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
@@ -46,6 +54,13 @@ public:
4654 void raise(unity::shell::application::MirSurfaceInterface *surface) override;
4755 void activate(unity::shell::application::MirSurfaceInterface *surface) override;
4856
57+ void forEachSurfaceInWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
58+ const std::function<void(unity::shell::application::MirSurfaceInterface*)> &callback) override;
59+ void moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface* surface,
60+ const std::shared_ptr<miral::Workspace> &workspace) override;
61+ void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &to,
62+ const std::shared_ptr<miral::Workspace> &from) override;
63+
4964 Q_INVOKABLE MirSurface* createSurface(const QString& name,
5065 Mir::Type type,
5166 Mir::State state,
@@ -95,6 +110,9 @@ private:
95110 void doRaise(unity::shell::application::MirSurfaceInterface *surface);
96111 void focusFirstAvailableSurface();
97112 void registerSurface(MirSurface *surface);
113+ unity::shell::application::MirSurfaceInterface* surfaceFor(const miral::Window &window) const;
114+ QVector<unity::shell::application::MirSurfaceInterface*> surfacesFor(const std::vector<miral::Window> &windows) const;
115+ miral::Window windowFor(unity::shell::application::MirSurfaceInterface* surface) const;
98116
99117 static SurfaceManager *m_instance;
100118
@@ -110,6 +128,9 @@ private:
110128
111129 QList<MirSurface*> m_surfaces;
112130
131+ QHash<WindowWrapper, unity::shell::application::MirSurfaceInterface*> m_windowToSurface;
132+ QHash<unity::shell::application::MirSurfaceInterface*, WindowWrapper> m_surfaceToWindow;
133+
113134 VirtualKeyboard *m_virtualKeyboard{nullptr};
114135};
115136
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/Application/resources/MirSurfaceItem.qml−3
@@ -20,9 +20,6 @@ Rectangle {
2020 id: root
2121 color: "pink"
2222
23− implicitWidth: width
24− implicitHeight: height
25−
2623 property alias screenshotSource: screenshotImage.source
2724 property int orientationAngle
2825
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/mockcontroller.cpp+10
@@ -18,10 +18,20 @@
1818
1919#include "qinputdeviceinfo_mock_p.h"
2020
21+#include <QQuickView>
22+#include <QQmlComponent>
23+#include <QQuickItem>
24+#include <paths.h>
25+
2126MockController::MockController(QObject *parent):
2227 QObject(parent)
2328{
29+}
2430
31+MockController *MockController::instance()
32+{
33+ static MockController* controller = new MockController();
34+ return controller;
2535}
2636
2737QInputDevice *MockController::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
tests/mocks/Unity/InputInfo/mockcontroller.h+3−1
@@ -24,9 +24,11 @@ class MockController: public QObject
2424{
2525 Q_OBJECT
2626public:
27− MockController(QObject *parent = 0);
27+ MockController(QObject *parent = nullptr);
2828 ~MockController() = default;
2929
30+ static MockController *instance();
31+
3032 Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
3133 Q_INVOKABLE void removeDevice(const QString &devicePath);
3234};
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();
3231}
3332
3433void InputInfoPlugin::registerTypes(const char *uri)
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/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/Unity/Screens/screens.hdeleted−82
@@ -1,82 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef SCREENS_H
18−#define SCREENS_H
19−
20−#include <QAbstractListModel>
21−#include <QScreen>
22−
23−class Screen;
24−
25−class Screens : public QAbstractListModel
26−{
27− Q_OBJECT
28−
29− Q_PROPERTY(int count READ count NOTIFY countChanged)
30−
31−public:
32− enum ItemRoles {
33− ScreenRole = Qt::UserRole + 1,
34− OutputTypeRole
35− };
36−
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)
55−
56− explicit Screens(QObject *parent = 0);
57− virtual ~Screens() noexcept;
58−
59− /* QAbstractItemModel */
60− QHash<int, QByteArray> roleNames() const override;
61− QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
62− int rowCount(const QModelIndex &parent = QModelIndex()) const override;
63−
64− int count() const;
65−
66−Q_SIGNALS:
67− void countChanged();
68− void screenAdded(QScreen *screen);
69− void screenRemoved(QScreen *screen);
70−
71−private:
72− QList<Screen *> m_screenList;
73−};
74−
75−class Screen
76−{
77−public:
78− Screens::OutputTypes outputTypes = Screens::Unknown;
79− QScreen *qScreen = nullptr;
80−};
81−
82−#endif // SCREENS_H
tests/mocks/WindowManager/CMakeLists.txtnew file+58
@@ -0,0 +1,58 @@
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+ ${libunity8-private_SOURCE_DIR}
11+)
12+
13+add_library(mockwindowmanagmentpolicy SHARED
14+ WindowManagementPolicy.cpp
15+)
16+target_link_libraries(mockwindowmanagmentpolicy
17+ ${MIRAL_LDFLAGS}
18+ unity8-private
19+)
20+qt5_use_modules(mockwindowmanagmentpolicy Core)
21+
22+install(TARGETS mockwindowmanagmentpolicy
23+ DESTINATION ${SHELL_INSTALL_QML}/mocks/WindowManager
24+ )
25+
26+set(WINDOWMANAGER_SRC
27+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Screen.cpp
28+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/ScreenAttached.cpp
29+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Screens.cpp
30+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/ScreenWindow.cpp
31+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/TopLevelWindowModel.cpp
32+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Window.cpp
33+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WindowManagerObjects.cpp
34+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceManager.cpp
35+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceModel.cpp
36+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
37+ MockScreens.cpp
38+ MockScreenWindow.cpp
39+ MockScreensConfiguration.cpp
40+ WindowManagerPlugin.cpp
41+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
42+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
43+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
44+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
45+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
46+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
47+)
48+
49+add_library(MockWindowManager-qml SHARED ${WINDOWMANAGER_SRC})
50+
51+target_link_libraries(MockWindowManager-qml
52+ ${QTMIRSERVER_LDFLAGS}
53+ mockwindowmanagmentpolicy
54+)
55+
56+qt5_use_modules(MockWindowManager-qml Qml Quick Gui)
57+
58+add_unity8_mock(WindowManager 1.0 WindowManager TARGETS MockWindowManager-qml)
tests/mocks/Unity/Screens/plugin.cpp → tests/mocks/WindowManager/MockScreenWindow.cpprenamed+14−9
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -14,16 +14,21 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#include "plugin.h"
18−#include "screens.h"
17+#include "MockScreenWindow.h"
18+#include "MockScreens.h"
1919
20−#include <QScreen>
20+// Qt
21+#include <QGuiApplication>
22+#include <QDebug>
2123
22−void UnityScreensPlugin::registerTypes(const char* uri)
24+MockScreenWindow::MockScreenWindow(QQuickWindow *parent)
25+ : ScreenWindow(parent)
2326{
24− Q_ASSERT(QLatin1String(uri) == QLatin1String("Unity.Screens"));
25−
26− qRegisterMetaType<QScreen*>("QScreen*");
27+ connect(this, &ScreenWindow::screenWrapperChanged, this, [this]() {
28+ MockScreens::instance()->connectWindow(this);
29+ });
30+}
2731
28− qmlRegisterType<Screens>(uri, 0, 1, "Screens");
32+MockScreenWindow::~MockScreenWindow()
33+{
2934}
tests/mocks/Unity/Screens/plugin.h → tests/mocks/WindowManager/MockScreenWindow.hrenamed+11−6
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
33 *
44 * This program is free software: you can redistribute it and/or modify it under
55 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -14,12 +14,17 @@
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_SCREENWINDOW_H
18+#define MOCK_SCREENWINDOW_H
1919
20−class UnityScreensPlugin : public QQmlExtensionPlugin {
20+#include "ScreenWindow.h"
21+
22+class MockScreenWindow : public ScreenWindow
23+{
2124 Q_OBJECT
22− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
2325public:
24− void registerTypes(const char* uri) override;
26+ explicit MockScreenWindow(QQuickWindow *parent = 0);
27+ ~MockScreenWindow();
2528};
29+
30+#endif // MOCK_SCREENWINDOW_H
tests/mocks/WindowManager/MockScreens.cppnew file+217
@@ -0,0 +1,217 @@
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+#include "ScreenWindow.h"
19+
20+// qtmirserver
21+#include <qtmir/screen.h>
22+
23+#include <QGuiApplication>
24+#include <QWindow>
25+#include <QWeakPointer>
26+
27+namespace {
28+
29+QWeakPointer<MockScreens> m_screens;
30+
31+class MockScreen : public qtmir::Screen
32+{
33+ Q_OBJECT
34+ Q_PROPERTY(QString outputTypeName READ outputTypeName NOTIFY outputTypeNameChanged)
35+public:
36+ MockScreen()
37+ {
38+ m_sizes.append(new qtmir::ScreenMode(50, QSize(800,568)));
39+ m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
40+ m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
41+ m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
42+ m_physicalSize = QSize(800,568);
43+ }
44+ ~MockScreen() {
45+ qDeleteAll(m_sizes);
46+ m_sizes.clear();
47+ }
48+
49+ void connectToWindow(QWindow* w)
50+ {
51+ if (m_connectedWindow == w) return;
52+
53+ if (m_connectedWindow) {
54+ disconnect(m_connectedWindow.data());
55+ }
56+
57+ m_connectedWindow = w;
58+
59+ if (w) {
60+ connect(w, &ScreenWindow::heightChanged, this, [this](int height) {
61+ if (height == 0 || height == m_sizes.first()->size.rheight()) {
62+ return;
63+ }
64+ m_sizes.first()->size.rheight() = height;
65+ Q_EMIT availableModesChanged();
66+
67+ });
68+ connect(w, &ScreenWindow::widthChanged, this, [this](int width) {
69+ if (width == 0 || width == m_sizes.first()->size.rwidth()) {
70+ return;
71+ }
72+ m_sizes.first()->size.rwidth() = width;
73+ Q_EMIT availableModesChanged();
74+ });
75+
76+ Q_EMIT availableModesChanged();
77+ }
78+ }
79+
80+ qtmir::OutputId outputId() const override { return m_id; }
81+ bool used() const override { return m_used; }
82+ QString name() const override { return m_name; }
83+ float scale() const override { return m_scale; }
84+ QSizeF physicalSize() const override { return m_physicalSize; }
85+ qtmir::FormFactor formFactor() const override { return m_formFactor; }
86+ qtmir::OutputTypes outputType() const override { return m_outputType; }
87+ QString outputTypeName() const { return QStringLiteral("Internal"); }
88+ MirPowerMode powerMode() const override { return m_powerMode; }
89+ Qt::ScreenOrientation orientation() const override { return m_orientation; }
90+ QPoint position() const override { return m_position; }
91+ uint currentModeIndex() const override { return m_currentModeIndex; }
92+ bool isActive() const override { return m_active; }
93+
94+ QQmlListProperty<qtmir::ScreenMode> availableModes() override {
95+ return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
96+ }
97+
98+ void setActive(bool active) override {
99+ if (m_active != active) {
100+ m_active = active;
101+ Q_EMIT activeChanged(m_active);
102+ }
103+ }
104+
105+ QScreen* qscreen() const override {
106+ if (qGuiApp->topLevelWindows().count() > 0) {
107+ return qGuiApp->topLevelWindows()[0]->screen();
108+ }
109+ return qGuiApp->primaryScreen();
110+ }
111+
112+ qtmir::ScreenConfiguration *beginConfiguration() const override {
113+ auto config = new qtmir::ScreenConfiguration;
114+ config->valid = true;
115+ config->id = m_id;
116+ config->used = m_used;
117+ config->topLeft = m_position;
118+ config->currentModeIndex = m_currentModeIndex;
119+ config->powerMode = m_powerMode;
120+ config->scale = m_scale;
121+ config->formFactor = m_formFactor;
122+ return config;
123+ }
124+
125+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override {
126+ m_used = configuration->used;
127+ m_position = configuration->topLeft;
128+ m_currentModeIndex = configuration->currentModeIndex;
129+ m_powerMode = configuration->powerMode;
130+ m_scale = configuration->scale;
131+ m_formFactor = configuration->formFactor;
132+ return true;
133+ }
134+
135+Q_SIGNALS:
136+ void outputTypeNameChanged();
137+
138+public:
139+ qtmir::OutputId m_id{0};
140+ bool m_active{false};
141+ bool m_used{true};
142+ QString m_name;
143+ qtmir::OutputTypes m_outputType{qtmir::Unknown};
144+ MirPowerMode m_powerMode{mir_power_mode_on};
145+ Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
146+ float m_scale{1.0};
147+ qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
148+ QPoint m_position;
149+ uint m_currentModeIndex{0};
150+ QList<qtmir::ScreenMode*> m_sizes;
151+ QSizeF m_physicalSize;
152+
153+ QPointer<QWindow> m_connectedWindow;
154+};
155+}
156+
157+MockScreens::MockScreens()
158+{
159+ bool ok = false;
160+ int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
161+ if (!ok) screenCount = 1;
162+ QPoint lastPoint(0,0);
163+ for (int i = 0; i < screenCount; ++i) {
164+ auto screen = new MockScreen();
165+ screen->m_id = qtmir::OutputId{i};
166+ screen->m_active = i == 0;
167+ screen->m_name = QString("Monitor %1").arg(i);
168+ screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
169+ screen->m_currentModeIndex = 0;
170+ m_mocks.append(screen);
171+
172+ lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
173+ }
174+}
175+
176+MockScreens::~MockScreens()
177+{
178+ qDeleteAll(m_mocks);
179+ m_mocks.clear();
180+}
181+
182+QVector<qtmir::Screen *> MockScreens::screens() const
183+{
184+ return m_mocks;
185+}
186+
187+qtmir::Screen *MockScreens::activeScreen() const
188+{
189+ Q_FOREACH(auto screen, m_mocks) {
190+ if (screen->isActive()) return screen;
191+ }
192+ return nullptr;
193+}
194+
195+QSharedPointer<MockScreens> MockScreens::instance()
196+{
197+ if (!m_screens) {
198+ QSharedPointer<MockScreens> screens(new MockScreens());
199+ m_screens = screens.toWeakRef();
200+ return screens;
201+ } else {
202+ return m_screens.lock();
203+ }
204+}
205+
206+void MockScreens::connectWindow(ScreenWindow *w)
207+{
208+ ConcreteScreen* screen = w->screenWrapper();
209+ if (!screen) return;
210+
211+ auto mockScreen = qobject_cast<MockScreen*>(screen->wrapped());
212+ if (mockScreen) {
213+ mockScreen->connectToWindow(w);
214+ }
215+}
216+
217+#include "MockScreens.moc"
tests/mocks/WindowManager/MockScreens.hnew file+54
@@ -0,0 +1,54 @@
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 MOCK_SCREENS_H
18+#define MOCK_SCREENS_H
19+
20+#include <QAbstractListModel>
21+#include <QSharedPointer>
22+
23+#include <qtmir/screens.h>
24+
25+namespace qtmir
26+{
27+class Screens;
28+}
29+
30+class ConcreteScreen;
31+class ScreenWindow;
32+
33+class MockScreens : public qtmir::Screens
34+{
35+ Q_OBJECT
36+public:
37+ MockScreens();
38+ ~MockScreens();
39+
40+ QVector<qtmir::Screen*> screens() const override;
41+
42+ qtmir::Screen *activeScreen() const override;
43+
44+ static QSharedPointer<MockScreens> instance();
45+
46+public Q_SLOTS:
47+ void connectWindow(ScreenWindow *w);
48+
49+private:
50+ QVector<qtmir::Screen*> m_mocks;
51+};
52+
53+
54+#endif // MOCK_SCREENS_H
tests/mocks/WindowManager/MockScreensConfiguration.cppnew file+47
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ScreensConfiguration.h"
18+#include "Screen.h"
19+#include "Workspace.h"
20+#include "WorkspaceManager.h"
21+
22+namespace
23+{
24+const int DefaultWorkspacesCount = 2;
25+QHash<QString, int> screensConfig;
26+}
27+
28+ScreensConfiguration::ScreensConfiguration()
29+{
30+}
31+
32+ScreensConfiguration::~ScreensConfiguration()
33+{
34+}
35+
36+void ScreensConfiguration::load(Screen *screen)
37+{
38+ int workspaces = screensConfig.value(screen->name(), DefaultWorkspacesCount);
39+ for (int i = 0; i < workspaces; i++) {
40+ WorkspaceManager::instance()->createWorkspace()->assign(screen->workspaces());
41+ }
42+}
43+
44+void ScreensConfiguration::save(Screen *screen)
45+{
46+ screensConfig[screen->name()] = screen->workspaces()->rowCount();
47+}
tests/mocks/WindowManager/WindowManagementPolicy.cppnew file+114
@@ -0,0 +1,114 @@
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()
22+ : m_dummyWorkspace(std::shared_ptr<miral::Workspace>())
23+{
24+ wmPolicyInterface = this;
25+ m_activeWorkspace = m_dummyWorkspace;
26+}
27+
28+WindowManagementPolicy *WindowManagementPolicy::instance()
29+{
30+ static WindowManagementPolicy* wmPolicy(new WindowManagementPolicy);
31+ return wmPolicy;
32+}
33+
34+std::shared_ptr<miral::Workspace> WindowManagementPolicy::createWorkspace()
35+{
36+ auto workspace = std::make_shared<miral::Workspace>();
37+ m_workspaces.insert(workspace);
38+
39+ if (m_activeWorkspace.lock() == m_dummyWorkspace) {
40+ moveWorkspaceContentToWorkspace(workspace, m_dummyWorkspace);
41+ m_activeWorkspace = workspace;
42+ }
43+ return workspace;
44+}
45+
46+void WindowManagementPolicy::releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
47+{
48+ auto iter = m_workspaces.find(workspace);
49+ if (iter != m_workspaces.end()) m_workspaces.erase(iter);
50+
51+ if (m_workspaces.size() == 0) {
52+ m_activeWorkspace = m_dummyWorkspace;
53+ moveWorkspaceContentToWorkspace(m_dummyWorkspace, workspace);
54+ }
55+}
56+
57+void WindowManagementPolicy::setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
58+{
59+ if (m_activeWorkspace.lock() == workspace)
60+ return;
61+ m_activeWorkspace = workspace ? workspace : m_dummyWorkspace;
62+}
63+
64+void WindowManagementPolicy::addWindow(const miral::Window &window)
65+{
66+ Q_EMIT windowAdded(window);
67+
68+ auto activeWorkspace = m_activeWorkspace.lock();
69+ if (activeWorkspace) {
70+ m_windows.insert(activeWorkspace, window);
71+
72+ Q_EMIT windowsAddedToWorkspace(activeWorkspace, {window});
73+ }
74+}
75+
76+void WindowManagementPolicy::forEachWindowInWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::function<void(const miral::Window &)> &callback)
77+{
78+ WorkspaceWindows::iterator i = m_windows.find(workspace);
79+ while (i != m_windows.end() && i.key() == workspace) {
80+ callback(i.value());
81+ ++i;
82+ }
83+}
84+
85+void WindowManagementPolicy::moveWindowToWorkspace(const miral::Window &window, const std::shared_ptr<miral::Workspace> &workspace)
86+{
87+ auto from = m_windows.key(window);
88+ if (from) {
89+ auto iter = m_windows.find(from, window);
90+ Q_EMIT windowsAboutToBeRemovedFromWorkspace(from, { window });
91+ m_windows.erase(iter);
92+ }
93+
94+ m_windows.insert(workspace, window);
95+ Q_EMIT windowsAddedToWorkspace(workspace, { window });
96+}
97+
98+void WindowManagementPolicy::moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &to, const std::shared_ptr<miral::Workspace> &from)
99+{
100+ std::vector<miral::Window> windows;
101+
102+ WorkspaceWindows::iterator i = m_windows.find(from);
103+ while (i != m_windows.end() && i.key() == from) {
104+ windows.push_back(i.value());
105+ ++i;
106+ }
107+ Q_EMIT windowsAboutToBeRemovedFromWorkspace(from, windows);
108+ m_windows.remove(from);
109+
110+ Q_FOREACH(miral::Window window, windows) {
111+ m_windows.insert(to, window);
112+ }
113+ Q_EMIT windowsAddedToWorkspace(to, windows);
114+}
tests/mocks/WindowManager/WindowManagementPolicy.hnew file+73
@@ -0,0 +1,73 @@
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 "wmpolicyinterface.h"
21+
22+#include <QObject>
23+#include <QMultiMap>
24+#include <QVector>
25+
26+#include <miral/window.h>
27+#include <memory>
28+#include <unordered_set>
29+
30+namespace miral {
31+class Workspace {};
32+}
33+
34+// A Fake window management policy for the mock.
35+class Q_DECL_EXPORT WindowManagementPolicy : public QObject,
36+ public WMPolicyInterface
37+{
38+ Q_OBJECT
39+public:
40+ WindowManagementPolicy();
41+
42+ // for use in mocks
43+ static WindowManagementPolicy *instance();
44+
45+ // From WMPolicyInterface
46+ std::shared_ptr<miral::Workspace> createWorkspace() override;
47+ void releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
48+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
49+
50+ void addWindow(const miral::Window& window);
51+
52+ void forEachWindowInWorkspace(std::shared_ptr<miral::Workspace> const &workspace,
53+ std::function<void(miral::Window const&)> const &callback);
54+
55+ void moveWindowToWorkspace(const miral::Window &window, const std::shared_ptr<miral::Workspace> &workspace);
56+
57+ void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &to,
58+ const std::shared_ptr<miral::Workspace> &from);
59+
60+Q_SIGNALS:
61+ void windowAdded(const miral::Window& window);
62+ void windowsAddedToWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
63+ void windowsAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
64+
65+private:
66+ std::weak_ptr<miral::Workspace> m_activeWorkspace;
67+ std::shared_ptr<miral::Workspace> m_dummyWorkspace;
68+ std::unordered_set<std::shared_ptr<miral::Workspace>> m_workspaces;
69+
70+ typedef QMultiMap<std::shared_ptr<miral::Workspace>, miral::Window> WorkspaceWindows;
71+ WorkspaceWindows m_windows;
72+};
73+#endif // UNITY_WINDOWMANAGEMENTPOLICY_H
tests/mocks/WindowManager/WindowManagerPlugin.cppnew file+84
@@ -0,0 +1,84 @@
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 "MockScreens.h"
20+#include "MockScreenWindow.h"
21+#include "Screen.h"
22+#include "ScreenAttached.h"
23+#include "Screens.h"
24+#include "TopLevelWindowModel.h"
25+#include "Window.h"
26+#include "WorkspaceManager.h"
27+#include "Workspace.h"
28+#include "WorkspaceModel.h"
29+#include "WindowManagementPolicy.h"
30+#include "WindowManagerObjects.h"
31+#include "ScreensConfiguration.h"
32+
33+#include <QtQml>
34+
35+static const QString notInstantiatable = QStringLiteral("Not instantiatable");
36+
37+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
38+{
39+ Q_UNUSED(engine)
40+ Q_UNUSED(scriptEngine)
41+ return WorkspaceManager::instance();
42+}
43+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
44+ Q_UNUSED(engine);
45+ Q_UNUSED(scriptEngine);
46+ return ConcreteScreens::self();
47+}
48+QObject* objectsSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
49+ Q_UNUSED(engine);
50+ Q_UNUSED(scriptEngine);
51+ return WindowManagerObjects::instance();
52+}
53+
54+void WindowManagerPlugin::registerTypes(const char *uri)
55+{
56+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
57+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", notInstantiatable);
58+ qmlRegisterSingletonType<ConcreteScreens>(uri, 1, 0, "Screens", screensSingleton);
59+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", notInstantiatable);
60+ qmlRegisterSingletonType<WindowManagerObjects>(uri, 1, 0, "WindowManagerObjects", objectsSingleton);
61+
62+ qRegisterMetaType<ConcreteScreen*>("ConcreteScreen*");
63+ qRegisterMetaType<ProxyScreens*>("ProxyScreens*");
64+ qRegisterMetaType<Workspace*>("Workspace*");
65+ qRegisterMetaType<TopLevelWindowModel*>("TopLevelWindowModel*");
66+
67+ qRegisterMetaType<Window*>("Window*");
68+ qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
69+
70+ qmlRegisterType<MockScreenWindow>(uri, 1, 0, "ScreenWindow");
71+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
72+
73+ qmlRegisterUncreatableType<WMScreen>(uri, 1, 0, "WMScreen", notInstantiatable);
74+}
75+
76+void WindowManagerPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
77+{
78+ QQmlExtensionPlugin::initializeEngine(engine, uri);
79+
80+ // Make sure we've initialized the wm policy.
81+ WindowManagementPolicy::instance();
82+ // Create Screens
83+ new ConcreteScreens(MockScreens::instance(), new ScreensConfiguration());
84+}
tests/mocks/WindowManager/WindowManagerPlugin.hnew file+33
@@ -0,0 +1,33 @@
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+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
31+};
32+
33+#endif // WINDOWMANAGER_PLUGIN_H
tests/mocks/WindowManager/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module WindowManager
2+plugin MockWindowManager-qml
tests/plugins/WindowManager/CMakeLists.txt+5−1
@@ -2,6 +2,7 @@ include_directories(
22 ${CMAKE_SOURCE_DIR}/plugins/WindowManager
33 ${CMAKE_CURRENT_BINARY_DIR}
44 ${CMAKE_SOURCE_DIR}/tests/mocks
5+ ${libunity8-private_SOURCE_DIR}
56 )
67
78add_executable(TopLevelWindowModelTestExec
@@ -19,7 +20,10 @@ add_executable(TopLevelWindowModelTestExec
1920 )
2021qt5_use_modules(TopLevelWindowModelTestExec Test Core Gui Qml Quick)
2122
22−target_link_libraries(TopLevelWindowModelTestExec windowmanager-qml)
23+target_link_libraries(TopLevelWindowModelTestExec
24+ windowmanager-qml
25+ unity8-private
26+ )
2327
2428install(TARGETS TopLevelWindowModelTestExec
2529 DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/plugins/WindowManager"
tests/plugins/WindowManager/UnityApplicationMocks.h+25
@@ -25,6 +25,8 @@
2525// from tests/mocks
2626#include <Unity/Application/MirSurfaceListModel.h>
2727
28+#include "wmpolicyinterface.h"
29+
2830using namespace unity::shell::application;
2931
3032class MirSurface : public MirSurfaceInterface
@@ -87,6 +89,13 @@ class SurfaceManager : public SurfaceManagerInterface
8789 Q_OBJECT
8890
8991public:
92+ void forEachSurfaceInWorkspace(const std::shared_ptr<miral::Workspace>&,
93+ const std::function<void(unity::shell::application::MirSurfaceInterface*)>&) override {}
94+ void moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface*,
95+ const std::shared_ptr<miral::Workspace>&) override {}
96+ void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace>&,
97+ const std::shared_ptr<miral::Workspace>&) override {}
98+
9099 void raise(MirSurfaceInterface *) override {}
91100 void activate(MirSurfaceInterface *) override {}
92101};
@@ -200,4 +209,20 @@ private:
200209 QList<Application*> m_applications;
201210};
202211
212+namespace miral {
213+class Workspace {};
214+}
215+
216+class WindowManagementPolicy : public WMPolicyInterface
217+{
218+public:
219+ WindowManagementPolicy() {}
220+
221+ std::shared_ptr<miral::Workspace> createWorkspace() override { return std::make_shared<miral::Workspace>(); }
222+
223+ void releaseWorkspace(const std::shared_ptr<miral::Workspace>&) override {}
224+
225+ void setActiveWorkspace(const std::shared_ptr<miral::Workspace>&) override {}
226+};
227+
203228#endif // UNITYAPPLICATIONMOCKS_H
tests/plugins/WindowManager/tst_TopLevelWindowModel.cpp+20−8
@@ -19,8 +19,13 @@
1919// WindowManager plugin
2020#include <TopLevelWindowModel.h>
2121#include <Window.h>
22+#include <WindowManagerObjects.h>
23+#include <Workspace.h>
24+#include <WorkspaceManager.h>
2225
2326#include "UnityApplicationMocks.h"
27+#include "wmpolicyinterface.h"
28+
2429
2530class tst_TopLevelWindowModel : public QObject
2631{
@@ -34,6 +39,7 @@ private Q_SLOTS:
3439 void secondSurfaceIsHidden();
3540
3641private:
42+ Workspace* workspace{nullptr};
3743 ApplicationManager *applicationManager{nullptr};
3844 SurfaceManager *surfaceManager{nullptr};
3945 TopLevelWindowModel *topLevelWindowModel{nullptr};
@@ -41,24 +47,30 @@ private:
4147
4248void tst_TopLevelWindowModel::init()
4349{
50+ wmPolicyInterface = new WindowManagementPolicy();
51+
4452 applicationManager = new ApplicationManager;
4553 surfaceManager = new SurfaceManager;
54+ WindowManagerObjects::instance()->setApplicationManager(applicationManager);
55+ WindowManagerObjects::instance()->setSurfaceManager(surfaceManager);
4656
47− topLevelWindowModel = new TopLevelWindowModel;
48− topLevelWindowModel->setApplicationManager(applicationManager);
49− topLevelWindowModel->setSurfaceManager(surfaceManager);
57+ workspace = WorkspaceManager::instance()->createWorkspace();
58+ topLevelWindowModel = workspace->windowModel();
5059}
5160
5261void tst_TopLevelWindowModel::cleanup()
5362{
54− delete topLevelWindowModel;
55− topLevelWindowModel = nullptr;
63+ delete workspace;
64+ workspace = nullptr;
5665
5766 delete surfaceManager;
5867 surfaceManager = nullptr;
5968
6069 delete applicationManager;
6170 applicationManager = nullptr;
71+
72+ delete wmPolicyInterface;
73+ wmPolicyInterface = nullptr;
6274}
6375
6476void tst_TopLevelWindowModel::singleSurfaceStartsHidden()
@@ -73,7 +85,7 @@ void tst_TopLevelWindowModel::singleSurfaceStartsHidden()
7385 auto surface = new MirSurface;
7486 surface->m_state = Mir::HiddenState;
7587 application->m_surfaceList.addSurface(surface);
76− Q_EMIT surfaceManager->surfaceCreated(surface);
88+ Q_EMIT surfaceManager->surfacesAddedToWorkspace(workspace->workspace(), {surface});
7789
7890 QCOMPARE(topLevelWindowModel->rowCount(), 1);
7991 // not showing the surface as it's still hidden
@@ -97,7 +109,7 @@ void tst_TopLevelWindowModel::secondSurfaceIsHidden()
97109
98110 auto firstSurface = new MirSurface;
99111 application->m_surfaceList.addSurface(firstSurface);
100− Q_EMIT surfaceManager->surfaceCreated(firstSurface);
112+ Q_EMIT surfaceManager->surfacesAddedToWorkspace(workspace->workspace(), {firstSurface});
101113
102114 QCOMPARE(topLevelWindowModel->rowCount(), 1);
103115 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)firstSurface);
@@ -105,7 +117,7 @@ void tst_TopLevelWindowModel::secondSurfaceIsHidden()
105117 auto secondSurface = new MirSurface;
106118 secondSurface->m_state = Mir::HiddenState;
107119 application->m_surfaceList.addSurface(secondSurface);
108− Q_EMIT surfaceManager->surfaceCreated(secondSurface);
120+ Q_EMIT surfaceManager->surfacesAddedToWorkspace(workspace->workspace(), {secondSurface});
109121
110122 // still only the first surface is exposed by TopLevelWindowModel
111123 QCOMPARE(topLevelWindowModel->rowCount(), 1);
tests/qmltests/ApplicationMenuDataLoader.qml+1−4
@@ -22,11 +22,8 @@ import Unity.Indicators 0.1 as Indicators
2222
2323Object {
2424
25− property alias surfaceManager: sMgrHandler.target
26−
2725 Connections {
28− id: sMgrHandler
29− target: null
26+ target: SurfaceManager
3027 onSurfaceCreated: {
3128 var fakeMenuPath = "/" + surface.persistentId.replace(/\W+/g, "");
3229
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+2−2
@@ -24,6 +24,7 @@ import Unity.Test 0.1
2424import Utils 0.1
2525
2626import "../../../qml/ApplicationMenus"
27+import "../../../qml/Components/PanelState"
2728import ".."
2829
2930Item {
@@ -42,10 +43,8 @@ Item {
4243 value: false
4344 }
4445
45− SurfaceManager { id: sMgr }
4646 ApplicationMenuDataLoader {
4747 id: appMenuData
48− surfaceManager: sMgr
4948 }
5049
5150 Rectangle {
@@ -67,6 +66,7 @@ Item {
6766 id: menuBackend
6867 modelData: appMenuData.generateTestData(10,5,2,3)
6968 }
69+ panelState: PanelState {}
7070 }
7171 }
7272
tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+2
@@ -24,6 +24,7 @@ import Unity.Test 0.1
2424import Utils 0.1
2525
2626import "../../../qml/ApplicationMenus"
27+import "../../../qml/Components/PanelState"
2728import ".."
2829
2930Item {
@@ -59,6 +60,7 @@ Item {
5960 }}
6061 ]
6162 }
63+ panelState: PanelState {}
6264 }
6365 }
6466
tests/qmltests/CMakeLists.txt+1
@@ -5,6 +5,7 @@ add_unity8_qmltest(. OrientedShell)
55add_unity8_qmltest(. DisabledScreenNotice)
66add_unity8_qmltest(. Shell)
77add_unity8_qmltest(. ShellWithPin)
8+add_unity8_qmltest(. ShellApplication)
89add_unity8_qmltest(. DeviceConfiguration)
910add_unity8_qmltest_data(. EdgeBarrierControls)
1011add_unity8_qmltest_data(. ApplicationMenuDataLoader)
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+18−16
@@ -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: {
@@ -99,6 +99,8 @@ PanelTest {
9999 model: root.indicatorsModel
100100 hides: [ panel.applicationMenus ]
101101 }
102+
103+ panelState: PanelState {}
102104 }
103105 }
104106 }
@@ -153,7 +155,7 @@ PanelTest {
153155 Layout.fillWidth: true
154156 CheckBox {
155157 id: windowControlsCB
156− onClicked: PanelState.decorationsVisible = checked
158+ onClicked: panelState.decorationsVisible = checked
157159 }
158160 Label {
159161 text: "Show window decorations"
@@ -164,7 +166,7 @@ PanelTest {
164166 RowLayout {
165167 Layout.fillWidth: true
166168 CheckBox {
167− onClicked: PanelState.title = checked ? "Fake window title" : ""
169+ onClicked: panelState.title = checked ? "Fake window title" : ""
168170 }
169171 Label {
170172 text: "Show fake window title"
@@ -250,7 +252,7 @@ PanelTest {
250252
251253 SignalSpy {
252254 id: windowControlButtonsSpy
253− target: PanelState
255+ target: panelState
254256 signalName: "closeClicked"
255257 }
256258
@@ -260,8 +262,8 @@ PanelTest {
260262 panel.fullscreenMode = false;
261263 callManager.foregroundCall = null;
262264
263− PanelState.title = "";
264− PanelState.decorationsVisible = false;
265+ panelState.title = "";
266+ panelState.decorationsVisible = false;
265267
266268 // Wait for the indicators to get into position.
267269 // (switches between normal and fullscreen modes are animated)
@@ -456,7 +458,7 @@ PanelTest {
456458 }
457459
458460 function test_hint(data) {
459− PanelState.title = "Fake Title"
461+ panelState.title = "Fake Title"
460462 panel.fullscreenMode = data.fullscreen;
461463 callManager.foregroundCall = data.call;
462464
@@ -498,7 +500,7 @@ PanelTest {
498500 // menus, first by running the hint animation, then after dragging down will
499501 // expose more of the panel. Releasing the touch will complete the show.
500502 function test_drag_applicationMenu_down_shows_menu(data) {
501− PanelState.title = "Fake Title";
503+ panelState.title = "Fake Title";
502504 panel.fullscreenMode = data.fullscreen;
503505 callManager.foregroundCall = data.call;
504506
@@ -589,7 +591,7 @@ PanelTest {
589591 }
590592
591593 function test_darkenedAreaEatsAllApplicationMenuEvents() {
592− PanelState.title = "Fake Title"
594+ panelState.title = "Fake Title"
593595
594596 // The center of the area not covered by the indicators menu
595597 // Ie, the visible darkened area behind the menu
@@ -710,7 +712,7 @@ PanelTest {
710712 var windowControlArea = findChild(panel, "windowControlArea");
711713 verify(windowControlArea, "Window control area should have been created in windowed mode")
712714
713− PanelState.decorationsVisible = true;
715+ panelState.decorationsVisible = true;
714716 // click in very topleft corner and verify the close button got clicked too
715717 mouseMove(panel, 0, 0);
716718 mouseClick(panel, 0, 0, undefined /*button*/, undefined /*modifiers*/, 100 /*short delay*/);
@@ -773,7 +775,7 @@ PanelTest {
773775 }
774776
775777 function test_stagedApplicationMenuBarShowOnMouseHover() {
776− PanelState.title = "Fake Title";
778+ panelState.title = "Fake Title";
777779 panel.mode = "staged";
778780 mouseEmulation.checked = false;
779781
@@ -791,7 +793,7 @@ PanelTest {
791793 }
792794
793795 function test_windowedApplicationMenuShowOnMouseHoverWhenDecorationsShown() {
794− PanelState.title = "Fake Title";
796+ panelState.title = "Fake Title";
795797 panel.mode = "windowed";
796798 mouseEmulation.checked = false;
797799
@@ -807,7 +809,7 @@ PanelTest {
807809 tryCompare(appTitle, "visible", true, undefined, "App title should still be visible on mouse hover when panel decorations are not visible");
808810 tryCompare(appMenuBar, "visible", false, undefined, "App menu bar should be visible on mouse hover when panel decorations are not visible");
809811
810− PanelState.decorationsVisible = true;
812+ panelState.decorationsVisible = true;
811813
812814 tryCompare(appTitle, "visible", false, undefined, "App title should still be visible on mouse hover when panel decorations are visible");
813815 tryCompare(appMenuBar, "visible", true, undefined, "App menu bar should be visible on mouse hover when panel decorations not visible");
@@ -855,7 +857,7 @@ PanelTest {
855857
856858 var indicatorsBar = findChild(panel.applicationMenus, "indicatorsBar");
857859
858− PanelState.title = "Fake Title"
860+ panelState.title = "Fake Title"
859861 pullDownApplicationsMenu(0 /*xPos*/);
860862 compare(aboutToShowCalledSpy.count, 1);
861863
@@ -888,7 +890,7 @@ PanelTest {
888890
889891 var indicatorsBar = findChild(panel.applicationMenus, "indicatorsBar");
890892
891− PanelState.title = "Fake Title"
893+ panelState.title = "Fake Title"
892894 pullDownApplicationsMenu(0 /*xPos*/);
893895
894896 tryCompare(indicatorsBar, "currentItemIndex", 0);
tests/qmltests/Stage/tst_ApplicationWindow.qml+10−44
@@ -37,8 +37,6 @@ Rectangle {
3737 }
3838 property QtObject fakeApplication: null
3939
40− SurfaceManager{}
41−
4240 Loader {
4341 id: applicationWindowLoader
4442 focus: true
@@ -247,13 +245,12 @@ Rectangle {
247245 function test_showSplashUntilAppFullyInit_data() {
248246 return [
249247 {tag: "state=Running then create surface", swapInitOrder: false},
250−
251248 {tag: "create surface then state=Running", swapInitOrder: true},
252249 ]
253250 }
254251
255252 function test_showSplashUntilAppFullyInit() {
256− verify(stateGroup.state === "splashScreen");
253+ verify(stateGroup.state === "splash");
257254
258255 if (data.swapInitOrder) {
259256 surfaceCheckbox.checked = true;
@@ -261,7 +258,7 @@ Rectangle {
261258 setApplicationState(appRunning);
262259 }
263260
264− verify(stateGroup.state === "splashScreen");
261+ verify(stateGroup.state === "splash");
265262
266263 if (data.swapInitOrder) {
267264 setApplicationState(appRunning);
@@ -286,27 +283,8 @@ Rectangle {
286283 waitUntilTransitionsEnd(stateGroup);
287284 }
288285
289− function test_killedAppShowsScreenshot() {
290− surfaceCheckbox.checked = true;
291− setApplicationState(appRunning);
292− tryCompare(stateGroup, "state", "surface");
293−
294− setApplicationState(appSuspended);
295−
296− verify(stateGroup.state === "surface");
297− verify(fakeApplication.surface !== null);
298−
299− // kill it!
300− surfaceCheckbox.checked = false;
301− setApplicationState(appStopped);
302−
303− tryCompare(stateGroup, "state", "screenshot");
304− tryCompare(fakeApplication.surfaceList, "count", 0);
305− }
306−
307286 function test_restartApp() {
308− var screenshotImage = findChild(applicationWindow, "screenshotImage");
309−
287+ tryCompare(stateGroup, "state", "splash");
310288 surfaceCheckbox.checked = true;
311289 setApplicationState(appRunning);
312290 tryCompare(stateGroup, "state", "surface");
@@ -318,26 +296,23 @@ Rectangle {
318296 surfaceCheckbox.checked = false;
319297 setApplicationState(appStopped);
320298
321− tryCompare(stateGroup, "state", "screenshot");
322299 waitUntilTransitionsEnd(stateGroup);
323− tryCompare(applicationWindow, "surface", null);
300+ tryCompare(stateGroup, "state", "surface");
324301
325302 // and restart it
326303 setApplicationState(appStarting);
327304
328305 waitUntilTransitionsEnd(stateGroup);
329− verify(stateGroup.state === "screenshot");
330− verify(applicationWindow.surface === null);
306+ verify(stateGroup.state === "surface");
331307
332308 setApplicationState(appRunning);
333309
334310 waitUntilTransitionsEnd(stateGroup);
335− verify(stateGroup.state === "screenshot");
311+ verify(stateGroup.state === "surface");
336312
337313 surfaceCheckbox.checked = true;
338314
339315 tryCompare(stateGroup, "state", "surface");
340− tryCompare(screenshotImage, "status", Image.Null);
341316 }
342317
343318 function test_appCrashed() {
@@ -345,13 +320,15 @@ Rectangle {
345320 setApplicationState(appRunning);
346321 tryCompare(stateGroup, "state", "surface");
347322 waitUntilTransitionsEnd(stateGroup);
323+ var surface = applicationWindow.surface;
348324
349325 // oh, it crashed...
350326 surfaceCheckbox.checked = false;
351327 setApplicationState(appStopped);
352328
353− tryCompare(stateGroup, "state", "screenshot");
354− tryCompare(applicationWindow, "surface", null);
329+ waitUntilTransitionsEnd(stateGroup);
330+ tryCompare(stateGroup, "state", "surface");
331+ tryCompare(applicationWindow, "surface", surface);
355332 }
356333
357334 function test_keepSurfaceWhileInvisible() {
@@ -395,17 +372,6 @@ Rectangle {
395372 verify(surfaceItem.touchReleaseCount === 1);
396373 }
397374
398− function test_showNothingOnSuddenSurfaceLoss() {
399− surfaceCheckbox.checked = true;
400− setApplicationState(appRunning);
401− tryCompare(stateGroup, "state", "surface");
402− waitUntilTransitionsEnd(stateGroup);
403−
404− applicationWindow.surface = null;
405−
406− tryCompare(stateGroup, "state", "void");
407− }
408−
409375 function test_surfaceActiveFocusFollowsAppWindowInterative() {
410376 applicationWindow.interactive = false;
411377 applicationWindow.interactive = 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+6−12
@@ -63,17 +63,11 @@ Item {
6363 }
6464 }
6565
66− SurfaceManager { id: sMgr }
6766 ApplicationMenuDataLoader {
6867 id: appMenuData
69− surfaceManager: sMgr
7068 }
7169
72− TopLevelWindowModel {
73− id: topSurfaceList
74− applicationManager: ApplicationManager
75− surfaceManager: sMgr
76− }
70+ readonly property var topSurfaceList: WorkspaceManager.activeWorkspace.windowModel
7771
7872 Loader {
7973 id: stageLoader
@@ -102,6 +96,7 @@ Item {
10296 topLevelSurfaceList: topSurfaceList
10397 interactive: true
10498 mode: "windowed"
99+ panelState: PanelState {}
105100 }
106101 }
107102 }
@@ -173,6 +168,7 @@ Item {
173168
174169 stage: stageLoader.status === Loader.Ready ? stageLoader.item : null
175170 topLevelSurfaceList: topSurfaceList
171+ property var panelState: stage ? stage.panelState : null
176172
177173 function init() {
178174 // wait until unity8-dash is up and running.
@@ -555,8 +551,6 @@ Item {
555551 var gmailDelegate = startApplication("gmail-webapp");
556552 verify(gmailDelegate);
557553
558− wait(2000)
559−
560554 var gmailMaximizeButton = findChild(gmailDelegate, "maximizeWindowButton");
561555 verify(gmailMaximizeButton);
562556 mouseClick(gmailMaximizeButton);
@@ -631,19 +625,19 @@ Item {
631625 maximizeDelegate(facebookAppDelegate);
632626
633627 // verify the drop shadow is still not visible
634− verify(PanelState.dropShadow == false);
628+ verify(panelState.dropShadow == false);
635629
636630 // start a foreground app, not maximized
637631 var dialerAppDelegate = startApplication("dialer-app");
638632
639633 // verify the drop shadow becomes visible
640− tryCompareFunction(function() { return PanelState.dropShadow; }, true);
634+ tryCompareFunction(function() { return panelState.dropShadow; }, true);
641635
642636 // close the maximized app
643637 ApplicationManager.stopApplication("facebook-webapp");
644638
645639 // verify the drop shadow is gone
646− tryCompare(PanelState, "dropShadow", false);
640+ tryCompare(panelState, "dropShadow", false);
647641 }
648642
649643 function test_threeFingerTapShowsWindowControls_data() {
tests/qmltests/Stage/tst_PhoneStage.qml+6−7
@@ -19,6 +19,7 @@ import QtTest 1.0
1919import Unity.Test 0.1 as UT
2020import ".."
2121import "../../../qml/Components"
22+import "../../../qml/Components/PanelState"
2223import "../../../qml/Stage"
2324import Ubuntu.Components 1.3
2425import Unity.Application 0.1
@@ -31,10 +32,10 @@ Item {
3132
3233 property var greeter: { fullyShown: true }
3334
34− SurfaceManager { id: sMgr }
35+ readonly property var topLevelSurfaceList: WorkspaceManager.activeWorkspace.windowModel
36+
3537 ApplicationMenuDataLoader {
3638 id: appMenuData
37− surfaceManager: sMgr
3839 }
3940
4041 Stage {
@@ -47,14 +48,12 @@ Item {
4748 orientations: Orientations {}
4849 applicationManager: ApplicationManager
4950 mode: "staged"
50− topLevelSurfaceList: TopLevelWindowModel {
51− id: topLevelSurfaceList
52− applicationManager: ApplicationManager
53− surfaceManager: sMgr
54− }
51+ topLevelSurfaceList: root.topLevelSurfaceList
52+
5553 Component.onCompleted: {
5654 ApplicationManager.startApplication("unity8-dash");
5755 }
56+ panelState: PanelState {}
5857 }
5958
6059 Flickable {
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+41−43
@@ -35,10 +35,10 @@ Rectangle {
3535
3636 property var greeter: { fullyShown: true }
3737
38− SurfaceManager { id: sMgr }
38+ readonly property var topLevelSurfaceList: WorkspaceManager.activeWorkspace.windowModel
39+
3940 ApplicationMenuDataLoader {
4041 id: appMenuData
41− surfaceManager: sMgr
4242 }
4343
4444 Stage {
@@ -56,12 +56,10 @@ Rectangle {
5656 focus: true
5757 mode: "stagedWithSideStage"
5858 applicationManager: ApplicationManager
59− topLevelSurfaceList: TopLevelWindowModel {
60− id: topLevelSurfaceList
61− applicationManager: ApplicationManager
62− surfaceManager: sMgr
63− }
59+ topLevelSurfaceList: root.topLevelSurfaceList
60+
6461 Component.onCompleted: {
62+ print("starting dash")
6563 ApplicationManager.startApplication("unity8-dash");
6664 }
6765 }
@@ -133,21 +131,21 @@ Rectangle {
133131 name: "TabletStage"
134132 when: windowShown
135133
136− readonly property alias topSurfaceList: stage.topLevelSurfaceList
134+ readonly property alias topLevelSurfaceList: root.topLevelSurfaceList
137135 property Item sideStage: stage ? findChild(stage, "sideStage") : null
138136
139137 function init() {
140138 stageSaver.clear();
141139
142140 ApplicationManager.startApplication("unity8-dash");
143− tryCompare(topSurfaceList, "count", 1);
144− compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
141+ tryCompare(topLevelSurfaceList, "count", 1);
142+ compare(topLevelSurfaceList.applicationAt(0).appId, "unity8-dash");
145143
146144 // this is very strange, but sometimes the test starts without
147145 // Stage components having finished loading themselves
148146 var appWindow = null
149147 while (!appWindow) {
150− appWindow = findAppWindowForSurfaceId(topSurfaceList.idAt(0));
148+ appWindow = findAppWindowForSurfaceId(topLevelSurfaceList.idAt(0));
151149 if (!appWindow) {
152150 console.log("didn't find unity8-dash appWindow in Stage. Trying again...");
153151 wait(50);
@@ -159,7 +157,7 @@ Rectangle {
159157 tryCompare(appRepeater, "count", 1);
160158 tryCompare(appRepeater.itemAt(0), "x", 0);
161159
162− waitUntilAppSurfaceShowsUp(topSurfaceList.idAt(0));
160+ waitUntilAppSurfaceShowsUp(topLevelSurfaceList.idAt(0));
163161 sideStage.hideNow()
164162 tryCompare(sideStage, "x", stage.width)
165163 }
@@ -274,7 +272,7 @@ Rectangle {
274272 function test_tappingSwitchesFocusBetweenStages() {
275273 WindowStateStorage.saveStage(dialerCheckBox.appId, ApplicationInfoInterface.SideStage)
276274
277− var webbrowserSurfaceId = topSurfaceList.nextId;
275+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
278276 webbrowserCheckBox.checked = true;
279277 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
280278 var webbrowserDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
@@ -285,7 +283,7 @@ Rectangle {
285283
286284 tryCompare(webbrowserWindow.surface, "activeFocus", true);
287285
288− var dialerSurfaceId = topSurfaceList.nextId;
286+ var dialerSurfaceId = topLevelSurfaceList.nextId;
289287 dialerCheckBox.checked = true;
290288 waitUntilAppSurfaceShowsUp(dialerSurfaceId);
291289
@@ -317,7 +315,7 @@ Rectangle {
317315 function test_closeAppInSideStage() {
318316 WindowStateStorage.saveStage(dialerCheckBox.appId, ApplicationInfoInterface.SideStage)
319317
320− var dialerSurfaceId = topSurfaceList.nextId;
318+ var dialerSurfaceId = topLevelSurfaceList.nextId;
321319 dialerCheckBox.checked = true;
322320 waitUntilAppSurfaceShowsUp(dialerSurfaceId);
323321
@@ -343,7 +341,7 @@ Rectangle {
343341 }
344342
345343 function test_suspendsAndResumesAppsInMainStage() {
346− var webbrowserSurfaceId = topSurfaceList.nextId;
344+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
347345 webbrowserCheckBox.checked = true;
348346 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
349347 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
@@ -352,7 +350,7 @@ Rectangle {
352350
353351 tryCompare(webbrowserApp, "state", ApplicationInfoInterface.Running);
354352
355− var gallerySurfaceId = topSurfaceList.nextId;
353+ var gallerySurfaceId = topLevelSurfaceList.nextId;
356354 galleryCheckBox.checked = true;
357355 waitUntilAppSurfaceShowsUp(gallerySurfaceId);
358356 var galleryApp = ApplicationManager.findApplication(galleryCheckBox.appId);
@@ -383,7 +381,7 @@ Rectangle {
383381 // launch two main stage apps
384382 // gallery will be on foreground and webbrowser on background
385383
386− var webbrowserSurfaceId = topSurfaceList.nextId;
384+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
387385 webbrowserCheckBox.checked = true;
388386 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
389387 var webbrowserDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
@@ -391,7 +389,7 @@ Rectangle {
391389 compare(webbrowserDelegate.stage, ApplicationInfoInterface.MainStage);
392390 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
393391
394− var gallerySurfaceId = topSurfaceList.nextId;
392+ var gallerySurfaceId = topLevelSurfaceList.nextId;
395393 galleryCheckBox.checked = true;
396394 waitUntilAppSurfaceShowsUp(gallerySurfaceId);
397395 var galleryApp = ApplicationManager.findApplication(galleryCheckBox.appId);
@@ -403,14 +401,14 @@ Rectangle {
403401 // then launch two side stage apps
404402 // facebook will be on foreground and dialer on background
405403
406− var dialerSurfaceId = topSurfaceList.nextId;
404+ var dialerSurfaceId = topLevelSurfaceList.nextId;
407405 dialerCheckBox.checked = true;
408406 waitUntilAppSurfaceShowsUp(dialerSurfaceId);
409407 var dialerApp = ApplicationManager.findApplication(dialerCheckBox.appId);
410408 var dialerDelegate = findChild(stage, "appDelegate_" + dialerSurfaceId);
411409 compare(dialerDelegate.stage, ApplicationInfoInterface.SideStage);
412410
413− var facebookSurfaceId = topSurfaceList.nextId;
411+ var facebookSurfaceId = topLevelSurfaceList.nextId;
414412 facebookCheckBox.checked = true;
415413 waitUntilAppSurfaceShowsUp(facebookSurfaceId);
416414 var facebookApp = ApplicationManager.findApplication(facebookCheckBox.appId);
@@ -445,14 +443,14 @@ Rectangle {
445443 function test_foregroundAppsAreSuspendedWhenStageIsSuspended() {
446444 WindowStateStorage.saveStage(dialerCheckBox.appId, ApplicationInfoInterface.SideStage)
447445
448− var webbrowserSurfaceId = topSurfaceList.nextId;
446+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
449447 webbrowserCheckBox.checked = true;
450448 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
451449 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
452450 var webbrowserDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
453451 compare(webbrowserDelegate.stage, ApplicationInfoInterface.MainStage);
454452
455− var dialerSurfaceId = topSurfaceList.nextId;
453+ var dialerSurfaceId = topLevelSurfaceList.nextId;
456454 dialerCheckBox.checked = true;
457455 waitUntilAppSurfaceShowsUp(dialerSurfaceId);
458456 var dialerApp = ApplicationManager.findApplication(dialerCheckBox.appId);
@@ -526,7 +524,7 @@ Rectangle {
526524 tryCompare(stagesPriv, "mainStageAppId", "unity8-dash");
527525 tryCompare(stagesPriv, "sideStageAppId", "");
528526
529− var appSurfaceId = topSurfaceList.nextId;
527+ var appSurfaceId = topLevelSurfaceList.nextId;
530528 var app = ApplicationManager.startApplication(data.appId);
531529 waitUntilAppSurfaceShowsUp(appSurfaceId);
532530
@@ -550,7 +548,7 @@ Rectangle {
550548 tryCompare(stagesPriv, "mainStageAppId", "unity8-dash");
551549 tryCompare(stagesPriv, "sideStageAppId", "");
552550
553− var webbrowserSurfaceId = topSurfaceList.nextId;
551+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
554552 webbrowserCheckBox.checked = true;
555553 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
556554
@@ -575,7 +573,7 @@ Rectangle {
575573 tryCompare(stagesPriv, "mainStageAppId", "unity8-dash");
576574 tryCompare(stagesPriv, "sideStageAppId", "");
577575
578− var webbrowserSurfaceId = topSurfaceList.nextId;
576+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
579577 webbrowserCheckBox.checked = true;
580578 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
581579
@@ -593,7 +591,7 @@ Rectangle {
593591 function test_loadSideStageByDraggingFromMainStage() {
594592 sideStage.showNow();
595593 print("sidestage now shown. launching browser")
596− var webbrowserSurfaceId = topSurfaceList.nextId;
594+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
597595 webbrowserCheckBox.checked = true;
598596 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
599597
@@ -614,7 +612,7 @@ Rectangle {
614612 tryCompareFunction(function() {
615613 return WindowStateStorage.getStage(webbrowserCheckBox.appId, ApplicationInfoInterface.MainStage) === ApplicationInfoInterface.SideStage
616614 }, true);
617− var webbrowserSurfaceId = topSurfaceList.nextId;
615+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
618616 webbrowserCheckBox.checked = true;
619617 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
620618
@@ -630,7 +628,7 @@ Rectangle {
630628
631629 /*
632630 1- Suspended app gets killed behind the scenes, causing its surface to go zombie.
633− 2- Surface gets screenshotted and removed. Its slot in the topSurfaceList remains,
631+ 2- Surface gets screenshotted and removed. Its slot in the topLevelSurfaceList remains,
634632 though (so ApplicationWindow can display the screenshot in its place).
635633 3- User taps on the screenshot of the long-gone surface.
636634
@@ -638,11 +636,11 @@ Rectangle {
638636 Application gets relaunched. Its new surface will seamlessly replace the screenshot.
639637 */
640638 function test_selectSuspendedAppWithoutSurface() {
641− compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
642− var dashSurfaceId = topSurfaceList.idAt(0);
643− var dashWindow = topSurfaceList.windowAt(0);
639+ compare(topLevelSurfaceList.applicationAt(0).appId, "unity8-dash");
640+ var dashSurfaceId = topLevelSurfaceList.idAt(0);
641+ var dashWindow = topLevelSurfaceList.windowAt(0);
644642
645− var webbrowserSurfaceId = topSurfaceList.nextId;
643+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
646644 webbrowserCheckBox.checked = true;
647645 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
648646 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
@@ -659,22 +657,22 @@ Rectangle {
659657
660658 // wait until the surface is gone
661659 tryCompare(webbrowserApp.surfaceList, "count", 0);
662− compare(topSurfaceList.surfaceAt(topSurfaceList.indexForId(webbrowserSurfaceId)), null);
660+ compare(topLevelSurfaceList.surfaceAt(topLevelSurfaceList.indexForId(webbrowserSurfaceId)), null);
663661
664662 switchToSurface(webbrowserSurfaceId);
665663
666664 // webbrowser should have been brought to front
667− tryCompareFunction(function(){return topSurfaceList.idAt(0);}, webbrowserSurfaceId);
665+ tryCompareFunction(function(){return topLevelSurfaceList.idAt(0);}, webbrowserSurfaceId);
668666
669667 // and it should eventually get a new surface and get resumed
670− tryCompareFunction(function(){return topSurfaceList.surfaceAt(0) !== null;}, true);
671− compare(topSurfaceList.count, 2); // still two top-level items
668+ tryCompareFunction(function(){return topLevelSurfaceList.surfaceAt(0) !== null;}, true);
669+ compare(topLevelSurfaceList.count, 2); // still two top-level items
672670 tryCompare(webbrowserApp, "state", ApplicationInfoInterface.Running);
673671 compare(webbrowserApp.surfaceList.count, 1);
674672 }
675673
676674 function test_draggingSurfaceKeepsSurfaceFocus() {
677− var webbrowserSurfaceId = topSurfaceList.nextId;
675+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
678676 webbrowserCheckBox.checked = true;
679677 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
680678
@@ -692,8 +690,8 @@ Rectangle {
692690
693691 function test_dashDoesNotDragToSidestage() {
694692 sideStage.showNow();
695− compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
696− var dashSurfaceId = topSurfaceList.idAt(0);
693+ compare(topLevelSurfaceList.applicationAt(0).appId, "unity8-dash");
694+ var dashSurfaceId = topLevelSurfaceList.idAt(0);
697695
698696 var appDelegate = findChild(stage, "appDelegate_" + dashSurfaceId);
699697 verify(appDelegate);
@@ -715,7 +713,7 @@ Rectangle {
715713
716714 function test_switchRestoreStageOnRotation() {
717715 WindowStateStorage.saveStage(webbrowserCheckBox.appId, ApplicationInfoInterface.SideStage)
718− var webbrowserSurfaceId = topSurfaceList.nextId;
716+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
719717 webbrowserCheckBox.checked = true;
720718 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
721719
@@ -734,7 +732,7 @@ Rectangle {
734732 }
735733
736734 function test_restoreSavedStageOnCloseReopen() {
737− var webbrowserSurfaceId = topSurfaceList.nextId;
735+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
738736 webbrowserCheckBox.checked = true;
739737 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
740738
@@ -752,7 +750,7 @@ Rectangle {
752750 // back to landscape
753751 stage.shellOrientation = Qt.LandscapeOrientation;
754752
755− webbrowserSurfaceId = topSurfaceList.nextId;
753+ webbrowserSurfaceId = topLevelSurfaceList.nextId;
756754 webbrowserCheckBox.checked = true;
757755 waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
758756
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+5−23
@@ -37,20 +37,10 @@ Rectangle {
3737 height: units.gu(71)
3838
3939 QtObject {
40− id: applicationArguments
41−
42− function hasGeometry() {
43− return false;
44− }
45−
46− function width() {
47− return 0;
48− }
49−
50− function height() {
51− return 0;
52− }
40+ id: _screenWindow
41+ property bool primary: true
5342 }
43+ property alias screenWindow: _screenWindow
5444
5545 Telephony.CallEntry {
5646 id: phoneCall
@@ -256,13 +246,7 @@ Rectangle {
256246 property real halfWidth: shell ? shell.width / 2 : 0
257247 property real halfHeight: shell ? shell.height / 2 : 0
258248
259− onShellChanged: {
260− if (shell) {
261− topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
262− } else {
263− topLevelSurfaceList = null;
264− }
265− }
249+ topLevelSurfaceList: shell ? shell.topLevelSurfaceList : null;
266250
267251 function init() {
268252 prepareShell();
@@ -327,9 +311,7 @@ Rectangle {
327311 }
328312
329313 function ensureInputMethodSurface() {
330− var surfaceManager = findInvisibleChild(shell, "surfaceManager");
331− verify(surfaceManager);
332− surfaceManager.createInputMethodSurface();
314+ SurfaceManager.createInputMethodSurface();
333315
334316 tryCompareFunction(function() { return topLevelSurfaceList.inputMethodSurface !== null }, true);
335317 }
tests/qmltests/tst_OrientedShell.qml+22−10
@@ -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
@@ -444,8 +449,17 @@ Rectangle {
444449 when: windowShown
445450
446451 property Item orientedShell: orientedShellLoader.status === Loader.Ready ? orientedShellLoader.item : null
447− property Item shell
448− property QtObject topLevelSurfaceList
452+ property Item shell: null
453+ property QtObject topLevelSurfaceList : shell ? shell.topLevelSurfaceList : null
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 }
@@ -504,7 +518,6 @@ Rectangle {
504518 function cleanup() {
505519 tryCompare(shell, "waitingOnGreeter", false, 10000); // make sure greeter didn't leave us in disabled state
506520 shell = null;
507− topLevelSurfaceList = null;
508521
509522 tearDown();
510523 }
@@ -1463,8 +1476,7 @@ Rectangle {
14631476 removeTimeConstraintsFromSwipeAreas(orientedShellLoader.item);
14641477
14651478 shell = findChild(orientedShell, "shell");
1466−
1467− topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
1479+ verify(shell);
14681480 verify(topLevelSurfaceList);
14691481
14701482 tryCompare(shell, "waitingOnGreeter", false); // reset by greeter when ready
@@ -1512,13 +1524,13 @@ Rectangle {
15121524 print("exptectedAngle", expectedAngle, point.x, point.y)
15131525 switch (expectedAngle) {
15141526 case 0:
1515− return point.x === 0 && point.y === PanelState.panelHeight;
1527+ return point.x === 0 && point.y === panelState.panelHeight;
15161528 case 90:
1517− return point.x === orientedShell.width - PanelState.panelHeight && point.y === 0;
1529+ return point.x === orientedShell.width - panelState.panelHeight && point.y === 0;
15181530 case 180:
1519− return point.x === orientedShell.width && point.y === orientedShell.height - PanelState.panelHeight;
1531+ return point.x === orientedShell.width && point.y === orientedShell.height - panelState.panelHeight;
15201532 default: // 270
1521− return point.x === PanelState.panelHeight && point.y === orientedShell.height;
1533+ return point.x === panelState.panelHeight && point.y === orientedShell.height;
15221534 }
15231535 }
15241536
tests/qmltests/tst_Shell.qml+28−25
@@ -38,7 +38,6 @@ import Unity.Indicators 0.1 as Indicators
3838
3939import "../../qml"
4040import "../../qml/Components"
41−import "../../qml/Components/PanelState"
4241import "Stage"
4342
4443Rectangle {
@@ -57,18 +56,22 @@ Rectangle {
5756 id: appMenuData
5857 }
5958
60− property var shell: shellLoader.item ? shellLoader.item : null
59+ readonly property var shell: shellLoader.item ? shellLoader.item : null
6160 onShellChanged: {
6261 if (shell) {
63− topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
64− appMenuData.surfaceManager = testCase.findInvisibleChild(shell, "surfaceManager");
62+ panelState = testCase.findInvisibleChild(shell, "panelState");
6563 } else {
66− topLevelSurfaceList = null;
67− appMenuData.surfaceManager = null;
64+ panelState = null;
6865 }
6966 }
67+ property var panelState: null
68+ readonly property alias topLevelSurfaceList: testCase.topLevelSurfaceList
7069
71− property var topLevelSurfaceList: null
70+ QtObject {
71+ id: _screenWindow
72+ property bool primary: true
73+ }
74+ property alias screenWindow: _screenWindow
7275
7376 Item {
7477 id: shellContainer
@@ -262,6 +265,7 @@ Rectangle {
262265 anchors { left: parent.left; right: parent.right }
263266 activeFocusOnPress: false
264267 model: ["phone", "tablet", "desktop"]
268+ selectedIndex: 2
265269 onSelectedIndexChanged: {
266270 shellLoader.state = model[selectedIndex];
267271 }
@@ -275,6 +279,7 @@ Rectangle {
275279 anchors { left: parent.left; right: parent.right }
276280 activeFocusOnPress: false
277281 model: ["phone", "tablet", "desktop"]
282+ selectedIndex: 2
278283 }
279284 MouseTouchEmulationCheckbox {
280285 id: mouseEmulation
@@ -560,6 +565,7 @@ Rectangle {
560565 when: windowShown
561566
562567 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
568+ topLevelSurfaceList: shell ? shell.topLevelSurfaceList : null
563569
564570 function init() {
565571 if (shellLoader.active) {
@@ -598,7 +604,6 @@ Rectangle {
598604 waitForGreeterToStabilize();
599605
600606 // from StageTestCase
601− topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
602607 verify(topLevelSurfaceList);
603608 stage = findChild(shell, "stage");
604609
@@ -678,9 +683,7 @@ Rectangle {
678683 }
679684
680685 function ensureInputMethodSurface() {
681− var surfaceManager = findInvisibleChild(shell, "surfaceManager");
682− verify(surfaceManager);
683− surfaceManager.createInputMethodSurface();
686+ SurfaceManager.createInputMethodSurface();
684687
685688 tryCompareFunction(function() { return root.topLevelSurfaceList.inputMethodSurface !== null }, true);
686689 }
@@ -1866,21 +1869,21 @@ Rectangle {
18661869 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
18671870
18681871 tryCompare(appDelegate, "state", "normal");
1869− tryCompare(PanelState, "decorationsVisible", false)
1872+ tryCompare(panelState, "decorationsVisible", false)
18701873
18711874 mouseClick(maximizeButton, maximizeButton.width / 2, maximizeButton.height / 2);
18721875 tryCompare(appDelegate, "state", "maximized");
1873− tryCompare(PanelState, "decorationsVisible", true)
1876+ tryCompare(panelState, "decorationsVisible", true)
18741877
18751878 ApplicationManager.stopApplication(application.appId);
1876− tryCompare(PanelState, "decorationsVisible", false)
1879+ tryCompare(panelState, "decorationsVisible", false)
18771880
18781881 // wait until all zombie surfaces are gone. As MirSurfaceItems hold references over them.
18791882 // They won't be gone until those surface items are destroyed.
18801883 tryCompareFunction(function() { return application.surfaceList.count }, 0);
18811884
18821885 ApplicationManager.startApplication(application.appId);
1883− tryCompare(PanelState, "decorationsVisible", true)
1886+ tryCompare(panelState, "decorationsVisible", true)
18841887 }
18851888
18861889 function test_newAppHasValidGeometry() {
@@ -1937,7 +1940,7 @@ Rectangle {
19371940 mousePress(appDelegate, appDelegate.width / 2, units.gu(1))
19381941 mouseMove(appDelegate, appDelegate.width / 2, -units.gu(100))
19391942
1940− compare(appDelegate.y >= PanelState.panelHeight, true);
1943+ compare(appDelegate.y >= panelState.panelHeight, true);
19411944 }
19421945
19431946 function test_cantResizeWindowUnderPanel() {
@@ -1965,7 +1968,7 @@ Rectangle {
19651968 mouseMove(decoration, decoration.width/2, -units.gu(100));
19661969
19671970 // verify we don't go past the panel
1968− compare(appDelegate.y >= PanelState.panelHeight, true);
1971+ compare(appDelegate.y >= panelState.panelHeight, true);
19691972 }
19701973
19711974 function test_restoreWindowStateFixesIfUnderPanel() {
@@ -1989,7 +1992,7 @@ Rectangle {
19891992 tryCompareFunction(function () { return topLevelSurfaceList.applicationAt(0).appId; }, application.appId);
19901993
19911994 appDelegate = appRepeater.itemAt(0);
1992− compare(appDelegate.y >= PanelState.panelHeight, true);
1995+ compare(appDelegate.y >= panelState.panelHeight, true);
19931996 }
19941997
19951998 function test_lifecyclePolicyForNonTouchApp_data() {
@@ -2652,9 +2655,9 @@ Rectangle {
26522655
26532656 function test_oskDisplacesWindow_data() {
26542657 return [
2655− {tag: "no need to displace", windowHeight: units.gu(10), windowY: units.gu(5), targetDisplacement: units.gu(5), oskEnabled: true},
2656− {tag: "displace to top", windowHeight: units.gu(50), windowY: units.gu(10), targetDisplacement: PanelState.panelHeight, oskEnabled: true},
2657− {tag: "osk not on this screen", windowHeight: units.gu(40), windowY: units.gu(10), targetDisplacement: units.gu(10), oskEnabled: false},
2658+ {tag: "no need to displace", windowHeight: units.gu(10), windowY: units.gu(5), targetDisplacement: function() { return units.gu(5); }, oskEnabled: true},
2659+ {tag: "displace to top", windowHeight: units.gu(50), windowY: units.gu(10), targetDisplacement: function() { return panelState.panelHeight; }, oskEnabled: true},
2660+ {tag: "osk not on this screen", windowHeight: units.gu(40), windowY: units.gu(10), targetDisplacement: function() { return units.gu(10); }, oskEnabled: false},
26582661 ]
26592662 }
26602663
@@ -2676,11 +2679,11 @@ Rectangle {
26762679 dashAppDelegate.windowedY = data.windowY;
26772680 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, 0, 0, 0));
26782681 var initialY = dashAppDelegate.y;
2679− print("intial", initialY, "panel", PanelState.panelHeight);
2680− verify(initialY > PanelState.panelHeight);
2682+ print("intial", initialY, "panel", panelState.panelHeight);
2683+ verify(initialY > panelState.panelHeight);
26812684
26822685 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, root.height / 2, root.width, root.height / 2));
2683− tryCompare(dashAppDelegate, "y", data.targetDisplacement);
2686+ tryCompare(dashAppDelegate, "y", data.targetDisplacement());
26842687
26852688 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, 0, 0, 0));
26862689 tryCompare(dashAppDelegate, "y", initialY);
@@ -3113,7 +3116,7 @@ Rectangle {
31133116 // double click the panel
31143117 var panel = findChild(shell, "panel");
31153118 verify(panel);
3116− mouseDoubleClickSequence(panel, panel.width/2, PanelState.panelHeight/2, Qt.LeftButton, Qt.NoModifier, 300);
3119+ mouseDoubleClickSequence(panel, panel.width/2, panelState.panelHeight/2, Qt.LeftButton, Qt.NoModifier, 300);
31173120 tryCompare(appDelegate, "state", "restored");
31183121 }
31193122
tests/qmltests/tst_ShellApplication.qmlnew file+168
@@ -0,0 +1,168 @@
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+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+import LightDM.FullLightDM 0.1 as LightDM
20+import LightDMController 0.1
21+import Unity.Application 0.1
22+import Unity.Test 0.1
23+
24+import "../../qml"
25+import "../../qml/Components"
26+import "Stage"
27+
28+Rectangle {
29+ id: root
30+ color: "grey"
31+ width: units.gu(100)
32+ height: units.gu(71)
33+
34+ QtObject {
35+ id: args
36+ property bool hasFullscreen: false
37+ property bool hasFrameless: false
38+ property bool hasGeometry: true
39+ property size windowGeometry: Qt.size(root.width, root.height)
40+ property string deviceName: "desktop"
41+ property string mode: "full-greeter"
42+ }
43+ property alias applicationArguments: args
44+
45+ Component.onCompleted: {
46+ // must set the mock mode before loading the Shell
47+ LightDMController.userMode = "single";
48+ }
49+
50+ Flickable {
51+ id: controls
52+ contentHeight: controlRect.height
53+
54+ anchors.top: root.top
55+ anchors.bottom: root.bottom
56+ anchors.right: root.right
57+ width: units.gu(30)
58+
59+ Rectangle {
60+ id: controlRect
61+ anchors { left: parent.left; right: parent.right }
62+ color: "darkgrey"
63+ height: childrenRect.height + units.gu(2)
64+
65+ Column {
66+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
67+ spacing: units.gu(1)
68+
69+ Flow {
70+ spacing: units.gu(1)
71+ anchors { left: parent.left; right: parent.right }
72+
73+ Button {
74+ text: "Show Greeter"
75+ activeFocusOnPress: false
76+ onClicked: {
77+ LightDM.Greeter.showGreeter();
78+ }
79+ }
80+ Button {
81+ text: "Hide Greeter"
82+ activeFocusOnPress: false
83+ onClicked: {
84+ LightDM.Greeter.hideGreeter()
85+ }
86+ }
87+ }
88+
89+ MouseTouchEmulationCheckbox {
90+ id: mouseEmulation
91+ checked: true
92+ }
93+
94+ Row {
95+ anchors { left: parent.left; right: parent.right }
96+ CheckBox {
97+ id: autohideLauncherCheckbox
98+ onCheckedChanged: {
99+ GSettingsController.setAutohideLauncher(checked)
100+ }
101+ }
102+ Label {
103+ text: "Autohide launcher"
104+ }
105+ }
106+
107+ Label { text: "Applications"; font.bold: true }
108+
109+ Button {
110+ text: "Start all apps"
111+ width: parent.width
112+ activeFocusOnPress: false
113+ onClicked: {
114+ for (var i = 0; i < ApplicationManager.availableApplications.length; i++) {
115+ var appId = ApplicationManager.availableApplications[i];
116+ ApplicationManager.startApplication(appId)
117+ }
118+ }
119+ }
120+
121+ Repeater {
122+ id: appCheckBoxRepeater
123+ model: ApplicationManager.availableApplications
124+ ApplicationCheckBox {
125+ appId: modelData
126+ }
127+ }
128+
129+ Label {
130+ text: "Fingerprint"
131+ }
132+ Row {
133+ Button {
134+ text: "Success"
135+ onClicked: {
136+ var biometryd = testCase.findInvisibleChild(shellContainer, "biometryd");
137+ var uid = 0;
138+ for (var i = 0; i < LightDM.Users.count; i++) {
139+ if (LightDM.Users.data(i, LightDM.UserRoles.NameRole) == AccountsService.user) {
140+ uid = LightDM.Users.data(i, LightDM.UserRoles.UidRole);
141+ break;
142+ }
143+ }
144+ biometryd.operation.mockSuccess(uid);
145+ }
146+ }
147+
148+ Button {
149+ text: "Failure"
150+ onClicked: {
151+ var biometryd = testCase.findInvisibleChild(shellContainer, "biometryd");
152+ biometryd.operation.mockFailure("error");
153+ }
154+ }
155+ }
156+ }
157+ }
158+ }
159+
160+ ShellApplication {
161+ }
162+
163+ UnityTestCase {
164+ id: testCase
165+ name: "ShellApplication"
166+ when: windowShown
167+ }
168+}
tests/qmltests/tst_ShellWithPin.qml+4−16
@@ -41,20 +41,10 @@ Item {
4141 }
4242
4343 QtObject {
44− id: applicationArguments
45−
46− function hasGeometry() {
47− return false;
48− }
49−
50− function width() {
51− return 0;
52− }
53−
54− function height() {
55− return 0;
56− }
44+ id: _screenWindow
45+ property bool primary: true
5746 }
47+ property alias screenWindow: _screenWindow
5848
5949 Row {
6050 id: contentRow
@@ -143,6 +133,7 @@ Item {
143133 when: windowShown
144134
145135 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
136+ topLevelSurfaceList: shell ? shell.topLevelSurfaceList : null
146137
147138 function init() {
148139 tryCompare(shell, "waitingOnGreeter", false); // will be set when greeter is all ready
@@ -159,7 +150,6 @@ Item {
159150
160151 // from StageTestCase
161152 stage = findChild(shell, "stage");
162− topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
163153 verify(topLevelSurfaceList);
164154
165155 startApplication("unity8-dash");
@@ -168,8 +158,6 @@ Item {
168158 function cleanup() {
169159 tryCompare(shell, "waitingOnGreeter", false); // make sure greeter didn't leave us in disabled state
170160
171− topLevelSurfaceList = null;
172−
173161 shellLoader.itemDestroyed = false
174162
175163 shellLoader.active = false
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));
tests/utils/modules/Unity/Test/StageTestCase.qml+1−1
@@ -62,7 +62,7 @@ UnityTestCase {
6262
6363 return findChild(stage, "appDelegate_" + surfaceId);
6464 } catch(err) {
65− throw new Error("startApplication("+appId+") called from line " + util.callerLine(1) + " failed!");
65+ throw new Error("startApplication("+appId+") called from line " + util.callerLine(1) + " failed! - " + err);
6666 }
6767 }
6868}
tests/utils/modules/Unity/Test/UnityTestCase.qml+13
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import QtTest 1.0
1919import Unity.Application 0.1
20+import WindowManager 1.0
2021import Ubuntu.Components 1.3
2122import Ubuntu.Test 1.0 as UbuntuTest
2223import Unity.Test 0.1 as UT
@@ -47,6 +48,18 @@ TestCase {
4748 }
4849 }
4950
51+ Binding {
52+ target: WindowManagerObjects
53+ property: "surfaceManager"
54+ value: SurfaceManager
55+ }
56+
57+ Binding {
58+ target: WindowManagerObjects
59+ property: "applicationManager"
60+ value: ApplicationManager
61+ }
62+
5063 // Fake implementation to be provided to items under test
5164 property var fakeDateTime: new function() {
5265 this.currentTimeMs = 0