Merge lp:~gerboland/miral/qt-add-window-model-qt-side into lp:miral
- qt-add-window-model-qt-side
- Merge into trunk
Proposed by
Gerry Boland
on 2016-07-27
| Status: | Merged |
|---|---|
| Approved by: | Alan Griffiths on 2016-07-27 |
| Approved revision: | 253 |
| Merged at revision: | 240 |
| Proposed branch: | lp:~gerboland/miral/qt-add-window-model-qt-side |
| Merge into: | lp:miral |
| Prerequisite: | lp:~gerboland/miral/qt-add-window-model-mir-side |
| Diff against target: |
1132 lines (+497/-93) 25 files modified
miral-qt/demos/qml-demo-shell/windowModel.qml (+38/-0) miral-qt/src/common/mirqtconversion.h (+31/-2) miral-qt/src/common/windowmodelinterface.h (+2/-2) miral-qt/src/modules/Unity/Application/CMakeLists.txt (+1/-0) miral-qt/src/modules/Unity/Application/dbuswindowstack.cpp (+9/-9) miral-qt/src/modules/Unity/Application/dbuswindowstack.h (+5/-5) miral-qt/src/modules/Unity/Application/mirsurface.cpp (+16/-0) miral-qt/src/modules/Unity/Application/mirsurface.h (+4/-0) miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h (+10/-0) miral-qt/src/modules/Unity/Application/plugin.cpp (+3/-0) miral-qt/src/modules/Unity/Application/windowmodel.cpp (+119/-0) miral-qt/src/modules/Unity/Application/windowmodel.h (+61/-0) miral-qt/src/platforms/mirserver/mirserver.cpp (+8/-2) miral-qt/src/platforms/mirserver/mirserver.h (+4/-0) miral-qt/src/platforms/mirserver/qmirserver.cpp (+2/-0) miral-qt/src/platforms/mirserver/screensmodel.cpp (+7/-1) miral-qt/src/platforms/mirserver/screensmodel.h (+4/-2) miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp (+128/-62) miral-qt/src/platforms/mirserver/windowmanagementpolicy.h (+15/-3) miral-qt/src/platforms/mirserver/windowmodel.cpp (+2/-2) miral-qt/tests/framework/fake_mirsurface.cpp (+10/-0) miral-qt/tests/framework/fake_mirsurface.h (+3/-0) miral-qt/tests/mirserver/ScreensModel/screensmodel_test.cpp (+3/-1) miral-qt/tests/mirserver/ScreensModel/stub_display.h (+9/-0) miral-qt/tests/mirserver/ScreensModel/testable_screensmodel.h (+3/-2) |
| To merge this branch: | bzr merge lp:~gerboland/miral/qt-add-window-model-qt-side |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Alan Griffiths | 2016-07-27 | Approve on 2016-07-27 | |
|
Review via email:
|
|||
Commit Message
[miral-qt] Add Qt-side window model
Description of the Change
To post a comment you must log in.
| Gerry Boland (gerboland) wrote : | # |
> Nits again:
>
> +#include <mir/shell/
>
> We only use <mir/shell/shell.h>
Fixed
> ~~~~
>
> In miral-qt/
>
> +#include <mir/shell/
>
> Not needed.
Fixed
> ~~~~
>
> + auto e = reinterpret_
>
> Is Mir missing a good way to do this? (C.f. mir_keyboard_
I couldn't find another way to achieve this in Mir's apis.
lp:~gerboland/miral/qt-add-window-model-qt-side
updated
on 2016-07-27
- 252. By Gerry Boland on 2016-07-27
-
Only use mir/shell/shell.h
- 253. By Gerry Boland on 2016-07-27
-
Another unnecessary header
| Alan Griffiths (alan-griffiths) wrote : | # |
Good stuff to have on trunk (even if it is still a little flaky).
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === added file 'miral-qt/demos/qml-demo-shell/windowModel.qml' |
| 2 | --- miral-qt/demos/qml-demo-shell/windowModel.qml 1970-01-01 00:00:00 +0000 |
| 3 | +++ miral-qt/demos/qml-demo-shell/windowModel.qml 2016-07-27 16:52:34 +0000 |
| 4 | @@ -0,0 +1,38 @@ |
| 5 | +import QtQuick 2.4 |
| 6 | +import Unity.Application 0.1 |
| 7 | + |
| 8 | +FocusScope { |
| 9 | + focus: true |
| 10 | + |
| 11 | + WindowModel { |
| 12 | + id: windowModel; |
| 13 | + } |
| 14 | + |
| 15 | + Repeater { |
| 16 | + anchors.fill: parent |
| 17 | + model: windowModel |
| 18 | + |
| 19 | + delegate: MirSurfaceItem { |
| 20 | + id: surfaceItem |
| 21 | + surface: model.surface |
| 22 | + consumesInput: true // QUESTION: why is this non-default? |
| 23 | + x: surface.position.x |
| 24 | + y: surface.position.y |
| 25 | + width: surface.size.width |
| 26 | + height: surface.size.height |
| 27 | + focus: surface.focused |
| 28 | + |
| 29 | + Rectangle { |
| 30 | + anchors { top: parent.bottom; right: parent.right } |
| 31 | + width: childrenRect.width |
| 32 | + height: childrenRect.height |
| 33 | + color: surface.focused ? "red" : "lightsteelblue" |
| 34 | + opacity: 0.8 |
| 35 | + Text { |
| 36 | + text: surface.position.x + "," + surface.position.y + " " + surface.size.width + "x" + surface.size.height |
| 37 | + font.pixelSize: 10 |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | |
| 44 | === modified file 'miral-qt/src/common/mirqtconversion.h' |
| 45 | --- miral-qt/src/common/mirqtconversion.h 2016-07-27 16:52:34 +0000 |
| 46 | +++ miral-qt/src/common/mirqtconversion.h 2016-07-27 16:52:34 +0000 |
| 47 | @@ -3,26 +3,55 @@ |
| 48 | |
| 49 | #include <QSize> |
| 50 | #include <QPoint> |
| 51 | +#include <QRect> |
| 52 | |
| 53 | #include <mir/geometry/size.h> |
| 54 | #include <mir/geometry/point.h> |
| 55 | +#include <mir/geometry/rectangle.h> |
| 56 | |
| 57 | namespace qtmir { |
| 58 | |
| 59 | /* |
| 60 | - * Some handy conversions from Mir types to Qt types |
| 61 | + * Some handy conversions from Mir types to Qt types and back |
| 62 | */ |
| 63 | |
| 64 | -inline QSize toQSize(mir::geometry::Size size) |
| 65 | +inline QSize toQSize(const mir::geometry::Size size) |
| 66 | { |
| 67 | return QSize(size.width.as_int(), size.height.as_int()); |
| 68 | } |
| 69 | |
| 70 | +inline mir::geometry::Size toMirSize(const QSize size) |
| 71 | +{ |
| 72 | + namespace mg = mir::geometry; |
| 73 | + return mg::Size{ mg::Width{ size.width()}, mg::Height{ size.height()} }; |
| 74 | +} |
| 75 | + |
| 76 | inline QPoint toQPoint(mir::geometry::Point point) |
| 77 | { |
| 78 | return QPoint(point.x.as_int(), point.y.as_int()); |
| 79 | } |
| 80 | |
| 81 | +inline mir::geometry::Point toMirPoint(const QPoint point) |
| 82 | +{ |
| 83 | + namespace mg = mir::geometry; |
| 84 | + return mg::Point{ mg::X{ point.x()}, mg::Y{ point.y()} }; |
| 85 | +} |
| 86 | + |
| 87 | +inline QRect toQRect(const mir::geometry::Rectangle rect) |
| 88 | +{ |
| 89 | + return QRect(rect.top_left.x.as_int(), rect.top_left.y.as_int(), |
| 90 | + rect.size.width.as_int(), rect.size.height.as_int()); |
| 91 | +} |
| 92 | + |
| 93 | +inline mir::geometry::Rectangle toMirRectangle(const QRect rect) |
| 94 | +{ |
| 95 | + namespace mg = mir::geometry; |
| 96 | + return mg::Rectangle{ |
| 97 | + mg::Point{ mg::X{ rect.x()}, mg::Y{ rect.y()} }, |
| 98 | + mg::Size{ mg::Width{ rect.width()}, mg::Height{ rect.height()} } |
| 99 | + }; |
| 100 | +} |
| 101 | + |
| 102 | } // namespace qtmir |
| 103 | |
| 104 | #endif // MIRQTCONVERSION_H |
| 105 | |
| 106 | === modified file 'miral-qt/src/common/windowmodelinterface.h' |
| 107 | --- miral-qt/src/common/windowmodelinterface.h 2016-07-27 16:52:34 +0000 |
| 108 | +++ miral-qt/src/common/windowmodelinterface.h 2016-07-27 16:52:34 +0000 |
| 109 | @@ -68,9 +68,9 @@ |
| 110 | virtual ~WindowModelInterface() = default; |
| 111 | |
| 112 | Q_SIGNALS: |
| 113 | - void windowAdded(const NumberedWindow); |
| 114 | + void windowAdded(const qtmir::NumberedWindow); |
| 115 | void windowRemoved(const unsigned int index); |
| 116 | - void windowChanged(const DirtiedWindow); |
| 117 | + void windowChanged(const qtmir::DirtiedWindow); |
| 118 | |
| 119 | private: |
| 120 | Q_DISABLE_COPY(WindowModelInterface) |
| 121 | |
| 122 | === modified file 'miral-qt/src/modules/Unity/Application/CMakeLists.txt' |
| 123 | --- miral-qt/src/modules/Unity/Application/CMakeLists.txt 2016-07-26 12:45:17 +0000 |
| 124 | +++ miral-qt/src/modules/Unity/Application/CMakeLists.txt 2016-07-27 16:52:34 +0000 |
| 125 | @@ -49,6 +49,7 @@ |
| 126 | timesource.cpp |
| 127 | tracepoints.c |
| 128 | settings.cpp |
| 129 | + windowmodel.cpp |
| 130 | # We need to run moc on these headers |
| 131 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h |
| 132 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h |
| 133 | |
| 134 | === modified file 'miral-qt/src/modules/Unity/Application/dbuswindowstack.cpp' |
| 135 | --- miral-qt/src/modules/Unity/Application/dbuswindowstack.cpp 2016-06-01 22:06:51 +0000 |
| 136 | +++ miral-qt/src/modules/Unity/Application/dbuswindowstack.cpp 2016-07-27 16:52:34 +0000 |
| 137 | @@ -28,10 +28,10 @@ |
| 138 | { |
| 139 | qRegisterMetaType<AppIdDesktopFile>(); |
| 140 | qDBusRegisterMetaType<AppIdDesktopFile>(); |
| 141 | - qRegisterMetaType<WindowInfo>(); |
| 142 | - qRegisterMetaType< QList<WindowInfo> >(); |
| 143 | - qDBusRegisterMetaType<WindowInfo>(); |
| 144 | - qDBusRegisterMetaType< QList<WindowInfo> >(); |
| 145 | + qRegisterMetaType<DBusWindowInfo>(); |
| 146 | + qRegisterMetaType< QList<DBusWindowInfo> >(); |
| 147 | + qDBusRegisterMetaType<DBusWindowInfo>(); |
| 148 | + qDBusRegisterMetaType< QList<DBusWindowInfo> >(); |
| 149 | |
| 150 | QDBusConnection::sessionBus().registerService("com.canonical.Unity.WindowStack"); |
| 151 | // TODO ExportScriptableSlots shouldn't be needed but without it i don't get the methods :-/ |
| 152 | @@ -54,13 +54,13 @@ |
| 153 | return res; |
| 154 | } |
| 155 | |
| 156 | -QList<WindowInfo> DBusWindowStack::GetWindowStack() |
| 157 | +QList<DBusWindowInfo> DBusWindowStack::GetWindowStack() |
| 158 | { |
| 159 | - QList<WindowInfo> res; |
| 160 | + QList<DBusWindowInfo> res; |
| 161 | ApplicationManager *appMgr = static_cast<ApplicationManager*>(parent()); |
| 162 | const QList<Application*> &applications = appMgr->list(); |
| 163 | Q_FOREACH(Application* app, applications) { |
| 164 | - WindowInfo wi; |
| 165 | + DBusWindowInfo wi; |
| 166 | wi.window_id = 0; |
| 167 | wi.app_id = app->appId(); |
| 168 | wi.focused = app->focused(); |
| 169 | @@ -96,7 +96,7 @@ |
| 170 | return a; |
| 171 | } |
| 172 | |
| 173 | -QDBusArgument &operator<<(QDBusArgument &a, const WindowInfo &wi) |
| 174 | +QDBusArgument &operator<<(QDBusArgument &a, const DBusWindowInfo &wi) |
| 175 | { |
| 176 | a.beginStructure(); |
| 177 | a << wi.window_id << wi.app_id << wi.focused << wi.stage; |
| 178 | @@ -104,7 +104,7 @@ |
| 179 | return a; |
| 180 | } |
| 181 | |
| 182 | -const QDBusArgument &operator>>(const QDBusArgument &a, WindowInfo &wi) |
| 183 | +const QDBusArgument &operator>>(const QDBusArgument &a, DBusWindowInfo &wi) |
| 184 | { |
| 185 | a.beginStructure(); |
| 186 | a >> wi.window_id >> wi.app_id >> wi.focused >> wi.stage; |
| 187 | |
| 188 | === modified file 'miral-qt/src/modules/Unity/Application/dbuswindowstack.h' |
| 189 | --- miral-qt/src/modules/Unity/Application/dbuswindowstack.h 2016-06-01 22:06:51 +0000 |
| 190 | +++ miral-qt/src/modules/Unity/Application/dbuswindowstack.h 2016-07-27 16:52:34 +0000 |
| 191 | @@ -34,7 +34,7 @@ |
| 192 | QDBusArgument &operator<<(QDBusArgument &a, const AppIdDesktopFile &aidf); |
| 193 | const QDBusArgument &operator>>(const QDBusArgument &a, AppIdDesktopFile &aidf); |
| 194 | |
| 195 | -class WindowInfo |
| 196 | +class DBusWindowInfo |
| 197 | { |
| 198 | public: |
| 199 | unsigned int window_id; |
| 200 | @@ -43,8 +43,8 @@ |
| 201 | unsigned int stage; |
| 202 | }; |
| 203 | |
| 204 | -QDBusArgument &operator<<(QDBusArgument &a, const WindowInfo &aidf); |
| 205 | -const QDBusArgument &operator>>(const QDBusArgument &a, WindowInfo &aidf); |
| 206 | +QDBusArgument &operator<<(QDBusArgument &a, const DBusWindowInfo &aidf); |
| 207 | +const QDBusArgument &operator>>(const QDBusArgument &a, DBusWindowInfo &aidf); |
| 208 | |
| 209 | class DBusWindowStack : public QObject |
| 210 | { |
| 211 | @@ -55,7 +55,7 @@ |
| 212 | ~DBusWindowStack(); |
| 213 | |
| 214 | Q_INVOKABLE Q_SCRIPTABLE qtmir::AppIdDesktopFile GetAppIdFromPid(unsigned int pid); |
| 215 | - Q_INVOKABLE Q_SCRIPTABLE QList<qtmir::WindowInfo> GetWindowStack(); |
| 216 | + Q_INVOKABLE Q_SCRIPTABLE QList<qtmir::DBusWindowInfo> GetWindowStack(); |
| 217 | Q_INVOKABLE Q_SCRIPTABLE QStringList GetWindowProperties(unsigned int window_id, const QString &app_id, const QStringList &names); |
| 218 | |
| 219 | Q_SIGNALS: |
| 220 | @@ -67,6 +67,6 @@ |
| 221 | } // namespace qtmir |
| 222 | |
| 223 | Q_DECLARE_METATYPE(qtmir::AppIdDesktopFile) |
| 224 | -Q_DECLARE_METATYPE(qtmir::WindowInfo) |
| 225 | +Q_DECLARE_METATYPE(qtmir::DBusWindowInfo) |
| 226 | |
| 227 | #endif // DBUSWINDOWSTACK_H |
| 228 | |
| 229 | === modified file 'miral-qt/src/modules/Unity/Application/mirsurface.cpp' |
| 230 | --- miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-07-26 12:45:17 +0000 |
| 231 | +++ miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-07-27 16:52:34 +0000 |
| 232 | @@ -21,6 +21,7 @@ |
| 233 | |
| 234 | // from common dir |
| 235 | #include <debughelpers.h> |
| 236 | +#include "mirqtconversion.h" |
| 237 | |
| 238 | // mirserver |
| 239 | #include <surfaceobserver.h> |
| 240 | @@ -196,6 +197,7 @@ |
| 241 | { |
| 242 | DEBUG_MSG << "()"; |
| 243 | |
| 244 | + m_position = toQPoint(surface->top_left()); |
| 245 | m_minimumWidth = creationHints.minWidth; |
| 246 | m_minimumHeight = creationHints.minHeight; |
| 247 | m_maximumWidth = creationHints.maxWidth; |
| 248 | @@ -518,6 +520,11 @@ |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | +QPoint MirSurface::position() const |
| 253 | +{ |
| 254 | + return m_position; |
| 255 | +} |
| 256 | + |
| 257 | QSize MirSurface::size() const |
| 258 | { |
| 259 | return m_size; |
| 260 | @@ -1017,6 +1024,15 @@ |
| 261 | m_session->session()->destroy_surface(m_surface); |
| 262 | } |
| 263 | |
| 264 | +void MirSurface::setPosition(const QPoint newPosition) |
| 265 | +{ |
| 266 | + if (m_position == newPosition) { |
| 267 | + return; |
| 268 | + } |
| 269 | + m_position = newPosition; |
| 270 | + Q_EMIT positionChanged(m_position); |
| 271 | +} |
| 272 | + |
| 273 | void MirSurface::setCloseTimer(AbstractTimer *timer) |
| 274 | { |
| 275 | bool timerWasRunning = false; |
| 276 | |
| 277 | === modified file 'miral-qt/src/modules/Unity/Application/mirsurface.h' |
| 278 | --- miral-qt/src/modules/Unity/Application/mirsurface.h 2016-07-26 12:45:17 +0000 |
| 279 | +++ miral-qt/src/modules/Unity/Application/mirsurface.h 2016-07-27 16:52:34 +0000 |
| 280 | @@ -72,6 +72,9 @@ |
| 281 | void resize(int width, int height) override; |
| 282 | void resize(const QSize &size) override { resize(size.width(), size.height()); } |
| 283 | |
| 284 | + QPoint position() const override; |
| 285 | + void setPosition(const QPoint newPosition) override; |
| 286 | + |
| 287 | Mir::State state() const override; |
| 288 | void setState(Mir::State qmlState) override; |
| 289 | |
| 290 | @@ -216,6 +219,7 @@ |
| 291 | |
| 292 | std::shared_ptr<SurfaceObserver> m_surfaceObserver; |
| 293 | |
| 294 | + QPoint m_position; |
| 295 | QSize m_size; |
| 296 | QString m_keymap; |
| 297 | |
| 298 | |
| 299 | === modified file 'miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h' |
| 300 | --- miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h 2016-07-26 12:45:17 +0000 |
| 301 | +++ miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h 2016-07-27 16:52:34 +0000 |
| 302 | @@ -24,6 +24,7 @@ |
| 303 | |
| 304 | // Qt |
| 305 | #include <QCursor> |
| 306 | +#include <QPoint> |
| 307 | #include <QSharedPointer> |
| 308 | #include <QTouchEvent> |
| 309 | |
| 310 | @@ -38,10 +39,18 @@ |
| 311 | { |
| 312 | Q_OBJECT |
| 313 | |
| 314 | + /** |
| 315 | + * @brief Position of the current surface buffer, in pixels. |
| 316 | + */ |
| 317 | + Q_PROPERTY(QPoint position READ position NOTIFY positionChanged) |
| 318 | + |
| 319 | public: |
| 320 | MirSurfaceInterface(QObject *parent = nullptr) : unity::shell::application::MirSurfaceInterface(parent) {} |
| 321 | virtual ~MirSurfaceInterface() {} |
| 322 | |
| 323 | + virtual QPoint position() const = 0; |
| 324 | + virtual void setPosition(const QPoint newPosition) = 0; |
| 325 | + |
| 326 | virtual void setLive(bool value) = 0; |
| 327 | |
| 328 | virtual bool isFirstFrameDrawn() const = 0; |
| 329 | @@ -125,6 +134,7 @@ |
| 330 | void framesPosted(); |
| 331 | void isBeingDisplayedChanged(); |
| 332 | void frameDropped(); |
| 333 | + void positionChanged(QPoint position); |
| 334 | }; |
| 335 | |
| 336 | } // namespace qtmir |
| 337 | |
| 338 | === modified file 'miral-qt/src/modules/Unity/Application/plugin.cpp' |
| 339 | --- miral-qt/src/modules/Unity/Application/plugin.cpp 2016-07-26 12:45:17 +0000 |
| 340 | +++ miral-qt/src/modules/Unity/Application/plugin.cpp 2016-07-27 16:52:34 +0000 |
| 341 | @@ -25,6 +25,7 @@ |
| 342 | #include "mirsurfaceinterface.h" |
| 343 | #include "mirsurfaceitem.h" |
| 344 | #include "mirsurfacelistmodel.h" |
| 345 | +#include "windowmodel.h" |
| 346 | |
| 347 | // platforms/mirserver |
| 348 | #include <mirsingleton.h> |
| 349 | @@ -94,6 +95,8 @@ |
| 350 | uri, 0, 1, "MirSurface", "MirSurface can't be instantiated from QML"); |
| 351 | qmlRegisterType<qtmir::MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem"); |
| 352 | qmlRegisterSingletonType<qtmir::Mir>(uri, 0, 1, "Mir", mirSingleton); |
| 353 | + |
| 354 | + qmlRegisterType<qtmir::WindowModel>(uri, 0, 1, "WindowModel"); |
| 355 | } |
| 356 | |
| 357 | virtual void initializeEngine(QQmlEngine *engine, const char *uri) |
| 358 | |
| 359 | === added file 'miral-qt/src/modules/Unity/Application/windowmodel.cpp' |
| 360 | --- miral-qt/src/modules/Unity/Application/windowmodel.cpp 1970-01-01 00:00:00 +0000 |
| 361 | +++ miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-07-27 16:52:34 +0000 |
| 362 | @@ -0,0 +1,119 @@ |
| 363 | +/* |
| 364 | + * Copyright (C) 2016 Canonical, Ltd. |
| 365 | + * |
| 366 | + * This program is free software: you can redistribute it and/or modify it under |
| 367 | + * the terms of the GNU Lesser General Public License version 3, as published by |
| 368 | + * the Free Software Foundation. |
| 369 | + * |
| 370 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 371 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
| 372 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 373 | + * Lesser General Public License for more details. |
| 374 | + * |
| 375 | + * You should have received a copy of the GNU Lesser General Public License |
| 376 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 377 | + */ |
| 378 | + |
| 379 | +#include "windowmodel.h" |
| 380 | + |
| 381 | +#include "mirsurface.h" |
| 382 | +#include "surfaceobserver.h" |
| 383 | + |
| 384 | +#include <mir/scene/surface.h> |
| 385 | + |
| 386 | +// mirserver |
| 387 | +#include "nativeinterface.h" |
| 388 | + |
| 389 | +// Qt |
| 390 | +#include <QGuiApplication> |
| 391 | +#include <QDebug> |
| 392 | + |
| 393 | +using namespace qtmir; |
| 394 | + |
| 395 | +WindowModel::WindowModel() |
| 396 | +{ |
| 397 | + |
| 398 | + auto nativeInterface = dynamic_cast<NativeInterface*>(QGuiApplication::platformNativeInterface()); |
| 399 | + |
| 400 | + if (!nativeInterface) { |
| 401 | + qFatal("ERROR: Unity.Application QML plugin requires use of the 'mirserver' QPA plugin"); |
| 402 | + } |
| 403 | + |
| 404 | + auto windowModel = static_cast<WindowModelInterface*>(nativeInterface->nativeResourceForIntegration("WindowModel")); |
| 405 | + |
| 406 | + connect(windowModel, &WindowModelInterface::windowAdded, this, &WindowModel::onWindowAdded); |
| 407 | + connect(windowModel, &WindowModelInterface::windowRemoved, this, &WindowModel::onWindowRemoved); |
| 408 | + connect(windowModel, &WindowModelInterface::windowChanged, this, &WindowModel::onWindowChanged); |
| 409 | +} |
| 410 | + |
| 411 | +QHash<int, QByteArray> WindowModel::roleNames() const |
| 412 | +{ |
| 413 | + QHash<int, QByteArray> roleNames; |
| 414 | + roleNames.insert(SurfaceRole, "surface"); |
| 415 | + return roleNames; |
| 416 | +} |
| 417 | + |
| 418 | +void WindowModel::onWindowAdded(const NumberedWindow window) |
| 419 | +{ |
| 420 | + qDebug() << "Window Added!" << window.index; |
| 421 | + std::shared_ptr<SurfaceObserver> surfaceObserver = std::make_shared<SurfaceObserver>(); |
| 422 | + const auto &surface = window.windowInfo.surface; |
| 423 | + SurfaceObserver::registerObserverForSurface(surfaceObserver.get(), surface.get()); |
| 424 | + surface->add_observer(surfaceObserver); |
| 425 | + |
| 426 | + auto mirSurface = new MirSurface(surface, nullptr, nullptr, surfaceObserver, CreationHints()); |
| 427 | + beginInsertRows(QModelIndex(), window.index, window.index); |
| 428 | + m_windowModel.insert(window.index, mirSurface); |
| 429 | + endInsertRows(); |
| 430 | + Q_EMIT countChanged(); |
| 431 | +} |
| 432 | + |
| 433 | +void WindowModel::onWindowRemoved(const unsigned int index) |
| 434 | +{ |
| 435 | + qDebug() << "Window Removed!" << index; |
| 436 | + beginRemoveRows(QModelIndex(), index, index); |
| 437 | + m_windowModel.remove(index); |
| 438 | + endRemoveRows(); |
| 439 | + Q_EMIT countChanged(); |
| 440 | +} |
| 441 | + |
| 442 | +void WindowModel::onWindowChanged(const DirtiedWindow window) |
| 443 | +{ |
| 444 | + qDebug() << "Window Change!" << window.index; |
| 445 | + auto mirSurface = m_windowModel.value(window.index); |
| 446 | + |
| 447 | + switch(window.dirtyWindowInfo) { |
| 448 | + case WindowInfo::DirtyStates::Size: { |
| 449 | + qDebug() << "size"; |
| 450 | + // Do nothing yet, it gets new size from swapped buffer for now |
| 451 | + } |
| 452 | + case WindowInfo::DirtyStates::Position: |
| 453 | + qDebug() << "position"; |
| 454 | + mirSurface->setPosition(window.windowInfo.position); |
| 455 | + case WindowInfo::DirtyStates::Focus: |
| 456 | + qDebug() << "focus"; |
| 457 | + mirSurface->setFocused(window.windowInfo.focused); |
| 458 | + } |
| 459 | + |
| 460 | + QModelIndex row = index(window.index); |
| 461 | + Q_EMIT dataChanged(row, row, QVector<int>() << SurfaceRole); |
| 462 | +} |
| 463 | + |
| 464 | +int WindowModel::rowCount(const QModelIndex &/*parent*/) const |
| 465 | +{ |
| 466 | + return m_windowModel.count(); |
| 467 | +} |
| 468 | + |
| 469 | +QVariant WindowModel::data(const QModelIndex &index, int role) const |
| 470 | +{ |
| 471 | + if (index.row() < 0 || index.row() >= m_windowModel.count()) |
| 472 | + return QVariant(); |
| 473 | + |
| 474 | + if (role == SurfaceRole) { |
| 475 | + MirSurfaceInterface *surface = m_windowModel.at(index.row()); |
| 476 | + return QVariant::fromValue(static_cast<MirSurfaceInterface*>(surface)); |
| 477 | + } else { |
| 478 | + return QVariant(); |
| 479 | + } |
| 480 | +} |
| 481 | + |
| 482 | |
| 483 | === added file 'miral-qt/src/modules/Unity/Application/windowmodel.h' |
| 484 | --- miral-qt/src/modules/Unity/Application/windowmodel.h 1970-01-01 00:00:00 +0000 |
| 485 | +++ miral-qt/src/modules/Unity/Application/windowmodel.h 2016-07-27 16:52:34 +0000 |
| 486 | @@ -0,0 +1,61 @@ |
| 487 | +/* |
| 488 | + * Copyright (C) 2016 Canonical, Ltd. |
| 489 | + * |
| 490 | + * This program is free software: you can redistribute it and/or modify it under |
| 491 | + * the terms of the GNU Lesser General Public License version 3, as published by |
| 492 | + * the Free Software Foundation. |
| 493 | + * |
| 494 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 495 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
| 496 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 497 | + * Lesser General Public License for more details. |
| 498 | + * |
| 499 | + * You should have received a copy of the GNU Lesser General Public License |
| 500 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 501 | + */ |
| 502 | + |
| 503 | +#ifndef WINDOWMODEL_H |
| 504 | +#define WINDOWMODEL_H |
| 505 | + |
| 506 | +#include <QAbstractListModel> |
| 507 | + |
| 508 | +#include "mirsurfaceinterface.h" |
| 509 | +#include "windowmodelinterface.h" |
| 510 | + |
| 511 | +namespace qtmir { |
| 512 | + |
| 513 | +class WindowModel : public QAbstractListModel |
| 514 | +{ |
| 515 | + Q_OBJECT |
| 516 | + |
| 517 | + Q_PROPERTY(int count READ count NOTIFY countChanged) |
| 518 | + |
| 519 | +public: |
| 520 | + enum Roles { |
| 521 | + SurfaceRole = Qt::UserRole |
| 522 | + }; |
| 523 | + |
| 524 | + WindowModel(); |
| 525 | + |
| 526 | + // QAbstractItemModel methods |
| 527 | + int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 528 | + QVariant data(const QModelIndex& index, int role) const override; |
| 529 | + |
| 530 | + QHash<int, QByteArray> roleNames() const override; |
| 531 | + |
| 532 | + int count() const { return rowCount(); } |
| 533 | + |
| 534 | +Q_SIGNALS: |
| 535 | + void countChanged(); |
| 536 | + |
| 537 | +private Q_SLOTS: |
| 538 | + void onWindowAdded(const NumberedWindow); |
| 539 | + void onWindowRemoved(const unsigned int index); |
| 540 | + void onWindowChanged(const DirtiedWindow); |
| 541 | + |
| 542 | +private: |
| 543 | + QVector<MirSurfaceInterface *> m_windowModel; |
| 544 | +}; |
| 545 | + |
| 546 | +} // namespace qtmir |
| 547 | +#endif // WINDOWMODEL_H |
| 548 | |
| 549 | === modified file 'miral-qt/src/platforms/mirserver/mirserver.cpp' |
| 550 | --- miral-qt/src/platforms/mirserver/mirserver.cpp 2016-06-21 12:35:41 +0000 |
| 551 | +++ miral-qt/src/platforms/mirserver/mirserver.cpp 2016-07-27 16:52:34 +0000 |
| 552 | @@ -42,6 +42,7 @@ |
| 553 | |
| 554 | // mir |
| 555 | #include <mir/graphics/cursor.h> |
| 556 | +#include <mir/shell/shell.h> |
| 557 | |
| 558 | namespace mg = mir::graphics; |
| 559 | namespace mo = mir::options; |
| 560 | @@ -114,7 +115,7 @@ |
| 561 | }); |
| 562 | |
| 563 | add_init_callback([this, &screensModel] { |
| 564 | - screensModel->init(the_display(), the_compositor()); |
| 565 | + screensModel->init(the_display(), the_compositor(), the_shell()); |
| 566 | }); |
| 567 | |
| 568 | usingHiddenCursor(*this); |
| 569 | @@ -192,7 +193,7 @@ |
| 570 | |
| 571 | UsingQtMirWindowManager::UsingQtMirWindowManager(const QSharedPointer<ScreensModel> &model) |
| 572 | : m_screensModel(model) |
| 573 | - , m_policy(miral::set_window_managment_policy<WindowManagementPolicy>(m_screensModel)) |
| 574 | + , m_policy(miral::set_window_managment_policy<WindowManagementPolicy>(m_windowModel, m_screensModel)) |
| 575 | { |
| 576 | } |
| 577 | |
| 578 | @@ -206,6 +207,11 @@ |
| 579 | return m_windowManager.lock().get(); |
| 580 | } |
| 581 | |
| 582 | +qtmir::WindowModelInterface *UsingQtMirWindowManager::windowModel() |
| 583 | +{ |
| 584 | + return &m_windowModel; |
| 585 | +} |
| 586 | + |
| 587 | mir::shell::Shell *MirServer::shell() |
| 588 | { |
| 589 | std::weak_ptr<mir::shell::Shell> m_shell = the_shell(); |
| 590 | |
| 591 | === modified file 'miral-qt/src/platforms/mirserver/mirserver.h' |
| 592 | --- miral-qt/src/platforms/mirserver/mirserver.h 2016-06-21 12:35:41 +0000 |
| 593 | +++ miral-qt/src/platforms/mirserver/mirserver.h 2016-07-27 16:52:34 +0000 |
| 594 | @@ -21,6 +21,7 @@ |
| 595 | #include <QSharedPointer> |
| 596 | #include <mir/server.h> |
| 597 | #include "miral/set_window_managment_policy.h" |
| 598 | +#include "windowmodel.h" |
| 599 | |
| 600 | class QtEventFeeder; |
| 601 | class MirDisplayConfigurationPolicy; |
| 602 | @@ -70,11 +71,13 @@ |
| 603 | UsingQtMirWindowManager(const QSharedPointer<ScreensModel> &model); |
| 604 | void operator()(mir::Server& server); |
| 605 | MirWindowManager *windowManager(); |
| 606 | + qtmir::WindowModelInterface *windowModel(); |
| 607 | |
| 608 | private: |
| 609 | const QSharedPointer<ScreensModel> &m_screensModel; |
| 610 | miral::SetWindowManagmentPolicy m_policy; |
| 611 | std::weak_ptr<MirWindowManager> m_windowManager; |
| 612 | + qtmir::WindowModel m_windowModel; |
| 613 | }; |
| 614 | |
| 615 | // We use virtual inheritance of mir::Server to facilitate derived classes (e.g. testing) |
| 616 | @@ -115,6 +118,7 @@ |
| 617 | using UsingQtMirSessionListener::sessionListener; |
| 618 | using UsingQtMirPromptSessionListener::promptSessionListener; |
| 619 | using UsingQtMirWindowManager::windowManager; |
| 620 | + using UsingQtMirWindowManager::windowModel; |
| 621 | mir::shell::Shell *shell(); |
| 622 | |
| 623 | QSharedPointer<ScreensModel> screensModel() const; |
| 624 | |
| 625 | === modified file 'miral-qt/src/platforms/mirserver/qmirserver.cpp' |
| 626 | --- miral-qt/src/platforms/mirserver/qmirserver.cpp 2016-06-01 22:06:51 +0000 |
| 627 | +++ miral-qt/src/platforms/mirserver/qmirserver.cpp 2016-07-27 16:52:34 +0000 |
| 628 | @@ -121,6 +121,8 @@ |
| 629 | result = d->server->promptSessionListener(); |
| 630 | else if (resource == "WindowManager") |
| 631 | result = d->server->windowManager(); |
| 632 | + else if (resource == "WindowModel") |
| 633 | + result = d->server->windowModel(); |
| 634 | else if (resource == "ScreensController") |
| 635 | result = screensController().data(); |
| 636 | } |
| 637 | |
| 638 | === modified file 'miral-qt/src/platforms/mirserver/screensmodel.cpp' |
| 639 | --- miral-qt/src/platforms/mirserver/screensmodel.cpp 2016-06-01 22:06:51 +0000 |
| 640 | +++ miral-qt/src/platforms/mirserver/screensmodel.cpp 2016-07-27 16:52:34 +0000 |
| 641 | @@ -21,10 +21,12 @@ |
| 642 | #include "logging.h" |
| 643 | #include "mirserverintegration.h" |
| 644 | #include "screen.h" |
| 645 | +#include "mirqtconversion.h" |
| 646 | |
| 647 | // Mir |
| 648 | #include <mir/graphics/display.h> |
| 649 | #include <mir/graphics/display_buffer.h> |
| 650 | +#include <mir/compositor/display_listener.h> |
| 651 | |
| 652 | // Qt |
| 653 | #include <QScreen> |
| 654 | @@ -47,10 +49,12 @@ |
| 655 | |
| 656 | // init only after MirServer has initialized - runs on MirServerThread!!! |
| 657 | void ScreensModel::init(const std::shared_ptr<mir::graphics::Display> &display, |
| 658 | - const std::shared_ptr<mir::compositor::Compositor> &compositor) |
| 659 | + const std::shared_ptr<mir::compositor::Compositor> &compositor, |
| 660 | + const std::shared_ptr<mir::compositor::DisplayListener> &displayListener) |
| 661 | { |
| 662 | m_display = display; |
| 663 | m_compositor = compositor; |
| 664 | + m_displayListener = displayListener; |
| 665 | |
| 666 | // Use a Blocking Queued Connection to enforce synchronization of Qt GUI thread with Mir thread(s) |
| 667 | // on compositor shutdown. Compositor startup can be lazy. |
| 668 | @@ -146,6 +150,7 @@ |
| 669 | // Announce new Screens to Qt |
| 670 | for (auto screen : newScreenList) { |
| 671 | Q_EMIT screenAdded(screen); |
| 672 | + m_displayListener->add_display(qtmir::toMirRectangle(screen->geometry())); |
| 673 | } |
| 674 | |
| 675 | // Move Windows from about-to-be-deleted Screens to new Screen |
| 676 | @@ -168,6 +173,7 @@ |
| 677 | if (!ok) { |
| 678 | qCWarning(QTMIR_SCREENS) << "Failed to invoke QGuiApplication::onScreenAboutToBeRemoved(QScreen*) slot."; |
| 679 | } |
| 680 | + m_displayListener->remove_display(qtmir::toMirRectangle(screen->geometry())); |
| 681 | Q_EMIT screenRemoved(screen); // should delete the backing Screen |
| 682 | } |
| 683 | |
| 684 | |
| 685 | === modified file 'miral-qt/src/platforms/mirserver/screensmodel.h' |
| 686 | --- miral-qt/src/platforms/mirserver/screensmodel.h 2016-06-01 22:06:51 +0000 |
| 687 | +++ miral-qt/src/platforms/mirserver/screensmodel.h 2016-07-27 16:52:34 +0000 |
| 688 | @@ -28,7 +28,7 @@ |
| 689 | |
| 690 | namespace mir { |
| 691 | namespace graphics { class Display; } |
| 692 | - namespace compositor { class Compositor; } |
| 693 | + namespace compositor { class Compositor; class DisplayListener; } |
| 694 | } |
| 695 | class Screen; |
| 696 | class QWindow; |
| 697 | @@ -74,7 +74,8 @@ |
| 698 | public: |
| 699 | // called by MirServer |
| 700 | void init(const std::shared_ptr<mir::graphics::Display> &display, |
| 701 | - const std::shared_ptr<mir::compositor::Compositor> &compositor); |
| 702 | + const std::shared_ptr<mir::compositor::Compositor> &compositor, |
| 703 | + const std::shared_ptr<mir::compositor::DisplayListener> &displayListener); |
| 704 | void terminate(); |
| 705 | |
| 706 | // override for testing purposes |
| 707 | @@ -91,6 +92,7 @@ |
| 708 | |
| 709 | std::weak_ptr<mir::graphics::Display> m_display; |
| 710 | std::shared_ptr<mir::compositor::Compositor> m_compositor; |
| 711 | + std::shared_ptr<mir::compositor::DisplayListener> m_displayListener; |
| 712 | QList<Screen*> m_screenList; |
| 713 | bool m_compositing; |
| 714 | }; |
| 715 | |
| 716 | === modified file 'miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp' |
| 717 | --- miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-07-27 16:52:34 +0000 |
| 718 | +++ miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-07-27 16:52:34 +0000 |
| 719 | @@ -18,57 +18,53 @@ |
| 720 | |
| 721 | #include "screensmodel.h" |
| 722 | |
| 723 | +#include "miral/window_manager_tools.h" |
| 724 | #include "miral/window_specification.h" |
| 725 | |
| 726 | +#include "mir/scene/surface.h" |
| 727 | +#include <QDebug> |
| 728 | + |
| 729 | WindowManagementPolicy::WindowManagementPolicy(miral::WindowManagerTools * const tools, |
| 730 | + qtmir::WindowModel &windowModel, |
| 731 | const QSharedPointer<ScreensModel> screensModel) |
| 732 | : CanonicalWindowManagerPolicy(tools) |
| 733 | , m_tools(tools) |
| 734 | + , m_windowModel(windowModel) |
| 735 | , m_eventFeeder(new QtEventFeeder(screensModel)) |
| 736 | { |
| 737 | - |
| 738 | -} |
| 739 | - |
| 740 | -void WindowManagementPolicy::advise_displays_updated(const Rectangles&/*displays*/) |
| 741 | -{ |
| 742 | - |
| 743 | -} |
| 744 | - |
| 745 | +} |
| 746 | + |
| 747 | +/* Following are hooks to allow custom policy be imposed */ |
| 748 | miral::WindowSpecification WindowManagementPolicy::place_new_surface( |
| 749 | - const miral::ApplicationInfo &/*app_info*/, |
| 750 | + const miral::ApplicationInfo &app_info, |
| 751 | const miral::WindowSpecification &request_parameters) |
| 752 | { |
| 753 | - auto parameters = request_parameters; |
| 754 | + auto parameters = CanonicalWindowManagerPolicy::place_new_surface(app_info, request_parameters); |
| 755 | + qDebug() << "Place surface" << parameters.top_left().value().x.as_int(); |
| 756 | return parameters; |
| 757 | } |
| 758 | |
| 759 | -void WindowManagementPolicy::advise_new_window(miral::WindowInfo &/*windowInfo*/) |
| 760 | -{ |
| 761 | - |
| 762 | -} |
| 763 | - |
| 764 | -void WindowManagementPolicy::handle_window_ready(miral::WindowInfo &/*windowInfo*/) |
| 765 | -{ |
| 766 | - |
| 767 | +void WindowManagementPolicy::handle_window_ready(miral::WindowInfo &windowInfo) |
| 768 | +{ |
| 769 | + qDebug("Window ready"); |
| 770 | + m_tools->select_active_window(windowInfo.window()); |
| 771 | } |
| 772 | |
| 773 | void WindowManagementPolicy::handle_modify_window( |
| 774 | - miral::WindowInfo &/*windowInfo*/, |
| 775 | - const miral::WindowSpecification &/*modifications*/) |
| 776 | -{ |
| 777 | - |
| 778 | -} |
| 779 | - |
| 780 | -void WindowManagementPolicy::advise_delete_window(const miral::WindowInfo &/*windowInfo*/) |
| 781 | -{ |
| 782 | - |
| 783 | -} |
| 784 | - |
| 785 | -void WindowManagementPolicy::advise_raise(const std::vector<miral::Window> &/*windows*/) |
| 786 | -{ |
| 787 | - |
| 788 | -} |
| 789 | - |
| 790 | + miral::WindowInfo &windowInfo, |
| 791 | + const miral::WindowSpecification &modifications) |
| 792 | +{ |
| 793 | + qDebug("Window Modified!"); |
| 794 | + m_tools->modify_window(windowInfo, modifications); |
| 795 | +} |
| 796 | + |
| 797 | +void WindowManagementPolicy::handle_raise_window(miral::WindowInfo &windowInfo) |
| 798 | +{ |
| 799 | + qDebug("Window Raise"); |
| 800 | + m_tools->select_active_window(windowInfo.window()); |
| 801 | +} |
| 802 | + |
| 803 | +/* Handle input events - here just inject them into Qt event loop for later processing */ |
| 804 | bool WindowManagementPolicy::handle_keyboard_event(const MirKeyboardEvent *event) |
| 805 | { |
| 806 | m_eventFeeder->dispatchKey(event); |
| 807 | @@ -87,50 +83,120 @@ |
| 808 | return true; |
| 809 | } |
| 810 | |
| 811 | +/* Below are notifications of window state changes */ |
| 812 | +void WindowManagementPolicy::advise_displays_updated(const Rectangles&/*displays*/) |
| 813 | +{ |
| 814 | + qDebug("Displays updated"); |
| 815 | +} |
| 816 | + |
| 817 | +void WindowManagementPolicy::advise_new_window(miral::WindowInfo &windowInfo) |
| 818 | +{ |
| 819 | + m_windowModel.addWindow(windowInfo); |
| 820 | +} |
| 821 | + |
| 822 | +void WindowManagementPolicy::advise_delete_window(const miral::WindowInfo &windowInfo) |
| 823 | +{ |
| 824 | + m_windowModel.removeWindow(windowInfo); |
| 825 | +} |
| 826 | + |
| 827 | +void WindowManagementPolicy::advise_raise(const std::vector<miral::Window> &windows) |
| 828 | +{ |
| 829 | + m_windowModel.raiseWindows(windows); |
| 830 | +} |
| 831 | + |
| 832 | void WindowManagementPolicy::advise_new_app(miral::ApplicationInfo &/*application*/) |
| 833 | { |
| 834 | - |
| 835 | + qDebug("New App"); |
| 836 | } |
| 837 | |
| 838 | void WindowManagementPolicy::advise_delete_app(const miral::ApplicationInfo &/*application*/) |
| 839 | { |
| 840 | - |
| 841 | + qDebug("Delete App"); |
| 842 | } |
| 843 | |
| 844 | void WindowManagementPolicy::advise_state_change(const miral::WindowInfo &/*windowInfo*/, MirSurfaceState /*state*/) |
| 845 | { |
| 846 | - |
| 847 | -} |
| 848 | - |
| 849 | -void WindowManagementPolicy::advise_move_to(const miral::WindowInfo &/*window_info*/, Point /*top_left*/) |
| 850 | -{ |
| 851 | - |
| 852 | -} |
| 853 | - |
| 854 | -void WindowManagementPolicy::advise_resize(const miral::WindowInfo &/*info*/, const Size &/*newSize*/) |
| 855 | -{ |
| 856 | - |
| 857 | -} |
| 858 | - |
| 859 | -void WindowManagementPolicy::handle_raise_window(miral::WindowInfo &/*windowInfo*/) |
| 860 | -{ |
| 861 | - |
| 862 | -} |
| 863 | - |
| 864 | -void WindowManagementPolicy::advise_focus_lost(const miral::WindowInfo &/*info*/) |
| 865 | -{ |
| 866 | - |
| 867 | -} |
| 868 | - |
| 869 | -void WindowManagementPolicy::advise_focus_gained(const miral::WindowInfo &/*info*/) |
| 870 | -{ |
| 871 | - |
| 872 | + qDebug("Window State Change"); |
| 873 | +} |
| 874 | + |
| 875 | +void WindowManagementPolicy::advise_move_to(const miral::WindowInfo &windowInfo, Point topLeft) |
| 876 | +{ |
| 877 | + qDebug("Window move"); |
| 878 | + m_windowModel.moveWindow(windowInfo, topLeft); |
| 879 | +} |
| 880 | + |
| 881 | +void WindowManagementPolicy::advise_resize(const miral::WindowInfo &windowInfo, const Size &newSize) |
| 882 | +{ |
| 883 | + qDebug("Window Resize"); |
| 884 | + m_windowModel.resizeWindow(windowInfo, newSize); |
| 885 | +} |
| 886 | + |
| 887 | +void WindowManagementPolicy::advise_focus_lost(const miral::WindowInfo &windowInfo) |
| 888 | +{ |
| 889 | + m_windowModel.focusWindow(windowInfo, false); |
| 890 | +} |
| 891 | + |
| 892 | +void WindowManagementPolicy::advise_focus_gained(const miral::WindowInfo &windowInfo) |
| 893 | +{ |
| 894 | + m_windowModel.focusWindow(windowInfo, true); |
| 895 | } |
| 896 | |
| 897 | void WindowManagementPolicy::advise_begin() |
| 898 | { |
| 899 | + // TODO |
| 900 | } |
| 901 | |
| 902 | void WindowManagementPolicy::advise_end() |
| 903 | { |
| 904 | + // TODO |
| 905 | +} |
| 906 | + |
| 907 | +/* Following methods all called from the Qt GUI thread to deliver events to clients */ |
| 908 | +void WindowManagementPolicy::deliver_keyboard_event(const MirKeyboardEvent *event, |
| 909 | + const std::shared_ptr<mir::scene::Surface> &surface) |
| 910 | +{ |
| 911 | + m_tools->invoke_under_lock([&surface, this]() { |
| 912 | + auto windowInfo = m_tools->info_for(surface); |
| 913 | + m_tools->select_active_window(windowInfo.window()); |
| 914 | + }); |
| 915 | + auto e = reinterpret_cast<MirEvent const*>(event); // naughty |
| 916 | + surface->consume(e); |
| 917 | +} |
| 918 | + |
| 919 | +void WindowManagementPolicy::deliver_touch_event(const MirTouchEvent *event, |
| 920 | + const std::shared_ptr<mir::scene::Surface> &surface) |
| 921 | +{ |
| 922 | + m_tools->invoke_under_lock([&surface, this]() { |
| 923 | + auto windowInfo = m_tools->info_for(surface); |
| 924 | + m_tools->select_active_window(windowInfo.window()); |
| 925 | + }); |
| 926 | + auto e = reinterpret_cast<MirEvent const*>(event); // naughty |
| 927 | + surface->consume(e); |
| 928 | +} |
| 929 | + |
| 930 | +void WindowManagementPolicy::deliver_pointer_event(const MirPointerEvent *event, |
| 931 | + const std::shared_ptr<mir::scene::Surface> &surface) |
| 932 | +{ |
| 933 | + m_tools->invoke_under_lock([&surface, this]() { |
| 934 | + auto windowInfo = m_tools->info_for(surface); |
| 935 | + m_tools->select_active_window(windowInfo.window()); |
| 936 | + }); |
| 937 | + auto e = reinterpret_cast<MirEvent const*>(event); // naughty |
| 938 | + surface->consume(e); |
| 939 | +} |
| 940 | + |
| 941 | +/* Methods to allow Shell to request changes to the window stack */ |
| 942 | +void WindowManagementPolicy::focus(const miral::Window window) |
| 943 | +{ |
| 944 | + m_tools->select_active_window(window); |
| 945 | +} |
| 946 | + |
| 947 | +void WindowManagementPolicy::resize(const miral::Window window, const Size &size) |
| 948 | +{ |
| 949 | + m_tools->place_and_size(m_tools->info_for(window), window.top_left(), size); |
| 950 | +} |
| 951 | + |
| 952 | +void WindowManagementPolicy::move(const miral::Window window, const Point &top_left) |
| 953 | +{ |
| 954 | + m_tools->place_and_size(m_tools->info_for(window), top_left, window.size() ); |
| 955 | } |
| 956 | |
| 957 | === modified file 'miral-qt/src/platforms/mirserver/windowmanagementpolicy.h' |
| 958 | --- miral-qt/src/platforms/mirserver/windowmanagementpolicy.h 2016-07-27 16:52:34 +0000 |
| 959 | +++ miral-qt/src/platforms/mirserver/windowmanagementpolicy.h 2016-07-27 16:52:34 +0000 |
| 960 | @@ -20,6 +20,7 @@ |
| 961 | #include "miral/canonical_window_manager.h" |
| 962 | |
| 963 | #include "qteventfeeder.h" |
| 964 | +#include "windowmodel.h" |
| 965 | |
| 966 | #include <QObject> |
| 967 | #include <QScopedPointer> |
| 968 | @@ -33,9 +34,10 @@ |
| 969 | { |
| 970 | public: |
| 971 | WindowManagementPolicy(miral::WindowManagerTools * const tools, |
| 972 | + qtmir::WindowModel &windowModel, |
| 973 | const QSharedPointer<ScreensModel> screensModel); |
| 974 | |
| 975 | - |
| 976 | + // From WindowManagementPolicy |
| 977 | auto place_new_surface(const miral::ApplicationInfo &app_info, |
| 978 | const miral::WindowSpecification &request_parameters) |
| 979 | -> miral::WindowSpecification override; |
| 980 | @@ -60,17 +62,27 @@ |
| 981 | void advise_focus_lost(const miral::WindowInfo &info) override; |
| 982 | void advise_focus_gained(const miral::WindowInfo &info) override; |
| 983 | void advise_state_change(const miral::WindowInfo &info, MirSurfaceState state) override; |
| 984 | - void advise_move_to(miral::WindowInfo const& window_info, Point top_left) override; |
| 985 | + void advise_move_to(const miral::WindowInfo &windowInfo, Point topLeft) override; |
| 986 | void advise_resize(const miral::WindowInfo &info, const Size &newSize) override; |
| 987 | void advise_delete_window(const miral::WindowInfo &windowInfo) override; |
| 988 | void advise_raise(std::vector<miral::Window> const& windows) override; |
| 989 | |
| 990 | void advise_displays_updated(const Rectangles &displays) override; |
| 991 | |
| 992 | + // Exposing some tools |
| 993 | + void deliver_keyboard_event(const MirKeyboardEvent *event, const std::shared_ptr<mir::scene::Surface> &surface); |
| 994 | + void deliver_touch_event(const MirTouchEvent *event, const std::shared_ptr<mir::scene::Surface> &surface); |
| 995 | + void deliver_pointer_event(const MirPointerEvent *event, const std::shared_ptr<mir::scene::Surface> &surface); |
| 996 | + |
| 997 | + void focus(const miral::Window window); |
| 998 | + void resize(const miral::Window window, const Size &size); |
| 999 | + void move(const miral::Window window, const Point &top_left); |
| 1000 | + |
| 1001 | Q_SIGNALS: |
| 1002 | |
| 1003 | private: |
| 1004 | - const miral::WindowManagerTools * const m_tools; |
| 1005 | + miral::WindowManagerTools * const m_tools; |
| 1006 | + qtmir::WindowModel &m_windowModel; |
| 1007 | const QScopedPointer<QtEventFeeder> m_eventFeeder; |
| 1008 | }; |
| 1009 | |
| 1010 | |
| 1011 | === modified file 'miral-qt/src/platforms/mirserver/windowmodel.cpp' |
| 1012 | --- miral-qt/src/platforms/mirserver/windowmodel.cpp 2016-07-27 16:52:34 +0000 |
| 1013 | +++ miral-qt/src/platforms/mirserver/windowmodel.cpp 2016-07-27 16:52:34 +0000 |
| 1014 | @@ -32,8 +32,8 @@ |
| 1015 | WindowModel::WindowModel() |
| 1016 | { |
| 1017 | qDebug("WindowModel::WindowModel"); |
| 1018 | - qRegisterMetaType<NumberedWindow>(); |
| 1019 | - qRegisterMetaType<DirtiedWindow>(); |
| 1020 | + qRegisterMetaType<qtmir::NumberedWindow>(); |
| 1021 | + qRegisterMetaType<qtmir::DirtiedWindow>(); |
| 1022 | } |
| 1023 | |
| 1024 | WindowModel::~WindowModel() |
| 1025 | |
| 1026 | === modified file 'miral-qt/tests/framework/fake_mirsurface.cpp' |
| 1027 | --- miral-qt/tests/framework/fake_mirsurface.cpp 2016-06-07 20:32:04 +0000 |
| 1028 | +++ miral-qt/tests/framework/fake_mirsurface.cpp 2016-07-27 16:52:34 +0000 |
| 1029 | @@ -56,6 +56,16 @@ |
| 1030 | |
| 1031 | QSize FakeMirSurface::size() const { return m_size; } |
| 1032 | |
| 1033 | +QPoint FakeMirSurface::position() const { return m_position; } |
| 1034 | + |
| 1035 | +void FakeMirSurface::setPosition(const QPoint position) |
| 1036 | +{ |
| 1037 | + if (m_position != position) { |
| 1038 | + m_position = position; |
| 1039 | + Q_EMIT positionChanged(position); |
| 1040 | + } |
| 1041 | +} |
| 1042 | + |
| 1043 | void FakeMirSurface::resize(int width, int height) |
| 1044 | { |
| 1045 | if (m_size.width() != width || m_size.height() != height) { |
| 1046 | |
| 1047 | === modified file 'miral-qt/tests/framework/fake_mirsurface.h' |
| 1048 | --- miral-qt/tests/framework/fake_mirsurface.h 2016-07-26 12:45:17 +0000 |
| 1049 | +++ miral-qt/tests/framework/fake_mirsurface.h 2016-07-27 16:52:34 +0000 |
| 1050 | @@ -54,6 +54,8 @@ |
| 1051 | Mir::Type type() const override; |
| 1052 | QString name() const override; |
| 1053 | QSize size() const override; |
| 1054 | + QPoint position() const override; |
| 1055 | + void setPosition(const QPoint position) override; |
| 1056 | void resize(int width, int height) override; |
| 1057 | void resize(const QSize &size) override; |
| 1058 | Mir::State state() const override; |
| 1059 | @@ -171,6 +173,7 @@ |
| 1060 | Mir::OrientationAngle m_orientationAngle; |
| 1061 | bool m_visible; |
| 1062 | QSize m_size; |
| 1063 | + QPoint m_position; |
| 1064 | QHash<int, bool> m_views; |
| 1065 | bool m_focused; |
| 1066 | |
| 1067 | |
| 1068 | === modified file 'miral-qt/tests/mirserver/ScreensModel/screensmodel_test.cpp' |
| 1069 | --- miral-qt/tests/mirserver/ScreensModel/screensmodel_test.cpp 2016-06-21 13:38:53 +0000 |
| 1070 | +++ miral-qt/tests/mirserver/ScreensModel/screensmodel_test.cpp 2016-07-27 16:52:34 +0000 |
| 1071 | @@ -40,6 +40,7 @@ |
| 1072 | |
| 1073 | ScreensModel *screensModel; |
| 1074 | std::shared_ptr<StubDisplay> display; |
| 1075 | + std::shared_ptr<StubDisplayListener> displayListener; |
| 1076 | std::shared_ptr<QtCompositor> compositor; |
| 1077 | QGuiApplication *app; |
| 1078 | }; |
| 1079 | @@ -51,9 +52,10 @@ |
| 1080 | |
| 1081 | screensModel = new TestableScreensModel; |
| 1082 | display = std::make_shared<StubDisplay>(); |
| 1083 | + displayListener = std::make_shared<StubDisplayListener>(); |
| 1084 | compositor = std::make_shared<QtCompositor>(); |
| 1085 | |
| 1086 | - static_cast<TestableScreensModel*>(screensModel)->do_init(display, compositor); |
| 1087 | + static_cast<TestableScreensModel*>(screensModel)->do_init(display, compositor, displayListener); |
| 1088 | |
| 1089 | int argc = 0; |
| 1090 | char **argv = nullptr; |
| 1091 | |
| 1092 | === modified file 'miral-qt/tests/mirserver/ScreensModel/stub_display.h' |
| 1093 | --- miral-qt/tests/mirserver/ScreensModel/stub_display.h 2016-06-01 22:06:51 +0000 |
| 1094 | +++ miral-qt/tests/mirserver/ScreensModel/stub_display.h 2016-07-27 16:52:34 +0000 |
| 1095 | @@ -21,6 +21,8 @@ |
| 1096 | #include "mock_gl_display_buffer.h" |
| 1097 | #include "mock_display_configuration.h" |
| 1098 | |
| 1099 | +#include <mir/compositor/display_listener.h> |
| 1100 | + |
| 1101 | namespace mg = mir::graphics; |
| 1102 | namespace geom = mir::geometry; |
| 1103 | |
| 1104 | @@ -99,4 +101,11 @@ |
| 1105 | std::vector<MockGLDisplayBuffer*> m_displayBuffers; |
| 1106 | }; |
| 1107 | |
| 1108 | +class StubDisplayListener : public mir::compositor::DisplayListener |
| 1109 | +{ |
| 1110 | + void add_display(mir::geometry::Rectangle const& /*area*/) override {}; |
| 1111 | + |
| 1112 | + void remove_display(mir::geometry::Rectangle const& /*area*/) override {}; |
| 1113 | +}; |
| 1114 | + |
| 1115 | #endif // STUB_DISPLAY_H |
| 1116 | |
| 1117 | === modified file 'miral-qt/tests/mirserver/ScreensModel/testable_screensmodel.h' |
| 1118 | --- miral-qt/tests/mirserver/ScreensModel/testable_screensmodel.h 2016-06-01 22:06:51 +0000 |
| 1119 | +++ miral-qt/tests/mirserver/ScreensModel/testable_screensmodel.h 2016-07-27 16:52:34 +0000 |
| 1120 | @@ -28,9 +28,10 @@ |
| 1121 | } |
| 1122 | |
| 1123 | void do_init(const std::shared_ptr<mir::graphics::Display> &display, |
| 1124 | - const std::shared_ptr<mir::compositor::Compositor> &compositor) |
| 1125 | + const std::shared_ptr<mir::compositor::Compositor> &compositor, |
| 1126 | + const std::shared_ptr<mir::compositor::DisplayListener> &displayListener) |
| 1127 | { |
| 1128 | - init(display, compositor); |
| 1129 | + init(display, compositor, displayListener); |
| 1130 | } |
| 1131 | |
| 1132 | void do_terminate() { terminate(); } |

Nits again:
+#include <mir/shell/ abstract_ shell.h>
We only use <mir/shell/shell.h>
~~~~
In miral-qt/ src/platforms/ mirserver/ screensmodel. h
+#include <mir/shell/ window_ manager. h>
Not needed.
~~~~
+ auto e = reinterpret_ cast<MirEvent const*>(event); // naughty
Is Mir missing a good way to do this? (C.f. mir_keyboard_ event_input_ event() )