Merge lp:~gerboland/miral/qtmir-555 into lp:miral

Proposed by Gerry Boland
Status: Superseded
Proposed branch: lp:~gerboland/miral/qtmir-555
Merge into: lp:miral
Diff against target: 1001 lines (+283/-57)
30 files modified
debian/libmiral1.symbols (+1/-0)
include/miral/window_manager_tools.h (+7/-0)
miral-qt/CMakeLists.txt (+1/-1)
miral-qt/debian/control (+4/-2)
miral-qt/debian/gles-patches/convert-to-gles.patch (+2/-2)
miral-qt/src/common/windowmodelnotifierinterface.h (+17/-5)
miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp (+35/-0)
miral-qt/src/modules/Unity/Application/dbusfocusinfo.h (+12/-2)
miral-qt/src/modules/Unity/Application/mirsurface.cpp (+43/-35)
miral-qt/src/modules/Unity/Application/mirsurface.h (+7/-2)
miral-qt/src/modules/Unity/Application/windowmodel.cpp (+1/-1)
miral-qt/src/modules/Unity/Application/windowmodel.h (+1/-1)
miral-qt/src/platforms/mirserver/nativeinterface.h (+2/-0)
miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp (+4/-2)
miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp (+4/-2)
miral-qt/src/platforms/mirserver/windowmodelnotifier.h (+1/-1)
miral-qt/tests/framework/CMakeLists.txt (+1/-0)
miral-qt/tests/framework/fake_mirsurface.cpp (+2/-0)
miral-qt/tests/framework/fake_mirsurface.h (+1/-0)
miral-qt/tests/framework/mock_persistent_surface_store.cpp (+30/-0)
miral-qt/tests/framework/mock_persistent_surface_store.h (+24/-0)
miral-qt/tests/framework/qtmir_test.cpp (+1/-0)
miral-qt/tests/framework/qtmir_test.h (+3/-0)
miral-qt/tests/modules/WindowManager/windowmodel_test.cpp (+1/-1)
miral/basic_window_manager.cpp (+11/-0)
miral/basic_window_manager.h (+2/-0)
miral/symbols.map (+1/-0)
miral/window_manager_tools.cpp (+3/-0)
miral/window_manager_tools_implementation.h (+1/-0)
test/persistent_surface_store.cpp (+60/-0)
To merge this branch: bzr merge lp:~gerboland/miral/qtmir-555
Reviewer Review Type Date Requested Status
Mir development team Pending
Review via email: mp+305112@code.launchpad.net

This proposal has been superseded by a proposal from 2016-09-07.

Commit message

[miral-qt] Merge rev 555 of qtmir: Added implementation for MirSurfaceInterface::persistentId - adapted to suit new arch

Based on https://code.launchpad.net/~unity-team/qtmir/persistent_surface_id/+merge/303580 by Daniel d'Andrada

To post a comment you must log in.
lp:~gerboland/miral/qtmir-555 updated
318. By Gerry Boland

