Merge lp:~aacid/unity-mir/improve_input_area_handling into lp:unity-mir

Proposed by Albert Astals Cid
Status: Merged
Approved by: Gerry Boland
Approved revision: 26
Merged at revision: 27
Proposed branch: lp:~aacid/unity-mir/improve_input_area_handling
Merge into: lp:unity-mir
Diff against target: 287 lines (+88/-59)
6 files modified
src/modules/Unity/SurfaceManager/inputarea.cpp (+8/-4)
src/modules/Unity/SurfaceManager/mirsurface.cpp (+32/-41)
src/modules/Unity/SurfaceManager/mirsurface.h (+6/-5)
src/modules/Unity/SurfaceManager/mirsurfacemanager.cpp (+34/-7)
src/modules/Unity/SurfaceManager/mirsurfacemanager.h (+7/-1)
src/modules/Unity/SurfaceManager/plugin.cpp (+1/-1)
To merge this branch: bzr merge lp:~aacid/unity-mir/improve_input_area_handling
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Mir development team Pending
Review via email: mp+177568@code.launchpad.net

Commit message

Improve InputArea<->MirSurface<->Mir::Surface mapping

This gets the lower row of buttons in http://bazaar.launchpad.net/~gerboland/+junk/qml-demo-shell/ to work

Rationale is, before this patch it's input area had it's own MirSurface but some of the MirSurfaces shared the same mir::surface, so they ended up overwriting eachother input_regions. Now there's just a MirSurface per surface that is shared with the various InputAreas and thus the input_regions nicely cooperate

To post a comment you must log in.
26. By Albert Astals Cid

Take into account m_surface may still not be there when setting enabled

Revision history for this message
Gerry Boland (gerboland) wrote :

