on 17872af help sign in
CMakeLists.txt+5−2
since splitsnapshots
unifiedsplit
@@ -70,7 +70,8 @@ find_package(Qt5DBus 5.6 REQUIRED)
70find_package(Qt5Concurrent 5.6 REQUIRED)
70find_package(Qt5Concurrent 5.6 REQUIRED)
71find_package(Qt5Sql 5.6 REQUIRED)
71find_package(Qt5Sql 5.6 REQUIRED)
72
72
73−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=26)
73+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=27)
74+pkg_check_modules(QTMIRSERVER REQUIRED qtmirserver>=0.6.0)
74pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
75pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
75pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
76pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
76pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
77pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
@@ -113,7 +114,9 @@ if(SHELL_PLUGINDIR STREQUAL "")
113 message(FATAL_ERROR "Could not determine plugin import dir.")
114 message(FATAL_ERROR "Could not determine plugin import dir.")
114endif()
115endif()
115
116
116−set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra")
117+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-permissive -pedantic -Wall -Wextra")
118+
119+set (CMAKE_CXX_STANDARD 14)
117
120
118if ("${CMAKE_BUILD_TYPE}" STREQUAL "release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "relwithdebinfo")
121if ("${CMAKE_BUILD_TYPE}" STREQUAL "release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "relwithdebinfo")
119 option(Werror "Treat warnings as errors" ON)
122 option(Werror "Treat warnings as errors" ON)
debian/control+5−3
@@ -38,7 +38,7 @@ Build-Depends: cmake,
38 libubuntugestures5-private-dev (>= 1.3.2030),
38 libubuntugestures5-private-dev (>= 1.3.2030),
39 libudev-dev,
39 libudev-dev,
40 libudm-common-dev,
40 libudm-common-dev,
41− libunity-api-dev (>= 8.2),
41+ libunity-api-dev (>= 8.3),
42 libusermetricsoutput1-dev,
42 libusermetricsoutput1-dev,
43# Need those X11 libs touch emulation from mouse events in manual QML tests on a X11 desktop
43# Need those X11 libs touch emulation from mouse events in manual QML tests on a X11 desktop
44 libx11-dev[!arm64 !armhf],
44 libx11-dev[!arm64 !armhf],
@@ -68,6 +68,7 @@ Build-Depends: cmake,
68 qtdeclarative5-private-dev (>= 5.6),
68 qtdeclarative5-private-dev (>= 5.6),
69 qtdeclarative5-ubuntu-content1,
69 qtdeclarative5-ubuntu-content1,
70 qtdeclarative5-ubuntu-settings-components (>= 0.11),
70 qtdeclarative5-ubuntu-settings-components (>= 0.11),
71+ qtmir-dev (>= 0.6.0),
71 ttf-ubuntu-font-family,
72 ttf-ubuntu-font-family,
72 xvfb,
73 xvfb,
73Standards-Version: 3.9.4
74Standards-Version: 3.9.4
@@ -131,6 +132,7 @@ Depends: dmz-cursor-theme,
131 qml-module-ubuntu-web,
132 qml-module-ubuntu-web,
132 qtdeclarative5-qtmir-plugin (>= 0.4.8),
133 qtdeclarative5-qtmir-plugin (>= 0.4.8),
133 qtdeclarative5-ubuntu-telephony0.1,
134 qtdeclarative5-ubuntu-telephony0.1,
135+ qtmir-desktop (>= 0.6.0) | qtmir-android (>= 0.6.0),
134 ubuntu-system-settings (>= 0.4),
136 ubuntu-system-settings (>= 0.4),
135 unity-launcher-impl-10,
137 unity-launcher-impl-10,
136 unity8-common (= ${source:Version}),
138 unity8-common (= ${source:Version}),
@@ -162,7 +164,7 @@ Depends: qml-module-qtquick-layouts,
162 qttranslations5-l10n,
164 qttranslations5-l10n,
163 ubuntu-thumbnailer-impl-0,
165 ubuntu-thumbnailer-impl-0,
164 ubuntu-wallpapers,
166 ubuntu-wallpapers,
165− unity-application-impl-26,
167+ unity-application-impl-27,
166 unity-notifications-impl-3,
168 unity-notifications-impl-3,
167 unity-plugin-scopes | unity-scopes-impl,
169 unity-plugin-scopes | unity-scopes-impl,
168 unity-scopes-impl-12,
170 unity-scopes-impl-12,
@@ -212,7 +214,7 @@ Depends: dbus-test-runner,
212 ${misc:Depends},
214 ${misc:Depends},
213 ${shlibs:Depends},
215 ${shlibs:Depends},
214Provides: unity-application-impl,
216Provides: unity-application-impl,
215− unity-application-impl-26,
217+ unity-application-impl-27,
216 unity8-fake-env,
218 unity8-fake-env,
217Replaces: unity8-autopilot (<< 8.02+15.04.20150422-0ubuntu1),
219Replaces: unity8-autopilot (<< 8.02+15.04.20150422-0ubuntu1),
218 unity8-fake-env,
220 unity8-fake-env,
debian/unity8.install+4
@@ -16,7 +16,11 @@ usr/share/unity8/Rotation
16usr/share/unity8/DeviceConfiguration.qml
16usr/share/unity8/DeviceConfiguration.qml
17usr/share/unity8/OrientedShell.qml
17usr/share/unity8/OrientedShell.qml
18usr/share/unity8/DisabledScreenNotice.qml
18usr/share/unity8/DisabledScreenNotice.qml
19+usr/share/unity8/qmldir
19usr/share/unity8/Shell.qml
20usr/share/unity8/Shell.qml
21+usr/share/unity8/ShellApplication.qml
22+usr/share/unity8/ShellNotifier.qml
23+usr/share/unity8/ShellScreen.qml
20usr/share/unity8/Stage
24usr/share/unity8/Stage
21usr/share/unity8/Tutorial
25usr/share/unity8/Tutorial
22usr/share/unity8/Wizard
26usr/share/unity8/Wizard
plugins/Cursor/CMakeLists.txt+1
@@ -15,6 +15,7 @@ set(QMLPLUGIN_SRC
15 CursorImageInfo.cpp
15 CursorImageInfo.cpp
16 CursorImageProvider.cpp
16 CursorImageProvider.cpp
17 MousePointer.cpp
17 MousePointer.cpp
18+ InputDispatcherFilter.cpp
18 # We need to run moc on this header
19 # We need to run moc on this header
19 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h
20 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h
20 )
21 )
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 @@
16
16
17#include "MousePointer.h"
17#include "MousePointer.h"
18#include "CursorImageProvider.h"
18#include "CursorImageProvider.h"
19−
19+#include "InputDispatcherFilter.h"
20−// Unity API
21−#include <unity/shell/application/MirPlatformCursor.h>
22
20
23#include <QQuickWindow>
21#include <QQuickWindow>
24−#include <QGuiApplication>
25−#include <QtMath>
26
22
27−#include <qpa/qwindowsysteminterface.h>
23+// Unity API
24+#include <unity/shell/application/MirPlatformCursor.h>
28
25
29MousePointer::MousePointer(QQuickItem *parent)
26MousePointer::MousePointer(QQuickItem *parent)
30 : MirMousePointerInterface(parent)
27 : MirMousePointerInterface(parent)
31 , m_cursorName(QStringLiteral("left_ptr"))
28 , m_cursorName(QStringLiteral("left_ptr"))
32 , m_themeName(QStringLiteral("default"))
29 , m_themeName(QStringLiteral("default"))
33{
30{
34−}
31+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedLeftBoundary,
35−
32+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
36−void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
33+ if (window() && window()->screen() == screen) {
37− Qt::KeyboardModifiers modifiers)
34+ Q_EMIT pushedLeftBoundary(amount, buttons);
38−{
39− if (!parentItem()) {
40− return;
41− }
42−
43− if (!movement.isNull()) {
44− Q_EMIT mouseMoved();
45− }
35+ }
46−
36+ });
47− m_accumulatedMovement += movement;
37+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedRightBoundary,
48− // don't apply the fractional part
38+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
49− QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
39+ if (window() && window()->screen() == screen) {
50− m_accumulatedMovement -= appliedMovement;
40+ Q_EMIT pushedRightBoundary(amount, buttons);
51−
41+ }
52− qreal newX = x() + appliedMovement.x();
42+ });
53− qreal newY = y() + appliedMovement.y();
43+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedTopBoundary,
54− const qreal sceneWidth = parentItem()->width();
44+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
55− const qreal sceneHeight = parentItem()->height();
45+ if (window() && window()->screen() == screen) {
56−
46+ Q_EMIT pushedTopBoundary(amount, buttons);
57− if (newX <= 0 && newY < m_topBoundaryOffset) { // top left corner
47+ }
58− const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-m_topBoundaryOffset, 2));
48+ });
59− Q_EMIT pushedTopLeftCorner(qAbs(distance), buttons);
49+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedTopLeftCorner,
60− m_pushing = true;
50+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
61− } else if (newX >= sceneWidth-1 && newY < m_topBoundaryOffset) { // top right corner
51+ if (window() && window()->screen() == screen) {
62− const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-m_topBoundaryOffset, 2));
52+ Q_EMIT pushedTopLeftCorner(amount, buttons);
63− Q_EMIT pushedTopRightCorner(qAbs(distance), buttons);
53+ }
64− m_pushing = true;
54+ });
65− } else if (newX < 0 && newY >= sceneHeight-1) { // bottom left corner
55+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedTopRightCorner,
66− const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-sceneHeight, 2));
56+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
67− Q_EMIT pushedBottomLeftCorner(qAbs(distance), buttons);
57+ if (window() && window()->screen() == screen) {
68− m_pushing = true;
58+ Q_EMIT pushedTopRightCorner(amount, buttons);
69− } else if (newX >= sceneWidth-1 && newY >= sceneHeight-1) { // bottom right corner
59+ }
70− const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-sceneHeight, 2));
60+ });
71− Q_EMIT pushedBottomRightCorner(qAbs(distance), buttons);
61+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedBottomLeftCorner,
72− m_pushing = true;
62+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
73− } else if (newX < 0) { // left edge
63+ if (window() && window()->screen() == screen) {
74− Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
64+ Q_EMIT pushedBottomLeftCorner(amount, buttons);
75− m_pushing = true;
65+ }
76− } else if (newX >= sceneWidth) { // right edge
66+ });
77− Q_EMIT pushedRightBoundary(newX - (sceneWidth - 1), buttons);
67+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedBottomRightCorner,
78− m_pushing = true;
68+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
79− } else if (newY < m_topBoundaryOffset) { // top edge
69+ if (window() && window()->screen() == screen) {
80− Q_EMIT pushedTopBoundary(qAbs(newY - m_topBoundaryOffset), buttons);
70+ Q_EMIT pushedBottomRightCorner(amount, buttons);
81− m_pushing = true;
71+ }
82− } else if (Q_LIKELY(newX > 0 && newX < sceneWidth-1 && newY > 0 && newY < sceneHeight-1)) { // normal pos, not pushing
72+ });
83− if (m_pushing) {
73+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushStopped,
74+ this, [this](QScreen* screen) {
75+ if (window() && window()->screen() == screen) {
84 Q_EMIT pushStopped();
76 Q_EMIT pushStopped();
85− m_pushing = false;
86 }
77 }
87− }
78+ });
88
79
89− applyItemConfinement(newX, newY);
80+ InputDispatcherFilter::instance()->registerPointer(this);
90−
81+}
91− setX(qBound(0.0, newX, sceneWidth - 1));
92− setY(qBound(0.0, newY, sceneHeight - 1));
93
82
94− QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
83+MousePointer::~MousePointer()
95− QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/,
84+{
96− buttons, modifiers);
85+ registerScreen(nullptr);
86+ InputDispatcherFilter::instance()->unregisterPointer(this);
97}
87}
98
88
99void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
89void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
@@ -121,17 +111,6 @@ void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
121 }
111 }
122}
112}
123
113
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−
135int MousePointer::topBoundaryOffset() const
114int MousePointer::topBoundaryOffset() const
136{
115{
137 return m_topBoundaryOffset;
116 return m_topBoundaryOffset;
@@ -182,7 +161,7 @@ void MousePointer::registerScreen(QScreen *screen)
182 if (m_registeredScreen) {
161 if (m_registeredScreen) {
183 auto previousCursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
162 auto previousCursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
184 if (previousCursor) {
163 if (previousCursor) {
185− previousCursor->setMousePointer(nullptr);
164+ previousCursor->unregisterMousePointer(this);
186 } else {
165 } else {
187 qCritical("QPlatformCursor is not a MirPlatformCursor! Cursor module only works in a Mir server.");
166 qCritical("QPlatformCursor is not a MirPlatformCursor! Cursor module only works in a Mir server.");
188 }
167 }
@@ -193,7 +172,7 @@ void MousePointer::registerScreen(QScreen *screen)
193 if (m_registeredScreen) {
172 if (m_registeredScreen) {
194 auto cursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
173 auto cursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
195 if (cursor) {
174 if (cursor) {
196− cursor->setMousePointer(this);
175+ cursor->registerMousePointer(this);
197 } else {
176 } else {
198 qCritical("QPlaformCursor is not a MirPlatformCursor! Cursor module only works in Mir.");
177 qCritical("QPlaformCursor is not a MirPlatformCursor! Cursor module only works in Mir.");
199 }
178 }
@@ -216,6 +195,12 @@ void MousePointer::setThemeName(const QString &themeName)
216 }
195 }
217}
196}
218
197
198+void MousePointer::moveTo(const QPoint &position)
199+{
200+ setPosition(position);
201+ Q_EMIT mouseMoved();
202+}
203+
219void MousePointer::setCustomCursor(const QCursor &customCursor)
204void MousePointer::setCustomCursor(const QCursor &customCursor)
220{
205{
221 CursorImageProvider::instance()->setCustomCursor(customCursor);
206 CursorImageProvider::instance()->setCustomCursor(customCursor);
plugins/Cursor/MousePointer.h+5−4
@@ -31,6 +31,7 @@ class MousePointer : public MirMousePointerInterface {
31 Q_PROPERTY(int topBoundaryOffset READ topBoundaryOffset WRITE setTopBoundaryOffset NOTIFY topBoundaryOffsetChanged)
31 Q_PROPERTY(int topBoundaryOffset READ topBoundaryOffset WRITE setTopBoundaryOffset NOTIFY topBoundaryOffsetChanged)
32public:
32public:
33 MousePointer(QQuickItem *parent = nullptr);
33 MousePointer(QQuickItem *parent = nullptr);
34+ ~MousePointer();
34
35
35 void setCursorName(const QString &qtCursorName) override;
36 void setCursorName(const QString &qtCursorName) override;
36 QString cursorName() const override { return m_cursorName; }
37 QString cursorName() const override { return m_cursorName; }
@@ -38,6 +39,8 @@ public:
38 void setThemeName(const QString &themeName) override;
39 void setThemeName(const QString &themeName) override;
39 QString themeName() const override { return m_themeName; }
40 QString themeName() const override { return m_themeName; }
40
41
42+ void moveTo(const QPoint& position) override;
43+
41 void setCustomCursor(const QCursor &) override;
44 void setCustomCursor(const QCursor &) override;
42
45
43 QQuickItem* confiningItem() const;
46 QQuickItem* confiningItem() const;
@@ -46,10 +49,7 @@ public:
46 int topBoundaryOffset() const;
49 int topBoundaryOffset() const;
47 void setTopBoundaryOffset(int topBoundaryOffset);
50 void setTopBoundaryOffset(int topBoundaryOffset);
48
51
49−public Q_SLOTS:
52+ QScreen* screen() const { return m_registeredScreen; }
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;
53
53
54Q_SIGNALS:
54Q_SIGNALS:
55 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
55 void pushedLeftBoundary(qreal amount, Qt::MouseButtons buttons);
@@ -79,6 +79,7 @@ private:
79 QPointer<QScreen> m_registeredScreen;
79 QPointer<QScreen> m_registeredScreen;
80 QString m_cursorName;
80 QString m_cursorName;
81 QString m_themeName;
81 QString m_themeName;
82+ bool m_active;
82
83
83 // Accumulated, unapplied, mouse movement.
84 // Accumulated, unapplied, mouse movement.
84 QPointF m_accumulatedMovement;
85 QPointF m_accumulatedMovement;
plugins/UInput/plugin.cpp+7−1
@@ -19,8 +19,14 @@
19
19
20#include <QtQml/qqml.h>
20#include <QtQml/qqml.h>
21
21
22+
23+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
24+{
25+ return new UInput;
26+}
27+
22void UInputPlugin::registerTypes(const char *uri)
28void UInputPlugin::registerTypes(const char *uri)
23{
29{
24 Q_ASSERT(uri == QLatin1String("UInput"));
30 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<UInput>(uri, 0, 1, "UInput");
31+ qmlRegisterSingletonType<UInput>(uri, 0, 1, "UInput", uinputSingleton);
26}
32}
plugins/Unity/CMakeLists.txt+1
@@ -1,5 +1,6 @@
1add_subdirectory(ApplicationMenu)
1add_subdirectory(ApplicationMenu)
2add_subdirectory(Connectivity)
2add_subdirectory(Connectivity)
3+add_subdirectory(Debug)
3add_subdirectory(Indicators)
4add_subdirectory(Indicators)
4add_subdirectory(Launcher)
5add_subdirectory(Launcher)
5add_subdirectory(Session)
6add_subdirectory(Session)
plugins/Unity/Debug/CMakeLists.txtnew file+30
@@ -0,0 +1,30 @@
1+include_directories(
2+ ${CMAKE_CURRENT_SOURCE_DIR}
3+ ${CMAKE_CURRENT_BINARY_DIR}
4+)
5+
6+include_directories(
7+ SYSTEM
8+ ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
9+ ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
10+ ${GIO_INCLUDE_DIRS}
11+)
12+
13+set(QMLPLUGIN_SRC
14+ consolelog.cpp
15+ plugin.cpp
16+ )
17+
18+add_library(Debug-qml SHARED
19+ ${QMLPLUGIN_SRC}
20+ )
21+
22+# Because this is an internal support library, we want
23+# to expose all symbols in it. Consider changing this
24+# either to a static library or just using the
25+# files directly in targets.
26+set_target_properties(Debug-qml PROPERTIES COMPILE_FLAGS -fvisibility=default)
27+
28+qt5_use_modules(Debug-qml Qml Quick Concurrent)
29+
30+add_unity8_plugin(Unity.Debug 0.1 Unity/Debug TARGETS Debug-qml)
plugins/Unity/Debug/consolelog.cppnew file+221
@@ -0,0 +1,221 @@
1+/*
2+ * Copyright 2016 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+*/
16+
17+#include "consolelog.h"
18+
19+#include <unistd.h>
20+#include <stdio.h>
21+#include <thread>
22+#include <iostream>
23+#include <sys/ioctl.h>
24+
25+#include <functional>
26+
27+namespace
28+{
29+
30+int wait_fd(std::function<int(void)> fn)
31+{
32+ int ret = -1;
33+ bool fd_blocked = false;
34+ do
35+ {
36+ ret = fn();
37+ fd_blocked = (errno == EINTR || errno == EBUSY);
38+ if (fd_blocked)
39+ QThread::msleep(10);
40+ }
41+ while (ret < 0);
42+ return ret;
43+}
44+
45+#define PIPE_WAIT(val) wait_fd(std::bind(pipe, val))
46+#define DUP_WAIT(fd) wait_fd(std::bind(dup, fd))
47+#define DUP2_WAIT(fd1, fd2) wait_fd(std::bind(dup2, fd1, fd2))
48+#define CLOSE_WAIT(fd) wait_fd(std::bind(close, fd))
49+
50+}
51+
52+LogRedirector::LogRedirector()
53+ : m_ref(0)
54+ , m_stop(false)
55+{
56+ setObjectName("ConsoleLog");
57+
58+ // make stdout & stderr streams unbuffered
59+ // so that we don't need to flush the streams
60+ // before capture and after capture
61+ // (fflush can cause a deadlock if the stream is currently being used)
62+ setvbuf(stdout,NULL,_IONBF,0);
63+ setvbuf(stderr,NULL,_IONBF,0);
64+}
65+
66+void LogRedirector::run()
67+{
68+ PIPE_WAIT(m_pipe);
69+
70+ int oldStdOut = DUP_WAIT(fileno(stdout));
71+ int oldStdErr = DUP_WAIT(fileno(stderr));
72+
73+ DUP2_WAIT(m_pipe[WRITE], fileno(stdout));
74+ DUP2_WAIT(m_pipe[WRITE], fileno(stderr));
75+ CLOSE_WAIT(m_pipe[WRITE]);
76+
77+ while(true) {
78+ {
79+ QMutexLocker lock(&m_mutex);
80+ if (m_stop) break;
81+ }
82+ checkLog();
83+ QThread::msleep(50);
84+ }
85+
86+ DUP2_WAIT(oldStdOut, fileno(stdout));
87+ DUP2_WAIT(oldStdErr, fileno(stderr));
88+
89+ CLOSE_WAIT(oldStdOut);
90+ CLOSE_WAIT(oldStdErr);
91+ CLOSE_WAIT(m_pipe[READ]);
92+}
93+
94+
95+void LogRedirector::checkLog()
96+{
97+ // Do not allow read to block with no data.
98+ // If we stop the thread while waiting a read,
99+ // it will block the main thread waiting for this thread to stop.
100+ int count = 0;
101+ ioctl(m_pipe[READ], FIONREAD, &count);
102+ if (count <= 0) return;
103+
104+ std::string captured;
105+ std::string buf;
106+ const int bufSize = 1024;
107+ buf.resize(bufSize);
108+ int bytesRead = 0;
109+ bytesRead = read(m_pipe[READ], &(*buf.begin()), bufSize);
110+ while(bytesRead == bufSize)
111+ {
112+ captured += buf;
113+ bytesRead = 0;
114+ bytesRead = read(m_pipe[READ], &(*buf.begin()), bufSize);
115+ }
116+ if (bytesRead > 0)
117+ {
118+ buf.resize(bytesRead);
119+ captured += buf;
120+ }
121+
122+ if (!captured.empty()) {
123+ Q_EMIT log(QString::fromStdString(captured));
124+ }
125+}
126+
127+LogRedirector *LogRedirector::instance()
128+{
129+ static LogRedirector* log = nullptr;
130+ if (!log) {
131+ log = new LogRedirector();
132+ }
133+ return log;
134+}
135+
136+void LogRedirector::add(ConsoleLog* logger)
137+{
138+ QMutexLocker lock(&m_mutex);
139+ connect(this, &LogRedirector::log, logger, &ConsoleLog::logged, Qt::UniqueConnection);
140+
141+ m_ref++;
142+ if (!LogRedirector::instance()->isRunning()) {
143+ m_stop = false;
144+ LogRedirector::instance()->start();
145+ }
146+}
147+
148+void LogRedirector::remove(ConsoleLog* logger)
149+{
150+ QMutexLocker lock(&m_mutex);
151+ disconnect(this, &LogRedirector::log, logger, &ConsoleLog::logged);
152+
153+ m_ref = qMax(m_ref-1, 0);
154+ if (m_ref == 0 && LogRedirector::instance()->isRunning()) {
155+ m_stop = true;
156+ lock.unlock();
157+ LogRedirector::instance()->wait();
158+ }
159+}
160+
161+ConsoleLog::ConsoleLog(QObject *parent)
162+ : QObject(parent)
163+ , m_enabled(false)
164+ , m_maxLines(60)
165+{
166+ auto updateEnabled = [this]() {
167+ if (m_enabled) {
168+ LogRedirector::instance()->add(this);
169+ } else {
170+ LogRedirector::instance()->remove(this);
171+ }
172+ };
173+ connect(this, &ConsoleLog::enabledChanged, this, updateEnabled);
174+}
175+
176+ConsoleLog::~ConsoleLog()
177+{
178+ if (m_enabled) {
179+ LogRedirector::instance()->remove(this);
180+ }
181+}
182+
183+void ConsoleLog::setEnabled(bool enabled)
184+{
185+ if (m_enabled == enabled) {
186+ return;
187+ }
188+
189+ m_enabled = enabled;
190+ Q_EMIT enabledChanged();
191+}
192+
193+QString ConsoleLog::out() const
194+{
195+ return m_out.join("\n");
196+}
197+
198+void ConsoleLog::setMaxLines(int maxLines)
199+{
200+ if (m_maxLines == maxLines) {
201+ return;
202+ }
203+
204+ m_maxLines = maxLines;
205+ while (m_out.count() > m_maxLines) {
206+ m_out.removeLast();
207+ }
208+ Q_EMIT outChanged();
209+ Q_EMIT maxLinesChanged();
210+}
211+
212+void ConsoleLog::logged(QString captured)
213+{
214+ QStringList li = captured.split("\n", QString::SkipEmptyParts);
215+ li << m_out;
216+ m_out = li;
217+ while (m_out.count() > m_maxLines) {
218+ m_out.removeLast();
219+ }
220+ Q_EMIT outChanged();
221+}
plugins/Unity/Debug/consolelog.hnew file+87
@@ -0,0 +1,87 @@
1+/*
2+ * Copyright 2016 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+*/
16+
17+#ifndef CONSOLELOG_H
18+#define CONSOLELOG_H
19+
20+#include <QThread>
21+#include <QMutex>
22+#include <QSet>
23+
24+class ConsoleLog;
25+
26+class LogRedirector : public QThread
27+{
28+ Q_OBJECT
29+public:
30+ static LogRedirector *instance();
31+
32+ void add(ConsoleLog* logger);
33+ void remove(ConsoleLog* logger);
34+
35+private Q_SLOTS:
36+ void checkLog();
37+
38+Q_SIGNALS:
39+ void log(QString log);
40+
41+private:
42+ LogRedirector();
43+ void run() Q_DECL_OVERRIDE;
44+
45+ QMutex m_mutex;
46+ int m_pipe[2];
47+ int m_ref;
48+ bool m_stop;
49+
50+ enum PIPES { READ, WRITE };
51+};
52+
53+class ConsoleLog : public QObject
54+{
55+ Q_OBJECT
56+ Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
57+ Q_PROPERTY(QString out READ out NOTIFY outChanged)
58+ Q_PROPERTY(int maxLines READ maxLines WRITE setMaxLines NOTIFY maxLinesChanged)
59+public:
60+ explicit ConsoleLog(QObject *parent = 0);
61+ ~ConsoleLog();
62+
63+ bool isEnabled() const { return m_enabled; }
64+ void setEnabled(bool enabled);
65+
66+ QString out() const;
67+
68+ int maxLines() const { return m_maxLines; }
69+ void setMaxLines(int maxLines);
70+
71+public Q_SLOTS:
72+ void logged(QString captured);
73+
74+Q_SIGNALS:
75+ void enabledChanged();
76+ void outChanged();
77+ void maxLinesChanged();
78+
79+private:
80+ void updateEnabled();
81+
82+ QStringList m_out;
83+ bool m_enabled;
84+ int m_maxLines;
85+};
86+
87+#endif // CONSOLELOG_H
plugins/Unity/Debug/plugin.cppnew file+31
@@ -0,0 +1,31 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+// Qt
18+#include <QtQml/qqml.h>
19+
20+// self
21+#include "plugin.h"
22+
23+// local
24+#include "consolelog.h"
25+
26+void UnityDebugPlugin::registerTypes(const char *uri)
27+{
28+ Q_ASSERT(uri == QLatin1String("Unity.Debug"));
29+
30+ qmlRegisterType<ConsoleLog>(uri, 0, 1, "ConsoleLog");
31+}
src/ShellView.h → plugins/Unity/Debug/plugin.hrenamed+9−11
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -14,21 +14,19 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#ifndef UNITY_SHELL_VIEW_H
17+#ifndef UNITYDEBUG_PLUGIN_H
18−#define UNITY_SHELL_VIEW_H
18+#define UNITYDEBUG_PLUGIN_H
19
19
20−#include <QQuickView>
20+#include <QtQml/QQmlEngine>
21+#include <QtQml/QQmlExtensionPlugin>
21
22
22−class ShellView : public QQuickView
23+class UnityDebugPlugin : public QQmlExtensionPlugin
23{
24{
24 Q_OBJECT
25 Q_OBJECT
26+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
25
27
26public:
28public:
27− ShellView(QQmlEngine *engine, QObject *qmlArgs);
29+ void registerTypes(const char *uri) override;
28−
29−private Q_SLOTS:
30− void onWidthChanged(int);
31− void onHeightChanged(int);
32};
30};
33
31
34−#endif // UNITY_SHELL_VIEW_H
32+#endif
plugins/Unity/Debug/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.Debug
2+plugin Debug-qml
3+typeinfo Debug.qmltypes
plugins/WindowManager/CMakeLists.txt+17−2
@@ -1,16 +1,31 @@
1+include_directories(
2+ SYSTEM
3+ ${QTMIRSERVER_INCLUDE_DIRS}
4+)
5+
1set(WINDOWMANAGER_SRC
6set(WINDOWMANAGER_SRC
2 TopLevelWindowModel.cpp
7 TopLevelWindowModel.cpp
3 Window.cpp
8 Window.cpp
4 WindowManagerPlugin.cpp
9 WindowManagerPlugin.cpp
10+ Screens.cpp
11+ Screen.cpp
12+ ScreenWindow.cpp
13+ Workspace.cpp
14+ WorkspaceManager.cpp
15+ WorkspaceModel.cpp
5 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
16 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
6 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
17 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
7 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
18 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
8 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
19 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
9 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
20 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
10− )
21+)
11
22
12add_library(windowmanager-qml SHARED ${WINDOWMANAGER_SRC})
23add_library(windowmanager-qml SHARED ${WINDOWMANAGER_SRC})
13
24
25+target_link_libraries(windowmanager-qml
26+ ${QTMIRSERVER_LDFLAGS}
27+)
28+
14qt5_use_modules(windowmanager-qml Qml Quick Gui)
29qt5_use_modules(windowmanager-qml Qml Quick Gui)
15
30
16−add_unity8_plugin(WindowManager 0.1 WindowManager TARGETS windowmanager-qml)
31+add_unity8_plugin(WindowManager 1.0 WindowManager TARGETS windowmanager-qml)
plugins/WindowManager/Screen.cppnew file+124
@@ -0,0 +1,124 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Screen.h"
18+#include "WorkspaceModel.h"
19+#include "WorkspaceManager.h"
20+#include "Workspace.h"
21+
22+Screen::Screen(qtmir::Screen* screen)
23+ : m_wrapped(screen)
24+ , m_workspaces(new WorkspaceModel)
25+{
26+ connect(m_wrapped, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
27+ connect(m_wrapped, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
28+ connect(m_wrapped, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
29+ connect(m_wrapped, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
30+ connect(m_wrapped, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
31+ connect(m_wrapped, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
32+ connect(m_wrapped, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
33+ connect(m_wrapped, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
34+ connect(m_wrapped, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
35+ connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
36+
37+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
38+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
39+}
40+
41+qtmir::OutputId Screen::outputId() const
42+{
43+ return m_wrapped->outputId();
44+}
45+
46+bool Screen::used() const
47+{
48+ return m_wrapped->used();
49+}
50+
51+QString Screen::name() const
52+{
53+ return m_wrapped->name();
54+}
55+
56+float Screen::scale() const
57+{
58+ return m_wrapped->scale();
59+}
60+
61+QSizeF Screen::physicalSize() const
62+{
63+ return m_wrapped->physicalSize();
64+}
65+
66+qtmir::FormFactor Screen::formFactor() const
67+{
68+ return m_wrapped->formFactor();
69+}
70+
71+qtmir::OutputTypes Screen::outputType() const
72+{
73+ return m_wrapped->outputType();
74+}
75+
76+MirPowerMode Screen::powerMode() const
77+{
78+ return m_wrapped->powerMode();
79+}
80+
81+Qt::ScreenOrientation Screen::orientation() const
82+{
83+ return m_wrapped->orientation();
84+}
85+
86+QPoint Screen::position() const
87+{
88+ return m_wrapped->position();
89+}
90+
91+QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
92+{
93+ return m_wrapped->availableModes();
94+}
95+
96+uint Screen::currentModeIndex() const
97+{
98+ return m_wrapped->currentModeIndex();
99+}
100+
101+bool Screen::isActive() const
102+{
103+ return m_wrapped->isActive();
104+}
105+
106+qtmir::ScreenConfiguration *Screen::beginConfiguration() const
107+{
108+ return m_wrapped->beginConfiguration();
109+}
110+
111+bool Screen::applyConfiguration(qtmir::ScreenConfiguration *configuration)
112+{
113+ return m_wrapped->applyConfiguration(configuration);
114+}
115+
116+void Screen::setActive(bool active)
117+{
118+ m_wrapped->setActive(active);
119+}
120+
121+QScreen *Screen::qscreen() const
122+{
123+ return m_wrapped->qscreen();
124+}
plugins/WindowManager/Screen.hnew file+46
@@ -0,0 +1,46 @@
1+#ifndef SCREEN_H
2+#define SCREEN_H
3+
4+#include <qtmir/screen.h>
5+#include <QScopedPointer>
6+
7+class WorkspaceModel;
8+
9+class Screen : public qtmir::Screen
10+{
11+ Q_OBJECT
12+ Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
13+
14+public:
15+ explicit Screen(qtmir::Screen*const wrapped);
16+
17+ qtmir::OutputId outputId() const override;
18+ bool used() const override;
19+ QString name() const override;
20+ float scale() const override;
21+ QSizeF physicalSize() const override;
22+ qtmir::FormFactor formFactor() const override;
23+ qtmir::OutputTypes outputType() const override;
24+ MirPowerMode powerMode() const override;
25+ Qt::ScreenOrientation orientation() const override;
26+ QPoint position() const override;
27+ QQmlListProperty<qtmir::ScreenMode> availableModes() override;
28+ uint currentModeIndex() const override;
29+ bool isActive() const override;
30+ void setActive(bool active) override;
31+
32+ QScreen* qscreen() const override;
33+
34+ qtmir::ScreenConfiguration *beginConfiguration() const override;
35+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override;
36+
37+ qtmir::Screen* wrapped() const { return m_wrapped; }
38+
39+ WorkspaceModel* workspaces() const { return m_workspaces.data(); }
40+
41+private:
42+ qtmir::Screen*const m_wrapped;
43+ const QScopedPointer<WorkspaceModel> m_workspaces;
44+};
45+
46+#endif // SCREEN_H
plugins/WindowManager/ScreenWindow.cppnew file+48
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ScreenWindow.h"
18+#include "Screen.h"
19+
20+// Qt
21+#include <QGuiApplication>
22+#include <QDebug>
23+
24+ScreenWindow::ScreenWindow(QQuickWindow *parent)
25+ : QQuickWindow(parent)
26+{
27+ if (qGuiApp->platformName() != QLatin1String("mirserver")) {
28+ qCritical("Not using 'mirserver' QPA plugin. Using ScreenWindow may produce unknown results.");
29+ }
30+}
31+
32+ScreenWindow::~ScreenWindow()
33+{
34+}
35+
36+Screen *ScreenWindow::screenWrapper() const
37+{
38+ return m_screen.data();
39+}
40+
41+void ScreenWindow::setScreenWrapper(Screen *screen)
42+{
43+ if (m_screen != screen) {
44+ m_screen = screen;
45+ Q_EMIT screenWrapperChanged();
46+ }
47+ QQuickWindow::setScreen(screen->qscreen());
48+}
plugins/WindowManager/ScreenWindow.hnew file+49
@@ -0,0 +1,49 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_SCREENWINDOW_H
18+#define UNITY_SCREENWINDOW_H
19+
20+#include <QQuickWindow>
21+#include <QPointer>
22+
23+#include "Screen.h"
24+
25+class ScreenAdapter;
26+
27+/*
28+ * ScreenWindow - wrapper of QQuickWindow to enable QML to specify destination screen.
29+**/
30+class ScreenWindow : public QQuickWindow
31+{
32+ Q_OBJECT
33+ Q_PROPERTY(Screen *screen READ screenWrapper WRITE setScreenWrapper NOTIFY screenWrapperChanged)
34+ Q_PROPERTY(int winId READ winId CONSTANT)
35+public:
36+ explicit ScreenWindow(QQuickWindow *parent = 0);
37+ ~ScreenWindow();
38+
39+ Screen *screenWrapper() const;
40+ void setScreenWrapper(Screen *screen);
41+
42+Q_SIGNALS:
43+ void screenWrapperChanged();
44+
45+private:
46+ QPointer<Screen> m_screen;
47+};
48+
49+#endif // UNITY_SCREENWINDOW_H
plugins/WindowManager/Screens.cppnew file+129
@@ -0,0 +1,129 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Screens.h"
18+#include "Screen.h"
19+
20+// qtmirserver
21+#include <qtmir/qtmir.h>
22+#include <qtmir/screens.h>
23+#include <QGuiApplication>
24+
25+// Qt
26+#include <QScreen>
27+#include <QWindow>
28+
29+Screens::Screens(QObject *parent)
30+ : QAbstractListModel(parent)
31+ , m_wrapped(qtmir::get_screen_model())
32+{
33+ if (qGuiApp->platformName() != QLatin1String("mirserver")) {
34+ qCritical("Not using 'mirserver' QPA plugin. Using qGuiApp may produce unknown results.");
35+ }
36+
37+ connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &Screens::onScreenAdded);
38+ connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
39+ connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &Screens::activeScreenChanged);
40+
41+ Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
42+ m_screenList.push_back(new Screen(screen));
43+ }
44+}
45+
46+QHash<int, QByteArray> Screens::roleNames() const
47+{
48+ QHash<int, QByteArray> roles;
49+ roles[ScreenRole] = "screen";
50+ return roles;
51+}
52+
53+QVariant Screens::data(const QModelIndex &index, int role) const
54+{
55+ if (!index.isValid() || index.row() >= m_screenList.size()) {
56+ return QVariant();
57+ }
58+
59+ switch(role) {
60+ case ScreenRole:
61+ return QVariant::fromValue(m_screenList.at(index.row()));
62+ } // switch
63+
64+ return QVariant();
65+}
66+
67+int Screens::rowCount(const QModelIndex &) const
68+{
69+ return count();
70+}
71+
72+int Screens::count() const
73+{
74+ return m_screenList.size();
75+}
76+
77+QVariant Screens::activeScreen() const
78+{
79+ for (int i = 0; i < m_screenList.count(); i++) {
80+ if (m_screenList[i]->isActive()) return i;
81+ }
82+ return QVariant();
83+}
84+
85+void Screens::activateScreen(const QVariant& vindex)
86+{
87+ bool ok = false;
88+ int index = vindex.toInt(&ok);
89+ if (!ok || index < 0 || m_screenList.count() <= index) return;
90+
91+ auto screen = m_screenList.at(index);
92+ screen->setActive(true);
93+}
94+
95+void Screens::onScreenAdded(qtmir::Screen *screen)
96+{
97+ Q_FOREACH(auto screenWrapper, m_screenList) {
98+ if (screenWrapper->wrapped() == screen) return;
99+ }
100+
101+ beginInsertRows(QModelIndex(), count(), count());
102+ auto screenWrapper(new Screen(screen));
103+ m_screenList.push_back(screenWrapper);
104+ endInsertRows();
105+ Q_EMIT screenAdded(screenWrapper);
106+ Q_EMIT countChanged();
107+}
108+
109+void Screens::onScreenRemoved(qtmir::Screen *screen)
110+{
111+ int index = 0;
112+ QMutableListIterator<Screen*> iter(m_screenList);
113+ while(iter.hasNext()) {
114+ auto screenWrapper = iter.next();
115+ if (screenWrapper->wrapped() == screen) {
116+
117+ beginRemoveRows(QModelIndex(), index, index);
118+ iter.remove();
119+ endRemoveRows();
120+
121+ Q_EMIT screenRemoved(screenWrapper);
122+ Q_EMIT countChanged();
123+
124+ screenWrapper->deleteLater();
125+ break;
126+ }
127+ index++;
128+ }
129+}
plugins/WindowManager/Screens.hnew file+71
@@ -0,0 +1,71 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_SCREENS_H
18+#define UNITY_SCREENS_H
19+
20+#include <QAbstractListModel>
21+#include <QSharedPointer>
22+
23+class Screen;
24+namespace qtmir
25+{
26+class Screen;
27+class Screens;
28+}
29+
30+class Screens : public QAbstractListModel
31+{
32+ Q_OBJECT
33+ Q_PROPERTY(int count READ count NOTIFY countChanged)
34+ Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
35+
36+public:
37+ enum ItemRoles {
38+ ScreenRole = Qt::UserRole + 1
39+ };
40+
41+ explicit Screens(QObject *parent = 0);
42+ virtual ~Screens() noexcept = default;
43+
44+ /* QAbstractItemModel */
45+ QHash<int, QByteArray> roleNames() const override;
46+ QVariant data(const QModelIndex &index, int role = ScreenRole) const override;
47+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
48+
49+ int count() const;
50+ QVariant activeScreen() const;
51+
52+public Q_SLOTS:
53+ void activateScreen(const QVariant& index);
54+
55+Q_SIGNALS:
56+ void countChanged();
57+ void activeScreenChanged();
58+
59+ void screenAdded(Screen* screen);
60+ void screenRemoved(Screen* screen);
61+
62+private Q_SLOTS:
63+ void onScreenAdded(qtmir::Screen *screen);
64+ void onScreenRemoved(qtmir::Screen *screen);
65+
66+private:
67+ QList<Screen*> m_screenList;
68+ QSharedPointer<qtmir::Screens> m_wrapped;
69+};
70+
71+#endif // SCREENS_H
plugins/WindowManager/WindowManagerPlugin.cpp+27
@@ -16,16 +16,43 @@
16
16
17#include "WindowManagerPlugin.h"
17#include "WindowManagerPlugin.h"
18
18
19+#include "Screens.h"
20+#include "Screen.h"
21+#include "ScreenWindow.h"
19#include "TopLevelWindowModel.h"
22#include "TopLevelWindowModel.h"
20#include "Window.h"
23#include "Window.h"
24+#include "WorkspaceManager.h"
25+#include "Workspace.h"
26+#include "WorkspaceModel.h"
21
27
22#include <QtQml>
28#include <QtQml>
23
29
30+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
31+{
32+ Q_UNUSED(engine)
33+ Q_UNUSED(scriptEngine)
34+ return WorkspaceManager::instance();
35+}
36+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
37+ Q_UNUSED(engine);
38+ Q_UNUSED(scriptEngine);
39+ return new Screens();
40+}
41+
24void WindowManagerPlugin::registerTypes(const char *uri)
42void WindowManagerPlugin::registerTypes(const char *uri)
25{
43{
26 qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
44 qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
45+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
46+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", "Not a creatable type");
47+ qmlRegisterSingletonType<Screens>(uri, 1, 0, "Screens", screensSingleton);
48+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", "ScreenMode is not creatable.");
27
49
28 qRegisterMetaType<Window*>("Window*");
50 qRegisterMetaType<Window*>("Window*");
51+ qRegisterMetaType<Workspace*>("Workspace*");
29
52
30 qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
53 qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
54+ qRegisterMetaType<Screen*>("Screen*");
55+
56+ qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
57+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
31}
58}
plugins/WindowManager/Workspace.cppnew file+63
@@ -0,0 +1,63 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Workspace.h"
18+#include "WorkspaceModel.h"
19+
20+Workspace::Workspace(QObject *parent)
21+ : QObject(parent)
22+ , m_model(nullptr)
23+{
24+
25+}
26+
27+Workspace::~Workspace()
28+{
29+ unassign();
30+}
31+
32+void Workspace::assign(WorkspaceModel *model)
33+{
34+ bool wasAssinged = false;
35+ if (m_model) {
36+ disconnect(model);
37+ m_model->remove(this);
38+ wasAssinged = true;
39+ }
40+
41+ m_model = model;
42+ if (model) {
43+ model->append(this);
44+
45+ connect(model, &QObject::destroyed, this, [this]() {
46+ m_model = nullptr;
47+ Q_EMIT unassigned();
48+ });
49+ Q_EMIT assigned();
50+ } else if (wasAssinged) {
51+ Q_EMIT unassigned();
52+ }
53+}
54+
55+void Workspace::unassign()
56+{
57+ if (m_model) {
58+ m_model->remove(this);
59+ m_model = nullptr;
60+
61+ Q_EMIT unassigned();
62+ }
63+}
plugins/WindowManager/Workspace.hnew file+44
@@ -0,0 +1,44 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef WORKSPACE_H
18+#define WORKSPACE_H
19+
20+#include <QObject>
21+
22+class WorkspaceModel;
23+
24+class Workspace : public QObject
25+{
26+ Q_OBJECT
27+public:
28+ explicit Workspace(QObject *parent = 0);
29+ ~Workspace();
30+
31+ Q_INVOKABLE void assign(WorkspaceModel* model);
32+
33+public Q_SLOT:
34+ void unassign();
35+
36+Q_SIGNALS:
37+ void assigned();
38+ void unassigned();
39+
40+private:
41+ WorkspaceModel* m_model;
42+};
43+
44+#endif // WORKSPACE_H
plugins/WindowManager/WorkspaceManager.cppnew file+47
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "WorkspaceManager.h"
18+#include "Workspace.h"
19+
20+// Qt
21+#include <QGuiApplication>
22+#include <QScreen>
23+#include <QQmlEngine>
24+
25+WorkspaceManager *WorkspaceManager::instance()
26+{
27+ static WorkspaceManager* workspaceManager(new WorkspaceManager());
28+ return workspaceManager;
29+}
30+
31+WorkspaceManager::WorkspaceManager()
32+{
33+}
34+Workspace *WorkspaceManager::createWorkspace()
35+{
36+ auto workspace = new Workspace(this);
37+ QQmlEngine::setObjectOwnership(workspace, QQmlEngine::CppOwnership);
38+ m_allWorkspaces.append(workspace);
39+ workspace->assign(this);
40+ return workspace;
41+}
42+
43+void WorkspaceManager::destroyWorkspace(Workspace *workspace)
44+{
45+ workspace->deleteLater();
46+}
47+
plugins/WindowManager/WorkspaceManager.hnew file+41
@@ -0,0 +1,41 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef WORKSPACEMANAGER_H
18+#define WORKSPACEMANAGER_H
19+
20+#include "WorkspaceModel.h"
21+
22+class Workspace;
23+
24+class WorkspaceManager : public WorkspaceModel
25+{
26+ Q_OBJECT
27+public:
28+ static WorkspaceManager* instance();
29+
30+private:
31+ WorkspaceManager();
32+
33+public Q_SLOTS:
34+ Workspace* createWorkspace();
35+ void destroyWorkspace(Workspace* workspace);
36+
37+private:
38+ QVector<Workspace*> m_allWorkspaces;
39+};
40+
41+#endif // WORKSPACEMANAGER_H
plugins/WindowManager/WorkspaceModel.cppnew file+90
@@ -0,0 +1,90 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "WorkspaceModel.h"
18+#include "Workspace.h"
19+
20+Q_LOGGING_CATEGORY(WORKSPACES, "Workspaces", QtInfoMsg)
21+
22+#define DEBUG_MSG qCDebug(WORKSPACES).nospace().noquote() << __func__
23+#define INFO_MSG qCInfo(WORKSPACES).nospace().noquote() << __func__
24+
25+WorkspaceModel::WorkspaceModel(QObject *parent)
26+ : QAbstractListModel(parent)
27+{
28+}
29+
30+void WorkspaceModel::append(Workspace *workspace)
31+{
32+ insert(m_workspaces.count(), workspace);
33+}
34+
35+void WorkspaceModel::insert(int index, Workspace *workspace)
36+{
37+ beginInsertRows(QModelIndex(), index, index);
38+ m_workspaces.append(workspace);
39+ endInsertRows();
40+ Q_EMIT countChanged();
41+}
42+
43+void WorkspaceModel::remove(Workspace *workspace)
44+{
45+ int index = m_workspaces.indexOf(workspace);
46+ if (index < 0) return;
47+
48+ beginRemoveRows(QModelIndex(), index, index);
49+ m_workspaces.removeAt(index);
50+ endRemoveRows();
51+ Q_EMIT countChanged();
52+}
53+
54+void WorkspaceModel::move(int from, int to)
55+{
56+ if (from == to) return;
57+ DEBUG_MSG << " from=" << from << " to=" << to;
58+
59+ if (from >= 0 && from < m_workspaces.size() && to >= 0 && to < m_workspaces.size()) {
60+ QModelIndex parent;
61+
62+ beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
63+#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
64+ const auto &window = m_windowModel.takeAt(from);
65+ m_workspaces.insert(to, window);
66+#else
67+ m_workspaces.move(from, to);
68+#endif
69+ endMoveRows();
70+ Q_EMIT countChanged();
71+ }
72+}
73+
74+int WorkspaceModel::rowCount(const QModelIndex &) const
75+{
76+ return m_workspaces.count();
77+}
78+
79+QVariant WorkspaceModel::data(const QModelIndex &index, int role) const
80+{
81+ if (index.row() < 0 || index.row() >= m_workspaces.size())
82+ return QVariant();
83+
84+ if (role == WorkspaceRole) {
85+ Workspace *workspace = m_workspaces.at(index.row());
86+ return QVariant::fromValue(workspace);
87+ } else {
88+ return QVariant();
89+ }
90+}
plugins/WindowManager/WorkspaceModel.hnew file+63
@@ -0,0 +1,63 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef WORKSPACEMODEL_H
18+#define WORKSPACEMODEL_H
19+
20+#include <QAbstractListModel>
21+#include <QLoggingCategory>
22+
23+Q_DECLARE_LOGGING_CATEGORY(WORKSPACES)
24+
25+class Workspace;
26+
27+class WorkspaceModel : public QAbstractListModel
28+{
29+ Q_OBJECT
30+ Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
31+public:
32+ /**
33+ * @brief The Roles supported by the model
34+ *
35+ * WorkspaceRole - A workspace.
36+ */
37+ enum Roles {
38+ WorkspaceRole = Qt::UserRole
39+ };
40+
41+ explicit WorkspaceModel(QObject *parent = 0);
42+
43+ void append(Workspace* workspace);
44+ void insert(int index, Workspace* workspace);
45+ void remove(Workspace* workspace);
46+ void move(int from, int to);
47+
48+ // From QAbstractItemModel
49+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
50+ QVariant data(const QModelIndex& index, int role) const override;
51+ QHash<int, QByteArray> roleNames() const override {
52+ QHash<int, QByteArray> roleNames { {WorkspaceRole, "workspace"} };
53+ return roleNames;
54+ }
55+
56+Q_SIGNALS:
57+ void countChanged();
58+
59+protected:
60+ QVector<Workspace*> m_workspaces;
61+};
62+
63+#endif // WORKSPACEMODEL_H
qml/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)
2
2
3install(FILES ${QML_JS_FILES}
3install(FILES ${QML_JS_FILES}
4 DESTINATION ${SHELL_APP_DIR}
4 DESTINATION ${SHELL_APP_DIR}
qml/Components/PanelState/PanelState.qml−1
@@ -14,7 +14,6 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−pragma Singleton
18import QtQuick 2.4
17import QtQuick 2.4
19
18
20QtObject {
19QtObject {
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
18import QtQuick.Layouts 1.1
18import QtQuick.Layouts 1.1
19import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
20import Qt.labs.settings 1.0
20import Qt.labs.settings 1.0
21−import Unity.Screens 0.1
21+import WindowManager 1.0
22import UInput 0.1
22import UInput 0.1
23import "../Components"
23import "../Components"
24
24
25Item {
25Item {
26 id: root
26 id: root
27− property var uinput: UInput {
28− Component.onCompleted: createMouse();
29− Component.onDestruction: removeMouse();
30− }
31
27
32 Component.onCompleted: {
28 Component.onCompleted: {
29+ UInput.createMouse();
33 if (!settings.touchpadTutorialHasRun) {
30 if (!settings.touchpadTutorialHasRun) {
34 root.runTutorial()
31 root.runTutorial()
35 }
32 }
36 }
33 }
34+ Component.onDestruction: UInput.removeMouse()
37
35
38 function runTutorial() {
36 function runTutorial() {
39 // If the tutorial animation is started too early, e.g. in Component.onCompleted,
37 // If the tutorial animation is started too early, e.g. in Component.onCompleted,
@@ -85,7 +83,7 @@ Item {
85 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
83 if (((point1.pressed && !point2.pressed) || (!point1.pressed && point2.pressed))
86 && clickTimer.running) {
84 && clickTimer.running) {
87 clickTimer.stop();
85 clickTimer.stop();
88− uinput.pressMouse(UInput.ButtonLeft)
86+ UInput.pressMouse(UInput.ButtonLeft)
89 isDoubleClick = true;
87 isDoubleClick = true;
90 }
88 }
91 isClick = true;
89 isClick = true;
@@ -104,7 +102,7 @@ Item {
104
102
105 onReleased: {
103 onReleased: {
106 if (isDoubleClick || isDrag) {
104 if (isDoubleClick || isDrag) {
107− uinput.releaseMouse(UInput.ButtonLeft)
105+ UInput.releaseMouse(UInput.ButtonLeft)
108 isDoubleClick = false;
106 isDoubleClick = false;
109 }
107 }
110 if (isClick) {
108 if (isClick) {
@@ -120,8 +118,8 @@ Item {
120 interval: 200
118 interval: 200
121 property int button: UInput.ButtonLeft
119 property int button: UInput.ButtonLeft
122 onTriggered: {
120 onTriggered: {
123− uinput.pressMouse(button);
121+ UInput.pressMouse(button);
124− uinput.releaseMouse(button);
122+ UInput.releaseMouse(button);
125 }
123 }
126 function scheduleClick(button) {
124 function scheduleClick(button) {
127 clickTimer.button = button;
125 clickTimer.button = button;
@@ -138,7 +136,7 @@ Item {
138 isDrag = true;
136 isDrag = true;
139 }
137 }
140
138
141− uinput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
139+ UInput.moveMouse(tp.x - tp.previousX, tp.y - tp.previousY);
142 }
140 }
143
141
144 function scroll(touchPoints) {
142 function scroll(touchPoints) {
@@ -166,7 +164,7 @@ Item {
166 dh /= 2;
164 dh /= 2;
167 dv /= 2;
165 dv /= 2;
168
166
169− uinput.scrollMouse(dh, dv);
167+ UInput.scrollMouse(dh, dv);
170 }
168 }
171
169
172 touchPoints: [
170 touchPoints: [
@@ -189,8 +187,8 @@ Item {
189 objectName: "leftButton"
187 objectName: "leftButton"
190 Layout.fillWidth: true
188 Layout.fillWidth: true
191 Layout.fillHeight: true
189 Layout.fillHeight: true
192− onPressed: uinput.pressMouse(UInput.ButtonLeft);
190+ onPressed: UInput.pressMouse(UInput.ButtonLeft);
193− onReleased: uinput.releaseMouse(UInput.ButtonLeft);
191+ onReleased: UInput.releaseMouse(UInput.ButtonLeft);
194 property bool highlight: false
192 property bool highlight: false
195 UbuntuShape {
193 UbuntuShape {
196 anchors.fill: parent
194 anchors.fill: parent
@@ -204,8 +202,8 @@ Item {
204 objectName: "rightButton"
202 objectName: "rightButton"
205 Layout.fillWidth: true
203 Layout.fillWidth: true
206 Layout.fillHeight: true
204 Layout.fillHeight: true
207− onPressed: uinput.pressMouse(UInput.ButtonRight);
205+ onPressed: UInput.pressMouse(UInput.ButtonRight);
208− onReleased: uinput.releaseMouse(UInput.ButtonRight);
206+ onReleased: UInput.releaseMouse(UInput.ButtonRight);
209 property bool highlight: false
207 property bool highlight: false
210 UbuntuShape {
208 UbuntuShape {
211 anchors.fill: parent
209 anchors.fill: parent
@@ -239,14 +237,10 @@ Item {
239 }
237 }
240 }
238 }
241
239
242− Screens {
243− id: screens
244− }
245−
246 InputMethod {
240 InputMethod {
247 id: inputMethod
241 id: inputMethod
248 // Don't resize when there is only one screen to avoid resize clashing with the InputMethod in the Shell.
242 // 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
250 objectName: "inputMethod"
244 objectName: "inputMethod"
251 anchors.fill: parent
245 anchors.fill: parent
252 }
246 }
qml/DisabledScreenNotice.qml+2−1
@@ -28,8 +28,9 @@ Item {
28 property var screen: Screen
28 property var screen: Screen
29 property var orientationLock: OrientationLock
29 property var orientationLock: OrientationLock
30
30
31+ property alias deviceConfiguration: _deviceConfiguration
31 DeviceConfiguration {
32 DeviceConfiguration {
32− id: deviceConfiguration
33+ id: _deviceConfiguration
33 name: applicationArguments.deviceName
34 name: applicationArguments.deviceName
34 }
35 }
35
36
qml/Greeter/Greeter.qml+21−3
@@ -25,6 +25,7 @@ import Unity.Launcher 0.1
25import Unity.Session 0.1
25import Unity.Session 0.1
26
26
27import "." 0.1
27import "." 0.1
28+import ".." 0.1
28import "../Components"
29import "../Components"
29
30
30Showable {
31Showable {
@@ -227,7 +228,7 @@ Showable {
227 if (forcedUnlock && shown) {
228 if (forcedUnlock && shown) {
228 hideView();
229 hideView();
229 if (hideNow) {
230 if (hideNow) {
230− root.hideNow(); // skip hide animation
231+ ShellNotifier.greeter.hide(true); // skip hide animation
231 }
232 }
232 }
233 }
233 }
234 }
@@ -375,7 +376,7 @@ Showable {
375 onEmergencyCall: root.emergencyCall()
376 onEmergencyCall: root.emergencyCall()
376 onRequiredChanged: {
377 onRequiredChanged: {
377 if (!loader.item.required) {
378 if (!loader.item.required) {
378− root.hide();
379+ ShellNotifier.greeter.hide(false);
379 }
380 }
380 }
381 }
381 }
382 }
@@ -498,12 +499,29 @@ Showable {
498 onRequestAuthenticationUser: d.selectUser(d.getUserIndex(user))
499 onRequestAuthenticationUser: d.selectUser(d.getUserIndex(user))
499 }
500 }
500
501
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+
501 Connections {
519 Connections {
502 target: DBusUnitySessionService
520 target: DBusUnitySessionService
503 onLockRequested: root.forceShow()
521 onLockRequested: root.forceShow()
504 onUnlocked: {
522 onUnlocked: {
505 root.forcedUnlock = true;
523 root.forcedUnlock = true;
506− root.hideNow();
524+ ShellNotifier.greeter.hide(true);
507 }
525 }
508 }
526 }
509
527
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+8−10
@@ -18,7 +18,7 @@ import QtQuick 2.4
18import QtQuick.Window 2.2
18import QtQuick.Window 2.2
19import Unity.InputInfo 0.1
19import Unity.InputInfo 0.1
20import Unity.Session 0.1
20import Unity.Session 0.1
21−import Unity.Screens 0.1
21+import WindowManager 1.0
22import Utils 0.1
22import Utils 0.1
23import GSettings 1.0
23import GSettings 1.0
24import "Components"
24import "Components"
@@ -32,15 +32,17 @@ Item {
32 implicitWidth: units.gu(40)
32 implicitWidth: units.gu(40)
33 implicitHeight: units.gu(71)
33 implicitHeight: units.gu(71)
34
34
35+ property alias deviceConfiguration: _deviceConfiguration
36+ property alias orientations: d.orientations
37+ property alias surfaceManager: shell.surfaceManager
38+
35 onWidthChanged: calculateUsageMode();
39 onWidthChanged: calculateUsageMode();
36
40
37 DeviceConfiguration {
41 DeviceConfiguration {
38− id: deviceConfiguration
42+ id: _deviceConfiguration
39 name: applicationArguments.deviceName
43 name: applicationArguments.deviceName
40 }
44 }
41
45
42− property alias orientations: d.orientations
43−
44 Item {
46 Item {
45 id: d
47 id: d
46
48
@@ -157,10 +159,6 @@ Item {
157 return false;
159 return false;
158 }
160 }
159
161
160− Screens {
161− id: screens
162− }
163−
164 property int orientation
162 property int orientation
165 onPhysicalOrientationChanged: {
163 onPhysicalOrientationChanged: {
166 if (!orientationLocked) {
164 if (!orientationLocked) {
@@ -258,7 +256,7 @@ Item {
258
256
259 Shell {
257 Shell {
260 id: shell
258 id: shell
261− objectName: "shell"
259+ objectName: "shell-"+screenWindow.objectName
262 width: root.width
260 width: root.width
263 height: root.height
261 height: root.height
264 orientation: root.angleToOrientation(orientationAngle)
262 orientation: root.angleToOrientation(orientationAngle)
@@ -272,7 +270,7 @@ Item {
272 // have multiple keyboards around. For now we only enable one keyboard at a time
270 // have multiple keyboards around. For now we only enable one keyboard at a time
273 // thus hiding it here if there is a physical one around or if we have a second
271 // thus hiding it here if there is a physical one around or if we have a second
274 // screen (the virtual touchpad & osk on the phone) attached.
272 // screen (the virtual touchpad & osk on the phone) attached.
275− oskEnabled: (keyboardsModel.count === 0 && screens.count === 1) ||
273+ oskEnabled: (keyboardsModel.count === 0 && Screens.count === 1) ||
276 forceOSKEnabled
274 forceOSKEnabled
277
275
278 usageScenario: {
276 usageScenario: {
qml/Panel/Panel.qml+14−14
@@ -47,8 +47,8 @@ Item {
47 property bool fullscreenMode: false
47 property bool fullscreenMode: false
48 property real panelAreaShowProgress: 1.0
48 property real panelAreaShowProgress: 1.0
49 property bool greeterShown: false
49 property bool greeterShown: false
50−
51 property string mode: "staged"
50 property string mode: "staged"
51+ property PanelState panelState
52
52
53 MouseArea {
53 MouseArea {
54 id: backMouseEater
54 id: backMouseEater
@@ -65,14 +65,14 @@ Item {
65 }
65 }
66
66
67 Binding {
67 Binding {
68− target: PanelState
68+ target: panelState
69 property: "panelHeight"
69 property: "panelHeight"
70 value: minimizedPanelHeight
70 value: minimizedPanelHeight
71 }
71 }
72
72
73 RegisteredApplicationMenuModel {
73 RegisteredApplicationMenuModel {
74 id: registeredMenuModel
74 id: registeredMenuModel
75− persistentSurfaceId: PanelState.focusedPersistentSurfaceId
75+ persistentSurfaceId: panelState.focusedPersistentSurfaceId
76 }
76 }
77
77
78 QtObject {
78 QtObject {
@@ -83,11 +83,11 @@ Item {
83 !indicators.shown &&
83 !indicators.shown &&
84 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
84 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
85
85
86− property bool showWindowDecorationControls: (revealControls && PanelState.decorationsVisible) ||
86+ property bool showWindowDecorationControls: (revealControls && panelState.decorationsVisible) ||
87− PanelState.decorationsAlwaysVisible
87+ panelState.decorationsAlwaysVisible
88
88
89 property bool showPointerMenu: revealControls &&
89 property bool showPointerMenu: revealControls &&
90− (PanelState.decorationsVisible || mode == "staged")
90+ (panelState.decorationsVisible || mode == "staged")
91
91
92 property bool enablePointerMenu: revealControls &&
92 property bool enablePointerMenu: revealControls &&
93 applicationMenus.available &&
93 applicationMenus.available &&
@@ -139,7 +139,7 @@ Item {
139 fill: panelAreaBackground
139 fill: panelAreaBackground
140 bottomMargin: -units.gu(1)
140 bottomMargin: -units.gu(1)
141 }
141 }
142− visible: PanelState.dropShadow
142+ visible: panelState.dropShadow
143 source: "graphics/rectangular_dropshadow.sci"
143 source: "graphics/rectangular_dropshadow.sci"
144 }
144 }
145
145
@@ -192,12 +192,12 @@ Item {
192 visible: opacity != 0
192 visible: opacity != 0
193 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
193 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
194
194
195− active: PanelState.decorationsVisible || PanelState.decorationsAlwaysVisible
195+ active: panelState.decorationsVisible || panelState.decorationsAlwaysVisible
196 windowIsMaximized: true
196 windowIsMaximized: true
197− onCloseClicked: PanelState.closeClicked()
197+ onCloseClicked: panelState.closeClicked()
198− onMinimizeClicked: PanelState.minimizeClicked()
198+ onMinimizeClicked: panelState.minimizeClicked()
199− onMaximizeClicked: PanelState.restoreClicked()
199+ onMaximizeClicked: panelState.restoreClicked()
200− closeButtonShown: PanelState.closeButtonShown
200+ closeButtonShown: panelState.closeButtonShown
201 }
201 }
202
202
203 Loader {
203 Loader {
@@ -219,7 +219,7 @@ Item {
219 anchors.left: parent.left
219 anchors.left: parent.left
220 anchors.margins: units.gu(1)
220 anchors.margins: units.gu(1)
221 height: menuBarLoader.height
221 height: menuBarLoader.height
222− enableKeyFilter: valid && PanelState.decorationsVisible
222+ enableKeyFilter: valid && panelState.decorationsVisible
223 unityMenuModel: __applicationMenus.model
223 unityMenuModel: __applicationMenus.model
224
224
225 Connections {
225 Connections {
@@ -267,7 +267,7 @@ Item {
267 }
267 }
268
268
269 showRowTitle: !expanded
269 showRowTitle: !expanded
270− rowTitle: PanelState.title
270+ rowTitle: panelState.title
271 rowItemDelegate: ActionItem {
271 rowItemDelegate: ActionItem {
272 id: actionItem
272 id: actionItem
273 property int ownIndex: index
273 property int ownIndex: index
qml/Shell.qml+48−12
@@ -1,4 +1,4 @@
1−/*
1+/*
2 * Copyright (C) 2013-2016 Canonical, Ltd.
2 * Copyright (C) 2013-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
@@ -38,12 +38,14 @@ import "Notifications"
38import "Stage"
38import "Stage"
39import "Tutorial"
39import "Tutorial"
40import "Wizard"
40import "Wizard"
41+import "Components/PanelState"
41import Unity.Notifications 1.0 as NotificationBackend
42import Unity.Notifications 1.0 as NotificationBackend
42import Unity.Session 0.1
43import Unity.Session 0.1
43import Unity.DashCommunicator 0.1
44import Unity.DashCommunicator 0.1
44import Unity.Indicators 0.1 as Indicators
45import Unity.Indicators 0.1 as Indicators
45import Cursor 1.1
46import Cursor 1.1
46import WindowManager 1.0
47import WindowManager 1.0
48+import Unity.Debug 0.1 as Debug
47
49
48
50
49StyledItem {
51StyledItem {
@@ -52,6 +54,7 @@ StyledItem {
52 theme.name: "Ubuntu.Components.Themes.SuruDark"
54 theme.name: "Ubuntu.Components.Themes.SuruDark"
53
55
54 // to be set from outside
56 // to be set from outside
57+ property alias surfaceManager: topLevelSurfaceList.surfaceManager
55 property int orientationAngle: 0
58 property int orientationAngle: 0
56 property int orientation
59 property int orientation
57 property Orientations orientations
60 property Orientations orientations
@@ -259,21 +262,21 @@ StyledItem {
259 schema.id: "com.canonical.Unity8"
262 schema.id: "com.canonical.Unity8"
260 }
263 }
261
264
265+ PanelState {
266+ id: panelState
267+ objectName: "panelState"
268+ }
269+
262 Item {
270 Item {
263 id: stages
271 id: stages
264 objectName: "stages"
272 objectName: "stages"
265 width: parent.width
273 width: parent.width
266 height: parent.height
274 height: parent.height
267
275
268− SurfaceManager {
269− id: surfaceMan
270− objectName: "surfaceManager"
271− }
272 TopLevelWindowModel {
276 TopLevelWindowModel {
273 id: topLevelSurfaceList
277 id: topLevelSurfaceList
274 objectName: "topLevelSurfaceList"
278 objectName: "topLevelSurfaceList"
275 applicationManager: ApplicationManager // it's a singleton
279 applicationManager: ApplicationManager // it's a singleton
276− surfaceManager: surfaceMan
277 }
280 }
278
281
279 Stage {
282 Stage {
@@ -315,6 +318,7 @@ StyledItem {
315 altTabPressed: physicalKeysMapper.altTabPressed
318 altTabPressed: physicalKeysMapper.altTabPressed
316 oskEnabled: shell.oskEnabled
319 oskEnabled: shell.oskEnabled
317 spreadEnabled: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
320 spreadEnabled: tutorial.spreadEnabled && (!greeter || (!greeter.hasLockedApp && !greeter.shown))
321+ panelState: panelState
318
322
319 onSpreadShownChanged: {
323 onSpreadShownChanged: {
320 panel.indicators.hide();
324 panel.indicators.hide();
@@ -369,8 +373,13 @@ StyledItem {
369 objectName: "greeterLoader"
373 objectName: "greeterLoader"
370 anchors.fill: parent
374 anchors.fill: parent
371 anchors.topMargin: panel.panelHeight
375 anchors.topMargin: panel.panelHeight
372− sourceComponent: shell.mode != "shell" ? integratedGreeter :
376+ sourceComponent: {
377+ if (shell.mode != "shell") {
378+ if (screenWindow.primary) return integratedGreeter;
379+ return secondaryGreeter;
380+ }
373− Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
381+ return Qt.createComponent(Qt.resolvedUrl("Greeter/ShimGreeter.qml"));
382+ }
374 onLoaded: {
383 onLoaded: {
375 item.objectName = "greeter"
384 item.objectName = "greeter"
376 }
385 }
@@ -420,6 +429,13 @@ StyledItem {
420 }
429 }
421 }
430 }
422
431
432+ Component {
433+ id: secondaryGreeter
434+ SecondaryGreeter {
435+ hides: [launcher, panel.indicators]
436+ }
437+ }
438+
423 Timer {
439 Timer {
424 // See powerConnection for why this is useful
440 // See powerConnection for why this is useful
425 id: showGreeterDelayed
441 id: showGreeterDelayed
@@ -533,6 +549,7 @@ StyledItem {
533 fullscreenMode: (focusedSurfaceIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0 && !stage.spreadShown)
549 fullscreenMode: (focusedSurfaceIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0 && !stage.spreadShown)
534 || greeter.hasLockedApp
550 || greeter.hasLockedApp
535 greeterShown: greeter && greeter.shown
551 greeterShown: greeter && greeter.shown
552+ panelState: panelState
536 }
553 }
537
554
538 Launcher {
555 Launcher {
@@ -772,12 +789,13 @@ StyledItem {
772
789
773 Cursor {
790 Cursor {
774 id: cursor
791 id: cursor
775− objectName: "cursor"
792+ objectName: "Pointer-"+screenWindow.objectName
776− visible: shell.hasMouse
793+
777 z: itemGrabber.z + 1
794 z: itemGrabber.z + 1
795+ opacity: 0
778 topBoundaryOffset: panel.panelHeight
796 topBoundaryOffset: panel.panelHeight
779−
797+ enabled: shell.hasMouse && screenWindow.active
780− confiningItem: stage.itemConfiningMouseCursor
798+ visible: enabled
781
799
782 property bool mouseNeverMoved: true
800 property bool mouseNeverMoved: true
783 Binding {
801 Binding {
@@ -789,6 +807,8 @@ StyledItem {
789 when: cursor.mouseNeverMoved && cursor.visible
807 when: cursor.mouseNeverMoved && cursor.visible
790 }
808 }
791
809
810+ confiningItem: stage.itemConfiningMouseCursor
811+
792 height: units.gu(3)
812 height: units.gu(3)
793
813
794 readonly property var previewRectangle: stage.previewRectangle.target &&
814 readonly property var previewRectangle: stage.previewRectangle.target &&
@@ -875,4 +895,20 @@ StyledItem {
875 }
895 }
876 }
896 }
877 }
897 }
898+
899+ Loader {
900+ z: shutdownFadeOutRectangle.z + 1
901+ active: DebuggingController.logOverlay
902+
903+ sourceComponent: Text {
904+ width: shell.width
905+ height: shell.height
906+
907+ text: consoleLog.out
908+ Debug.ConsoleLog {
909+ id: consoleLog
910+ enabled: true
911+ }
912+ }
913+ }
878}
914}
qml/ShellApplication.qmlnew file+52
@@ -0,0 +1,52 @@
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+ property QtObject surfaceMan: SurfaceManager {}
27+
28+ ShellScreen {
29+ id: window
30+ objectName: "screen"+index
31+ screen: model.screen
32+ visibility: applicationArguments.hasFullscreen ? Window.FullScreen : Window.Windowed
33+ flags: applicationArguments.hasFrameless ? Qt.FramelessWindowHint : 0
34+ surfaceManager: surfaceMan
35+
36+ Binding {
37+ when: applicationArguments.hasGeometry
38+ target: window
39+ property: "width"
40+ value: applicationArguments.windowGeometry.width
41+ }
42+ Binding {
43+ when: applicationArguments.hasGeometry
44+ target: window
45+ property: "height"
46+ value: applicationArguments.windowGeometry.height
47+ }
48+
49+ Component.onCompleted: screen.active = primary
50+ primary: index == 0
51+ }
52+}
src/SecondaryWindow.h → qml/ShellNotifier.qmlrenamed+12−12
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -14,17 +14,17 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#ifndef UNITY_SECONDARY_WINDOW_H
17+/*
18−#define UNITY_SECONDARY_WINDOW_H
18+ Shared signals & properties on multi-window desktop
19−
19+ */
20−#include <QQuickView>
21
20
22−class SecondaryWindow : public QQuickView
21+pragma Singleton
23−{
22+import QtQuick 2.4
24− Q_OBJECT
25
23
26−public:
24+QtObject {
27− SecondaryWindow(QQmlEngine *engine);
25+ property var greeter: QtObject {
28−};
26+ signal hide(bool now)
29
27
30−#endif // UNITY_SECONDARY_WINDOW_H
28+ property bool shown: true
29+ }
30+}
qml/ShellScreen.qmlnew file+65
@@ -0,0 +1,65 @@
1+/*
2+* Copyright (C) 2016 Canonical, Ltd.
3+*
4+* This program is free software; you can redistribute it and/or modify
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+ property QtObject surfaceManager: null
30+
31+ DeviceConfiguration {
32+ id: deviceConfiguration
33+ name: applicationArguments.deviceName
34+ }
35+
36+ 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+ surfaceManager: screenWindow.surfaceManager
54+
55+ deviceConfiguration {
56+ name: Screens.count > 1 ? "desktop" : applicationArguments.deviceName
57+ }
58+ }
59+ }
60+
61+ Component {
62+ id: disabledScreenComponent
63+ DisabledScreenNotice {}
64+ }
65+}
qml/Stage/DecoratedWindow.qml+3−1
@@ -72,6 +72,8 @@ FocusScope {
72
72
73 readonly property Item clientAreaItem: applicationWindow
73 readonly property Item clientAreaItem: applicationWindow
74
74
75+ property PanelState panelState
76+
75 signal closeClicked()
77 signal closeClicked()
76 signal maximizeClicked()
78 signal maximizeClicked()
77 signal maximizeHorizontallyClicked()
79 signal maximizeHorizontallyClicked()
@@ -225,7 +227,7 @@ FocusScope {
225 enableMenus: {
227 enableMenus: {
226 return active &&
228 return active &&
227 surface &&
229 surface &&
228− (PanelState.focusedPersistentSurfaceId === surface.persistentId && !PanelState.decorationsVisible)
230+ (panelState.focusedPersistentSurfaceId === surface.persistentId && !panelState.decorationsVisible)
229 }
231 }
230 menu: sharedAppModel.model
232 menu: sharedAppModel.model
231
233
qml/Stage/FakeMaximizeDelegate.qml+12−11
@@ -35,6 +35,7 @@ Rectangle {
35 property int leftMargin
35 property int leftMargin
36 property real appContainerWidth
36 property real appContainerWidth
37 property real appContainerHeight
37 property real appContainerHeight
38+ property PanelState panelState
38
39
39 readonly property real hintThreshold: 0.1
40 readonly property real hintThreshold: 0.1
40
41
@@ -178,7 +179,7 @@ Rectangle {
178 ParallelAnimation {
179 ParallelAnimation {
179 id: fakeMaximizeAnimation
180 id: fakeMaximizeAnimation
180 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
181 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 }
182 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: appContainerWidth - leftMargin }
183 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: appContainerWidth - leftMargin }
183 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight }
184 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight }
184 }
185 }
@@ -186,39 +187,39 @@ Rectangle {
186 ParallelAnimation {
187 ParallelAnimation {
187 id: fakeMaximizeLeftAnimation
188 id: fakeMaximizeLeftAnimation
188 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
189 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 }
190 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
191 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 }
192 }
193 }
193
194
194 ParallelAnimation {
195 ParallelAnimation {
195 id: fakeMaximizeRightAnimation
196 id: fakeMaximizeRightAnimation
196 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
197 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 }
198 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
199 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 }
200 }
201 }
201
202
202 ParallelAnimation {
203 ParallelAnimation {
203 id: fakeMaximizeTopLeftAnimation
204 id: fakeMaximizeTopLeftAnimation
204 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
205 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 }
206 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
207 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 }
208 }
209 }
209
210
210 ParallelAnimation {
211 ParallelAnimation {
211 id: fakeMaximizeTopRightAnimation
212 id: fakeMaximizeTopRightAnimation
212 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
213 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 }
214 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
215 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 }
216 }
217 }
217
218
218 ParallelAnimation {
219 ParallelAnimation {
219 id: fakeMaximizeBottomLeftAnimation
220 id: fakeMaximizeBottomLeftAnimation
220 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: leftMargin }
221 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 }
222 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
223 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
223 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }
224 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }
224 }
225 }
@@ -226,7 +227,7 @@ Rectangle {
226 ParallelAnimation {
227 ParallelAnimation {
227 id: fakeMaximizeBottomRightAnimation
228 id: fakeMaximizeBottomRightAnimation
228 UbuntuNumberAnimation { target: fakeRectangle; properties: "x"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth + leftMargin)/2 }
229 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 }
230 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
231 UbuntuNumberAnimation { target: fakeRectangle; properties: "width"; duration: UbuntuAnimation.BriskDuration; to: (appContainerWidth - leftMargin)/2 }
231 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }
232 UbuntuNumberAnimation { target: fakeRectangle; properties: "height"; duration: UbuntuAnimation.BriskDuration; to: appContainerHeight/2 }
232 }
233 }
qml/Stage/Spread/ScreensAndWorkspaces.qmlnew file+181
@@ -0,0 +1,181 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import Ubuntu.Components.Popups 1.3
4+import Unity.Screens 0.1
5+import Unity.Application 0.1
6+import ".."
7+
8+Item {
9+ id: root
10+
11+ property string background
12+
13+ Row {
14+ id: row
15+ anchors.bottom: parent.bottom
16+ anchors.horizontalCenter: parent.horizontalCenter
17+ Behavior on anchors.horizontalCenterOffset { NumberAnimation { duration: UbuntuAnimation.SlowDuration } }
18+// anchors.left: parent.left
19+ spacing: units.gu(1)
20+
21+ Repeater {
22+ model: Screens
23+
24+ delegate: Item {
25+ height: root.height - units.gu(6)
26+ width: workspaces.width
27+ clip: true
28+
29+ UbuntuShape {
30+ id: header
31+ anchors { left: parent.left; top: parent.top; right: parent.right }
32+ height: units.gu(7)
33+ backgroundColor: "white"
34+ z: 1
35+
36+ DropArea {
37+ anchors.fill: parent
38+ keys: ["workspace"]
39+
40+ onEntered: {
41+ workspaces.workspaceModel.insert(workspaces.workspaceModel.count, {text: drag.source.text})
42+ drag.source.inDropArea = true;
43+ }
44+
45+ onExited: {
46+ workspaces.workspaceModel.remove(workspaces.workspaceModel.count - 1, 1)
47+ drag.source.inDropArea = false;
48+ }
49+
50+ onDropped: {
51+ drag.source.inDropArea = false;
52+ }
53+ }
54+
55+ Column {
56+ anchors.fill: parent
57+ anchors.margins: units.gu(1)
58+
59+ Label {
60+ text: model.screen.name
61+ color: "black"
62+ }
63+
64+ Label {
65+ text: model.screen.outputType === Screens.LVDS ? "Built-in" : "Clone"
66+ color: "black"
67+ fontSize: "x-small"
68+ }
69+
70+ Label {
71+ text: model.screen.physicalSize.width + "x" + model.screen.physicalSize.height
72+ color: "black"
73+ fontSize: "x-small"
74+ }
75+ }
76+
77+ MouseArea {
78+ anchors.fill: parent
79+// acceptedButtons: Qt.RightButton
80+
81+
82+ onClicked: {
83+ print("should open popup")
84+ PopupUtils.open(contextMenu)
85+ }
86+ }
87+
88+ Component {
89+ id: contextMenu
90+ ActionSelectionPopover {
91+ actions: ActionList {
92+ Action {
93+ text: "Add workspace"
94+ onTriggered: workspaces.workspaceModel.append({text: "" + (workspaces.workspaceModel.count + 1)})
95+ }
96+ }
97+ }
98+ }
99+ }
100+
101+
102+ Workspaces {
103+ id: workspaces
104+ height: parent.height - header.height - units.gu(2)
105+ width: Math.min(implicitWidth, index == 0 ? units.gu(80) : units.gu(40), root.width)
106+ Behavior on width { UbuntuNumberAnimation {} }
107+ anchors.bottom: parent.bottom
108+ anchors.bottomMargin: units.gu(1)
109+ anchors.horizontalCenter: parent.horizontalCenter
110+ screen: model.screen
111+ background: root.background
112+
113+ workspaceModel: ListModel {
114+ onCountChanged: print("model count changed to", count)
115+ ListElement {text: "1"}
116+ ListElement {text: "2"}
117+ ListElement {text: "3"}
118+ ListElement {text: "4"}
119+ ListElement {text: "5"}
120+ ListElement {text: "6"}
121+// ListElement {text: "7"}
122+// ListElement {text: "8"}
123+// ListElement {text: "9"}
124+ }
125+ }
126+ }
127+ }
128+ }
129+
130+ Rectangle {
131+ anchors { left: parent.left; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
132+ width: units.gu(5)
133+ color: "#33000000"
134+ visible: (row.width - root.width + units.gu(10)) / 2 - row.anchors.horizontalCenterOffset > units.gu(5)
135+ MouseArea {
136+ id: leftScrollArea
137+ anchors.fill: parent
138+ hoverEnabled: true
139+ onPressed: mouse.accepted = false;
140+ }
141+ DropArea {
142+ id: leftFakeDropArea
143+ anchors.fill: parent
144+ keys: ["application", "workspace"]
145+ }
146+ }
147+ Rectangle {
148+ anchors { right: parent.right; top: parent.top; bottom: parent.bottom; topMargin: units.gu(6); bottomMargin: units.gu(1) }
149+ width: units.gu(5)
150+ color: "#33000000"
151+ visible: (row.width - root.width + units.gu(10)) / 2 + row.anchors.horizontalCenterOffset > units.gu(5)
152+ MouseArea {
153+ id: rightScrollArea
154+ anchors.fill: parent
155+ hoverEnabled: true
156+ onPressed: mouse.accepted = false;
157+ }
158+ DropArea {
159+ id: rightFakeDropArea
160+ anchors.fill: parent
161+ keys: ["application", "workspace"]
162+ }
163+ }
164+ Timer {
165+ repeat: true
166+ running: leftScrollArea.containsMouse || rightScrollArea.containsMouse || leftFakeDropArea.containsDrag || rightFakeDropArea.containsDrag
167+ interval: UbuntuAnimation.SlowDuration
168+ triggeredOnStart: true
169+ onTriggered: {
170+ var newOffset = row.anchors.horizontalCenterOffset;
171+ var maxOffset = Math.max((row.width - root.width + units.gu(10)) / 2, 0);
172+ if (leftScrollArea.containsMouse || leftFakeDropArea.containsDrag) {
173+ newOffset += units.gu(20)
174+ } else {
175+ newOffset -= units.gu(20)
176+ }
177+ newOffset = Math.max(-maxOffset, Math.min(maxOffset, newOffset));
178+ row.anchors.horizontalCenterOffset = newOffset;
179+ }
180+ }
181+}
qml/Stage/Spread/Spread.qml+5−5
@@ -28,10 +28,10 @@ Item {
28 property var spreadFlickable
28 property var spreadFlickable
29
29
30 // some config options
30 // some config options
31− property real contentMargin: 0.16 * root.height
31+ property real contentMargin: 0.1 * root.height
32− property real contentTopMargin: contentMargin
32+ property real contentTopMargin: contentMargin + root.y + windowTitle.height
33− property real contentBottomMargin: 0.35 * contentMargin
33+ property real contentBottomMargin: contentMargin
34− property real windowTitleTopMargin: 3/4 * (contentTopMargin - windowTitle.height)
34+ property real windowTitleTopMargin: contentMargin - windowTitle.height
35 property int stackItemCount: 3
35 property int stackItemCount: 3
36 property real leftRotationAngle: 22
36 property real leftRotationAngle: 22
37 property real rightRotationAngle: 32
37 property real rightRotationAngle: 32
@@ -51,7 +51,7 @@ Item {
51
51
52 readonly property real spreadWidth: rightStackXPos - leftStackXPos
52 readonly property real spreadWidth: rightStackXPos - leftStackXPos
53 readonly property real spreadHeight: root.height
53 readonly property real spreadHeight: root.height
54− readonly property real spreadItemHeight: spreadHeight - contentTopMargin - contentBottomMargin
54+ readonly property real spreadItemHeight: spreadHeight - contentMargin * 2
55 readonly property real spreadItemWidth: stackHeight
55 readonly property real spreadItemWidth: stackHeight
56
56
57 readonly property real dynamicLeftRotationAngle: leftRotationAngle * rotationAngleFactor
57 readonly property real dynamicLeftRotationAngle: leftRotationAngle * rotationAngleFactor
qml/Stage/Spread/SpreadDelegateInputArea.qml+26−11
@@ -85,15 +85,15 @@ Item {
85 }
85 }
86
86
87 // Event eater
87 // Event eater
88− MouseArea {
88+// MouseArea {
89− anchors.fill: parent
89+// anchors.fill: parent
90− onClicked: root.clicked()
90+// onClicked: root.clicked()
91− onWheel: wheel.accepted = true
91+// onWheel: wheel.accepted = true
92− }
92+// }
93
93
94 MultiPointTouchArea {
94 MultiPointTouchArea {
95 anchors.fill: parent
95 anchors.fill: parent
96− mouseEnabled: false
96+// mouseEnabled: false
97 maximumTouchPoints: 1
97 maximumTouchPoints: 1
98 property int offset: 0
98 property int offset: 0
99
99
@@ -109,7 +109,7 @@ Item {
109 }
109 }
110
110
111 onTouchUpdated: {
111 onTouchUpdated: {
112− if (!d.moving) {
112+ if (!d.moving || !tp.pressed) {
113 if (Math.abs(tp.startY - tp.y) > d.threshold) {
113 if (Math.abs(tp.startY - tp.y) > d.threshold) {
114 d.moving = true;
114 d.moving = true;
115 d.dragEvents = []
115 d.dragEvents = []
@@ -119,17 +119,32 @@ Item {
119 }
119 }
120 }
120 }
121
121
122− if (root.closeable) {
122+
123− d.distance = tp.y - tp.startY - offset
123+ var value = tp.y - tp.startY - offset;
124+ if (value < 0) {
125+ var coords = mapToItem(shell, tp.x, tp.y);
126+ fakeDragItem.x = coords.x - units.gu(5)
127+ fakeDragItem.y = coords.y - units.gu(5)
128+ fakeDragItem.Drag.hotSpot.x = units.gu(5)
129+ fakeDragItem.Drag.hotSpot.y = units.gu(5)
130+ fakeDragItem.Drag.active = true;
131+ fakeDragItem.surface = model.window.surface;
132+
124 } else {
133 } else {
125− var value = tp.y - tp.startY - offset;
134+ if (root.closeable) {
135+ d.distance = value
136+ } else {
126− d.distance = Math.sqrt(Math.abs(value)) * (value < 0 ? -1 : 1) * 3
137+ d.distance = Math.sqrt(Math.abs(value)) * (value < 0 ? -1 : 1) * 3
138+ }
127 }
139 }
128
140
129 d.pushDragEvent(tp);
141 d.pushDragEvent(tp);
130 }
142 }
131
143
132 onReleased: {
144 onReleased: {
145+ print("released!")
146+ fakeDragItem.surface = null;
147+
133 if (!d.moving) {
148 if (!d.moving) {
134 root.clicked()
149 root.clicked()
135 }
150 }
qml/Stage/Spread/WorkspacePreview.qmlnew file+220
@@ -0,0 +1,220 @@
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 ".."
6+import "../../Components"
7+
8+Item {
9+ id: previewSpace
10+ clip: true
11+
12+ property string background
13+ property int screenHeight
14+
15+ property real previewScale: previewSpace.height / previewSpace.screenHeight
16+
17+ property bool containsDrag: false
18+
19+ Image {
20+ source: previewSpace.background
21+ anchors.fill: parent
22+ sourceSize.width: width
23+ sourceSize.height: height
24+
25+ Repeater {
26+ id: topLevelSurfaceRepeater
27+ model: visible ? topLevelSurfaceList : null
28+ delegate: Rectangle {
29+ width: surfaceItem.width
30+ height: surfaceItem.height + decorationHeight * previewScale
31+ x: model.window.position.x * previewScale
32+ y: (model.window.position.y - decorationHeight) * previewScale
33+ color: "blue"
34+ z: topLevelSurfaceRepeater.count - index
35+
36+ property int decorationHeight: units.gu(3)
37+
38+ WindowDecoration {
39+ width: surfaceItem.implicitWidth
40+ height: parent.decorationHeight
41+ transform: Scale {
42+ origin.x: 0
43+ origin.y: 0
44+ xScale: previewScale
45+ yScale: previewScale
46+ }
47+ title: model.window && model.window.surface ? model.window.surface.name : ""
48+ z: 3
49+ }
50+
51+ MirSurfaceItem {
52+ id: surfaceItem
53+ y: parent.decorationHeight * previewScale
54+ width: implicitWidth * previewScale
55+ height: implicitHeight * previewScale
56+ surfaceWidth: -1
57+ surfaceHeight: -1
58+ onImplicitHeightChanged: print("item", surfaceItem, "height changed", implicitHeight)
59+ surface: model.window.surface
60+ }
61+ }
62+ }
63+
64+ }
65+
66+ Rectangle {
67+ anchors.fill: parent
68+ border.color: UbuntuColors.blue
69+ border.width: units.gu(.5)
70+ color: "transparent"
71+ visible: previewSpace.containsDrag
72+ }
73+}
74+
75+ // Repeater {
76+ // id: topLevelSurfaceRepeater
77+ // model: visible ? topLevelSurfaceList : null
78+ // delegate: Rectangle {
79+ // width: surfaceItem.width
80+ // height: surfaceItem.height + decorationHeight * previewScale
81+ // x: model.window.position.x * previewScale
82+ // y: (model.window.position.y - decorationHeight) * previewScale
83+ // color: "blue"
84+ // z: topLevelSurfaceRepeater.count - index
85+
86+ // property int decorationHeight: units.gu(3)
87+
88+ // WindowDecoration {
89+ // width: surfaceItem.implicitWidth
90+ // height: parent.decorationHeight
91+ // transform: Scale {
92+ // origin.x: 0
93+ // origin.y: 0
94+ // xScale: previewScale
95+ // yScale: previewScale
96+ // }
97+ // title: model.window && model.window.surface ? model.window.surface.name : ""
98+ // z: 3
99+ // }
100+
101+ // MirSurfaceItem {
102+ // id: surfaceItem
103+ // y: parent.decorationHeight * previewScale
104+ // width: implicitWidth * previewScale
105+ // height: implicitHeight * previewScale
106+ // surfaceWidth: -1
107+ // surfaceHeight: -1
108+ // onImplicitHeightChanged: print("item", surfaceItem, "height changed", implicitHeight)
109+ // surface: model.window.surface
110+ // }
111+ // }
112+ // }
113+// }
114+// }
115+
116+
117+// MouseArea {
118+// id: mouseArea
119+// anchors.centerIn: parent
120+// anchors.verticalCenterOffset: header.height / 2
121+// width: units.gu(8)
122+// height: width
123+// hoverEnabled: true
124+// opacity: containsMouse ? 1 : 0
125+
126+// Rectangle {
127+// anchors.fill: parent
128+// color: "#80000000"
129+// radius: height / 2
130+// }
131+
132+// NumberAnimation {
133+// target: canvas
134+// property: "progress"
135+// duration: 2000
136+// running: mouseArea.containsMouse
137+// from: 0
138+// to: 1
139+// }
140+
141+// Canvas {
142+// id: canvas
143+// height: parent.height
144+// width: height
145+// anchors.centerIn: parent
146+
147+// property real progress: 0.5
148+// property int lineWidth: units.dp(4)
149+// onProgressChanged: {
150+// requestPaint();
151+// if (progress == 1) {
152+// Screens.activateScreen(index);
153+// }
154+// }
155+
156+// rotation: -90
157+
158+// onPaint: {
159+// var ctx = canvas.getContext("2d");
160+// ctx.save();
161+// ctx.reset();
162+
163+// ctx.lineWidth = lineWidth;
164+
165+// ctx.strokeStyle = "#3bffffff"
166+// ctx.beginPath();
167+// ctx.arc(canvas.width/2,canvas.height/2, (canvas.height - ctx.lineWidth) / 2, 0, (Math.PI*2),false);
168+// ctx.stroke();
169+// ctx.closePath();
170+
171+// ctx.strokeStyle = "white"
172+// ctx.beginPath();
173+// ctx.arc(canvas.width/2,canvas.height/2, (canvas.height - ctx.lineWidth) / 2, 0, (Math.PI*2*(progress)),false);
174+// ctx.stroke();
175+// ctx.closePath();
176+
177+// ctx.restore();
178+// }
179+// }
180+
181+// Icon {
182+// source: "graphics/multi-monitor_leave.png"
183+// height: units.gu(4)
184+// width: height
185+// anchors.centerIn: parent
186+// }
187+// }
188+// }
189+
190+// FloatingFlickable {
191+// id: flickable
192+// anchors.fill: parent
193+// contentWidth: workspaceRepeater.count * previewSpace.screenWidth * previewScale
194+// property real progress: contentX / contentWidth
195+// onContentXChanged: print("contentX:", contentX, "progress:", progress)
196+// }
197+
198+// MouseArea {
199+// anchors.fill: parent
200+// hoverEnabled: true
201+// property int scrollAreaWidth: width / 3
202+
203+// onMouseXChanged: {
204+// var margins = flickable.width * 0.05;
205+
206+// // do we need to scroll?
207+// if (mouseX < scrollAreaWidth + margins) {
208+// var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
209+// var contentX = (1 - progress) * (flickable.contentWidth - flickable.width)
210+// flickable.contentX = Math.max(0, Math.min(flickable.contentX, contentX))
211+// }
212+// if (mouseX > flickable.width - scrollAreaWidth) {
213+// var progress = Math.min(1, (mouseX - (flickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
214+// var contentX = progress * (flickable.contentWidth - flickable.width)
215+// flickable.contentX = Math.min(flickable.contentWidth - flickable.width, Math.max(flickable.contentX, contentX))
216+// }
217+// }
218+// }
219+// }
220+//}
qml/Stage/Spread/Workspaces.qmlnew file+307
@@ -0,0 +1,307 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import "MathUtils.js" as MathUtils
4+import "../../Components"
5+
6+Item {
7+ id: root
8+ implicitWidth: listView.count * (height * 16/9 + listView.spacing) - listView.spacing
9+// color: "blue"
10+
11+ property QtObject screen: null
12+ property alias workspaceModel: listView.model
13+ property var background // TODO: should be stored in the workspace data
14+
15+ DropArea {
16+ anchors.fill: root
17+
18+ keys: ['workspace']
19+
20+ onEntered: {
21+ var index = listView.getDropIndex(drag);
22+ listView.model.insert(index, {text: drag.source.text})
23+ listView.dropItemIndex = index;
24+ drag.source.inDropArea = true;
25+ }
26+
27+ onPositionChanged: {
28+ var index = listView.getDropIndex(drag);
29+ if (listView.dropItemIndex == index) return;
30+ listView.model.move(listView.dropItemIndex, index, 1);
31+ listView.dropItemIndex = index;
32+ }
33+
34+ onExited: {
35+ listView.model.remove(listView.dropItemIndex, 1);
36+ listView.dropItemIndex = -1;
37+ drag.source.inDropArea = false;
38+ }
39+
40+ onDropped: {
41+ listView.dropItemIndex = -1;
42+ drag.source.inDropArea = false;
43+ }
44+ }
45+ DropArea {
46+ anchors.fill: parent
47+ keys: ["application"]
48+
49+ onPositionChanged: {
50+ listView.progressiveScroll(drag.x)
51+ listView.hoveredWorkspaceIndex = listView.getDropIndex(drag)
52+ }
53+ onExited: {
54+ listView.hoveredWorkspaceIndex = -1
55+ }
56+ }
57+
58+ ListView {
59+ id: listView
60+ anchors.fill: parent
61+ anchors.leftMargin: -itemWidth
62+ anchors.rightMargin: -itemWidth
63+// interactive: false
64+
65+ orientation: ListView.Horizontal
66+ spacing: units.gu(1)
67+ leftMargin: itemWidth
68+ rightMargin: itemWidth
69+
70+ property int itemWidth: height * 16 / 9
71+ property int foldingAreaWidth: units.gu(10)
72+ property real realContentX: contentX - originX + leftMargin
73+ property int dropItemIndex: -1
74+ property int hoveredWorkspaceIndex: -1
75+
76+ function getDropIndex(drag) {
77+ var coords = mapToItem(listView.contentItem, drag.x, drag.y)
78+ var index = Math.floor((drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing));
79+ if (index < 0) index = 0;
80+ var upperLimit = dropItemIndex == -1 ? listView.count : listView.count - 1
81+ if (index > upperLimit) index = upperLimit;
82+ return index;
83+ }
84+
85+ function progressiveScroll(mouseX) {
86+ var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
87+ print("p", progress, mouseX)
88+ listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
89+ }
90+
91+ displaced: Transition { UbuntuNumberAnimation { properties: "x" } }
92+
93+ delegate: Item {
94+ objectName: "delegate" + index
95+ height: parent.height
96+ width: listView.itemWidth
97+ Behavior on width { UbuntuNumberAnimation {} }
98+ visible: listView.dropItemIndex !== index
99+
100+ property int itemX: -listView.realContentX + index * (listView.itemWidth + listView.spacing)
101+ property int distanceFromLeft: itemX //- listView.leftMargin
102+ property int distanceFromRight: listView.width - listView.leftMargin - listView.rightMargin - itemX - listView.itemWidth
103+
104+ property int maxAngle: 40
105+
106+ property int itemAngle: {
107+ if (index == 0) {
108+ if (distanceFromLeft < 0) {
109+ var progress = (distanceFromLeft + listView.foldingAreaWidth) / listView.foldingAreaWidth
110+ return MathUtils.linearAnimation(1, -1, 0, maxAngle, Math.max(-1, Math.min(1, progress)));
111+ }
112+ return 0
113+ }
114+ if (index == listView.count - 1) {
115+ if (distanceFromRight < 0) {
116+ var progress = (distanceFromRight + listView.foldingAreaWidth) / listView.foldingAreaWidth
117+ return MathUtils.linearAnimation(1, -1, 0, -maxAngle, Math.max(-1, Math.min(1, progress)));
118+ }
119+ return 0
120+ }
121+
122+ if (distanceFromLeft < listView.foldingAreaWidth) {
123+ // itemX : 10gu = p : 100
124+ var progress = distanceFromLeft / listView.foldingAreaWidth
125+ return MathUtils.linearAnimation(1, -1, 0, maxAngle, Math.max(-1, Math.min(1, progress)));
126+ }
127+ if (distanceFromRight < listView.foldingAreaWidth) {
128+ var progress = distanceFromRight / listView.foldingAreaWidth
129+ return MathUtils.linearAnimation(1, -1, 0, -maxAngle, Math.max(-1, Math.min(1, progress)));
130+ }
131+ return 0
132+ }
133+
134+ property int itemOffset: {
135+ var rotationOffset = (1 - Math.cos(itemAngle * Math.PI / 360)) * listView.itemWidth
136+ if (index == 0) {
137+ if (distanceFromLeft < 0) {
138+ return -distanceFromLeft - rotationOffset
139+ }
140+ return 0
141+ }
142+ if (index == listView.count - 1) {
143+ if (distanceFromRight < 0) {
144+ return distanceFromRight + rotationOffset
145+ }
146+ return 0
147+ }
148+
149+ if (itemX < -listView.foldingAreaWidth) {
150+ return -itemX - rotationOffset
151+ }
152+ if (distanceFromLeft < listView.foldingAreaWidth) {
153+ return (listView.foldingAreaWidth - distanceFromLeft) / 2 - rotationOffset
154+ }
155+
156+ if (distanceFromRight < -listView.foldingAreaWidth) {
157+ return distanceFromRight + rotationOffset
158+ }
159+
160+ if (distanceFromRight < listView.foldingAreaWidth) {
161+ return -(listView.foldingAreaWidth - distanceFromRight) / 2 + rotationOffset
162+ }
163+
164+ return 0
165+ }
166+
167+// onItemXChanged: if (index == 1) print("x", itemX, listView.contentX)
168+
169+ z: itemOffset < 0 ? itemOffset : -itemOffset
170+ transform: [
171+ Rotation {
172+ angle: itemAngle
173+ axis { x: 0; y: 1; z: 0 }
174+ origin { x: listView.itemWidth / 2; y: height / 2 }
175+ },
176+ Translate {
177+ x: itemOffset
178+ }
179+ ]
180+
181+ WorkspacePreview {
182+ height: listView.height
183+ width: listView.itemWidth
184+ background: root.background
185+ screenHeight: root.screen.physicalSize.height
186+ containsDrag: listView.hoveredWorkspaceIndex == index
187+
188+ Label {
189+ anchors.centerIn: parent
190+ text: model.text
191+ color: "red"
192+ fontSize: "large"
193+ }
194+ }
195+ }
196+
197+ MouseArea {
198+ id: mouseArea
199+ anchors.fill: parent
200+ hoverEnabled: true
201+ propagateComposedEvents: true
202+ anchors.leftMargin: listView.leftMargin
203+ anchors.rightMargin: listView.rightMargin
204+
205+ property int draggedIndex: -1
206+
207+ property int startX: 0
208+ property int startY: 0
209+
210+ onMouseXChanged: {
211+ if (!pressed || dragging) {
212+ listView.progressiveScroll(mouseX)
213+ }
214+ }
215+ onMouseYChanged: {
216+ if (Math.abs(mouseY - startY) > units.gu(3)) {
217+ drag.axis = Drag.XAndYAxis;
218+ }
219+ }
220+
221+ onReleased: {
222+ fakeDragItem.Drag.drop();
223+ drag.target = null;
224+ }
225+
226+ property bool dragging: drag.active
227+ onDraggingChanged: {
228+ if (drag.active) {
229+ print("drai", draggedIndex)
230+ listView.model.remove(draggedIndex, 1)
231+ }
232+ }
233+
234+ onPressed: {
235+ startX = mouseX;
236+ startY = mouseY;
237+ if (listView.model.count < 2) return;
238+
239+ var coords = mapToItem(listView.contentItem, mouseX, mouseY)
240+ draggedIndex = listView.indexAt(coords.x, coords.y)
241+ var clickedItem = listView.itemAt(coords.x, coords.y)
242+
243+ var itemCoords = clickedItem.mapToItem(listView, -listView.leftMargin, 0);
244+ fakeDragItem.x = itemCoords.x
245+ fakeDragItem.y = itemCoords.y
246+ fakeDragItem.text = listView.model.get(draggedIndex).text
247+
248+ var mouseCoordsInItem = mapToItem(clickedItem, mouseX, mouseY);
249+ fakeDragItem.Drag.hotSpot.x = mouseCoordsInItem.x
250+ fakeDragItem.Drag.hotSpot.y = mouseCoordsInItem.y
251+
252+ drag.axis = Drag.YAxis;
253+ drag.target = fakeDragItem;
254+ }
255+
256+ WorkspacePreview {
257+ id: fakeDragItem
258+ height: listView.height
259+ width: listView.itemWidth
260+ background: root.background
261+ screenHeight: root.screen.physicalSize.height
262+ visible: Drag.active
263+
264+ Drag.active: mouseArea.drag.active
265+ Drag.keys: ['workspace']
266+
267+ property string text
268+ property bool inDropArea: false
269+ Label {
270+ anchors.centerIn: parent
271+ text: parent.text
272+ color: "red"
273+ fontSize: "large"
274+ }
275+
276+ Rectangle {
277+ anchors.fill: parent
278+ color: "#33000000"
279+ opacity: parent.inDropArea ? 0 : 1
280+ Behavior on opacity { UbuntuNumberAnimation { } }
281+ Rectangle {
282+ anchors.centerIn: parent
283+ width: units.gu(6)
284+ height: units.gu(6)
285+ radius: width / 2
286+ color: "#aa000000"
287+ }
288+
289+ Icon {
290+ height: units.gu(3)
291+ width: height
292+ anchors.centerIn: parent
293+ name: "edit-delete"
294+ color: "white"
295+ }
296+ }
297+
298+ states: [
299+ State {
300+ when: fakeDragItem.Drag.active
301+ ParentChange { target: fakeDragItem; parent: shell }
302+ }
303+ ]
304+ }
305+ }
306+ }
307+}
qml/Stage/Stage.qml+138−103
@@ -47,6 +47,7 @@ FocusScope {
47 property bool oskEnabled: false
47 property bool oskEnabled: false
48 property rect inputMethodRect
48 property rect inputMethodRect
49 property real rightEdgePushProgress: 0
49 property real rightEdgePushProgress: 0
50+ property PanelState panelState
50
51
51 // Configuration
52 // Configuration
52 property string mode: "staged"
53 property string mode: "staged"
@@ -349,23 +350,23 @@ FocusScope {
349 readonly property real virtualKeyboardHeight: root.inputMethodRect.height
350 readonly property real virtualKeyboardHeight: root.inputMethodRect.height
350 }
351 }
351
352
352− Component.onCompleted: priv.updateMainAndSideStageIndexes();
353+ Component.onCompleted: {priv.updateMainAndSideStageIndexes(); print("size", root.width, root.height)}
353
354
354 Connections {
355 Connections {
355− target: PanelState
356+ target: panelState
356 onCloseClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
357 onCloseClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.close(); } }
357 onMinimizeClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestMinimize(); } }
358 onMinimizeClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestMinimize(); } }
358 onRestoreClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestRestore(); } }
359 onRestoreClicked: { if (priv.focusedAppDelegate) { priv.focusedAppDelegate.requestRestore(); } }
359 }
360 }
360
361
361 Binding {
362 Binding {
362− target: PanelState
363+ target: panelState
363 property: "decorationsVisible"
364 property: "decorationsVisible"
364 value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.maximized // FIXME for Locally integrated menus
365 value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.maximized // FIXME for Locally integrated menus
365 }
366 }
366
367
367 Binding {
368 Binding {
368− target: PanelState
369+ target: panelState
369 property: "title"
370 property: "title"
370 value: {
371 value: {
371 if (priv.focusedAppDelegate !== null) {
372 if (priv.focusedAppDelegate !== null) {
@@ -380,7 +381,7 @@ FocusScope {
380 }
381 }
381
382
382 Binding {
383 Binding {
383− target: PanelState
384+ target: panelState
384 property: "focusedPersistentSurfaceId"
385 property: "focusedPersistentSurfaceId"
385 value: {
386 value: {
386 if (priv.focusedAppDelegate !== null) {
387 if (priv.focusedAppDelegate !== null) {
@@ -394,21 +395,21 @@ FocusScope {
394 }
395 }
395
396
396 Binding {
397 Binding {
397− target: PanelState
398+ target: panelState
398 property: "dropShadow"
399 property: "dropShadow"
399 value: priv.focusedAppDelegate && !priv.focusedAppDelegate.maximized && priv.foregroundMaximizedAppDelegate !== null && mode == "windowed"
400 value: priv.focusedAppDelegate && !priv.focusedAppDelegate.maximized && priv.foregroundMaximizedAppDelegate !== null && mode == "windowed"
400 }
401 }
401
402
402 Binding {
403 Binding {
403− target: PanelState
404+ target: panelState
404 property: "closeButtonShown"
405 property: "closeButtonShown"
405 value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized && !priv.focusedAppDelegate.isDash
406 value: priv.focusedAppDelegate && priv.focusedAppDelegate.maximized && !priv.focusedAppDelegate.isDash
406 }
407 }
407
408
408 Component.onDestruction: {
409 Component.onDestruction: {
409− PanelState.title = "";
410+ panelState.title = "";
410− PanelState.decorationsVisible = false;
411+ panelState.decorationsVisible = false;
411− PanelState.dropShadow = false;
412+ panelState.dropShadow = false;
412 }
413 }
413
414
414 Instantiator {
415 Instantiator {
@@ -454,6 +455,7 @@ FocusScope {
454 PropertyChanges { target: cancelSpreadMouseArea; enabled: true }
455 PropertyChanges { target: cancelSpreadMouseArea; enabled: true }
455 PropertyChanges { target: blurLayer; visible: true; blurRadius: 32; brightness: .65; opacity: 1 }
456 PropertyChanges { target: blurLayer; visible: true; blurRadius: 32; brightness: .65; opacity: 1 }
456 PropertyChanges { target: wallpaper; visible: false }
457 PropertyChanges { target: wallpaper; visible: false }
458+ PropertyChanges { target: screensAndWorkspaces; opacity: 1 }
457 },
459 },
458 State {
460 State {
459 name: "stagedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "staged"
461 name: "stagedRightEdge"; when: root.spreadEnabled && (rightEdgeDragArea.dragging || rightEdgePushProgress > 0) && root.mode == "staged"
@@ -502,10 +504,13 @@ FocusScope {
502 from: "stagedRightEdge,sideStagedRightEdge,windowedRightEdge"; to: "spread"
504 from: "stagedRightEdge,sideStagedRightEdge,windowedRightEdge"; to: "spread"
503 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
505 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: -1 }
504 PropertyAnimation { target: blurLayer; properties: "brightness,blurRadius"; duration: priv.animationDuration }
506 PropertyAnimation { target: blurLayer; properties: "brightness,blurRadius"; duration: priv.animationDuration }
507+ UbuntuNumberAnimation { target: screensAndWorkspaces; property: "opacity"; duration: priv.animationDuration }
505 },
508 },
506 Transition {
509 Transition {
507 to: "spread"
510 to: "spread"
508 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: appRepeater.count > 1 ? 1 : 0 }
511 PropertyAction { target: spreadItem; property: "highlightedIndex"; value: appRepeater.count > 1 ? 1 : 0 }
512+ PropertyAction { target: floatingFlickable; property: "contentX"; value: 0 }
513+ UbuntuNumberAnimation { target: screensAndWorkspaces; property: "opacity"; duration: priv.animationDuration }
509 },
514 },
510 Transition {
515 Transition {
511 from: "spread"
516 from: "spread"
@@ -563,10 +568,19 @@ FocusScope {
563 visible: false
568 visible: false
564 }
569 }
565
570
571+ ScreensAndWorkspaces {
572+ id: screensAndWorkspaces
573+ anchors { left: parent.left; top: parent.top; right: parent.right; leftMargin: root.leftMargin }
574+ height: parent.height / 3
575+ background: root.background
576+ opacity: 0
577+ visible: opacity > 0
578+ }
579+
566 Spread {
580 Spread {
567 id: spreadItem
581 id: spreadItem
568 objectName: "spreadItem"
582 objectName: "spreadItem"
569− anchors.fill: appContainer
583+ anchors { left: parent.left; bottom: parent.bottom; right: parent.right; top: screensAndWorkspaces.bottom }
570 leftMargin: root.leftMargin
584 leftMargin: root.leftMargin
571 model: root.topLevelSurfaceList
585 model: root.topLevelSurfaceList
572 spreadFlickable: floatingFlickable
586 spreadFlickable: floatingFlickable
@@ -575,6 +589,83 @@ FocusScope {
575 onLeaveSpread: {
589 onLeaveSpread: {
576 priv.goneToSpread = false;
590 priv.goneToSpread = false;
577 }
591 }
592+
593+ FloatingFlickable {
594+ id: floatingFlickable
595+ objectName: "spreadFlickable"
596+ anchors.fill: parent
597+ enabled: false
598+ contentWidth: spreadItem.spreadTotalWidth
599+
600+ function snap(toIndex) {
601+ var delegate = appRepeater.itemAt(toIndex)
602+ var targetContentX = floatingFlickable.contentWidth / spreadItem.totalItemCount * toIndex;
603+ if (targetContentX - floatingFlickable.contentX > spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) {
604+ var offset = (spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) - (targetContentX - floatingFlickable.contentX)
605+ snapAnimation.to = floatingFlickable.contentX - offset;
606+ snapAnimation.start();
607+ } else if (targetContentX - floatingFlickable.contentX < spreadItem.leftStackXPos + units.gu(1)) {
608+ var offset = (spreadItem.leftStackXPos + units.gu(1)) - (targetContentX - floatingFlickable.contentX);
609+ snapAnimation.to = floatingFlickable.contentX - offset;
610+ snapAnimation.start();
611+ }
612+ }
613+ UbuntuNumberAnimation {id: snapAnimation; target: floatingFlickable; property: "contentX"}
614+ }
615+
616+ MouseArea {
617+ id: hoverMouseArea
618+ objectName: "hoverMouseArea"
619+ anchors.fill: parent
620+ propagateComposedEvents: true
621+ hoverEnabled: true
622+ enabled: false
623+ visible: enabled
624+
625+ property int scrollAreaWidth: width / 3
626+ property bool progressiveScrollingEnabled: false
627+
628+ onPressed: mouse.accepted = false
629+
630+ onMouseXChanged: {
631+ mouse.accepted = false
632+
633+ if (hoverMouseArea.pressed) {
634+ return;
635+ }
636+
637+ // Find the hovered item and mark it active
638+ for (var i = appRepeater.count - 1; i >= 0; i--) {
639+ var appDelegate = appRepeater.itemAt(i);
640+ var mapped = mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
641+ var itemUnder = appDelegate.childAt(mapped.x, mapped.y);
642+ if (itemUnder && (itemUnder.objectName === "dragArea" || itemUnder.objectName === "windowInfoItem" || itemUnder.objectName == "closeMouseArea")) {
643+ spreadItem.highlightedIndex = i;
644+ break;
645+ }
646+ }
647+
648+ if (floatingFlickable.contentWidth > floatingFlickable.width) {
649+ var margins = floatingFlickable.width * 0.05;
650+
651+ if (!progressiveScrollingEnabled && mouseX < floatingFlickable.width - scrollAreaWidth) {
652+ progressiveScrollingEnabled = true
653+ }
654+
655+ // do we need to scroll?
656+ if (mouseX < scrollAreaWidth + margins) {
657+ var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
658+ var contentX = (1 - progress) * (floatingFlickable.contentWidth - floatingFlickable.width)
659+ floatingFlickable.contentX = Math.max(0, Math.min(floatingFlickable.contentX, contentX))
660+ }
661+ if (mouseX > floatingFlickable.width - scrollAreaWidth && progressiveScrollingEnabled) {
662+ var progress = Math.min(1, (mouseX - (floatingFlickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
663+ var contentX = progress * (floatingFlickable.contentWidth - floatingFlickable.width)
664+ floatingFlickable.contentX = Math.min(floatingFlickable.contentWidth - floatingFlickable.width, Math.max(floatingFlickable.contentX, contentX))
665+ }
666+ }
667+ }
668+ }
578 }
669 }
579
670
580 Connections {
671 Connections {
@@ -669,10 +760,27 @@ FocusScope {
669 }
760 }
670 }
761 }
671
762
763+ MirSurfaceItem {
764+ id: fakeDragItem
765+ property real previewScale: .5
766+ width: implicitWidth * previewScale
767+ height: implicitHeight * previewScale
768+ surfaceWidth: -1
769+ surfaceHeight: -1
770+ opacity: surface != null ? 1 : 0
771+ Behavior on opacity { UbuntuNumberAnimation {} }
772+ visible: opacity > 0
773+
774+ Drag.active: surface != null
775+ Drag.keys: ["application"]
776+
777+ z: 1000
778+ }
779+
672 Item {
780 Item {
673 id: boundariesForWindowPlacement
781 id: boundariesForWindowPlacement
674 anchors.fill: parent
782 anchors.fill: parent
675− anchors.topMargin: PanelState.panelHeight
783+ anchors.topMargin: panelState.panelHeight
676 visible: false
784 visible: false
677 }
785 }
678
786
@@ -704,6 +812,9 @@ FocusScope {
704 }
812 }
705 z: normalZ
813 z: normalZ
706
814
815+ opacity: fakeDragItem.surface == model.window.surface && fakeDragItem.Drag.active ? 0 : 1
816+ Behavior on opacity { UbuntuNumberAnimation {} }
817+
707 // Normally we want x/y where the surface thinks it is. Width/height of our delegate will
818 // Normally we want x/y where the surface thinks it is. Width/height of our delegate will
708 // match what the actual surface size is.
819 // match what the actual surface size is.
709 // Don't write to those, they will be set by states
820 // Don't write to those, they will be set by states
@@ -764,7 +875,7 @@ FocusScope {
764 target: appDelegate
875 target: appDelegate
765 property: "y"
876 property: "y"
766 value: appDelegate.requestedY -
877 value: appDelegate.requestedY -
767− Math.min(appDelegate.requestedY - PanelState.panelHeight,
878+ Math.min(appDelegate.requestedY - panelState.panelHeight,
768 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
879 Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
769 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
880 when: root.oskEnabled && appDelegate.focus && (appDelegate.state == "normal" || appDelegate.state == "restored")
770 && root.inputMethodRect.height > 0
881 && root.inputMethodRect.height > 0
@@ -1148,7 +1259,7 @@ FocusScope {
1148 progress: 0
1259 progress: 0
1149 targetHeight: spreadItem.stackHeight
1260 targetHeight: spreadItem.stackHeight
1150 targetX: spreadMaths.targetX
1261 targetX: spreadMaths.targetX
1151− startY: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1262+ startY: appDelegate.fullscreen ? 0 : panelState.panelHeight
1152 targetY: spreadMaths.targetY
1263 targetY: spreadMaths.targetY
1153 targetAngle: spreadMaths.targetAngle
1264 targetAngle: spreadMaths.targetAngle
1154 targetScale: spreadMaths.targetScale
1265 targetScale: spreadMaths.targetScale
@@ -1267,9 +1378,9 @@ FocusScope {
1267 PropertyChanges {
1378 PropertyChanges {
1268 target: appDelegate
1379 target: appDelegate
1269 x: stageMaths.itemX
1380 x: stageMaths.itemX
1270− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1381+ y: appDelegate.fullscreen ? 0 : panelState.panelHeight
1271 requestedWidth: appContainer.width
1382 requestedWidth: appContainer.width
1272− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1383+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
1273 visuallyMaximized: true
1384 visuallyMaximized: true
1274 visible: appDelegate.x < root.width
1385 visible: appDelegate.x < root.width
1275 }
1386 }
@@ -1295,10 +1406,10 @@ FocusScope {
1295 PropertyChanges {
1406 PropertyChanges {
1296 target: appDelegate
1407 target: appDelegate
1297 x: stageMaths.itemX
1408 x: stageMaths.itemX
1298− y: appDelegate.fullscreen ? 0 : PanelState.panelHeight
1409+ y: appDelegate.fullscreen ? 0 : panelState.panelHeight
1299 z: stageMaths.itemZ
1410 z: stageMaths.itemZ
1300 requestedWidth: stageMaths.itemWidth
1411 requestedWidth: stageMaths.itemWidth
1301− requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - PanelState.panelHeight
1412+ requestedHeight: appDelegate.fullscreen ? appContainer.height : appContainer.height - panelState.panelHeight
1302 visuallyMaximized: true
1413 visuallyMaximized: true
1303 visible: appDelegate.x < root.width
1414 visible: appDelegate.x < root.width
1304 }
1415 }
@@ -1363,9 +1474,9 @@ FocusScope {
1363 PropertyChanges {
1474 PropertyChanges {
1364 target: appDelegate
1475 target: appDelegate
1365 windowedX: root.leftMargin
1476 windowedX: root.leftMargin
1366− windowedY: PanelState.panelHeight
1477+ windowedY: panelState.panelHeight
1367 windowedWidth: (appContainer.width - root.leftMargin)/2
1478 windowedWidth: (appContainer.width - root.leftMargin)/2
1368− windowedHeight: appContainer.height - PanelState.panelHeight
1479+ windowedHeight: appContainer.height - panelState.panelHeight
1369 }
1480 }
1370 },
1481 },
1371 State {
1482 State {
@@ -1382,9 +1493,9 @@ FocusScope {
1382 PropertyChanges {
1493 PropertyChanges {
1383 target: appDelegate
1494 target: appDelegate
1384 windowedX: root.leftMargin
1495 windowedX: root.leftMargin
1385− windowedY: PanelState.panelHeight
1496+ windowedY: panelState.panelHeight
1386 windowedWidth: (appContainer.width - root.leftMargin)/2
1497 windowedWidth: (appContainer.width - root.leftMargin)/2
1387− windowedHeight: (appContainer.height - PanelState.panelHeight)/2
1498+ windowedHeight: (appContainer.height - panelState.panelHeight)/2
1388 }
1499 }
1389 },
1500 },
1390 State {
1501 State {
@@ -1401,7 +1512,7 @@ FocusScope {
1401 PropertyChanges {
1512 PropertyChanges {
1402 target: appDelegate
1513 target: appDelegate
1403 windowedX: root.leftMargin
1514 windowedX: root.leftMargin
1404− windowedY: (appContainer.height + PanelState.panelHeight)/2
1515+ windowedY: (appContainer.height + panelState.panelHeight)/2
1405 windowedWidth: (appContainer.width - root.leftMargin)/2
1516 windowedWidth: (appContainer.width - root.leftMargin)/2
1406 windowedHeight: appContainer.height/2
1517 windowedHeight: appContainer.height/2
1407 }
1518 }
@@ -1423,8 +1534,8 @@ FocusScope {
1423 State {
1534 State {
1424 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
1535 name: "maximizedVertically"; when: appDelegate.maximizedVertically && !appDelegate.minimized
1425 extend: "normal"
1536 extend: "normal"
1426− PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: PanelState.panelHeight;
1537+ PropertyChanges { target: appDelegate; windowedX: windowedX; windowedY: panelState.panelHeight;
1427− windowedWidth: windowedWidth; windowedHeight: appContainer.height - PanelState.panelHeight }
1538+ windowedWidth: windowedWidth; windowedHeight: appContainer.height - panelState.panelHeight }
1428 },
1539 },
1429 State {
1540 State {
1430 name: "minimized"; when: appDelegate.minimized
1541 name: "minimized"; when: appDelegate.minimized
@@ -1540,7 +1651,7 @@ FocusScope {
1540 ]
1651 ]
1541
1652
1542 Binding {
1653 Binding {
1543− target: PanelState
1654+ target: panelState
1544 property: "decorationsAlwaysVisible"
1655 property: "decorationsAlwaysVisible"
1545 value: appDelegate && appDelegate.maximized && touchControls.overlayShown
1656 value: appDelegate && appDelegate.maximized && touchControls.overlayShown
1546 }
1657 }
@@ -1785,83 +1896,7 @@ FocusScope {
1785 leftMargin: root.leftMargin
1896 leftMargin: root.leftMargin
1786 appContainerWidth: appContainer.width
1897 appContainerWidth: appContainer.width
1787 appContainerHeight: appContainer.height
1898 appContainerHeight: appContainer.height
1788− }
1899+ panelState: root.panelState
1789−
1790− MouseArea {
1791− id: hoverMouseArea
1792− objectName: "hoverMouseArea"
1793− anchors.fill: appContainer
1794− propagateComposedEvents: true
1795− hoverEnabled: true
1796− enabled: false
1797− visible: enabled
1798−
1799− property int scrollAreaWidth: width / 3
1800− property bool progressiveScrollingEnabled: false
1801−
1802− onMouseXChanged: {
1803− mouse.accepted = false
1804−
1805− if (hoverMouseArea.pressed) {
1806− return;
1807− }
1808−
1809− // Find the hovered item and mark it active
1810− for (var i = appRepeater.count - 1; i >= 0; i--) {
1811− var appDelegate = appRepeater.itemAt(i);
1812− var mapped = mapToItem(appDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
1813− var itemUnder = appDelegate.childAt(mapped.x, mapped.y);
1814− if (itemUnder && (itemUnder.objectName === "dragArea" || itemUnder.objectName === "windowInfoItem" || itemUnder.objectName == "closeMouseArea")) {
1815− spreadItem.highlightedIndex = i;
1816− break;
1817− }
1818− }
1819−
1820− if (floatingFlickable.contentWidth > floatingFlickable.width) {
1821− var margins = floatingFlickable.width * 0.05;
1822−
1823− if (!progressiveScrollingEnabled && mouseX < floatingFlickable.width - scrollAreaWidth) {
1824− progressiveScrollingEnabled = true
1825− }
1826−
1827− // do we need to scroll?
1828− if (mouseX < scrollAreaWidth + margins) {
1829− var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
1830− var contentX = (1 - progress) * (floatingFlickable.contentWidth - floatingFlickable.width)
1831− floatingFlickable.contentX = Math.max(0, Math.min(floatingFlickable.contentX, contentX))
1832− }
1833− if (mouseX > floatingFlickable.width - scrollAreaWidth && progressiveScrollingEnabled) {
1834− var progress = Math.min(1, (mouseX - (floatingFlickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
1835− var contentX = progress * (floatingFlickable.contentWidth - floatingFlickable.width)
1836− floatingFlickable.contentX = Math.min(floatingFlickable.contentWidth - floatingFlickable.width, Math.max(floatingFlickable.contentX, contentX))
1837− }
1838− }
1839− }
1840−
1841− onPressed: mouse.accepted = false
1842− }
1843−
1844− FloatingFlickable {
1845− id: floatingFlickable
1846− objectName: "spreadFlickable"
1847− anchors.fill: appContainer
1848− enabled: false
1849− contentWidth: spreadItem.spreadTotalWidth
1850−
1851− function snap(toIndex) {
1852− var delegate = appRepeater.itemAt(toIndex)
1853− var targetContentX = floatingFlickable.contentWidth / spreadItem.totalItemCount * toIndex;
1854− if (targetContentX - floatingFlickable.contentX > spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) {
1855− var offset = (spreadItem.rightStackXPos - (spreadItem.spreadItemWidth / 2)) - (targetContentX - floatingFlickable.contentX)
1856− snapAnimation.to = Math.max(0, floatingFlickable.contentX - offset);
1857− snapAnimation.start();
1858− } else if (targetContentX - floatingFlickable.contentX < spreadItem.leftStackXPos + units.gu(1)) {
1859− var offset = (spreadItem.leftStackXPos + units.gu(1)) - (targetContentX - floatingFlickable.contentX);
1860− snapAnimation.to = Math.max(0, floatingFlickable.contentX - offset);
1861− snapAnimation.start();
1862− }
1863− }
1864− UbuntuNumberAnimation {id: snapAnimation; target: floatingFlickable; property: "contentX"}
1865 }
1900 }
1866
1901
1867 PropertyAnimation {
1902 PropertyAnimation {
qml/Stage/SurfaceContainer.qml+2
@@ -66,6 +66,8 @@ FocusScope {
66 fillMode: MirSurfaceItem.PadOrCrop
66 fillMode: MirSurfaceItem.PadOrCrop
67 consumesInput: true
67 consumesInput: true
68
68
69+ onSurfaceChanged: print("surface changed", surface, implicitWidth, implicitHeight)
70+
69 surfaceWidth: root.requestedWidth
71 surfaceWidth: root.requestedWidth
70 surfaceHeight: root.requestedHeight
72 surfaceHeight: root.requestedHeight
71
73
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/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 @@
16
16
17#include "ApplicationArguments.h"
17#include "ApplicationArguments.h"
18
18
19−ApplicationArguments::ApplicationArguments(QObject *parent)
19+ApplicationArguments::ApplicationArguments(QCoreApplication *app)
20− : QObject(parent)
20+ : QObject(app)
21+ , UnityCommandLineParser(*app)
21{
22{
22}
23}
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 @@
23#include <QSize>
23#include <QSize>
24#include <QString>
24#include <QString>
25
25
26+#include "UnityCommandLineParser.h"
27+
26−class ApplicationArguments : public QObject
28+class ApplicationArguments : public QObject,
29+ public UnityCommandLineParser
27{
30{
28 Q_OBJECT
31 Q_OBJECT
29 Q_PROPERTY(QString deviceName READ deviceName NOTIFY deviceNameChanged)
32 Q_PROPERTY(QString deviceName READ deviceName NOTIFY deviceNameChanged)
30 Q_PROPERTY(QString mode READ mode CONSTANT)
33 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+
31public:
44public:
32− ApplicationArguments(QObject *parent = nullptr);
45+ ApplicationArguments(QCoreApplication *app);
33
46
34− void setDeviceName(const QString &deviceName) {
47+ 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; }
41
48
42− void setMode(const QString &mode) { m_mode = mode; }
49+ bool hasGeometry() const { return m_windowGeometry.isValid(); }
43− QString mode() const { return m_mode; }
44
50
45Q_SIGNALS:
51Q_SIGNALS:
46 void deviceNameChanged(const QString&);
52 void deviceNameChanged(const QString&);
47−
48−private:
49− QString m_deviceName;
50− QString m_mode;
51};
53};
52
54
53#endif // APPLICATION_ARGUMENTS_H
55#endif // APPLICATION_ARGUMENTS_H
src/CMakeLists.txt+2−3
@@ -7,6 +7,7 @@ include_directories(
7 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
7 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
8 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
8 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
9 ${CONNECTIVITY_INCLUDE_DIRS}
9 ${CONNECTIVITY_INCLUDE_DIRS}
10+ ${QTMIRSERVER_INCLUDE_DIRS}
10)
11)
11
12
12include_directories(
13include_directories(
@@ -27,9 +28,7 @@ set(SOURCE_FILES
27 ApplicationArguments.cpp
28 ApplicationArguments.cpp
28 main.cpp
29 main.cpp
29 CachingNetworkManagerFactory.cpp
30 CachingNetworkManagerFactory.cpp
30− SecondaryWindow.cpp
31 ShellApplication.cpp
31 ShellApplication.cpp
32− ShellView.cpp
33 UnityCommandLineParser.cpp
32 UnityCommandLineParser.cpp
34 UnixSignalHandler.cpp
33 UnixSignalHandler.cpp
35 DebuggingController.cpp
34 DebuggingController.cpp
@@ -47,7 +46,7 @@ qt5_use_modules(${SHELL_APP} DBus Gui Qml Quick Test)
47if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
46if (NOT "${ANDROID_PROPERTIES_INCLUDE_DIRS}" STREQUAL "")
48 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
47 set_target_properties(${SHELL_APP} PROPERTIES INCLUDE_DIRECTORIES ${ANDROID_PROPERTIES_INCLUDE_DIRS})
49endif()
48endif()
50−target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} UbuntuGestures connectivity-qt1 unity8-private)
49+target_link_libraries(${SHELL_APP} ${ANDROID_PROPERTIES_LDFLAGS} UbuntuGestures connectivity-qt1 unity8-private qtmirserver)
51
50
52if (ENABLE_TOUCH_EMULATION)
51if (ENABLE_TOUCH_EMULATION)
53 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
52 target_link_libraries(${SHELL_APP} ${MOUSETOUCHADAPTOR_LIBS_LDFLAGS})
src/DebuggingController.cpp+12−1
@@ -49,7 +49,8 @@ public:
49};
49};
50
50
51DebuggingController::DebuggingController(QObject *parent):
51DebuggingController::DebuggingController(QObject *parent):
52− UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent)
52+ UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent),
53+ m_logOverlay(false)
53{
54{
54}
55}
55
56
@@ -90,3 +91,13 @@ void DebuggingController::SetLoggingFilterRules(const QString &filterRules)
90{
91{
91 QLoggingCategory::setFilterRules(filterRules);
92 QLoggingCategory::setFilterRules(filterRules);
92}
93}
94+
95+void DebuggingController::SetLogOverlay(bool logOverlay)
96+{
97+ if (logOverlay == m_logOverlay) {
98+ return;
99+ }
100+
101+ m_logOverlay = logOverlay;
102+ Q_EMIT logOverlayChanged(m_logOverlay);
103+}
src/DebuggingController.h+14
@@ -32,10 +32,14 @@ class DebuggingController: public UnityDBusObject
32 Q_OBJECT
32 Q_OBJECT
33 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Debugging")
33 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Debugging")
34
34
35+ Q_PROPERTY(bool logOverlay READ logOverlay NOTIFY logOverlayChanged)
36+
35public:
37public:
36 DebuggingController(QObject *parent = nullptr);
38 DebuggingController(QObject *parent = nullptr);
37 ~DebuggingController() = default;
39 ~DebuggingController() = default;
38
40
41+ bool logOverlay() const { return m_logOverlay; }
42+
39public Q_SLOTS:
43public Q_SLOTS:
40 /**
44 /**
41 * Set the QSG_VISUALIZE mode. This follows the vlues supported by Qt in
45 * Set the QSG_VISUALIZE mode. This follows the vlues supported by Qt in
@@ -53,5 +57,15 @@ public Q_SLOTS:
53 */
57 */
54 Q_SCRIPTABLE void SetLoggingFilterRules(const QString &filterRules);
58 Q_SCRIPTABLE void SetLoggingFilterRules(const QString &filterRules);
55
59
60+ /**
61+ * Enable/Disable the shell console log overlay
62+ */
63+ Q_SCRIPTABLE void SetLogOverlay(bool logOverlay);
64+
65+Q_SIGNALS:
66+ void logOverlayChanged(bool logOverlay);
67+
68+private:
69+ bool m_logOverlay;
56};
70};
57#endif // DEBUGGINGCONTROLLER_H
71#endif // DEBUGGINGCONTROLLER_H
src/SecondaryWindow.cppdeleted−40
@@ -1,40 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "SecondaryWindow.h"
18−
19−// local
20−#include <paths.h>
21−
22−#include <QQmlContext>
23−
24−SecondaryWindow::SecondaryWindow(QQmlEngine *engine)
25− : QQuickView(engine, nullptr)
26−{
27− QByteArray pxpguEnv = qgetenv("GRID_UNIT_PX");
28− bool ok;
29− int pxpgu = pxpguEnv.toInt(&ok);
30− if (!ok) {
31− pxpgu = 8;
32− }
33− engine->rootContext()->setContextProperty(QStringLiteral("internalGu"), pxpgu);
34− setResizeMode(QQuickView::SizeRootObjectToView);
35− setColor("black");
36− setTitle(QStringLiteral("Unity8 Shell - Secondary Screen"));
37−
38− QUrl source(::qmlDirectory() + "/DisabledScreenNotice.qml");
39− setSource(source);
40−}
src/ShellApplication.cpp+46−111
@@ -20,6 +20,7 @@
20#include <QLibrary>
20#include <QLibrary>
21#include <QProcess>
21#include <QProcess>
22#include <QScreen>
22#include <QScreen>
23+#include <QQmlContext>
23
24
24#include <libintl.h>
25#include <libintl.h>
25
26
@@ -32,32 +33,49 @@
32#include "UnityCommandLineParser.h"
33#include "UnityCommandLineParser.h"
33#include "DebuggingController.h"
34#include "DebuggingController.h"
34
35
36+#include <QDebug>
37+
38+#include <qtmir/windowmanagementpolicy.h>
39+
40+class WindowManagementPolicy : public qtmir::WindowManagementPolicy
41+{
42+public:
43+ WindowManagementPolicy(const miral::WindowManagerTools &tools, qtmir::WindowManagementPolicyPrivate& dd)
44+ : qtmir::WindowManagementPolicy(tools, dd)
45+ {}
46+
47+// virtual void advise_adding_to_workspace(
48+// std::shared_ptr<miral::Workspace> const& workspace,
49+// std::vector<miral::Window> const& windows) override
50+// {
51+// }
52+
53+// virtual void advise_removing_from_workspace(
54+// std::shared_ptr<miral::Workspace> const& workspace,
55+// std::vector<miral::Window> const& windows) override
56+// {
57+// }
58+};
59+
60+
35−ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
61+ShellApplication::ShellApplication(int & argc, char ** argv)
36− : QGuiApplication(argc, argv)
62+ : qtmir::MirServerApplication(argc, argv, {})
63+ , m_qmlArgs(this)
37{
64{
38 setApplicationName(QStringLiteral("unity8"));
65 setApplicationName(QStringLiteral("unity8"));
39 setOrganizationName(QStringLiteral("Canonical"));
66 setOrganizationName(QStringLiteral("Canonical"));
40
67
41− connect(this, &QGuiApplication::screenAdded, this, &ShellApplication::onScreenAdded);
68+ setupQmlEngine();
42
69
43− setupQmlEngine(isMirServer);
44−
45− UnityCommandLineParser parser(*this);
46−
47− if (!parser.deviceName().isEmpty()) {
70+ if (m_qmlArgs.deviceName().isEmpty()) {
48− m_deviceName = parser.deviceName();
49− } else {
50 char buffer[200];
71 char buffer[200];
51 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
72 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
52− m_deviceName = QString(buffer);
73+ m_qmlArgs.setDeviceName(QString(buffer));
53 }
74 }
54− m_qmlArgs.setDeviceName(m_deviceName);
55−
56− m_qmlArgs.setMode(parser.mode());
57
75
58 // The testability driver is only loaded by QApplication but not by QGuiApplication.
76 // The testability driver is only loaded by QApplication but not by QGuiApplication.
59 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
77 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
60− if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
78+ if (m_qmlArgs.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
61 QLibrary testLib(QStringLiteral("qttestability"));
79 QLibrary testLib(QStringLiteral("qttestability"));
62 if (testLib.load()) {
80 if (testLib.load()) {
63 typedef void (*TasInitialize)(void);
81 typedef void (*TasInitialize)(void);
@@ -75,57 +93,30 @@ ShellApplication::ShellApplication(int & argc, char ** argv, bool isMirServer)
75 bindtextdomain("unity8", translationDirectory().toUtf8().data());
93 bindtextdomain("unity8", translationDirectory().toUtf8().data());
76 textdomain("unity8");
94 textdomain("unity8");
77
95
78− m_shellView = new ShellView(m_qmlEngine, &m_qmlArgs);
96+ m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("applicationArguments"), &m_qmlArgs);
97+ m_qmlEngine->rootContext()->setContextProperty("DebuggingController", new DebuggingController(this));
79
98
80− if (parser.windowGeometry().isValid()) {
99+ QByteArray pxpguEnv = qgetenv("GRID_UNIT_PX");
81− m_shellView->setWidth(parser.windowGeometry().width());
100+ bool ok;
82− m_shellView->setHeight(parser.windowGeometry().height());
101+ int pxpgu = pxpguEnv.toInt(&ok);
102+ if (!ok) {
103+ pxpgu = 8;
83 }
104 }
84−
105+ m_qmlEngine->rootContext()->setContextProperty("internalGu", pxpgu);
85− if (parser.hasFrameless()) {
106+ m_qmlEngine->load(::qmlDirectory() + "/ShellApplication.qml");
86− m_shellView->setFlags(Qt::FramelessWindowHint);
87− }
88−
89
107
90 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
108 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
91 // You will need this if you want to interact with touch-only components using a mouse
109 // You will need this if you want to interact with touch-only components using a mouse
92 // Needed only when manually testing on a desktop.
110 // Needed only when manually testing on a desktop.
93− if (parser.hasMouseToTouch()) {
111+ if (m_qmlArgs.hasMouseToTouch()) {
94 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
112 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
95 }
113 }
96 #endif
114 #endif
97
115
98− new DebuggingController(this);
99−
100− // Some hard-coded policy for now.
101− // NB: We don't support more than two screens at the moment
102− //
103− // TODO: Support an arbitrary number of screens and different policies
104− // (eg cloned desktop, several desktops, etc)
105− if (isMirServer && screens().count() == 2) {
106− m_shellView->setScreen(screens().at(1));
107− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
108−
109− m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
110− m_secondaryWindow->setScreen(screens().at(0));
111− // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
112− m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
113− m_secondaryWindow->setVisible(true);
114− }
115−
116− if (parser.mode().compare("greeter") == 0) {
116+ if (m_qmlArgs.mode().compare("greeter") == 0) {
117− QSize primaryScreenSize = this->primaryScreen()->size();
118− m_shellView->setHeight(primaryScreenSize.height());
119− m_shellView->setWidth(primaryScreenSize.width());
120− m_shellView->show();
121− m_shellView->requestActivate();
122 if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
117 if (!QProcess::startDetached("initctl emit --no-wait unity8-greeter-started")) {
123 qDebug() << "Unable to send unity8-greeter-started event to Upstart";
118 qDebug() << "Unable to send unity8-greeter-started event to Upstart";
124 }
119 }
125− } else if (isMirServer || parser.hasFullscreen()) {
126− m_shellView->showFullScreen();
127− } else {
128− m_shellView->show();
129 }
120 }
130}
121}
131
122
@@ -136,14 +127,6 @@ ShellApplication::~ShellApplication()
136
127
137void ShellApplication::destroyResources()
128void ShellApplication::destroyResources()
138{
129{
139− // Deletion order is important. Don't use QScopedPointers and the like
140− // Otherwise the process will hang on shutdown (bug somewhere I guess).
141− delete m_shellView;
142− m_shellView = nullptr;
143−
144− delete m_secondaryWindow;
145− m_secondaryWindow = nullptr;
146−
147 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
130 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
148 delete m_mouseTouchAdaptor;
131 delete m_mouseTouchAdaptor;
149 m_mouseTouchAdaptor = nullptr;
132 m_mouseTouchAdaptor = nullptr;
@@ -153,64 +136,16 @@ void ShellApplication::destroyResources()
153 m_qmlEngine = nullptr;
136 m_qmlEngine = nullptr;
154}
137}
155
138
156−void ShellApplication::setupQmlEngine(bool isMirServer)
139+void ShellApplication::setupQmlEngine()
157{
140{
158− m_qmlEngine = new QQmlEngine(this);
141+ m_qmlEngine = new QQmlApplicationEngine(this);
159
142
160 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
143 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
161
144
162 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
145 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
163− if (!isMirServer) {
164− prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
165− }
166 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
146 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
167
147
168 m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
148 m_qmlEngine->setNetworkAccessManagerFactory(new CachingNetworkManagerFactory);
169
149
170 QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
150 QObject::connect(m_qmlEngine, &QQmlEngine::quit, this, &QGuiApplication::quit);
171}
151}
172−
173−void ShellApplication::onScreenAdded(QScreen * /*screen*/)
174−{
175− // TODO: Support an arbitrary number of screens and different policies
176− // (eg cloned desktop, several desktops, etc)
177− if (screens().count() == 2) {
178− m_shellView->setScreen(screens().at(1));
179− m_qmlArgs.setDeviceName(QStringLiteral("desktop"));
180− // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
181− // its backing QPlatformWindow recreated). So lets refocus it.
182− m_shellView->requestActivate();
183− // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
184− // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
185− m_shellView->setVisible(true);
186−
187− m_secondaryWindow = new SecondaryWindow(m_qmlEngine);
188− m_secondaryWindow->setScreen(screens().at(0));
189−
190− // QWindow::showFullScreen() also calls QWindow::requestActivate() and we don't want that!
191− m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
192− m_secondaryWindow->setVisible(true);
193− }
194−}
195−
196−void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
197−{
198− // TODO: Support an arbitrary number of screens and different policies
199− // (eg cloned desktop, several desktops, etc)
200− if (screen == m_shellView->screen()) {
201− const QList<QScreen *> allScreens = screens();
202− Q_ASSERT(allScreens.count() > 1);
203− Q_ASSERT(allScreens.at(0) != screen);
204− Q_ASSERT(m_secondaryWindow);
205− delete m_secondaryWindow;
206− m_secondaryWindow = nullptr;
207− m_shellView->setScreen(allScreens.first());
208− m_qmlArgs.setDeviceName(m_deviceName);
209− // Changing the QScreen where a QWindow is drawn makes it also lose focus (besides having
210− // its backing QPlatformWindow recreated). So lets refocus it.
211− m_shellView->requestActivate();
212− // QWindow::destroy() is called when it changes between screens. We have to manually make it visible again
213− // <dandrader> This bug is supposedly fixed in Qt 5.5.1, although I can still reproduce it there. :-/
214− m_shellView->setVisible(true);
215− }
216−}
src/ShellApplication.h+6−16
@@ -18,7 +18,7 @@
18#define SHELLAPPLICATION_H
18#define SHELLAPPLICATION_H
19
19
20#include <QGuiApplication>
20#include <QGuiApplication>
21−#include <QQmlEngine>
21+#include <QQmlApplicationEngine>
22#include <QQuickView>
22#include <QQuickView>
23#include <QScopedPointer>
23#include <QScopedPointer>
24
24
@@ -28,36 +28,26 @@
28#include "MouseTouchAdaptor.h"
28#include "MouseTouchAdaptor.h"
29#endif
29#endif
30
30
31−#include "SecondaryWindow.h"
31+#include <qtmir/mirserverapplication.h>
32−#include "ShellView.h"
33
32
34−class ShellApplication : public QGuiApplication
33+class ShellApplication : public qtmir::MirServerApplication
35{
34{
36 Q_OBJECT
35 Q_OBJECT
37public:
36public:
38− ShellApplication(int & argc, char ** argv, bool isMirServer);
37+ ShellApplication(int & argc, char ** argv);
39 virtual ~ShellApplication();
38 virtual ~ShellApplication();
40
39
41 void destroyResources();
40 void destroyResources();
42−public Q_SLOTS:
43− // called by qtmir
44− void onScreenAboutToBeRemoved(QScreen *screen);
45−
46−private Q_SLOTS:
47− void onScreenAdded(QScreen*);
48
41
49private:
42private:
50− void setupQmlEngine(bool isMirServer);
43+ void setupQmlEngine();
51− QString m_deviceName;
52 ApplicationArguments m_qmlArgs;
44 ApplicationArguments m_qmlArgs;
53− ShellView *m_shellView{nullptr};
54− SecondaryWindow *m_secondaryWindow{nullptr};
55
45
56 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
46 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
57 MouseTouchAdaptor *m_mouseTouchAdaptor{nullptr};
47 MouseTouchAdaptor *m_mouseTouchAdaptor{nullptr};
58 #endif
48 #endif
59
49
60− QQmlEngine *m_qmlEngine{nullptr};
50+ QQmlApplicationEngine *m_qmlEngine{nullptr};
61};
51};
62
52
63#endif // SHELLAPPLICATION_H
53#endif // SHELLAPPLICATION_H
src/ShellView.cppdeleted−63
@@ -1,63 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "ShellView.h"
18−
19−// Qt
20−#include <QQmlContext>
21−#include <QQuickItem>
22−
23−// local
24−#include <paths.h>
25−
26−ShellView::ShellView(QQmlEngine *engine, QObject *qmlArgs)
27− : QQuickView(engine, nullptr)
28−{
29− setResizeMode(QQuickView::SizeRootObjectToView);
30− setColor("black");
31− setTitle(QStringLiteral("Unity8"));
32−
33− rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
34−
35− QUrl source(::qmlDirectory() + "/OrientedShell.qml");
36− setSource(source);
37−
38− connect(this, &QWindow::widthChanged, this, &ShellView::onWidthChanged);
39− connect(this, &QWindow::heightChanged, this, &ShellView::onHeightChanged);
40−}
41−
42−void ShellView::onWidthChanged(int w)
43−{
44− // For good measure in case SizeRootObjectToView doesn't fulfill its promise.
45− //
46− // There's at least one situation that's know to leave the root object with an outdated size.
47− // (really looks like Qt bug)
48− // Happens when starting unity8 with an external monitor already connected.
49− // The QResizeEvent we get still has the size of the first screen and since the resize move is triggered
50− // from the resize event handler, the root item doesn't get resized.
51− // TODO: Confirm the Qt bug and submit a patch upstream
52− if (rootObject()) {
53− rootObject()->setWidth(w);
54− }
55−}
56−
57−void ShellView::onHeightChanged(int h)
58−{
59− // See comment in ShellView::onWidthChanged()
60− if (rootObject()) {
61− rootObject()->setHeight(h);
62− }
63−}
src/UnityCommandLineParser.h+1−1
@@ -36,8 +36,8 @@ public:
36 bool hasFullscreen() const { return m_hasFullscreen; }
36 bool hasFullscreen() const { return m_hasFullscreen; }
37 QString deviceName() const { return m_deviceName; }
37 QString deviceName() const { return m_deviceName; }
38 QString mode() const { return m_mode; }
38 QString mode() const { return m_mode; }
39−private:
40
39
40+protected:
41 int parsePixelsValue(const QString &str);
41 int parsePixelsValue(const QString &str);
42 static float getenvFloat(const char* name, float defaultValue);
42 static float getenvFloat(const char* name, float defaultValue);
43 void resolveMode(QCommandLineParser &parser, QCommandLineOption &modeOption);
43 void resolveMode(QCommandLineParser &parser, QCommandLineOption &modeOption);
src/main.cpp+1−7
@@ -27,17 +27,11 @@ int main(int argc, const char *argv[])
27{
27{
28 qSetMessagePattern("[%{time yyyy-MM-dd:hh:mm:ss.zzz}] %{if-category}%{category}: %{endif}%{message}");
28 qSetMessagePattern("[%{time yyyy-MM-dd:hh:mm:ss.zzz}] %{if-category}%{category}: %{endif}%{message}");
29
29
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−
36 if (enableQmlDebugger(argc, argv)) {
30 if (enableQmlDebugger(argc, argv)) {
37 QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true);
31 QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true);
38 }
32 }
39
33
40− ShellApplication *application = new ShellApplication(argc, (char**)argv, isMirServer);
34+ ShellApplication *application = new ShellApplication(argc, (char**)argv);
41
35
42 UnixSignalHandler signalHandler([]{
36 UnixSignalHandler signalHandler([]{
43 QGuiApplication::exit(0);
37 QGuiApplication::exit(0);
tests/mocks/CMakeLists.txt+1
@@ -43,6 +43,7 @@ add_subdirectory(SessionBroadcast)
43add_subdirectory(Ubuntu)
43add_subdirectory(Ubuntu)
44add_subdirectory(Unity)
44add_subdirectory(Unity)
45add_subdirectory(QtMultimedia)
45add_subdirectory(QtMultimedia)
46+add_subdirectory(WindowManager)
46add_subdirectory(Wizard)
47add_subdirectory(Wizard)
47add_subdirectory(Utils)
48add_subdirectory(Utils)
48add_subdirectory(UInput)
49add_subdirectory(UInput)
tests/mocks/Cursor/Cursor.qml+49−2
@@ -15,8 +15,11 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18+import UInput 0.1
19+
20+Canvas {
21+ id: root
18
22
19−Item {
20 property int topBoundaryOffset // effectively panel height
23 property int topBoundaryOffset // effectively panel height
21 property Item confiningItem
24 property Item confiningItem
22
25
@@ -30,5 +33,49 @@ Item {
30 signal pushStopped()
33 signal pushStopped()
31 signal mouseMoved()
34 signal mouseMoved()
32
35
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
33− onMouseMoved: opacity = 1;
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+ }
34}
81}
tests/mocks/GSettings.1.0/plugin.cpp+12
@@ -18,6 +18,8 @@
18#include "fake_gsettings.h"
18#include "fake_gsettings.h"
19
19
20#include <QtQml/qqml.h>
20#include <QtQml/qqml.h>
21+#include <QQmlEngine>
22+#include <QQmlContext>
21
23
22static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
24static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
23{
25{
@@ -31,3 +33,13 @@ void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
31 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
33 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
32 "GSettingsSchema can only be used inside of a GSettings component");
34 "GSettingsSchema can only be used inside of a GSettings component");
33}
35}
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
26
26
27public:
27public:
28 void registerTypes(const char *uri) override;
28 void registerTypes(const char *uri) override;
29+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
29};
30};
30
31
31#endif // PLUGIN_H
32#endif // PLUGIN_H
tests/mocks/UInput/plugin.cpp+6−1
@@ -19,8 +19,13 @@
19
19
20#include <QtQml/qqml.h>
20#include <QtQml/qqml.h>
21
21
22+QObject* uinputSingleton(QQmlEngine*, QJSEngine*)
23+{
24+ return new MockUInput;
25+}
26+
22void MockUInputPlugin::registerTypes(const char *uri)
27void MockUInputPlugin::registerTypes(const char *uri)
23{
28{
24 Q_ASSERT(uri == QLatin1String("UInput"));
29 Q_ASSERT(uri == QLatin1String("UInput"));
25− qmlRegisterType<MockUInput>(uri, 0, 1, "UInput");
30+ qmlRegisterSingletonType<MockUInput>(uri, 0, 1, "UInput", uinputSingleton);
26}
31}
tests/mocks/Unity/Application/MirSurfaceItem.cpp+27−4
@@ -189,9 +189,15 @@ void MirSurfaceItem::createQmlContentItem()
189 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
189 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
190 m_qmlItem->setParentItem(this);
190 m_qmlItem->setParentItem(this);
191
191
192+ if (m_fillMode == FillMode::Stretch && width() != 0 && height() != 0) {
193+ m_qmlItem->setWidth(width());
194+ m_qmlItem->setHeight(height());
195+ } else {
192− m_qmlItem->setWidth(m_surfaceWidth);
196+ m_qmlItem->setWidth(m_surfaceWidth);
193− m_qmlItem->setHeight(m_surfaceHeight);
197+ m_qmlItem->setHeight(m_surfaceHeight);
198+ }
194
199
200+ qDebug() << "set size to" << m_surfaceWidth;
195 setImplicitWidth(m_qmlItem->implicitWidth());
201 setImplicitWidth(m_qmlItem->implicitWidth());
196 setImplicitHeight(m_qmlItem->implicitHeight());
202 setImplicitHeight(m_qmlItem->implicitHeight());
197
203
@@ -308,6 +314,16 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
308 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
314 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
309 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
315 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
310 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
316 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
317+ connect(m_qmlSurface, &MirSurface::sizeChanged, this, [this] () {
318+ if (m_fillMode == FillMode::Stretch) {
319+ m_qmlItem->setSize(QSize(this->width(), this->height()));
320+ } else {
321+ m_qmlItem->setSize(m_qmlSurface->size());
322+ }
323+ setImplicitSize(m_qmlSurface->width(), m_qmlSurface->height());
324+ });
325+ m_surfaceWidth = surface->size().width();
326+ m_surfaceHeight = surface->size().height();
311
327
312 QUrl qmlComponentFilePath;
328 QUrl qmlComponentFilePath;
313 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
329 if (!m_qmlSurface->qmlFilePath().isEmpty()) {
@@ -321,6 +337,7 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
321 switch (m_qmlContentComponent->status()) {
337 switch (m_qmlContentComponent->status()) {
322 case QQmlComponent::Ready:
338 case QQmlComponent::Ready:
323 createQmlContentItem();
339 createQmlContentItem();
340+ qDebug() << "content created" << m_surfaceWidth << implicitWidth() << width();
324 break;
341 break;
325 case QQmlComponent::Loading:
342 case QQmlComponent::Loading:
326 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
343 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
@@ -399,9 +416,15 @@ void MirSurfaceItem::updateSurfaceSize()
399 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
416 if (m_qmlSurface && m_surfaceWidth > 0 && m_surfaceHeight > 0) {
400 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
417 m_qmlSurface->resize(m_surfaceWidth, m_surfaceHeight);
401 if (m_qmlItem) {
418 if (m_qmlItem) {
419+ if (m_fillMode == FillMode::Stretch) {
420+ m_qmlItem->setWidth(width());
421+ m_qmlItem->setHeight(height());
422+ } else {
402− m_qmlItem->setWidth(m_surfaceWidth);
423+ m_qmlItem->setWidth(m_surfaceWidth);
403− m_qmlItem->setHeight(m_surfaceHeight);
424+ m_qmlItem->setHeight(m_surfaceHeight);
425+ }
404 }
426 }
427+ qDebug() << this << "setting implicitsize" << m_surfaceWidth << m_surfaceHeight;
405 setImplicitSize(m_surfaceWidth, m_surfaceHeight);
428 setImplicitSize(m_surfaceWidth, m_surfaceHeight);
406 }
429 }
407}
430}
tests/mocks/Unity/Application/SurfaceManager.cpp+1−1
@@ -21,7 +21,7 @@
21
21
22#include <paths.h>
22#include <paths.h>
23
23
24−#define SURFACEMANAGER_DEBUG 0
24+#define SURFACEMANAGER_DEBUG 1
25
25
26#if SURFACEMANAGER_DEBUG
26#if SURFACEMANAGER_DEBUG
27#define DEBUG_MSG(params) qDebug().nospace() << "SurfaceManager[" << (void*)this << "]::" << __func__ << params
27#define DEBUG_MSG(params) qDebug().nospace() << "SurfaceManager[" << (void*)this << "]::" << __func__ << params
tests/mocks/Unity/CMakeLists.txt−1
@@ -6,7 +6,6 @@ add_subdirectory(InputInfo)
6add_subdirectory(Launcher)
6add_subdirectory(Launcher)
7add_subdirectory(Notifications)
7add_subdirectory(Notifications)
8add_subdirectory(DashCommunicator)
8add_subdirectory(DashCommunicator)
9−add_subdirectory(Screens)
10add_subdirectory(Platform)
9add_subdirectory(Platform)
11
10
12pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
11pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
tests/mocks/Unity/InputInfo/InputWindow.qmlnew file+68
@@ -0,0 +1,68 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import Unity.InputInfo 0.1
4+
5+Rectangle {
6+ id: rect
7+ color: "white"
8+ width: parent.width
9+ height: parent.height
10+
11+ Action {
12+ id: mouseAction
13+ text: checked ? "Remove Mouse" : "Add Mouse"
14+ onTriggered: {
15+ if (checked) {
16+ console.log("ADD")
17+ MockInputDeviceBackend.addMockDevice("/mouse0", InputInfo.Mouse);
18+ } else {
19+ console.log("REMOVE")
20+ MockInputDeviceBackend.removeDevice("/mouse0");
21+ }
22+ }
23+ iconName: "input-mouse-symbolic"
24+ checkable: true
25+ checked: false
26+ }
27+
28+ Action {
29+ id: kbAction
30+ text: checked ? "Remove Keyboard" : "Add Keyboard"
31+ onTriggered: {
32+ if (checked) {
33+ MockInputDeviceBackend.addMockDevice("/kbd0", InputInfo.Keyboard);
34+ } else {
35+ MockInputDeviceBackend.removeDevice("/kbd0");
36+ }
37+ }
38+ iconName: "input-keyboard-symbolic"
39+ checkable: true
40+ checked: false
41+ }
42+
43+ Column {
44+ anchors {
45+ fill: parent
46+ margins: units.gu(1)
47+ }
48+ spacing: units.gu(1)
49+
50+ Button {
51+ anchors {
52+ left: parent.left
53+ right: parent.right
54+ }
55+ action: mouseAction
56+ color: mouseAction.checked ? UbuntuColors.red : UbuntuColors.green
57+ }
58+
59+ Button {
60+ anchors {
61+ left: parent.left
62+ right: parent.right
63+ }
64+ action: kbAction
65+ color: kbAction.checked ? UbuntuColors.red : UbuntuColors.green
66+ }
67+ }
68+}
tests/mocks/Unity/InputInfo/mockcontroller.cpp+24−2
@@ -18,10 +18,32 @@
18
18
19#include "qinputdeviceinfo_mock_p.h"
19#include "qinputdeviceinfo_mock_p.h"
20
20
21+#include <QQuickView>
22+#include <QQmlComponent>
23+#include <QQuickItem>
24+#include <paths.h>
25+
21−MockController::MockController(QObject *parent):
26+MockController::MockController(QQmlEngine *engine)
22− QObject(parent)
23{
27{
28+ QQmlComponent component(engine);
29+ component.setData("import QtQuick 2.4; import Unity.InputInfo 0.1; InputWindow { }", ::qmlDirectory());
30+ QObject *myObject = component.create();
31+ QQuickItem *item = qobject_cast<QQuickItem*>(myObject);
32+ if (item) {
33+ auto window = new QQuickView();
34+ window->setTitle("Input");
35+ item->setParentItem(window->contentItem());
36+ window->setResizeMode(QQuickView::SizeRootObjectToView);
37+ window->setWidth(200);
38+ window->setHeight(100);
39+ window->show();
40+ }
41+}
24
42
43+MockController *MockController::instance(QQmlEngine *engine)
44+{
45+ static MockController* controller = new MockController(engine);
46+ return controller;
25}
47}
26
48
27QInputDevice *MockController::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
49QInputDevice *MockController::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
tests/mocks/Unity/InputInfo/mockcontroller.h+5−1
@@ -20,13 +20,17 @@
20#include <QObject>
20#include <QObject>
21#include "qinputinfo.h"
21#include "qinputinfo.h"
22
22
23+class QQmlEngine;
24+
23class MockController: public QObject
25class MockController: public QObject
24{
26{
25 Q_OBJECT
27 Q_OBJECT
26public:
28public:
27− MockController(QObject *parent = 0);
29+ MockController(QQmlEngine *engine);
28 ~MockController() = default;
30 ~MockController() = default;
29
31
32+ static MockController *instance(QQmlEngine *engine);
33+
30 Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
34 Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
31 Q_INVOKABLE void removeDevice(const QString &devicePath);
35 Q_INVOKABLE void removeDevice(const QString &devicePath);
32};
36};
tests/mocks/Unity/InputInfo/plugin.cpp+1−2
@@ -26,9 +26,8 @@
26
26
27static QObject *backendProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
27static QObject *backendProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
28{
28{
29− Q_UNUSED(engine)
30 Q_UNUSED(scriptEngine)
29 Q_UNUSED(scriptEngine)
31− return new MockController(engine);
30+ return MockController::instance(engine);
32}
31}
33
32
34void InputInfoPlugin::registerTypes(const char *uri)
33void InputInfoPlugin::registerTypes(const char *uri)
tests/mocks/Unity/InputInfo/qmldir+2
@@ -1,2 +1,4 @@
1module Unity.InputInfo
1module Unity.InputInfo
2plugin MockInputInfo
2plugin MockInputInfo
3+
4+InputWindow 0.1 InputWindow.qml
tests/mocks/Unity/Screens/CMakeLists.txtdeleted−14
@@ -1,14 +0,0 @@
1−include_directories(
2− ${CMAKE_CURRENT_SOURCE_DIR}
3−)
4−
5−set(MockScreens_SOURCES
6− plugin.cpp
7− screens.cpp
8−)
9−
10−add_library(MockScreensPlugin MODULE ${MockScreens_SOURCES})
11−
12−qt5_use_modules(MockScreensPlugin Gui Qml)
13−
14−add_unity8_mock(Unity.Screens 0.1 Unity/Screens PREFIX mocks TARGETS MockScreensPlugin)
tests/mocks/Unity/Screens/plugin.cppdeleted−29
@@ -1,29 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "plugin.h"
18−#include "screens.h"
19−
20−#include <QScreen>
21−
22−void UnityScreensPlugin::registerTypes(const char* uri)
23−{
24− Q_ASSERT(QLatin1String(uri) == QLatin1String("Unity.Screens"));
25−
26− qRegisterMetaType<QScreen*>("QScreen*");
27−
28− qmlRegisterType<Screens>(uri, 0, 1, "Screens");
29−}
tests/mocks/Unity/Screens/plugin.hdeleted−25
@@ -1,25 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include <QQmlExtensionPlugin>
18−#include <QtQml/qqml.h>
19−
20−class UnityScreensPlugin : public QQmlExtensionPlugin {
21− Q_OBJECT
22− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
23−public:
24− void registerTypes(const char* uri) override;
25−};
tests/mocks/Unity/Screens/qmldirdeleted−2
@@ -1,2 +0,0 @@
1−module Unity.Screens
2−plugin MockScreensPlugin
tests/mocks/Unity/Screens/screens.cppdeleted−71
@@ -1,71 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "screens.h"
18−
19−// Qt
20−#include <QGuiApplication>
21−#include <QScreen>
22−#include <QDebug>
23−
24−Q_DECLARE_METATYPE(QScreen*)
25−
26−Screens::Screens(QObject *parent) :
27− QAbstractListModel(parent)
28−{
29− // start with one screen attached
30− m_screenList.append(new Screen());
31−}
32−
33−Screens::~Screens() noexcept
34−{
35− qDeleteAll(m_screenList);
36− m_screenList.clear();
37−}
38−
39−QHash<int, QByteArray> Screens::roleNames() const
40−{
41− QHash<int, QByteArray> roles;
42− roles[ScreenRole] = "screen";
43− roles[OutputTypeRole] = "outputType";
44− return roles;
45−}
46−
47−QVariant Screens::data(const QModelIndex &index, int role) const
48−{
49− if (!index.isValid() || index.row() >= m_screenList.size()) {
50− return QVariant();
51− }
52−
53− switch(role) {
54− case ScreenRole:
55− return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
56− case OutputTypeRole:
57− return m_screenList.at(index.row())->outputTypes;
58− }
59−
60− return QVariant();
61−}
62−
63−int Screens::rowCount(const QModelIndex &) const
64−{
65− return count();
66−}
67−
68−int Screens::count() const
69−{
70− return m_screenList.size();
71−}
tests/mocks/WindowManager/CMakeLists.txtnew file+35
@@ -0,0 +1,35 @@
1+include_directories(
2+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager
3+)
4+
5+include_directories(
6+ SYSTEM
7+ ${QTMIRSERVER_INCLUDE_DIRS}
8+)
9+
10+set(WINDOWMANAGER_SRC
11+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/TopLevelWindowModel.cpp
12+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Window.cpp
13+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/Workspace.cpp
14+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceManager.cpp
15+ ${CMAKE_SOURCE_DIR}/plugins/WindowManager/WorkspaceModel.cpp
16+ WindowManagerPlugin.cpp
17+ Screens.cpp
18+ Screen.cpp
19+ ScreenWindow.cpp
20+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
21+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
22+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
23+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
24+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h
25+)
26+
27+add_library(MockWindowManager-qml SHARED ${WINDOWMANAGER_SRC})
28+
29+target_link_libraries(MockWindowManager-qml
30+ ${QTMIRSERVER_LDFLAGS}
31+)
32+
33+qt5_use_modules(MockWindowManager-qml Qml Quick Gui)
34+
35+add_unity8_mock(WindowManager 1.0 WindowManager TARGETS MockWindowManager-qml)
tests/mocks/WindowManager/Screen.cppnew file+65
@@ -0,0 +1,65 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Screen.h"
18+#include "WorkspaceModel.h"
19+#include "WorkspaceManager.h"
20+#include "Workspace.h"
21+
22+Screen::Screen()
23+ : m_workspaces(new WorkspaceModel)
24+{
25+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
26+ WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
27+}
28+
29+QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
30+{
31+ return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
32+}
33+
34+qtmir::ScreenConfiguration *Screen::beginConfiguration() const
35+{
36+ auto config = new qtmir::ScreenConfiguration;
37+ config->valid = true;
38+ config->id = m_id;
39+ config->used = m_used;
40+ config->topLeft = m_position;
41+ config->currentModeIndex = m_currentModeIndex;
42+ config->powerMode = m_powerMode;
43+ config->scale = m_scale;
44+ config->formFactor = m_formFactor;
45+ return config;
46+}
47+
48+bool Screen::applyConfiguration(qtmir::ScreenConfiguration *configuration)
49+{
50+ m_used = configuration->used;
51+ m_position = configuration->topLeft;
52+ m_currentModeIndex = configuration->currentModeIndex;
53+ m_powerMode = configuration->powerMode;
54+ m_scale = configuration->scale;
55+ m_formFactor = configuration->formFactor;
56+
57+// m_orientation = configuration->orientation;
58+ return true;
59+}
60+
61+void Screen::setActive(bool active)
62+{
63+ m_active = active;
64+ Q_EMIT activeChanged(active);
65+}
tests/mocks/WindowManager/Screen.hnew file+56
@@ -0,0 +1,56 @@
1+#ifndef MOCK_SCREEN_H
2+#define MOCK_SCREEN_H
3+
4+#include <qtmir/screen.h>
5+#include <QScopedPointer>
6+
7+class WorkspaceModel;
8+
9+class Screen : public qtmir::Screen
10+{
11+ Q_OBJECT
12+ Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
13+
14+public:
15+ Screen();
16+
17+ qtmir::OutputId outputId() const override { return m_id; }
18+ bool used() const override { return m_used; }
19+ QString name() const override { return m_name; }
20+ float scale() const override { return m_scale; }
21+ QSizeF physicalSize() const override { return m_physicalSize; }
22+ qtmir::FormFactor formFactor() const override { return m_formFactor; }
23+ qtmir::OutputTypes outputType() const override { return m_outputType; }
24+ MirPowerMode powerMode() const override { return m_powerMode; }
25+ Qt::ScreenOrientation orientation() const override { return m_orientation; }
26+ QPoint position() const override { return m_position; }
27+ QQmlListProperty<qtmir::ScreenMode> availableModes() override;
28+ uint currentModeIndex() const override { return m_currentModeIndex; }
29+ bool isActive() const override { return m_active; }
30+ void setActive(bool active) override;
31+
32+ QScreen* qscreen() const override { return nullptr; }
33+
34+ qtmir::ScreenConfiguration *beginConfiguration() const override;
35+ bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override;
36+
37+ WorkspaceModel* workspaces() const { return m_workspaces.data(); }
38+
39+public:
40+ qtmir::OutputId m_id{0};
41+ bool m_active{false};
42+ bool m_used{true};
43+ QString m_name;
44+ qtmir::OutputTypes m_outputType{qtmir::Unknown};
45+ MirPowerMode m_powerMode{mir_power_mode_on};
46+ Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
47+ float m_scale{1.0};
48+ qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
49+ QPoint m_position;
50+ uint m_currentModeIndex{0};
51+ QList<qtmir::ScreenMode*> m_sizes;
52+ QSizeF m_physicalSize;
53+ const QScopedPointer<WorkspaceModel> m_workspaces;
54+};
55+
56+#endif // MOCK_SCREEN_H
tests/mocks/WindowManager/ScreenWindow.cppnew file+48
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ScreenWindow.h"
18+#include "Screen.h"
19+
20+// Qt
21+#include <QGuiApplication>
22+#include <QDebug>
23+
24+ScreenWindow::ScreenWindow(QQuickWindow *parent)
25+ : QQuickWindow(parent)
26+{
27+ if (qGuiApp->platformName() != QLatin1String("mirserver")) {
28+ qCritical("Not using 'mirserver' QPA plugin. Using ScreenWindow may produce unknown results.");
29+ }
30+}
31+
32+ScreenWindow::~ScreenWindow()
33+{
34+}
35+
36+Screen *ScreenWindow::screenWrapper() const
37+{
38+ return m_screen.data();
39+}
40+
41+void ScreenWindow::setScreenWrapper(Screen *screen)
42+{
43+ if (m_screen != screen) {
44+ m_screen = screen;
45+ Q_EMIT screenWrapperChanged();
46+ }
47+ QQuickWindow::setScreen(screen->qscreen());
48+}
tests/mocks/WindowManager/ScreenWindow.hnew file+49
@@ -0,0 +1,49 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_SCREENWINDOW_H
18+#define UNITY_SCREENWINDOW_H
19+
20+#include <QQuickWindow>
21+#include <QPointer>
22+
23+#include "Screen.h"
24+
25+class ScreenAdapter;
26+
27+/*
28+ * ScreenWindow - wrapper of QQuickWindow to enable QML to specify destination screen.
29+**/
30+class ScreenWindow : public QQuickWindow
31+{
32+ Q_OBJECT
33+ Q_PROPERTY(Screen *screen READ screenWrapper WRITE setScreenWrapper NOTIFY screenWrapperChanged)
34+ Q_PROPERTY(int winId READ winId CONSTANT)
35+public:
36+ explicit ScreenWindow(QQuickWindow *parent = 0);
37+ ~ScreenWindow();
38+
39+ Screen *screenWrapper() const;
40+ void setScreenWrapper(Screen *screen);
41+
42+Q_SIGNALS:
43+ void screenWrapperChanged();
44+
45+private:
46+ QPointer<Screen> m_screen;
47+};
48+
49+#endif // UNITY_SCREENWINDOW_H
tests/mocks/WindowManager/Screens.cppnew file+101
@@ -0,0 +1,101 @@
1+/*
2+ * Copyright (C) 2016-2017 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Screens.h"
18+#include "Screen.h"
19+
20+// qtmirserver
21+#include <qtmir/qtmir.h>
22+#include <qtmir/screens.h>
23+#include <QGuiApplication>
24+
25+// Qt
26+#include <QScreen>
27+#include <QWindow>
28+
29+Screens::Screens(QObject *parent)
30+ : QAbstractListModel(parent)
31+{
32+ bool ok = false;
33+ int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
34+ if (!ok) screenCount = 1;
35+ QPoint lastPoint(0,0);
36+ for (int i = 0; i < screenCount; ++i) {
37+ auto screen = new Screen();
38+ screen->m_id = qtmir::OutputId{i};
39+ screen->m_active = i == 0;
40+ screen->m_name = QString("Monitor %1").arg(i);
41+ screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
42+ screen->m_sizes.append(new qtmir::ScreenMode(50, QSize(640,480)));
43+ screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
44+ screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
45+ screen->m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
46+ screen->m_currentModeIndex = 3;
47+ screen->m_physicalSize = QSize(800,568);
48+ m_screenList.append(screen);
49+
50+ lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
51+ }
52+}
53+
54+QHash<int, QByteArray> Screens::roleNames() const
55+{
56+ QHash<int, QByteArray> roles;
57+ roles[ScreenRole] = "screen";
58+ return roles;
59+}
60+
61+QVariant Screens::data(const QModelIndex &index, int role) const
62+{
63+ if (!index.isValid() || index.row() >= m_screenList.size()) {
64+ return QVariant();
65+ }
66+
67+ switch(role) {
68+ case ScreenRole:
69+ return QVariant::fromValue(m_screenList.at(index.row()));
70+ } // switch
71+
72+ return QVariant();
73+}
74+
75+int Screens::rowCount(const QModelIndex &) const
76+{
77+ return count();
78+}
79+
80+int Screens::count() const
81+{
82+ return m_screenList.size();
83+}
84+
85+QVariant Screens::activeScreen() const
86+{
87+ for (int i = 0; i < m_screenList.count(); i++) {
88+ if (m_screenList[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_screenList.count() <= index) return;
98+
99+ auto screen = m_screenList.at(index);
100+ screen->setActive(true);
101+}
tests/mocks/Unity/Screens/screens.h → tests/mocks/WindowManager/Screens.hrenamed+20−37
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software: you can redistribute it and/or modify it under
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
5 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -14,47 +14,31 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#ifndef SCREENS_H
17+#ifndef UNITY_SCREENS_H
18−#define SCREENS_H
18+#define UNITY_SCREENS_H
19
19
20#include <QAbstractListModel>
20#include <QAbstractListModel>
21−#include <QScreen>
21+#include <QSharedPointer>
22
22
23class Screen;
23class Screen;
24+namespace qtmir
25+{
26+class Screens;
27+}
24
28
25class Screens : public QAbstractListModel
29class Screens : public QAbstractListModel
26{
30{
27 Q_OBJECT
31 Q_OBJECT
28−
29 Q_PROPERTY(int count READ count NOTIFY countChanged)
32 Q_PROPERTY(int count READ count NOTIFY countChanged)
33+ Q_PROPERTY(QVariant activeScreen READ activeScreen WRITE activateScreen NOTIFY activeScreenChanged)
30
34
31public:
35public:
32 enum ItemRoles {
36 enum ItemRoles {
33− ScreenRole = Qt::UserRole + 1,
37+ ScreenRole = Qt::UserRole + 1
34− OutputTypeRole
35 };
38 };
36
39
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);
40 explicit Screens(QObject *parent = 0);
57− virtual ~Screens() noexcept;
41+ virtual ~Screens() noexcept = default;
58
42
59 /* QAbstractItemModel */
43 /* QAbstractItemModel */
60 QHash<int, QByteArray> roleNames() const override;
44 QHash<int, QByteArray> roleNames() const override;
@@ -62,21 +46,20 @@ public:
62 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
46 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
63
47
64 int count() const;
48 int count() const;
49+ QVariant activeScreen() const;
50+
51+public Q_SLOTS:
52+ void activateScreen(const QVariant& index);
65
53
66Q_SIGNALS:
54Q_SIGNALS:
67 void countChanged();
55 void countChanged();
68− void screenAdded(QScreen *screen);
56+ void activeScreenChanged();
69− void screenRemoved(QScreen *screen);
70
57
71−private:
58+ void screenAdded(Screen* screen);
72− QList<Screen *> m_screenList;
59+ void screenRemoved(Screen* screen);
73−};
74
60
75−class Screen
61+private:
76−{
62+ QList<Screen*> m_screenList;
77−public:
78− Screens::OutputTypes outputTypes = Screens::Unknown;
79− QScreen *qScreen = nullptr;
80};
63};
81
64
82#endif // SCREENS_H
65#endif // SCREENS_H
tests/mocks/WindowManager/WindowManagerPlugin.cppnew file+58
@@ -0,0 +1,58 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "WindowManagerPlugin.h"
18+
19+#include "Screens.h"
20+#include "Screen.h"
21+#include "ScreenWindow.h"
22+#include "TopLevelWindowModel.h"
23+#include "Window.h"
24+#include "WorkspaceManager.h"
25+#include "Workspace.h"
26+#include "WorkspaceModel.h"
27+
28+#include <QtQml>
29+
30+static QObject *workspace_manager(QQmlEngine *engine, QJSEngine *scriptEngine)
31+{
32+ Q_UNUSED(engine)
33+ Q_UNUSED(scriptEngine)
34+ return WorkspaceManager::instance();
35+}
36+QObject* screensSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
37+ Q_UNUSED(engine);
38+ Q_UNUSED(scriptEngine);
39+ return new Screens();
40+}
41+
42+void WindowManagerPlugin::registerTypes(const char *uri)
43+{
44+ qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
45+ qmlRegisterSingletonType<WorkspaceManager>(uri, 1, 0, "WorkspaceManager", workspace_manager);
46+ qmlRegisterUncreatableType<WorkspaceModel>(uri, 1, 0, "WorkspaceModel", "Not a creatable type");
47+ qmlRegisterSingletonType<Screens>(uri, 1, 0, "Screens", screensSingleton);
48+ qmlRegisterUncreatableType<qtmir::ScreenMode>(uri, 1, 0, "ScreenMode", "ScreenMode is not creatable.");
49+
50+ qRegisterMetaType<Window*>("Window*");
51+ qRegisterMetaType<Workspace*>("Workspace*");
52+
53+ qRegisterMetaType<QAbstractListModel*>("QAbstractListModel*");
54+ qRegisterMetaType<Screen*>("Screen*");
55+
56+ qmlRegisterType<ScreenWindow>(uri, 1, 0, "ScreenWindow");
57+ qmlRegisterRevision<QWindow,1>(uri, 1, 0);
58+}
tests/mocks/WindowManager/WindowManagerPlugin.hnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef WINDOWMANAGER_PLUGIN_H
18+#define WINDOWMANAGER_PLUGIN_H
19+
20+#include <QtQml/QQmlEngine>
21+#include <QtQml/QQmlExtensionPlugin>
22+
23+class WindowManagerPlugin : public QQmlExtensionPlugin
24+{
25+ Q_OBJECT
26+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27+
28+public:
29+ void registerTypes(const char *uri) override;
30+};
31+
32+#endif // WINDOWMANAGER_PLUGIN_H
tests/mocks/WindowManager/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module WindowManager
2+plugin MockWindowManager-qml
tests/qmltests/Components/tst_VirtualTouchPad.qml+2−2
@@ -39,11 +39,11 @@ Rectangle {
39
39
40 SignalSpy {
40 SignalSpy {
41 id: mouseEventSpy1
41 id: mouseEventSpy1
42− target: touchScreenPad.uinput
42+ target: UInput
43 }
43 }
44 SignalSpy {
44 SignalSpy {
45 id: mouseEventSpy2
45 id: mouseEventSpy2
46− target: touchScreenPad.uinput
46+ target: UInput
47 }
47 }
48
48
49 UnityTestCase {
49 UnityTestCase {
tests/qmltests/Panel/tst_Panel.qml+14−12
@@ -42,6 +42,8 @@ PanelTest {
42 value: keyboardAttached.checked
42 value: keyboardAttached.checked
43 }
43 }
44
44
45+ readonly property alias panelState: panel.panelState
46+
45 SurfaceManager { id: sMgr }
47 SurfaceManager { id: sMgr }
46 ApplicationMenuDataLoader {
48 ApplicationMenuDataLoader {
47 id: appMenuData
49 id: appMenuData
@@ -148,7 +150,7 @@ PanelTest {
148 Layout.fillWidth: true
150 Layout.fillWidth: true
149 CheckBox {
151 CheckBox {
150 id: windowControlsCB
152 id: windowControlsCB
151− onClicked: PanelState.decorationsVisible = checked
153+ onClicked: panelState.decorationsVisible = checked
152 }
154 }
153 Label {
155 Label {
154 text: "Show window decorations"
156 text: "Show window decorations"
@@ -159,7 +161,7 @@ PanelTest {
159 RowLayout {
161 RowLayout {
160 Layout.fillWidth: true
162 Layout.fillWidth: true
161 CheckBox {
163 CheckBox {
162− onClicked: PanelState.title = checked ? "Fake window title" : ""
164+ onClicked: panelState.title = checked ? "Fake window title" : ""
163 }
165 }
164 Label {
166 Label {
165 text: "Show fake window title"
167 text: "Show fake window title"
@@ -245,7 +247,7 @@ PanelTest {
245
247
246 SignalSpy {
248 SignalSpy {
247 id: windowControlButtonsSpy
249 id: windowControlButtonsSpy
248− target: PanelState
250+ target: panelState
249 signalName: "closeClicked"
251 signalName: "closeClicked"
250 }
252 }
251
253
@@ -255,8 +257,8 @@ PanelTest {
255 panel.fullscreenMode = false;
257 panel.fullscreenMode = false;
256 callManager.foregroundCall = null;
258 callManager.foregroundCall = null;
257
259
258− PanelState.title = "";
260+ panelState.title = "";
259− PanelState.decorationsVisible = false;
261+ panelState.decorationsVisible = false;
260
262
261 // Wait for the indicators to get into position.
263 // Wait for the indicators to get into position.
262 // (switches between normal and fullscreen modes are animated)
264 // (switches between normal and fullscreen modes are animated)
@@ -447,7 +449,7 @@ PanelTest {
447 }
449 }
448
450
449 function test_hint(data) {
451 function test_hint(data) {
450− PanelState.title = "Fake Title"
452+ panelState.title = "Fake Title"
451 panel.fullscreenMode = data.fullscreen;
453 panel.fullscreenMode = data.fullscreen;
452 callManager.foregroundCall = data.call;
454 callManager.foregroundCall = data.call;
453
455
@@ -489,7 +491,7 @@ PanelTest {
489 // menus, first by running the hint animation, then after dragging down will
491 // menus, first by running the hint animation, then after dragging down will
490 // expose more of the panel. Releasing the touch will complete the show.
492 // expose more of the panel. Releasing the touch will complete the show.
491 function test_drag_applicationMenu_down_shows_menu(data) {
493 function test_drag_applicationMenu_down_shows_menu(data) {
492− PanelState.title = "Fake Title";
494+ panelState.title = "Fake Title";
493 panel.fullscreenMode = data.fullscreen;
495 panel.fullscreenMode = data.fullscreen;
494 callManager.foregroundCall = data.call;
496 callManager.foregroundCall = data.call;
495
497
@@ -580,7 +582,7 @@ PanelTest {
580 }
582 }
581
583
582 function test_darkenedAreaEatsAllApplicationMenuEvents() {
584 function test_darkenedAreaEatsAllApplicationMenuEvents() {
583− PanelState.title = "Fake Title"
585+ panelState.title = "Fake Title"
584
586
585 // The center of the area not covered by the indicators menu
587 // The center of the area not covered by the indicators menu
586 // Ie, the visible darkened area behind the menu
588 // Ie, the visible darkened area behind the menu
@@ -701,7 +703,7 @@ PanelTest {
701 var windowControlArea = findChild(panel, "windowControlArea");
703 var windowControlArea = findChild(panel, "windowControlArea");
702 verify(windowControlArea, "Window control area should have been created in windowed mode")
704 verify(windowControlArea, "Window control area should have been created in windowed mode")
703
705
704− PanelState.decorationsVisible = true;
706+ panelState.decorationsVisible = true;
705 // click in very topleft corner and verify the close button got clicked too
707 // click in very topleft corner and verify the close button got clicked too
706 mouseMove(panel, 0, 0);
708 mouseMove(panel, 0, 0);
707 mouseClick(panel, 0, 0, undefined /*button*/, undefined /*modifiers*/, 100 /*short delay*/);
709 mouseClick(panel, 0, 0, undefined /*button*/, undefined /*modifiers*/, 100 /*short delay*/);
@@ -762,7 +764,7 @@ PanelTest {
762 }
764 }
763
765
764 function test_stagedApplicationMenuBarShowOnMouseHover() {
766 function test_stagedApplicationMenuBarShowOnMouseHover() {
765− PanelState.title = "Fake Title";
767+ panelState.title = "Fake Title";
766 panel.mode = "staged";
768 panel.mode = "staged";
767 mouseEmulation.checked = false;
769 mouseEmulation.checked = false;
768
770
@@ -780,7 +782,7 @@ PanelTest {
780 }
782 }
781
783
782 function test_windowedApplicationMenuShowOnMouseHoverWhenDecorationsShown() {
784 function test_windowedApplicationMenuShowOnMouseHoverWhenDecorationsShown() {
783− PanelState.title = "Fake Title";
785+ panelState.title = "Fake Title";
784 panel.mode = "windowed";
786 panel.mode = "windowed";
785 mouseEmulation.checked = false;
787 mouseEmulation.checked = false;
786
788
@@ -796,7 +798,7 @@ PanelTest {
796 tryCompare(appTitle, "visible", true, undefined, "App title should still be visible on mouse hover when panel decorations are not visible");
798 tryCompare(appTitle, "visible", true, undefined, "App title should still be visible on mouse hover when panel decorations are not visible");
797 tryCompare(appMenuBar, "visible", false, undefined, "App menu bar should be visible on mouse hover when panel decorations are not visible");
799 tryCompare(appMenuBar, "visible", false, undefined, "App menu bar should be visible on mouse hover when panel decorations are not visible");
798
800
799− PanelState.decorationsVisible = true;
801+ panelState.decorationsVisible = true;
800
802
801 tryCompare(appTitle, "visible", false, undefined, "App title should still be visible on mouse hover when panel decorations are visible");
803 tryCompare(appTitle, "visible", false, undefined, "App title should still be visible on mouse hover when panel decorations are visible");
802 tryCompare(appMenuBar, "visible", true, undefined, "App menu bar should be visible on mouse hover when panel decorations not visible");
804 tryCompare(appMenuBar, "visible", true, undefined, "App menu bar should be visible on mouse hover when panel decorations not visible");
tests/qmltests/Stage/tst_DecoratedWindow.qml+5−1
@@ -52,6 +52,10 @@ Rectangle {
52 surfaceManager: sMgr
52 surfaceManager: sMgr
53 }
53 }
54
54
55+ PanelState {
56+ id: panelState
57+ }
58+
55 Item {
59 Item {
56 id: fakeShell
60 id: fakeShell
57
61
@@ -99,7 +103,7 @@ Rectangle {
99 surface: fakeApplication && fakeApplication.surfaceList.count > 0 ? fakeApplication.surfaceList.get(0) : null
103 surface: fakeApplication && fakeApplication.surfaceList.count > 0 ? fakeApplication.surfaceList.get(0) : null
100
104
101 Binding {
105 Binding {
102− target: PanelState
106+ target: panelState
103 property: "focusedPersistentSurfaceId"
107 property: "focusedPersistentSurfaceId"
104 value: decoratedWindow.surface ? decoratedWindow.surface.persistentId : "x"
108 value: decoratedWindow.surface ? decoratedWindow.surface.persistentId : "x"
105 }
109 }
tests/qmltests/Stage/tst_DesktopStage.qml+8−3
@@ -44,6 +44,10 @@ Item {
44 value: false
44 value: false
45 }
45 }
46
46
47+ PanelState {
48+ id: panelState
49+ }
50+
47 Component.onCompleted: {
51 Component.onCompleted: {
48 ApplicationMenusLimits.screenWidth = Qt.binding( function() { return stageLoader.width; } );
52 ApplicationMenusLimits.screenWidth = Qt.binding( function() { return stageLoader.width; } );
49 ApplicationMenusLimits.screenHeight = Qt.binding( function() { return stageLoader.height; } );
53 ApplicationMenusLimits.screenHeight = Qt.binding( function() { return stageLoader.height; } );
@@ -102,6 +106,7 @@ Item {
102 topLevelSurfaceList: topSurfaceList
106 topLevelSurfaceList: topSurfaceList
103 interactive: true
107 interactive: true
104 mode: "windowed"
108 mode: "windowed"
109+ panelState: panelState
105 }
110 }
106 }
111 }
107 }
112 }
@@ -631,19 +636,19 @@ Item {
631 maximizeDelegate(facebookAppDelegate);
636 maximizeDelegate(facebookAppDelegate);
632
637
633 // verify the drop shadow is still not visible
638 // verify the drop shadow is still not visible
634− verify(PanelState.dropShadow == false);
639+ verify(panelState.dropShadow == false);
635
640
636 // start a foreground app, not maximized
641 // start a foreground app, not maximized
637 var dialerAppDelegate = startApplication("dialer-app");
642 var dialerAppDelegate = startApplication("dialer-app");
638
643
639 // verify the drop shadow becomes visible
644 // verify the drop shadow becomes visible
640− verify(PanelState.dropShadow == true);
645+ verify(panelState.dropShadow == true);
641
646
642 // close the maximized app
647 // close the maximized app
643 ApplicationManager.stopApplication("facebook-webapp");
648 ApplicationManager.stopApplication("facebook-webapp");
644
649
645 // verify the drop shadow is gone
650 // verify the drop shadow is gone
646− tryCompare(PanelState, "dropShadow", false);
651+ tryCompare(panelState, "dropShadow", false);
647 }
652 }
648
653
649 function test_threeFingerTapShowsWindowControls_data() {
654 function test_threeFingerTapShowsWindowControls_data() {
tests/qmltests/Stage/tst_WindowResizeArea.qml+1−8
@@ -19,7 +19,6 @@ import QtQuick.Layouts 1.1
19import QtTest 1.0
19import QtTest 1.0
20import Unity.Test 0.1
20import Unity.Test 0.1
21import ".."
21import ".."
22−import "../../../qml/Components/PanelState"
23import "../../../qml/Stage"
22import "../../../qml/Stage"
24import Ubuntu.Components 1.3
23import Ubuntu.Components 1.3
25import Ubuntu.Components.ListItems 1.3 as ListItem
24import Ubuntu.Components.ListItems 1.3 as ListItem
@@ -31,12 +30,6 @@ Item {
31 height: units.gu(60)
30 height: units.gu(60)
32 width: units.gu(85)
31 width: units.gu(85)
33
32
34− Binding {
35− target: PanelState
36− property: "panelHeight"
37− value: units.gu(3)
38− }
39−
40 Component {
33 Component {
41 id: fakeWindowComponent
34 id: fakeWindowComponent
42
35
@@ -362,7 +355,7 @@ Item {
362
355
363 // Make sure it's again where we left it in normal state before destroying
356 // Make sure it's again where we left it in normal state before destroying
364 compare(fakeWindow.requestedX >= 0, true)
357 compare(fakeWindow.requestedX >= 0, true)
365− compare(fakeWindow.requestedY >= PanelState.panelHeight, true)
358+ compare(fakeWindow.requestedY >= 0, true)
366 compare(fakeWindow.requestedX + fakeWindow.width <= root.width, true)
359 compare(fakeWindow.requestedX + fakeWindow.width <= root.width, true)
367 compare(fakeWindow.requestedY + fakeWindow.height <= root.height, true)
360 compare(fakeWindow.requestedY + fakeWindow.height <= root.height, true)
368
361
tests/qmltests/tst_OrientedShell.qml+24−5
@@ -30,7 +30,6 @@ import Utils 0.1
30
30
31import "../../qml"
31import "../../qml"
32import "../../qml/Components"
32import "../../qml/Components"
33−import "../../qml/Components/PanelState"
34import "Stage"
33import "Stage"
35
34
36Rectangle {
35Rectangle {
@@ -82,6 +81,12 @@ Rectangle {
82 deviceFilter: InputInfo.Keyboard
81 deviceFilter: InputInfo.Keyboard
83 }
82 }
84
83
84+ QtObject {
85+ id: _screenWindow
86+ property bool primary: true
87+ }
88+ property alias screenWindow: _screenWindow
89+
85 property int physicalOrientation0
90 property int physicalOrientation0
86 property int physicalOrientation90
91 property int physicalOrientation90
87 property int physicalOrientation180
92 property int physicalOrientation180
@@ -174,6 +179,11 @@ Rectangle {
174 Component.onDestruction: {
179 Component.onDestruction: {
175 orientedShellLoader.itemDestroyed = true;
180 orientedShellLoader.itemDestroyed = true;
176 }
181 }
182+
183+ SurfaceManager {
184+ id: surfaceMan
185+ }
186+ surfaceManager: surfaceMan
177 }
187 }
178 }
188 }
179 }
189 }
@@ -446,6 +456,15 @@ Rectangle {
446 property Item orientedShell: orientedShellLoader.status === Loader.Ready ? orientedShellLoader.item : null
456 property Item orientedShell: orientedShellLoader.status === Loader.Ready ? orientedShellLoader.item : null
447 property Item shell
457 property Item shell
448 property QtObject topLevelSurfaceList
458 property QtObject topLevelSurfaceList
459+ property var panelState: undefined
460+
461+ onOrientedShellChanged: {
462+ if (orientedShell) {
463+ panelState = findInvisibleChild(orientedShell, "panelState");
464+ } else {
465+ panelState = undefined;
466+ }
467+ }
449
468
450 SignalSpy { id: signalSpy }
469 SignalSpy { id: signalSpy }
451 SignalSpy { id: signalSpy2 }
470 SignalSpy { id: signalSpy2 }
@@ -1510,13 +1529,13 @@ Rectangle {
1510 print("exptectedAngle", expectedAngle, point.x, point.y)
1529 print("exptectedAngle", expectedAngle, point.x, point.y)
1511 switch (expectedAngle) {
1530 switch (expectedAngle) {
1512 case 0:
1531 case 0:
1513− return point.x === 0 && point.y === PanelState.panelHeight;
1532+ return point.x === 0 && point.y === panelState.panelHeight;
1514 case 90:
1533 case 90:
1515− return point.x === orientedShell.width - PanelState.panelHeight && point.y === 0;
1534+ return point.x === orientedShell.width - panelState.panelHeight && point.y === 0;
1516 case 180:
1535 case 180:
1517− return point.x === orientedShell.width && point.y === orientedShell.height - PanelState.panelHeight;
1536+ return point.x === orientedShell.width && point.y === orientedShell.height - panelState.panelHeight;
1518 default: // 270
1537 default: // 270
1519− return point.x === PanelState.panelHeight && point.y === orientedShell.height;
1538+ return point.x === panelState.panelHeight && point.y === orientedShell.height;
1520 }
1539 }
1521 }
1540 }
1522
1541
tests/qmltests/tst_Shell.qml+27−11
@@ -62,13 +62,22 @@ Rectangle {
62 if (shell) {
62 if (shell) {
63 topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
63 topLevelSurfaceList = testCase.findInvisibleChild(shell, "topLevelSurfaceList");
64 appMenuData.surfaceManager = testCase.findInvisibleChild(shell, "surfaceManager");
64 appMenuData.surfaceManager = testCase.findInvisibleChild(shell, "surfaceManager");
65+ panelState = testCase.findInvisibleChild(shell, "panelState");
65 } else {
66 } else {
66 topLevelSurfaceList = null;
67 topLevelSurfaceList = null;
67 appMenuData.surfaceManager = null;
68 appMenuData.surfaceManager = null;
69+ panelState = undefined;
68 }
70 }
69 }
71 }
70
72
71 property var topLevelSurfaceList: null
73 property var topLevelSurfaceList: null
74+ property var panelState: undefined
75+
76+ QtObject {
77+ id: _screenWindow
78+ property bool primary: false
79+ }
80+ property alias screenWindow: _screenWindow
72
81
73 Item {
82 Item {
74 id: shellContainer
83 id: shellContainer
@@ -143,6 +152,11 @@ Rectangle {
143 Component.onDestruction: {
152 Component.onDestruction: {
144 shellLoader.itemDestroyed = true;
153 shellLoader.itemDestroyed = true;
145 }
154 }
155+
156+ SurfaceManager {
157+ id: surfaceMan
158+ }
159+ surfaceManager: surfaceMan
146 }
160 }
147 }
161 }
148 }
162 }
@@ -261,6 +275,7 @@ Rectangle {
261 anchors { left: parent.left; right: parent.right }
275 anchors { left: parent.left; right: parent.right }
262 activeFocusOnPress: false
276 activeFocusOnPress: false
263 model: ["phone", "tablet", "desktop"]
277 model: ["phone", "tablet", "desktop"]
278+ selectedIndex: 2
264 onSelectedIndexChanged: {
279 onSelectedIndexChanged: {
265 shellLoader.state = model[selectedIndex];
280 shellLoader.state = model[selectedIndex];
266 }
281 }
@@ -274,6 +289,7 @@ Rectangle {
274 anchors { left: parent.left; right: parent.right }
289 anchors { left: parent.left; right: parent.right }
275 activeFocusOnPress: false
290 activeFocusOnPress: false
276 model: ["phone", "tablet", "desktop"]
291 model: ["phone", "tablet", "desktop"]
292+ selectedIndex: 2
277 }
293 }
278 MouseTouchEmulationCheckbox {
294 MouseTouchEmulationCheckbox {
279 id: mouseEmulation
295 id: mouseEmulation
@@ -680,7 +696,7 @@ Rectangle {
680 }
696 }
681
697
682 function ensureInputMethodSurface() {
698 function ensureInputMethodSurface() {
683− var surfaceManager = findInvisibleChild(shell, "surfaceManager");
699+ var surfaceManager = shell.surfaceManager;
684 verify(surfaceManager);
700 verify(surfaceManager);
685 surfaceManager.createInputMethodSurface();
701 surfaceManager.createInputMethodSurface();
686
702
@@ -1868,21 +1884,21 @@ Rectangle {
1868 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
1884 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
1869
1885
1870 tryCompare(appDelegate, "state", "normal");
1886 tryCompare(appDelegate, "state", "normal");
1871− tryCompare(PanelState, "decorationsVisible", false)
1887+ tryCompare(panelState, "decorationsVisible", false)
1872
1888
1873 mouseClick(maximizeButton, maximizeButton.width / 2, maximizeButton.height / 2);
1889 mouseClick(maximizeButton, maximizeButton.width / 2, maximizeButton.height / 2);
1874 tryCompare(appDelegate, "state", "maximized");
1890 tryCompare(appDelegate, "state", "maximized");
1875− tryCompare(PanelState, "decorationsVisible", true)
1891+ tryCompare(panelState, "decorationsVisible", true)
1876
1892
1877 ApplicationManager.stopApplication(application.appId);
1893 ApplicationManager.stopApplication(application.appId);
1878− tryCompare(PanelState, "decorationsVisible", false)
1894+ tryCompare(panelState, "decorationsVisible", false)
1879
1895
1880 // wait until all zombie surfaces are gone. As MirSurfaceItems hold references over them.
1896 // wait until all zombie surfaces are gone. As MirSurfaceItems hold references over them.
1881 // They won't be gone until those surface items are destroyed.
1897 // They won't be gone until those surface items are destroyed.
1882 tryCompareFunction(function() { return application.surfaceList.count }, 0);
1898 tryCompareFunction(function() { return application.surfaceList.count }, 0);
1883
1899
1884 ApplicationManager.startApplication(application.appId);
1900 ApplicationManager.startApplication(application.appId);
1885− tryCompare(PanelState, "decorationsVisible", true)
1901+ tryCompare(panelState, "decorationsVisible", true)
1886 }
1902 }
1887
1903
1888 function test_newAppHasValidGeometry() {
1904 function test_newAppHasValidGeometry() {
@@ -1939,7 +1955,7 @@ Rectangle {
1939 mousePress(appDelegate, appDelegate.width / 2, units.gu(1))
1955 mousePress(appDelegate, appDelegate.width / 2, units.gu(1))
1940 mouseMove(appDelegate, appDelegate.width / 2, -units.gu(100))
1956 mouseMove(appDelegate, appDelegate.width / 2, -units.gu(100))
1941
1957
1942− compare(appDelegate.y >= PanelState.panelHeight, true);
1958+ compare(appDelegate.y >= panelState.panelHeight, true);
1943 }
1959 }
1944
1960
1945 function test_cantResizeWindowUnderPanel() {
1961 function test_cantResizeWindowUnderPanel() {
@@ -1967,7 +1983,7 @@ Rectangle {
1967 mouseMove(decoration, decoration.width/2, -units.gu(100));
1983 mouseMove(decoration, decoration.width/2, -units.gu(100));
1968
1984
1969 // verify we don't go past the panel
1985 // verify we don't go past the panel
1970− compare(appDelegate.y >= PanelState.panelHeight, true);
1986+ compare(appDelegate.y >= panelState.panelHeight, true);
1971 }
1987 }
1972
1988
1973 function test_restoreWindowStateFixesIfUnderPanel() {
1989 function test_restoreWindowStateFixesIfUnderPanel() {
@@ -1991,7 +2007,7 @@ Rectangle {
1991 tryCompareFunction(function () { return topLevelSurfaceList.applicationAt(0).appId; }, application.appId);
2007 tryCompareFunction(function () { return topLevelSurfaceList.applicationAt(0).appId; }, application.appId);
1992
2008
1993 appDelegate = appRepeater.itemAt(0);
2009 appDelegate = appRepeater.itemAt(0);
1994− compare(appDelegate.y >= PanelState.panelHeight, true);
2010+ compare(appDelegate.y >= panelState.panelHeight, true);
1995 }
2011 }
1996
2012
1997 function test_lifecyclePolicyForNonTouchApp_data() {
2013 function test_lifecyclePolicyForNonTouchApp_data() {
@@ -2639,7 +2655,7 @@ Rectangle {
2639 function test_oskDisplacesWindow_data() {
2655 function test_oskDisplacesWindow_data() {
2640 return [
2656 return [
2641 {tag: "no need to displace", windowHeight: units.gu(10), windowY: units.gu(5), targetDisplacement: units.gu(5), oskEnabled: true},
2657 {tag: "no need to displace", windowHeight: units.gu(10), windowY: units.gu(5), targetDisplacement: units.gu(5), oskEnabled: true},
2642− {tag: "displace to top", windowHeight: units.gu(50), windowY: units.gu(10), targetDisplacement: PanelState.panelHeight, oskEnabled: true},
2658+ {tag: "displace to top", windowHeight: units.gu(50), windowY: units.gu(10), targetDisplacement: panelState.panelHeight, oskEnabled: true},
2643 {tag: "osk not on this screen", windowHeight: units.gu(40), windowY: units.gu(10), targetDisplacement: units.gu(10), oskEnabled: false},
2659 {tag: "osk not on this screen", windowHeight: units.gu(40), windowY: units.gu(10), targetDisplacement: units.gu(10), oskEnabled: false},
2644 ]
2660 ]
2645 }
2661 }
@@ -2662,8 +2678,8 @@ Rectangle {
2662 dashAppDelegate.windowedY = data.windowY;
2678 dashAppDelegate.windowedY = data.windowY;
2663 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, 0, 0, 0));
2679 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, 0, 0, 0));
2664 var initialY = dashAppDelegate.y;
2680 var initialY = dashAppDelegate.y;
2665− print("intial", initialY, "panel", PanelState.panelHeight);
2681+ print("intial", initialY, "panel", panelState.panelHeight);
2666− verify(initialY > PanelState.panelHeight);
2682+ verify(initialY > panelState.panelHeight);
2667
2683
2668 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, root.height / 2, root.width, root.height / 2));
2684 topLevelSurfaceList.inputMethodSurface.setInputBounds(Qt.rect(0, root.height / 2, root.width, root.height / 2));
2669 tryCompare(dashAppDelegate, "y", data.targetDisplacement);
2685 tryCompare(dashAppDelegate, "y", data.targetDisplacement);
tests/uqmlscene/main.cpp+2
@@ -479,6 +479,8 @@ int main(int argc, char ** argv)
479 // TODO: as soon as the engine construction completes, the debug service is
479 // TODO: as soon as the engine construction completes, the debug service is
480 // listening for connections. But actually we aren't ready to debug anything.
480 // listening for connections. But actually we aren't ready to debug anything.
481 QQmlEngine engine;
481 QQmlEngine engine;
482+ engine.rootContext()->setContextProperty("DebuggingController", new DebuggingController(&app));
483+
482 QQmlComponent *component = new QQmlComponent(&engine);
484 QQmlComponent *component = new QQmlComponent(&engine);
483 for (int i = 0; i < imports.size(); ++i)
485 for (int i = 0; i < imports.size(); ++i)
484 engine.addImportPath(imports.at(i));
486 engine.addImportPath(imports.at(i));