Merge lp:~gerboland/miral/focus-on-click into lp:miral

Proposed by Gerry Boland
Status: Merged
Approved by: Alan Griffiths
Approved revision: 311
Merged at revision: 309
Proposed branch: lp:~gerboland/miral/focus-on-click
Merge into: lp:miral
Diff against target: 167 lines (+29/-30)
4 files modified
miral-qt/src/common/windowmodelnotifierinterface.h (+5/-0)
miral-qt/src/modules/Unity/Application/mirsurface.cpp (+11/-20)
miral-qt/src/modules/Unity/Application/windowmodel.cpp (+7/-7)
miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp (+6/-3)
To merge this branch: bzr merge lp:~gerboland/miral/focus-on-click
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+304633@code.launchpad.net

Commit message

[miral-qt] Implement focus-on-click window management policy

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+ std::shared_ptr<mir::scene::Surface> surface;

I'm not totally happy about holding a strong pointer (I've a slight preference for a wrapper that noops when appropriate). But I can't think of an actual problem.

As this code uses libmiral APIs it needs revisiting later anyway.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'miral-qt/src/common/windowmodelnotifierinterface.h'
--- miral-qt/src/common/windowmodelnotifierinterface.h 2016-08-24 12:40:48 +0000
+++ miral-qt/src/common/windowmodelnotifierinterface.h 2016-09-01 12:11:43 +0000
@@ -42,6 +42,7 @@
42 , minHeight(windowInfo.min_height())42 , minHeight(windowInfo.min_height())
43 , maxWidth(windowInfo.max_width())43 , maxWidth(windowInfo.max_width())
44 , maxHeight(windowInfo.max_height())44 , maxHeight(windowInfo.max_height())
45 , surface(window)
45 {}46 {}
4647
47 miral::Window window;48 miral::Window window;
@@ -55,6 +56,10 @@
55 mir::geometry::Height minHeight;56 mir::geometry::Height minHeight;
56 mir::geometry::Width maxWidth;57 mir::geometry::Width maxWidth;
57 mir::geometry::Height maxHeight;58 mir::geometry::Height maxHeight;
59
60 // hold copy of Surface shared pointer, as miral::Window has just a weak pointer to the Surface
61 // but MirSurface needs to share ownership of the Surface with Mir
62 std::shared_ptr<mir::scene::Surface> surface;
58};63};
5964
6065
6166
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.cpp'
--- miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-08-22 16:06:32 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-09-01 12:11:43 +0000
@@ -212,9 +212,8 @@
212{212{
213 DEBUG_MSG << "()";213 DEBUG_MSG << "()";
214214
215 const auto &surface = static_cast<std::shared_ptr<mir::scene::Surface>>(windowInfo.window);215 SurfaceObserver::registerObserverForSurface(m_surfaceObserver.get(), windowInfo.surface.get());
216 SurfaceObserver::registerObserverForSurface(m_surfaceObserver.get(), surface.get());216 m_windowInfo.surface->add_observer(m_surfaceObserver);
217 surface->add_observer(m_surfaceObserver);
218217
219 //m_shellChrome = creationHints.shellChrome; TODO - where will this come from now?218 //m_shellChrome = creationHints.shellChrome; TODO - where will this come from now?
220219
@@ -259,8 +258,7 @@
259 Q_ASSERT(m_views.isEmpty());258 Q_ASSERT(m_views.isEmpty());
260259
261 QMutexLocker locker(&m_mutex);260 QMutexLocker locker(&m_mutex);
262// auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);261 m_windowInfo.surface->remove_observer(m_surfaceObserver);
263// window->remove_observer(m_surfaceObserver); // FIXME - window null at this stage!
264262
265 delete m_closeTimer;263 delete m_closeTimer;
266264
@@ -341,8 +339,7 @@
341339
342 const void* const userId = (void*)123; // TODO: Multimonitor support340 const void* const userId = (void*)123; // TODO: Multimonitor support
343341
344 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);342 const int framesPending = m_windowInfo.surface->buffers_ready_for_compositor(userId);
345 int framesPending = window->buffers_ready_for_compositor(userId);
346 if (framesPending > 0) {343 if (framesPending > 0) {
347 m_textureUpdated = false;344 m_textureUpdated = false;
348345
@@ -403,11 +400,10 @@
403 }400 }
404401
405 const void* const userId = (void*)123;402 const void* const userId = (void*)123;
406 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);403 auto renderables = m_windowInfo.surface->generate_renderables(userId);
407 auto renderables = window->generate_renderables(userId);
408404
409 if (renderables.size() > 0 &&405 if (renderables.size() > 0 &&
410 (window->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())406 (m_windowInfo.surface->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())
411 ) {407 ) {
412 // Avoid holding two buffers for the compositor at the same time. Thus free the current408 // Avoid holding two buffers for the compositor at the same time. Thus free the current
413 // before acquiring the next409 // before acquiring the next
@@ -423,7 +419,7 @@
423 m_textureUpdated = true;419 m_textureUpdated = true;
424 }420 }
425421
426 if (window->buffers_ready_for_compositor(userId) > 0) {422 if (m_windowInfo.surface->buffers_ready_for_compositor(userId) > 0) {
427 // restart the frame dropper to give MirSurfaceItems enough time to render the next frame.423 // restart the frame dropper to give MirSurfaceItems enough time to render the next frame.
428 // queued since the timer lives in a different thread424 // queued since the timer lives in a different thread
429 QMetaObject::invokeMethod(&m_frameDropperTimer, "start", Qt::QueuedConnection);425 QMetaObject::invokeMethod(&m_frameDropperTimer, "start", Qt::QueuedConnection);
@@ -442,8 +438,7 @@
442{438{
443 QMutexLocker locker(&m_mutex);439 QMutexLocker locker(&m_mutex);
444 const void* const userId = (void*)123;440 const void* const userId = (void*)123;
445 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);441 return m_windowInfo.surface->buffers_ready_for_compositor(userId);
446 return window->buffers_ready_for_compositor(userId);
447}442}
448443
449void MirSurface::setFocused(bool value)444void MirSurface::setFocused(bool value)
@@ -508,8 +503,7 @@
508 m_closeTimer->start();503 m_closeTimer->start();
509504
510 if (m_windowInfo.window) {505 if (m_windowInfo.window) {
511 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);506 m_windowInfo.surface->request_client_surface_close();
512 window->request_client_surface_close();
513 }507 }
514}508}
515509
@@ -615,8 +609,7 @@
615 }609 }
616610
617 if (m_windowInfo.window) {611 if (m_windowInfo.window) {
618 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);612 m_windowInfo.surface->set_orientation(mirOrientation);
619 window->set_orientation(mirOrientation);
620 }613 }
621614
622 Q_EMIT orientationAngleChanged(angle);615 Q_EMIT orientationAngleChanged(angle);
@@ -907,9 +900,7 @@
907 return;900 return;
908 }901 }
909902
910 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);903 m_windowInfo.surface->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");
911
912 window->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");
913}904}
914905
915QCursor MirSurface::cursor() const906QCursor MirSurface::cursor() const
916907
=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.cpp'
--- miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-08-25 10:20:56 +0000
+++ miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-09-01 12:11:43 +0000
@@ -53,13 +53,13 @@
5353
54void WindowModel::connectToWindowModelNotifier(WindowModelNotifierInterface *notifier)54void WindowModel::connectToWindowModelNotifier(WindowModelNotifierInterface *notifier)
55{55{
56 connect(notifier, &WindowModelNotifierInterface::windowAdded, this, &WindowModel::onWindowAdded);56 connect(notifier, &WindowModelNotifierInterface::windowAdded, this, &WindowModel::onWindowAdded, Qt::QueuedConnection);
57 connect(notifier, &WindowModelNotifierInterface::windowRemoved, this, &WindowModel::onWindowRemoved);57 connect(notifier, &WindowModelNotifierInterface::windowRemoved, this, &WindowModel::onWindowRemoved, Qt::QueuedConnection);
58 connect(notifier, &WindowModelNotifierInterface::windowMoved, this, &WindowModel::onWindowMoved);58 connect(notifier, &WindowModelNotifierInterface::windowMoved, this, &WindowModel::onWindowMoved, Qt::QueuedConnection);
59 connect(notifier, &WindowModelNotifierInterface::windowResized, this, &WindowModel::onWindowResized);59 connect(notifier, &WindowModelNotifierInterface::windowResized, this, &WindowModel::onWindowResized, Qt::QueuedConnection);
60 connect(notifier, &WindowModelNotifierInterface::windowFocused, this, &WindowModel::onWindowFocused);60 connect(notifier, &WindowModelNotifierInterface::windowFocused, this, &WindowModel::onWindowFocused, Qt::QueuedConnection);
61 connect(notifier, &WindowModelNotifierInterface::windowInfoChanged, this, &WindowModel::onWindowInfoChanged);61 connect(notifier, &WindowModelNotifierInterface::windowInfoChanged, this, &WindowModel::onWindowInfoChanged, Qt::QueuedConnection);
62 connect(notifier, &WindowModelNotifierInterface::windowsRaised, this, &WindowModel::onWindowsRaised);62 connect(notifier, &WindowModelNotifierInterface::windowsRaised, this, &WindowModel::onWindowsRaised, Qt::QueuedConnection);
63}63}
6464
65QHash<int, QByteArray> WindowModel::roleNames() const65QHash<int, QByteArray> WindowModel::roleNames() const
6666
=== modified file 'miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp'
--- miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-08-17 16:18:17 +0000
+++ miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-09-01 12:11:43 +0000
@@ -178,9 +178,12 @@
178void WindowManagementPolicy::deliver_pointer_event(const MirPointerEvent *event,178void WindowManagementPolicy::deliver_pointer_event(const MirPointerEvent *event,
179 const miral::Window &window)179 const miral::Window &window)
180{180{
181 m_tools.invoke_under_lock([&window, this]() {181 // Prevent mouse hover events causing window focus to change
182 m_tools.select_active_window(window);182 if (mir_pointer_event_action(event) == mir_pointer_action_button_down) {
183 });183 m_tools.invoke_under_lock([&window, this]() {
184 m_tools.select_active_window(window);
185 });
186 }
184 auto e = reinterpret_cast<MirEvent const*>(event); // naughty187 auto e = reinterpret_cast<MirEvent const*>(event); // naughty
185188
186 if (auto surface = std::weak_ptr<mir::scene::Surface>(window).lock()) {189 if (auto surface = std::weak_ptr<mir::scene::Surface>(window).lock()) {

Subscribers

People subscribed via source and target branches