Nice fixing, thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/SurfaceManager/inputarea.cpp'
2--- src/modules/Unity/SurfaceManager/inputarea.cpp 2013-07-19 17:29:44 +0000
3+++ src/modules/Unity/SurfaceManager/inputarea.cpp 2013-07-30 15:59:58 +0000
4@@ -7,6 +7,7 @@
5 // local
6 #include "inputarea.h"
7 #include "mirsurface.h"
8+#include "mirsurfacemanager.h"
9 #include "qmirserverapplication.h"
10 #include "shellserverconfiguration.h"
11 #include "surfacesource.h"
12@@ -32,8 +33,10 @@
13
14 void InputArea::surfaceReady(std::shared_ptr<mir::shell::Surface> const& surface)
15 {
16- m_surface = new MirSurface(surface);
17- m_surface->installInputArea(this);
18+ m_surface = MirSurfaceManager::singleton()->surfaceFor(surface);
19+ if (m_enabled) {
20+ m_surface->installInputArea(this);
21+ }
22 }
23
24 bool InputArea::enabled() const
25@@ -45,7 +48,9 @@
26 {
27 if (enabled != m_enabled) {
28 m_enabled = enabled;
29- m_surface->enableInputArea(this, enabled);
30+ if (m_surface) {
31+ m_surface->enableInputArea(this, enabled);
32+ }
33 Q_EMIT enabledChanged();
34 }
35 }
36@@ -125,7 +130,6 @@
37 m_mirInputArea.size.height = Height{rect.height()};
38
39 if (m_surface) {
40- m_surface->removeInputArea(this);
41 m_surface->installInputArea(this);
42 }
43 }
44
45=== modified file 'src/modules/Unity/SurfaceManager/mirsurface.cpp'
46--- src/modules/Unity/SurfaceManager/mirsurface.cpp 2013-07-24 15:13:01 +0000
47+++ src/modules/Unity/SurfaceManager/mirsurface.cpp 2013-07-30 15:59:58 +0000
48@@ -16,7 +16,6 @@
49
50 MirSurface::~MirSurface()
51 {
52- m_mirInputAreas.clear();
53 // Q_FOREACH(auto inputArea, m_inputAreas) {
54 // delete inputArea;
55 // }
56@@ -138,46 +137,38 @@
57 LOG("MirSurface::installInputArea - surface does not support input");
58 }
59
60- m_inputAreas.push_back(area);
61- m_mirInputAreas.push_back(area->m_mirInputArea);
62-
63+ m_inputAreas.insert(area);
64+ updateMirInputRegion();
65+}
66+
67+bool MirSurface::removeInputArea(const InputArea* area)
68+{
69+ const bool res = m_inputAreas.remove(area);
70+ updateMirInputRegion();
71+ return res;
72+}
73+
74+bool MirSurface::enableInputArea(const InputArea* area, bool enable)
75+{
76+ bool res;
77+ if (enable) {
78+ m_inputAreas.insert(area);
79+ res = true;
80+ } else {
81+ res = m_inputAreas.remove(area);
82+ }
83+ updateMirInputRegion();
84+ return res;
85+}
86+
87+void MirSurface::updateMirInputRegion()
88+{
89 /* WARNING: by default, a surface has an input region covering the whole surface.
90 Once the surface input region is set, the default will *not* be restored when
91 all input regions are removed/disabled */
92- m_surface->set_input_region(m_mirInputAreas);
93-}
94-
95-bool MirSurface::removeInputArea(const InputArea* area)
96-{
97- int index = m_inputAreas.indexOf(area);
98- if (index < 0) return false;
99-
100- disableMirInputArea(area->m_mirInputArea);
101-
102- m_inputAreas.remove(index);
103- return true;
104-}
105-
106-bool MirSurface::enableInputArea(const InputArea* area, bool enable)
107-{
108- if (m_inputAreas.contains(area)) return false;
109-
110- if (enable) {
111- m_mirInputAreas.push_back(area->m_mirInputArea);
112- return true;
113- } else {
114- return disableMirInputArea(area->m_mirInputArea);
115- }
116-}
117-
118-bool MirSurface::disableMirInputArea(const mir::geometry::Rectangle& rect)
119-{
120- for (auto it = m_mirInputAreas.begin(); it != m_mirInputAreas.end(); it++) {
121- if (it->size == rect.size && it->top_left == rect.top_left) {
122- m_mirInputAreas.erase(it);
123- return true;
124- }
125- }
126- return false;
127-}
128-
129+ std::vector<mir::geometry::Rectangle> mirInputAreas;
130+ for (auto const& area : m_inputAreas) {
131+ mirInputAreas.push_back(area->m_mirInputArea);
132+ }
133+ m_surface->set_input_region(mirInputAreas);
134+}
135
136=== modified file 'src/modules/Unity/SurfaceManager/mirsurface.h'
137--- src/modules/Unity/SurfaceManager/mirsurface.h 2013-07-25 13:51:47 +0000
138+++ src/modules/Unity/SurfaceManager/mirsurface.h 2013-07-30 15:59:58 +0000
139@@ -3,7 +3,7 @@
140
141 // Qt
142 #include <QQuickItem>
143-#include <QVector>
144+#include <QSet>
145
146 // mir
147 #include <mir/shell/surface.h>
148@@ -85,16 +85,17 @@
149 std::shared_ptr<mir::shell::Surface> m_surface;
150
151 private:
152- // start of methods used by InputFilter
153+ // start of methods used by InputArea
154 void installInputArea(const InputArea* area);
155 bool removeInputArea(const InputArea* area);
156 bool enableInputArea(const InputArea* area, bool enable = true);
157- // end of methods used by InputFilter
158+ // end of methods used by InputArea
159+
160+ void updateMirInputRegion();
161
162 bool disableMirInputArea(const mir::geometry::Rectangle& rect);
163
164- QVector<const InputArea*> m_inputAreas;
165- std::vector<mir::geometry::Rectangle> m_mirInputAreas;
166+ QSet<const InputArea*> m_inputAreas;
167
168 bool m_visible:true; //FIXME(greyback) state should be in Mir::Shell::Surface, not here
169
170
171=== modified file 'src/modules/Unity/SurfaceManager/mirsurfacemanager.cpp'
172--- src/modules/Unity/SurfaceManager/mirsurfacemanager.cpp 2013-07-24 17:22:08 +0000
173+++ src/modules/Unity/SurfaceManager/mirsurfacemanager.cpp 2013-07-30 15:59:58 +0000
174@@ -14,8 +14,19 @@
175
176 namespace msh = mir::shell;
177
178+MirSurfaceManager *MirSurfaceManager::the_surface_manager = nullptr;
179+
180+MirSurfaceManager* MirSurfaceManager::singleton()
181+{
182+ if (!the_surface_manager) {
183+ the_surface_manager = new MirSurfaceManager();
184+ }
185+ return the_surface_manager;
186+}
187+
188 MirSurfaceManager::MirSurfaceManager(QObject *parent)
189 : QObject(parent)
190+ , m_shellSurface(nullptr)
191 {
192 DLOG("MirSurfaceManager::MirSurfaceManager (this=%p)", this);
193
194@@ -42,12 +53,29 @@
195 m_surfaces.clear();
196 }
197
198+MirSurface *MirSurfaceManager::surfaceFor(std::shared_ptr<mir::shell::Surface> surface, QQuickItem *parent)
199+{
200+ auto it = m_surfaces.find(surface.get());
201+ if (it != m_surfaces.end()) {
202+ return *it;
203+ }
204+ if (!m_shellSurface) {
205+ // If sessionCreatedSurface was not called assume it is the shell surface
206+ m_shellSurface = new MirSurface(surface, parent);
207+ m_surfaces.insert(surface.get(), m_shellSurface);
208+ return m_shellSurface;
209+ } else {
210+ DLOG("MirSurfaceManager::surfaceFor (this=%p) with surface name '%s' asking for a surface that was not created and is not the shell surface", this, surface->name().c_str());
211+ return nullptr;
212+ }
213+}
214+
215 void MirSurfaceManager::sessionCreatedSurface(mir::shell::ApplicationSession const*, std::shared_ptr<mir::shell::Surface> const& surface)
216 {
217 DLOG("MirSurfaceManager::sessionCreatedSurface (this=%p) with surface name '%s'", this, surface->name().c_str());
218 auto qmlSurface = new MirSurface(surface);
219
220- m_surfaces.prepend(qmlSurface);
221+ m_surfaces.insert(surface.get(), qmlSurface);
222 Q_EMIT surfaceCreated(qmlSurface);
223 }
224
225@@ -55,12 +83,11 @@
226 {
227 DLOG("MirSurfaceManager::sessionDestroyingSurface (this=%p) with surface name '%s'", this, surface->name().c_str());
228
229- Q_FOREACH(MirSurface* s, m_surfaces) {
230- if (s->m_surface == surface) {
231- m_surfaces.removeOne(s);
232- Q_EMIT surfaceDestroyed(s);
233- return;
234- }
235+ auto it = m_surfaces.find(surface.get());
236+ if (it != m_surfaces.end()) {
237+ m_surfaces.erase(it);
238+ Q_EMIT surfaceDestroyed(*it);
239+ delete *it;
240 }
241
242 DLOG("MirSurfaceManager::sessionDestroyingSurface: unable to find MirSurface corresponding to surface '%s'", surface->name().c_str());
243
244=== modified file 'src/modules/Unity/SurfaceManager/mirsurfacemanager.h'
245--- src/modules/Unity/SurfaceManager/mirsurfacemanager.h 2013-07-24 17:22:08 +0000
246+++ src/modules/Unity/SurfaceManager/mirsurfacemanager.h 2013-07-30 15:59:58 +0000
247@@ -17,11 +17,15 @@
248 Q_OBJECT
249
250 public:
251+ static MirSurfaceManager* singleton();
252+
253 MirSurfaceManager(QObject *parent = 0);
254 ~MirSurfaceManager();
255
256 MirSurface* shellSurface() const;
257
258+ MirSurface *surfaceFor(std::shared_ptr<mir::shell::Surface> surface, QQuickItem *parent = 0);
259+
260 Q_SIGNALS:
261 void surfaceCreated(MirSurface* surface);
262 void surfaceDestroyed(MirSurface* surface);
263@@ -33,8 +37,10 @@
264 void sessionDestroyingSurface(mir::shell::ApplicationSession const*, std::shared_ptr<mir::shell::Surface> const&);
265
266 private:
267- QList<MirSurface*> m_surfaces;
268+ QHash<mir::shell::Surface *, MirSurface *> m_surfaces;
269+ MirSurface* m_shellSurface;
270 ShellServerConfiguration* m_mirServer;
271+ static MirSurfaceManager *the_surface_manager;
272 };
273
274 #endif // MIR_SURFACE_MANAGER_H
275
276=== modified file 'src/modules/Unity/SurfaceManager/plugin.cpp'
277--- src/modules/Unity/SurfaceManager/plugin.cpp 2013-07-19 17:29:44 +0000
278+++ src/modules/Unity/SurfaceManager/plugin.cpp 2013-07-30 15:59:58 +0000
279@@ -8,7 +8,7 @@
280 Q_UNUSED(engine);
281 Q_UNUSED(scriptEngine);
282 DLOG("surfaceManagerSingleton (engine=%p, scriptEngine=%p)", engine, scriptEngine);
283- return new MirSurfaceManager();
284+ return MirSurfaceManager::singleton();
285 }
286
287 class UbuntuApplicationPlugin : public QQmlExtensionPlugin {

Subscribers

People subscribed via source and target branches