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
1=== modified file 'miral-qt/src/common/windowmodelnotifierinterface.h'
2--- miral-qt/src/common/windowmodelnotifierinterface.h 2016-08-24 12:40:48 +0000
3+++ miral-qt/src/common/windowmodelnotifierinterface.h 2016-09-01 12:11:43 +0000
4@@ -42,6 +42,7 @@
5 , minHeight(windowInfo.min_height())
6 , maxWidth(windowInfo.max_width())
7 , maxHeight(windowInfo.max_height())
8+ , surface(window)
9 {}
10
11 miral::Window window;
12@@ -55,6 +56,10 @@
13 mir::geometry::Height minHeight;
14 mir::geometry::Width maxWidth;
15 mir::geometry::Height maxHeight;
16+
17+ // hold copy of Surface shared pointer, as miral::Window has just a weak pointer to the Surface
18+ // but MirSurface needs to share ownership of the Surface with Mir
19+ std::shared_ptr<mir::scene::Surface> surface;
20 };
21
22
23
24=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.cpp'
25--- miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-08-22 16:06:32 +0000
26+++ miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-09-01 12:11:43 +0000
27@@ -212,9 +212,8 @@
28 {
29 DEBUG_MSG << "()";
30
31- const auto &surface = static_cast<std::shared_ptr<mir::scene::Surface>>(windowInfo.window);
32- SurfaceObserver::registerObserverForSurface(m_surfaceObserver.get(), surface.get());
33- surface->add_observer(m_surfaceObserver);
34+ SurfaceObserver::registerObserverForSurface(m_surfaceObserver.get(), windowInfo.surface.get());
35+ m_windowInfo.surface->add_observer(m_surfaceObserver);
36
37 //m_shellChrome = creationHints.shellChrome; TODO - where will this come from now?
38
39@@ -259,8 +258,7 @@
40 Q_ASSERT(m_views.isEmpty());
41
42 QMutexLocker locker(&m_mutex);
43-// auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
44-// window->remove_observer(m_surfaceObserver); // FIXME - window null at this stage!
45+ m_windowInfo.surface->remove_observer(m_surfaceObserver);
46
47 delete m_closeTimer;
48
49@@ -341,8 +339,7 @@
50
51 const void* const userId = (void*)123; // TODO: Multimonitor support
52
53- auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
54- int framesPending = window->buffers_ready_for_compositor(userId);
55+ const int framesPending = m_windowInfo.surface->buffers_ready_for_compositor(userId);
56 if (framesPending > 0) {
57 m_textureUpdated = false;
58
59@@ -403,11 +400,10 @@
60 }
61
62 const void* const userId = (void*)123;
63- auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
64- auto renderables = window->generate_renderables(userId);
65+ auto renderables = m_windowInfo.surface->generate_renderables(userId);
66
67 if (renderables.size() > 0 &&
68- (window->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())
69+ (m_windowInfo.surface->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())
70 ) {
71 // Avoid holding two buffers for the compositor at the same time. Thus free the current
72 // before acquiring the next
73@@ -423,7 +419,7 @@
74 m_textureUpdated = true;
75 }
76
77- if (window->buffers_ready_for_compositor(userId) > 0) {
78+ if (m_windowInfo.surface->buffers_ready_for_compositor(userId) > 0) {
79 // restart the frame dropper to give MirSurfaceItems enough time to render the next frame.
80 // queued since the timer lives in a different thread
81 QMetaObject::invokeMethod(&m_frameDropperTimer, "start", Qt::QueuedConnection);
82@@ -442,8 +438,7 @@
83 {
84 QMutexLocker locker(&m_mutex);
85 const void* const userId = (void*)123;
86- auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
87- return window->buffers_ready_for_compositor(userId);
88+ return m_windowInfo.surface->buffers_ready_for_compositor(userId);
89 }
90
91 void MirSurface::setFocused(bool value)
92@@ -508,8 +503,7 @@
93 m_closeTimer->start();
94
95 if (m_windowInfo.window) {
96- auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
97- window->request_client_surface_close();
98+ m_windowInfo.surface->request_client_surface_close();
99 }
100 }
101
102@@ -615,8 +609,7 @@
103 }
104
105 if (m_windowInfo.window) {
106- auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
107- window->set_orientation(mirOrientation);
108+ m_windowInfo.surface->set_orientation(mirOrientation);
109 }
110
111 Q_EMIT orientationAngleChanged(angle);
112@@ -907,9 +900,7 @@
113 return;
114 }
115
116- auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
117-
118- window->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");
119+ m_windowInfo.surface->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");
120 }
121
122 QCursor MirSurface::cursor() const
123
124=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.cpp'
125--- miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-08-25 10:20:56 +0000
126+++ miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-09-01 12:11:43 +0000
127@@ -53,13 +53,13 @@
128
129 void WindowModel::connectToWindowModelNotifier(WindowModelNotifierInterface *notifier)
130 {
131- connect(notifier, &WindowModelNotifierInterface::windowAdded, this, &WindowModel::onWindowAdded);
132- connect(notifier, &WindowModelNotifierInterface::windowRemoved, this, &WindowModel::onWindowRemoved);
133- connect(notifier, &WindowModelNotifierInterface::windowMoved, this, &WindowModel::onWindowMoved);
134- connect(notifier, &WindowModelNotifierInterface::windowResized, this, &WindowModel::onWindowResized);
135- connect(notifier, &WindowModelNotifierInterface::windowFocused, this, &WindowModel::onWindowFocused);
136- connect(notifier, &WindowModelNotifierInterface::windowInfoChanged, this, &WindowModel::onWindowInfoChanged);
137- connect(notifier, &WindowModelNotifierInterface::windowsRaised, this, &WindowModel::onWindowsRaised);
138+ connect(notifier, &WindowModelNotifierInterface::windowAdded, this, &WindowModel::onWindowAdded, Qt::QueuedConnection);
139+ connect(notifier, &WindowModelNotifierInterface::windowRemoved, this, &WindowModel::onWindowRemoved, Qt::QueuedConnection);
140+ connect(notifier, &WindowModelNotifierInterface::windowMoved, this, &WindowModel::onWindowMoved, Qt::QueuedConnection);
141+ connect(notifier, &WindowModelNotifierInterface::windowResized, this, &WindowModel::onWindowResized, Qt::QueuedConnection);
142+ connect(notifier, &WindowModelNotifierInterface::windowFocused, this, &WindowModel::onWindowFocused, Qt::QueuedConnection);
143+ connect(notifier, &WindowModelNotifierInterface::windowInfoChanged, this, &WindowModel::onWindowInfoChanged, Qt::QueuedConnection);
144+ connect(notifier, &WindowModelNotifierInterface::windowsRaised, this, &WindowModel::onWindowsRaised, Qt::QueuedConnection);
145 }
146
147 QHash<int, QByteArray> WindowModel::roleNames() const
148
149=== modified file 'miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp'
150--- miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-08-17 16:18:17 +0000
151+++ miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-09-01 12:11:43 +0000
152@@ -178,9 +178,12 @@
153 void WindowManagementPolicy::deliver_pointer_event(const MirPointerEvent *event,
154 const miral::Window &window)
155 {
156- m_tools.invoke_under_lock([&window, this]() {
157- m_tools.select_active_window(window);
158- });
159+ // Prevent mouse hover events causing window focus to change
160+ if (mir_pointer_event_action(event) == mir_pointer_action_button_down) {
161+ m_tools.invoke_under_lock([&window, this]() {
162+ m_tools.select_active_window(window);
163+ });
164+ }
165 auto e = reinterpret_cast<MirEvent const*>(event); // naughty
166
167 if (auto surface = std::weak_ptr<mir::scene::Surface>(window).lock()) {

Subscribers

People subscribed via source and target branches