Merge miral trunk

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libmiral1.symbols'
2--- debian/libmiral1.symbols 2016-09-06 08:05:38 +0000
3+++ debian/libmiral1.symbols 2016-09-07 20:36:39 +0000
4@@ -163,6 +163,7 @@
5 (c++)"miral::WindowManagerTools::focus_next_application()@MIRAL_0.1" 0.1.0
6 (c++)"miral::WindowManagerTools::focus_next_within_application()@MIRAL_0.1" 0.1.0
7 (c++)"miral::WindowManagerTools::for_each_application(std::function<void (miral::ApplicationInfo&)> const&)@MIRAL_0.1" 0.1.0
8+ (c++)"miral::WindowManagerTools::id_for_window[abi:cxx11](miral::Window const&) const@MIRAL_0.1" 0.1.0
9 (c++)"miral::WindowManagerTools::info_for(miral::Window const&) const@MIRAL_0.1" 0.1.0
10 (c++)"miral::WindowManagerTools::info_for(std::weak_ptr<mir::scene::Session> const&) const@MIRAL_0.1" 0.1.0
11 (c++)"miral::WindowManagerTools::info_for(std::weak_ptr<mir::scene::Surface> const&) const@MIRAL_0.1" 0.1.0
12
13=== modified file 'include/miral/window_manager_tools.h'
14--- include/miral/window_manager_tools.h 2016-08-15 15:36:00 +0000
15+++ include/miral/window_manager_tools.h 2016-09-07 20:36:39 +0000
16@@ -105,6 +105,13 @@
17 */
18 auto info_for_window_id(std::string const& id) const -> WindowInfo&;
19
20+ /** retrieve the persistent surface id for a window
21+ *
22+ * @param id the window
23+ * @return the persistent surface id
24+ */
25+ auto id_for_window(Window const& window) const -> std::string;
26+
27 /// Send close request to the window
28 void ask_client_to_close(Window const& window);
29
30
31=== modified file 'miral-qt/CMakeLists.txt'
32--- miral-qt/CMakeLists.txt 2016-08-16 14:21:14 +0000
33+++ miral-qt/CMakeLists.txt 2016-09-07 20:36:39 +0000
34@@ -90,7 +90,7 @@
35 pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt)
36 pkg_check_modules(QTDBUSTEST libqtdbustest-1 REQUIRED)
37 pkg_check_modules(QTDBUSMOCK libqtdbusmock-1 REQUIRED)
38-pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=20)
39+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=21)
40 pkg_check_modules(CGMANAGER libcgmanager REQUIRED)
41
42 add_definitions(-DMIR_REQUIRE_DEPRECATED_EVENT_OPT_IN=1)
43
44=== modified file 'miral-qt/debian/control'
45--- miral-qt/debian/control 2016-08-16 14:21:14 +0000
46+++ miral-qt/debian/control 2016-09-07 20:36:39 +0000
47@@ -23,7 +23,7 @@
48 libubuntu-app-launch2-dev (>= 0.9),
49 libubuntu-application-api-dev (>= 2.1.0),
50 libudev-dev,
51- libunity-api-dev (>= 7.117),
52+ libunity-api-dev (>= 7.118),
53 liburl-dispatcher1-dev,
54 libxkbcommon-dev,
55 libxrender-dev,
56@@ -37,6 +37,8 @@
57 qtdeclarative5-dev,
58 qtdeclarative5-private-dev,
59 quilt,
60+# libmirserver-dev should have brought this dep. Bug lp:1617435
61+ uuid-dev,
62 Standards-Version: 3.9.5
63 Homepage: https://launchpad.net/qtmir
64 # if you don't have have commit access to this branch but would like to upload
65@@ -94,7 +96,7 @@
66 Conflicts: libqtmir,
67 libunity-mir1,
68 Provides: unity-application-impl,
69- unity-application-impl-20,
70+ unity-application-impl-21,
71 Description: Qt plugin for Unity specific Mir APIs
72 QtMir provides Qt/QML bindings for Mir features that are exposed through the
73 qtmir-desktop or qtmir-android QPA plugin such as Application management
74
75=== modified file 'miral-qt/debian/gles-patches/convert-to-gles.patch'
76--- miral-qt/debian/gles-patches/convert-to-gles.patch 2016-08-16 14:21:14 +0000
77+++ miral-qt/debian/gles-patches/convert-to-gles.patch 2016-09-07 20:36:39 +0000
78@@ -9,7 +9,7 @@
79 Priority: optional
80 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
81 @@ -16,7 +16,13 @@ Build-Depends: cmake,
82- libmirserver-dev (>= 0.19.0),
83+ libmirserver-dev (>= 0.24.0),
84 libmtdev-dev,
85 libprocess-cpp-dev,
86 + libqt5gui5-gles,
87@@ -84,7 +84,7 @@
88 -Conflicts: libqtmir,
89 - libunity-mir1,
90 -Provides: unity-application-impl,
91-- unity-application-impl-20,
92+- unity-application-impl-21,
93 -Description: Qt plugin for Unity specific Mir APIs
94 - QtMir provides Qt/QML bindings for Mir features that are exposed through the
95 - qtmir-desktop or qtmir-android QPA plugin such as Application management
96
97=== modified file 'miral-qt/src/common/windowmodelnotifierinterface.h'
98--- miral-qt/src/common/windowmodelnotifierinterface.h 2016-09-01 11:37:38 +0000
99+++ miral-qt/src/common/windowmodelnotifierinterface.h 2016-09-07 20:36:39 +0000
100@@ -31,8 +31,7 @@
101 public:
102 WindowInfo() = default;
103 WindowInfo(const miral::WindowInfo &windowInfo)
104- : window(windowInfo.window())
105- , name(windowInfo.name())
106+ : name(windowInfo.name())
107 , type(windowInfo.type())
108 , state(windowInfo.state())
109 , restoreRect(windowInfo.restore_rect())
110@@ -42,10 +41,8 @@
111 , minHeight(windowInfo.min_height())
112 , maxWidth(windowInfo.max_width())
113 , maxHeight(windowInfo.max_height())
114- , surface(window)
115 {}
116
117- miral::Window window;
118 mir::optional_value<std::string> name;
119 MirSurfaceType type;
120 MirSurfaceState state;
121@@ -56,6 +53,20 @@
122 mir::geometry::Height minHeight;
123 mir::geometry::Width maxWidth;
124 mir::geometry::Height maxHeight;
125+};
126+
127+class NewWindowInfo : public WindowInfo {
128+public:
129+ NewWindowInfo() = default;
130+ NewWindowInfo(const miral::WindowInfo &windowInfo, const std::string &persistentId = "")
131+ : WindowInfo(windowInfo)
132+ , window(windowInfo.window())
133+ , persistentId(persistentId)
134+ , surface(window)
135+ {}
136+
137+ miral::Window window;
138+ std::string persistentId;
139
140 // hold copy of Surface shared pointer, as miral::Window has just a weak pointer to the Surface
141 // but MirSurface needs to share ownership of the Surface with Mir
142@@ -71,7 +82,7 @@
143 virtual ~WindowModelNotifierInterface() = default;
144
145 Q_SIGNALS:
146- void windowAdded(const qtmir::WindowInfo, const int index);
147+ void windowAdded(const qtmir::NewWindowInfo, const int index);
148 void windowRemoved(const int index);
149 void windowMoved(const QPoint topLeft, const int index);
150 void windowResized(const QSize size, const int index);
151@@ -85,6 +96,7 @@
152
153 } // namespace qtmir
154
155+Q_DECLARE_METATYPE(qtmir::NewWindowInfo)
156 Q_DECLARE_METATYPE(qtmir::WindowInfo)
157
158 #endif // WINDOWMODELNOTIFIERINTERFACE_H
159
160=== modified file 'miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp'
161--- miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp 2016-07-26 12:30:51 +0000
162+++ miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp 2016-09-07 20:36:39 +0000
163@@ -18,6 +18,9 @@
164
165 // local
166 #include "cgmanager.h"
167+#include "mirsurfacelistmodel.h"
168+#include "mirsurfaceinterface.h"
169+#include "session_interface.h"
170
171 // QPA mirserver
172 #include <logging.h>
173@@ -87,3 +90,35 @@
174 }
175 return nullptr;
176 }
177+
178+bool DBusFocusInfo::isSurfaceFocused(const QString &serializedId)
179+{
180+ MirSurfaceInterface *qmlSurface = findQmlSurface(serializedId);
181+ bool result = qmlSurface ? qmlSurface->activeFocus() : false;
182+ qCDebug(QTMIR_DBUS).nospace() << "DBusFocusInfo: isSurfaceFocused("<<serializedId<<") -> " << result;
183+ return result;
184+}
185+
186+MirSurfaceInterface *DBusFocusInfo::findQmlSurface(const QString &serializedId)
187+{
188+ for (Application* application : m_applications) {
189+ auto session = application->session();
190+
191+ auto surfaceList = static_cast<MirSurfaceListModel*>(session->surfaceList());
192+ for (int i = 0; i < surfaceList->count(); ++i) {
193+ auto qmlSurface = static_cast<MirSurfaceInterface*>(surfaceList->get(i));
194+ if (qmlSurface->persistentId() == serializedId) {
195+ return qmlSurface;
196+ }
197+ }
198+
199+ surfaceList = static_cast<MirSurfaceListModel*>(session->promptSurfaceList());
200+ for (int i = 0; i < surfaceList->count(); ++i) {
201+ auto qmlSurface = static_cast<MirSurfaceInterface*>(surfaceList->get(i));
202+ if (qmlSurface->persistentId() == serializedId) {
203+ return qmlSurface;
204+ }
205+ }
206+ }
207+ return nullptr;
208+}
209
210=== modified file 'miral-qt/src/modules/Unity/Application/dbusfocusinfo.h'
211--- miral-qt/src/modules/Unity/Application/dbusfocusinfo.h 2016-07-26 12:30:36 +0000
212+++ miral-qt/src/modules/Unity/Application/dbusfocusinfo.h 2016-09-07 20:36:39 +0000
213@@ -22,10 +22,11 @@
214 namespace qtmir {
215
216 class CGManager;
217+class MirSurfaceInterface;
218
219 /*
220- FIXME: This is a hack to provide OSK with needed info for avoiding input snooping.
221- Remove when possible
222+ Enables other processes to check what is the currently focused application or surface,
223+ normally for security purposes.
224 */
225 class DBusFocusInfo : public QObject
226 {
227@@ -39,12 +40,21 @@
228
229 /*
230 Returns true if the application with the given PID has input focus
231+
232+ FIXME: Identifying an app through its PID is deemed racy.
233+ isSurfaceFocused() is the preferred method.
234 */
235 Q_SCRIPTABLE bool isPidFocused(unsigned int pid);
236
237+ /*
238+ Returns true if the surface with the given id has input focus
239+ */
240+ Q_SCRIPTABLE bool isSurfaceFocused(const QString &surfaceId);
241+
242 private:
243 QSet<pid_t> fetchAssociatedPids(pid_t pid);
244 SessionInterface* findSessionWithPid(const QSet<pid_t> &pidSet);
245+ MirSurfaceInterface *findQmlSurface(const QString &serializedId);
246
247 const QList<Application*> &m_applications;
248
249
250=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.cpp'
251--- miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-09-01 10:58:43 +0000
252+++ miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-09-07 20:36:39 +0000
253@@ -44,8 +44,8 @@
254
255 using namespace qtmir;
256
257-#define DEBUG_MSG qCDebug(QTMIR_SURFACES).nospace() << "MirSurface[" << (void*)this << "," << appId() <<"]::" << __func__
258-#define WARNING_MSG qCWarning(QTMIR_SURFACES).nospace() << "MirSurface[" << (void*)this << "," << appId() <<"]::" << __func__
259+#define DEBUG_MSG qCDebug(QTMIR_SURFACES).nospace() << "MirSurface[" << (void*)this << "," << appId() << "]::" << __func__
260+#define WARNING_MSG qCWarning(QTMIR_SURFACES).nospace() << "MirSurface[" << (void*)this << "," << appId() << "]::" << __func__
261
262 namespace {
263
264@@ -195,25 +195,28 @@
265
266 } // namespace {
267
268-MirSurface::MirSurface(WindowInfo windowInfo,
269+MirSurface::MirSurface(NewWindowInfo windowInfo,
270 WindowControllerInterface* controller)
271 : MirSurfaceInterface()
272 , m_windowInfo(windowInfo)
273+ , m_window(windowInfo.window)
274+ , m_surface(windowInfo.surface)
275 , m_controller(controller)
276+ , m_persistentId(QString::fromStdString(windowInfo.persistentId))
277 , m_firstFrameDrawn(false)
278 , m_orientationAngle(Mir::Angle0)
279 , m_textureUpdated(false)
280 , m_currentFrameNumber(0)
281 , m_live(true)
282 , m_surfaceObserver(std::make_shared<SurfaceObserver>())
283- , m_position(toQPoint(windowInfo.window.top_left()))
284- , m_size(toQSize(windowInfo.window.size()))
285+ , m_position(toQPoint(m_window.top_left()))
286+ , m_size(toQSize(m_window.size()))
287 , m_shellChrome(Mir::NormalChrome)
288 {
289 DEBUG_MSG << "()";
290
291- SurfaceObserver::registerObserverForSurface(m_surfaceObserver.get(), windowInfo.surface.get());
292- m_windowInfo.surface->add_observer(m_surfaceObserver);
293+ SurfaceObserver::registerObserverForSurface(m_surfaceObserver.get(), m_surface.get());
294+ m_surface->add_observer(m_surfaceObserver);
295
296 //m_shellChrome = creationHints.shellChrome; TODO - where will this come from now?
297
298@@ -253,12 +256,12 @@
299
300 MirSurface::~MirSurface()
301 {
302- qCDebug(QTMIR_SURFACES).nospace() << "MirSurface[" << (void*)this << "]::~MirSurface() viewCount=" << m_views.count();
303+ DEBUG_MSG << "() viewCount=" << m_views.count();
304
305 Q_ASSERT(m_views.isEmpty());
306
307 QMutexLocker locker(&m_mutex);
308- m_windowInfo.surface->remove_observer(m_surfaceObserver);
309+ m_surface->remove_observer(m_surfaceObserver);
310
311 delete m_closeTimer;
312
313@@ -339,7 +342,7 @@
314
315 const void* const userId = (void*)123; // TODO: Multimonitor support
316
317- const int framesPending = m_windowInfo.surface->buffers_ready_for_compositor(userId);
318+ const int framesPending = m_surface->buffers_ready_for_compositor(userId);
319 if (framesPending > 0) {
320 m_textureUpdated = false;
321
322@@ -400,10 +403,10 @@
323 }
324
325 const void* const userId = (void*)123;
326- auto renderables = m_windowInfo.surface->generate_renderables(userId);
327+ auto renderables = m_surface->generate_renderables(userId);
328
329 if (renderables.size() > 0 &&
330- (m_windowInfo.surface->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())
331+ (m_surface->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())
332 ) {
333 // Avoid holding two buffers for the compositor at the same time. Thus free the current
334 // before acquiring the next
335@@ -419,7 +422,7 @@
336 m_textureUpdated = true;
337 }
338
339- if (m_windowInfo.surface->buffers_ready_for_compositor(userId) > 0) {
340+ if (m_surface->buffers_ready_for_compositor(userId) > 0) {
341 // restart the frame dropper to give MirSurfaceItems enough time to render the next frame.
342 // queued since the timer lives in a different thread
343 QMetaObject::invokeMethod(&m_frameDropperTimer, "start", Qt::QueuedConnection);
344@@ -438,7 +441,7 @@
345 {
346 QMutexLocker locker(&m_mutex);
347 const void* const userId = (void*)123;
348- return m_windowInfo.surface->buffers_ready_for_compositor(userId);
349+ return m_surface->buffers_ready_for_compositor(userId);
350 }
351
352 void MirSurface::setFocused(bool value)
353@@ -481,10 +484,10 @@
354
355 if (m_activelyFocusedViews.isEmpty()) {
356 DEBUG_MSG << "() unfocused";
357- m_controller->setActiveFocus(m_windowInfo.window, false);
358+ m_controller->setActiveFocus(m_window, false);
359 } else {
360 DEBUG_MSG << "() focused";
361- m_controller->setActiveFocus(m_windowInfo.window, true);
362+ m_controller->setActiveFocus(m_window, true);
363 }
364
365 m_neverSetSurfaceFocus = false;
366@@ -502,14 +505,14 @@
367 Q_EMIT closeRequested();
368 m_closeTimer->start();
369
370- if (m_windowInfo.window) {
371- m_windowInfo.surface->request_client_surface_close();
372+ if (m_window) {
373+ m_surface->request_client_surface_close();
374 }
375 }
376
377 void MirSurface::resize(int width, int height)
378 {
379- auto const &window = m_windowInfo.window;
380+ auto const &window = m_window;
381
382 bool mirSizeIsDifferent = width != m_size.width() || height != m_size.height();
383
384@@ -535,7 +538,7 @@
385
386 void MirSurface::requestPosition(const QPoint newPosition)
387 {
388- m_controller->move(m_windowInfo.window, newPosition);
389+ m_controller->move(m_window, newPosition);
390 }
391
392 void MirSurface::setSize(const QSize newSize)
393@@ -608,8 +611,8 @@
394 return;
395 }
396
397- if (m_windowInfo.window) {
398- m_windowInfo.surface->set_orientation(mirOrientation);
399+ if (m_surface) {
400+ m_surface->set_orientation(mirOrientation);
401 }
402
403 Q_EMIT orientationAngleChanged(angle);
404@@ -623,6 +626,11 @@
405 return QString::fromStdString(m_windowInfo.name.value());
406 }
407
408+QString MirSurface::persistentId() const
409+{
410+ return m_persistentId;
411+}
412+
413 void MirSurface::setState(Mir::State qmlState)
414 {
415 MirSurfaceState mirState;
416@@ -662,7 +670,7 @@
417 break;
418 }
419
420- m_controller->setState(m_windowInfo.window, mirState);
421+ m_controller->setState(m_window, mirState);
422 }
423
424 void MirSurface::setLive(bool value)
425@@ -692,7 +700,7 @@
426 {
427 auto ev = makeMirEvent(event, mir_pointer_action_button_down);
428 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
429- m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
430+ m_controller->deliverPointerEvent(m_window, ev1);
431 event->accept();
432 }
433
434@@ -700,7 +708,7 @@
435 {
436 auto ev = makeMirEvent(event, mir_pointer_action_motion);
437 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
438- m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
439+ m_controller->deliverPointerEvent(m_window, ev1);
440 event->accept();
441 }
442
443@@ -708,7 +716,7 @@
444 {
445 auto ev = makeMirEvent(event, mir_pointer_action_button_up);
446 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
447- m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
448+ m_controller->deliverPointerEvent(m_window, ev1);
449 event->accept();
450 }
451
452@@ -716,7 +724,7 @@
453 {
454 auto ev = makeMirEvent(event, mir_pointer_action_enter);
455 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
456- m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
457+ m_controller->deliverPointerEvent(m_window, ev1);
458 event->accept();
459 }
460
461@@ -724,7 +732,7 @@
462 {
463 auto ev = makeMirEvent(event, mir_pointer_action_leave);
464 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
465- m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
466+ m_controller->deliverPointerEvent(m_window, ev1);
467 event->accept();
468 }
469
470@@ -732,7 +740,7 @@
471 {
472 auto ev = makeMirEvent(event, mir_pointer_action_motion);
473 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
474- m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
475+ m_controller->deliverPointerEvent(m_window, ev1);
476 event->accept();
477 }
478
479@@ -740,7 +748,7 @@
480 {
481 auto ev = makeMirEvent(event);
482 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
483- m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
484+ m_controller->deliverPointerEvent(m_window, ev1);
485 event->accept();
486 }
487
488@@ -748,7 +756,7 @@
489 {
490 auto ev = makeMirEvent(qtEvent);
491 auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
492- m_controller->deliverKeyboardEvent(m_windowInfo.window, ev1);
493+ m_controller->deliverKeyboardEvent(m_window, ev1);
494 qtEvent->accept();
495 }
496
497@@ -756,7 +764,7 @@
498 {
499 auto ev = makeMirEvent(qtEvent);
500 auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
501- m_controller->deliverKeyboardEvent(m_windowInfo.window, ev1);
502+ m_controller->deliverKeyboardEvent(m_window, ev1);
503 qtEvent->accept();
504 }
505
506@@ -767,7 +775,7 @@
507 {
508 auto ev = makeMirEvent(mods, touchPoints, touchPointStates, timestamp);
509 auto ev1 = reinterpret_cast<MirTouchEvent const*>(ev.get());
510- m_controller->deliverTouchEvent(m_windowInfo.window, ev1);
511+ m_controller->deliverTouchEvent(m_window, ev1);
512 }
513
514 bool MirSurface::clientIsRunning() const
515@@ -900,7 +908,7 @@
516 return;
517 }
518
519- m_windowInfo.surface->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");
520+ m_surface->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");
521 }
522
523 QCursor MirSurface::cursor() const
524@@ -1054,7 +1062,7 @@
525
526 m_closingState = CloseOverdue;
527
528- m_controller->requestClose(m_windowInfo.window);
529+ m_controller->requestClose(m_window);
530 }
531
532 void MirSurface::setCloseTimer(AbstractTimer *timer)
533
534=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.h'
535--- miral-qt/src/modules/Unity/Application/mirsurface.h 2016-08-22 22:31:41 +0000
536+++ miral-qt/src/modules/Unity/Application/mirsurface.h 2016-09-07 20:36:39 +0000
537@@ -49,7 +49,7 @@
538 Q_OBJECT
539
540 public:
541- MirSurface(WindowInfo windowInfo,
542+ MirSurface(NewWindowInfo windowInfo,
543 WindowControllerInterface *controller);
544 virtual ~MirSurface();
545
546@@ -60,6 +60,8 @@
547
548 QString name() const override;
549
550+ QString persistentId() const override;
551+
552 QSize size() const override;
553 void resize(int width, int height) override;
554 Q_INVOKABLE void resize(const QSize &size) override { resize(size.width(), size.height()); }
555@@ -158,7 +160,7 @@
556 // useful for tests
557 void setCloseTimer(AbstractTimer *timer);
558 std::shared_ptr<SurfaceObserver> surfaceObserver() const;
559- WindowInfo windowInfo() const { return m_windowInfo; }
560+ miral::Window window() const { return m_window; }
561
562 public Q_SLOTS:
563 void onCompositorSwappedBuffers() override;
564@@ -183,8 +185,11 @@
565 void updateActiveFocus();
566
567 WindowInfo m_windowInfo;
568+ miral::Window m_window;
569+ std::shared_ptr<mir::scene::Surface> m_surface; // keep copy of the Surface for lifecycle
570 QPointer<SessionInterface> m_session;
571 WindowControllerInterface *const m_controller;
572+ QString m_persistentId;
573 bool m_firstFrameDrawn;
574
575 //FIXME - have to save the state as Mir has no getter for it (bug:1357429)
576
577=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.cpp'
578--- miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-09-06 15:21:11 +0000
579+++ miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-09-07 20:36:39 +0000
580@@ -69,7 +69,7 @@
581 return roleNames;
582 }
583
584-void WindowModel::onWindowAdded(const WindowInfo windowInfo, const int index)
585+void WindowModel::onWindowAdded(const NewWindowInfo windowInfo, const int index)
586 {
587 auto mirSurface = new MirSurface(windowInfo, m_windowController);
588 beginInsertRows(QModelIndex(), index, index);
589
590=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.h'
591--- miral-qt/src/modules/Unity/Application/windowmodel.h 2016-08-24 12:40:48 +0000
592+++ miral-qt/src/modules/Unity/Application/windowmodel.h 2016-09-07 20:36:39 +0000
593@@ -53,7 +53,7 @@
594 void countChanged();
595
596 private Q_SLOTS:
597- void onWindowAdded(const WindowInfo windowInfo, const int index);
598+ void onWindowAdded(const NewWindowInfo windowInfo, const int index);
599 void onWindowRemoved(const int index);
600 void onWindowMoved(const QPoint topLeft, const int index);
601 void onWindowResized(const QSize size, const int index);
602
603=== modified file 'miral-qt/src/platforms/mirserver/nativeinterface.h'
604--- miral-qt/src/platforms/mirserver/nativeinterface.h 2016-08-16 14:15:26 +0000
605+++ miral-qt/src/platforms/mirserver/nativeinterface.h 2016-09-07 20:36:39 +0000
606@@ -28,6 +28,7 @@
607
608 // mir
609 namespace mir { namespace scene { class PromptSessionManager; }}
610+namespace mir { namespace shell { class PersistentSurfaceStore; }}
611
612 class NativeInterface : public QPlatformNativeInterface
613 {
614@@ -42,6 +43,7 @@
615 QVariant windowProperty(QPlatformWindow *window, const QString &name, const QVariant &defaultValue) const override;
616
617 std::shared_ptr<mir::scene::PromptSessionManager> thePromptSessionManager() const;
618+ std::shared_ptr<mir::shell::PersistentSurfaceStore> thePersistentSurfaceStore() const;
619
620 private:
621 QMirServer *m_qMirServer;
622
623=== modified file 'miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp'
624--- miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-09-06 12:21:43 +0000
625+++ miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-09-07 20:36:39 +0000
626@@ -21,7 +21,7 @@
627 #include "miral/window_manager_tools.h"
628 #include "miral/window_specification.h"
629
630-#include "mir/scene/surface.h"
631+#include <mir/scene/surface.h>
632 #include <QDebug>
633
634 WindowManagementPolicy::WindowManagementPolicy(const miral::WindowManagerTools &tools,
635@@ -88,7 +88,9 @@
636 void WindowManagementPolicy::advise_new_window(const miral::WindowInfo &windowInfo)
637 {
638 // TODO: attach surface observer here
639- m_windowModel.addWindow(windowInfo);
640+ std::string persistentId = m_tools.id_for_window(windowInfo.window());
641+
642+ m_windowModel.addWindow(windowInfo, persistentId);
643 }
644
645 void WindowManagementPolicy::advise_delete_window(const miral::WindowInfo &windowInfo)
646
647=== modified file 'miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp'
648--- miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp 2016-09-06 15:31:41 +0000
649+++ miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp 2016-09-07 20:36:39 +0000
650@@ -31,6 +31,7 @@
651
652 WindowModelNotifier::WindowModelNotifier()
653 {
654+ qRegisterMetaType<qtmir::NewWindowInfo>();
655 qRegisterMetaType<qtmir::WindowInfo>();
656 qRegisterMetaType<QVector<int>>();
657 }
658@@ -40,12 +41,13 @@
659
660 }
661
662-void WindowModelNotifier::addWindow(const miral::WindowInfo &windowInfo)
663+void WindowModelNotifier::addWindow(const miral::WindowInfo &windowInfo, const std::string &persistentId)
664 {
665 auto stackPosition = m_windowStack.count();
666 m_windowStack.push_back(windowInfo.window()); // ASSUMPTION: Mir should tell us where in stack
667
668- Q_EMIT windowAdded(windowInfo, stackPosition);
669+ NewWindowInfo newWindowInfo{windowInfo, persistentId};
670+ Q_EMIT windowAdded(newWindowInfo, stackPosition);
671 }
672
673 void WindowModelNotifier::removeWindow(const miral::WindowInfo &windowInfo)
674
675=== modified file 'miral-qt/src/platforms/mirserver/windowmodelnotifier.h'
676--- miral-qt/src/platforms/mirserver/windowmodelnotifier.h 2016-08-24 12:30:45 +0000
677+++ miral-qt/src/platforms/mirserver/windowmodelnotifier.h 2016-09-07 20:36:39 +0000
678@@ -32,7 +32,7 @@
679 WindowModelNotifier();
680 virtual ~WindowModelNotifier();
681
682- void addWindow(const miral::WindowInfo &windowInfo);
683+ void addWindow(const miral::WindowInfo &windowInfo, const std::string &persistentId = "");
684 void removeWindow(const miral::WindowInfo &windowInfo);
685
686 void moveWindow(const miral::WindowInfo &windowInfo, mir::geometry::Point topLeft);
687
688=== modified file 'miral-qt/tests/framework/CMakeLists.txt'
689--- miral-qt/tests/framework/CMakeLists.txt 2016-08-22 21:34:31 +0000
690+++ miral-qt/tests/framework/CMakeLists.txt 2016-09-07 20:36:39 +0000
691@@ -29,6 +29,7 @@
692 mock_shared_wakelock.cpp
693 mock_surface.cpp
694 mock_task_controller.cpp
695+ mock_persistent_surface_store.cpp
696 stub_input_channel.cpp
697 fake_surface.h
698 qtmir_test.cpp
699
700=== modified file 'miral-qt/tests/framework/fake_mirsurface.cpp'
701--- miral-qt/tests/framework/fake_mirsurface.cpp 2016-08-10 15:01:44 +0000
702+++ miral-qt/tests/framework/fake_mirsurface.cpp 2016-09-07 20:36:39 +0000
703@@ -54,6 +54,8 @@
704
705 QString FakeMirSurface::name() const { return QString("Fake MirSurface"); }
706
707+QString FakeMirSurface::persistentId() const { return QString("FakeSurfaceId"); }
708+
709 QSize FakeMirSurface::size() const { return m_size; }
710
711 QPoint FakeMirSurface::position() const { return m_position; }
712
713=== modified file 'miral-qt/tests/framework/fake_mirsurface.h'
714--- miral-qt/tests/framework/fake_mirsurface.h 2016-08-10 15:01:44 +0000
715+++ miral-qt/tests/framework/fake_mirsurface.h 2016-09-07 20:36:39 +0000
716@@ -53,6 +53,7 @@
717 // unity.shell.application.MirSurfaceInterface
718 Mir::Type type() const override;
719 QString name() const override;
720+ QString persistentId() const override;
721 QSize size() const override;
722 void resize(int width, int height) override;
723 void resize(const QSize &size) override;
724
725=== added file 'miral-qt/tests/framework/mock_persistent_surface_store.cpp'
726--- miral-qt/tests/framework/mock_persistent_surface_store.cpp 1970-01-01 00:00:00 +0000
727+++ miral-qt/tests/framework/mock_persistent_surface_store.cpp 2016-09-07 20:36:39 +0000
728@@ -0,0 +1,30 @@
729+/*
730+ * Copyright (C) 2016 Canonical, Ltd.
731+ *
732+ * This program is free software: you can redistribute it and/or modify it under
733+ * the terms of the GNU Lesser General Public License version 3, as published by
734+ * the Free Software Foundation.
735+ *
736+ * This program is distributed in the hope that it will be useful, but WITHOUT
737+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
738+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
739+ * Lesser General Public License for more details.
740+ *
741+ * You should have received a copy of the GNU Lesser General Public License
742+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
743+ */
744+
745+#include "mock_persistent_surface_store.h"
746+
747+namespace mir
748+{
749+namespace shell
750+{
751+
752+MockPersistentSurfaceStore::MockPersistentSurfaceStore()
753+{
754+
755+}
756+
757+} // namespace shell
758+} // namespace mir
759
760=== added file 'miral-qt/tests/framework/mock_persistent_surface_store.h'
761--- miral-qt/tests/framework/mock_persistent_surface_store.h 1970-01-01 00:00:00 +0000
762+++ miral-qt/tests/framework/mock_persistent_surface_store.h 2016-09-07 20:36:39 +0000
763@@ -0,0 +1,24 @@
764+#ifndef MOCKPERSISTENTSURFACESTORE_H
765+#define MOCKPERSISTENTSURFACESTORE_H
766+
767+#include <mir/shell/persistent_surface_store.h>
768+#include <gmock/gmock.h>
769+
770+namespace mir
771+{
772+namespace shell
773+{
774+
775+class MockPersistentSurfaceStore : public PersistentSurfaceStore
776+{
777+public:
778+ MockPersistentSurfaceStore();
779+
780+ MOCK_METHOD1(id_for_surface, Id(std::shared_ptr<scene::Surface> const& surface));
781+ MOCK_CONST_METHOD1(surface_for_id, std::shared_ptr<scene::Surface>(Id const& id));
782+};
783+
784+}
785+}
786+
787+#endif // MOCKPERSISTENTSURFACESTORE_H
788
789=== modified file 'miral-qt/tests/framework/qtmir_test.cpp'
790--- miral-qt/tests/framework/qtmir_test.cpp 2016-08-23 11:42:28 +0000
791+++ miral-qt/tests/framework/qtmir_test.cpp 2016-09-07 20:36:39 +0000
792@@ -109,6 +109,7 @@
793
794 QtMirTest::QtMirTest()
795 : promptSessionManager(std::make_shared<StubPromptSessionManager>())
796+ , persistentSurfaceStore(std::make_shared<StubPersistentSurfaceStore>())
797 , applicationManager(taskControllerSharedPointer,
798 QSharedPointer<MockSharedWakelock>(&sharedWakelock, [](MockSharedWakelock *){}),
799 QSharedPointer<ProcInfo>(&procInfo,[](ProcInfo *){}),
800
801=== modified file 'miral-qt/tests/framework/qtmir_test.h'
802--- miral-qt/tests/framework/qtmir_test.h 2016-08-23 11:42:28 +0000
803+++ miral-qt/tests/framework/qtmir_test.h 2016-09-07 20:36:39 +0000
804@@ -38,6 +38,7 @@
805 #include "mock_shared_wakelock.h"
806 #include "mock_settings.h"
807 #include "mock_task_controller.h"
808+#include "mock_persistent_surface_store.h"
809
810 namespace ms = mir::scene;
811 using namespace qtmir;
812@@ -45,6 +46,7 @@
813 namespace qtmir {
814
815 typedef testing::NiceMock<mir::scene::MockPromptSessionManager> StubPromptSessionManager;
816+typedef testing::NiceMock<mir::shell::MockPersistentSurfaceStore> StubPersistentSurfaceStore;
817
818 // For better output in ASSERT_* and EXPECT_* error messages
819 void PrintTo(const Application::InternalState& state, ::std::ostream* os);
820@@ -71,6 +73,7 @@
821 testing::NiceMock<MockSharedWakelock> sharedWakelock;
822 testing::NiceMock<MockSettings> settings;
823 std::shared_ptr<StubPromptSessionManager> promptSessionManager;
824+ std::shared_ptr<StubPersistentSurfaceStore> persistentSurfaceStore;
825
826 mir::shell::Shell *mirShell{nullptr};
827 ApplicationManager applicationManager;
828
829=== modified file 'miral-qt/tests/modules/WindowManager/windowmodel_test.cpp'
830--- miral-qt/tests/modules/WindowManager/windowmodel_test.cpp 2016-08-25 10:34:52 +0000
831+++ miral-qt/tests/modules/WindowManager/windowmodel_test.cpp 2016-09-07 20:36:39 +0000
832@@ -66,7 +66,7 @@
833
834 miral::Window getMirALWindowFromModel(const WindowModel &model, int index)
835 {
836- return getMirSurfaceFromModel(model, index)->windowInfo().window;
837+ return getMirSurfaceFromModel(model, index)->window();
838 }
839
840 const std::shared_ptr<StubSession> stubSession{std::make_shared<StubSession>()};
841
842=== modified file 'miral/basic_window_manager.cpp'
843--- miral/basic_window_manager.cpp 2016-09-05 15:50:13 +0000
844+++ miral/basic_window_manager.cpp 2016-09-07 20:36:39 +0000
845@@ -646,6 +646,17 @@
846 #endif
847 }
848
849+auto miral::BasicWindowManager::id_for_window(Window const& window) const -> std::string
850+{
851+ if (!window)
852+ BOOST_THROW_EXCEPTION(std::runtime_error{"Null Window has no Persistent ID"});
853+
854+#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 24, 0)
855+ return persistent_surface_store->id_for_surface(window).serialize_to_string();
856+#else
857+ BOOST_THROW_EXCEPTION(std::runtime_error{"Persistent IDs unavailable with this Mir server version"});
858+#endif
859+}
860
861 void miral::BasicWindowManager::place_and_size(WindowInfo& root, Point const& new_pos, Size const& new_size)
862 {
863
864=== modified file 'miral/basic_window_manager.h'
865--- miral/basic_window_manager.h 2016-08-29 16:17:16 +0000
866+++ miral/basic_window_manager.h 2016-09-07 20:36:39 +0000
867@@ -131,6 +131,8 @@
868
869 auto info_for_window_id(std::string const& id) const -> WindowInfo& override;
870
871+ auto id_for_window(Window const& window) const -> std::string override;
872+
873 void invoke_under_lock(std::function<void()> const& callback) override;
874
875 private:
876
877=== modified file 'miral/symbols.map'
878--- miral/symbols.map 2016-09-06 08:05:38 +0000
879+++ miral/symbols.map 2016-09-07 20:36:39 +0000
880@@ -152,6 +152,7 @@
881 miral::WindowManagerTools::focus_next_application*;
882 miral::WindowManagerTools::focus_next_within_application*;
883 miral::WindowManagerTools::for_each_application*;
884+ miral::WindowManagerTools::id_for_window*;
885 miral::WindowManagerTools::info_for*;
886 miral::WindowManagerTools::info_for_window_id*;
887 miral::WindowManagerTools::invoke_under_lock*;
888
889=== modified file 'miral/window_manager_tools.cpp'
890--- miral/window_manager_tools.cpp 2016-08-15 15:36:00 +0000
891+++ miral/window_manager_tools.cpp 2016-09-07 20:36:39 +0000
892@@ -80,5 +80,8 @@
893 auto miral::WindowManagerTools::info_for_window_id(std::string const& id) const -> WindowInfo&
894 { return tools->info_for_window_id(id); }
895
896+auto miral::WindowManagerTools::id_for_window(Window const& window) const -> std::string
897+{ return tools->id_for_window(window); }
898+
899 void miral::WindowManagerTools::invoke_under_lock(std::function<void()> const& callback)
900 { tools->invoke_under_lock(callback); }
901
902=== modified file 'miral/window_manager_tools_implementation.h'
903--- miral/window_manager_tools_implementation.h 2016-08-15 15:36:00 +0000
904+++ miral/window_manager_tools_implementation.h 2016-09-07 20:36:39 +0000
905@@ -63,6 +63,7 @@
906 virtual void raise_tree(Window const& root) = 0;
907 virtual void modify_window(WindowInfo& window_info, WindowSpecification const& modifications) = 0;
908 virtual auto info_for_window_id(std::string const& id) const -> WindowInfo& = 0;
909+ virtual auto id_for_window(Window const& window) const -> std::string = 0;
910 /** @} */
911
912 /** @name Multi-thread support
913
914=== modified file 'test/persistent_surface_store.cpp'
915--- test/persistent_surface_store.cpp 2016-08-12 11:27:38 +0000
916+++ test/persistent_surface_store.cpp 2016-09-07 20:36:39 +0000
917@@ -20,6 +20,8 @@
918 #include <miral/toolkit/surface.h>
919 #include <miral/toolkit/surface_spec.h>
920
921+#include <miral/application_info.h>
922+
923 #include <mir/version.h>
924
925 #include <gtest/gtest.h>
926@@ -56,6 +58,31 @@
927 ASSERT_THAT(window_info.name(), Eq(test_name));
928 });
929 }
930+
931+TEST_F(PersistentSurfaceId, server_returns_correct_id_for_window)
932+{
933+ char const* const test_name = __PRETTY_FUNCTION__;
934+ using namespace miral::toolkit;
935+
936+ auto const connection = connect_client(test_name);
937+ auto const spec = SurfaceSpec::for_normal_surface(connection, 50, 50, mir_pixel_format_argb_8888)
938+ .set_name(test_name);
939+
940+ Surface const surface{spec.create_surface()};
941+
942+ miral::toolkit::PersistentId client_surface_id{surface};
943+
944+ tools.invoke_under_lock([&]
945+ {
946+ // Bit of a journey to get the miral::Window for the above surface
947+ auto app = tools.find_application([&](miral::ApplicationInfo const& /*info*/){return true;});
948+ auto app_info = tools.info_for(app);
949+ auto window = app_info.windows()[0];
950+ auto id = tools.id_for_window(window);
951+
952+ ASSERT_THAT(client_surface_id.c_str(), Eq(id));
953+ });
954+}
955 #else
956 TEST_F(PersistentSurfaceId, server_fails_gracefully_to_identify_window_specified_by_client)
957 {
958@@ -75,6 +102,30 @@
959 EXPECT_THROW(tools.info_for_window_id(client_surface_id.c_str()), std::runtime_error);
960 });
961 }
962+
963+TEST_F(PersistentSurfaceId, server_fails_gracefully_to_return_id_for_window)
964+{
965+ char const* const test_name = __PRETTY_FUNCTION__;
966+ using namespace miral::toolkit;
967+
968+ auto const connection = connect_client(test_name);
969+ auto const spec = SurfaceSpec::for_normal_surface(connection, 50, 50, mir_pixel_format_argb_8888)
970+ .set_name(test_name);
971+
972+ Surface const surface{spec.create_surface()};
973+
974+ miral::toolkit::PersistentId client_surface_id{surface};
975+
976+ tools.invoke_under_lock([&]
977+ {
978+ // Bit of a journey to get the miral::Window for the above surface
979+ auto app = tools.find_application([&](miral::ApplicationInfo const& /*info*/){return true;});
980+ auto app_info = tools.info_for(app);
981+ auto window = app_info.windows()[0];
982+
983+ EXPECT_THROW(tools.id_for_window(window), std::runtime_error);
984+ });
985+}
986 #endif
987
988 TEST_F(PersistentSurfaceId, server_fails_gracefully_to_identify_window_from_garbage_id)
989@@ -95,3 +146,12 @@
990 EXPECT_THROW(tools.info_for_window_id("garbage"), std::exception);
991 });
992 }
993+
994+TEST_F(PersistentSurfaceId, server_fails_gracefully_when_id_for_null_window_requested)
995+{
996+ tools.invoke_under_lock([&]
997+ {
998+ miral::Window window;
999+ EXPECT_THROW(tools.id_for_window(window), std::runtime_error);
1000+ });
1001+}

Subscribers

People subscribed via source and target branches