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
=== modified file 'src/modules/Unity/SurfaceManager/inputarea.cpp'
--- src/modules/Unity/SurfaceManager/inputarea.cpp 2013-07-19 17:29:44 +0000
+++ src/modules/Unity/SurfaceManager/inputarea.cpp 2013-07-30 15:59:58 +0000
@@ -7,6 +7,7 @@
7// local7// local
8#include "inputarea.h"8#include "inputarea.h"
9#include "mirsurface.h"9#include "mirsurface.h"
10#include "mirsurfacemanager.h"
10#include "qmirserverapplication.h"11#include "qmirserverapplication.h"
11#include "shellserverconfiguration.h"12#include "shellserverconfiguration.h"
12#include "surfacesource.h"13#include "surfacesource.h"
@@ -32,8 +33,10 @@
3233
33void InputArea::surfaceReady(std::shared_ptr<mir::shell::Surface> const& surface)34void InputArea::surfaceReady(std::shared_ptr<mir::shell::Surface> const& surface)
34{35{
35 m_surface = new MirSurface(surface);36 m_surface = MirSurfaceManager::singleton()->surfaceFor(surface);
36 m_surface->installInputArea(this);37 if (m_enabled) {
38 m_surface->installInputArea(this);
39 }
37}40}
3841
39bool InputArea::enabled() const42bool InputArea::enabled() const
@@ -45,7 +48,9 @@
45{48{
46 if (enabled != m_enabled) {49 if (enabled != m_enabled) {
47 m_enabled = enabled;50 m_enabled = enabled;
48 m_surface->enableInputArea(this, enabled);51 if (m_surface) {
52 m_surface->enableInputArea(this, enabled);
53 }
49 Q_EMIT enabledChanged();54 Q_EMIT enabledChanged();
50 }55 }
51}56}
@@ -125,7 +130,6 @@
125 m_mirInputArea.size.height = Height{rect.height()};130 m_mirInputArea.size.height = Height{rect.height()};
126131
127 if (m_surface) {132 if (m_surface) {
128 m_surface->removeInputArea(this);
129 m_surface->installInputArea(this);133 m_surface->installInputArea(this);
130 }134 }
131}135}
132136
=== modified file 'src/modules/Unity/SurfaceManager/mirsurface.cpp'
--- src/modules/Unity/SurfaceManager/mirsurface.cpp 2013-07-24 15:13:01 +0000
+++ src/modules/Unity/SurfaceManager/mirsurface.cpp 2013-07-30 15:59:58 +0000
@@ -16,7 +16,6 @@
1616
17MirSurface::~MirSurface()17MirSurface::~MirSurface()
18{18{
19 m_mirInputAreas.clear();
20// Q_FOREACH(auto inputArea, m_inputAreas) {19// Q_FOREACH(auto inputArea, m_inputAreas) {
21// delete inputArea;20// delete inputArea;
22// }21// }
@@ -138,46 +137,38 @@
138 LOG("MirSurface::installInputArea - surface does not support input");137 LOG("MirSurface::installInputArea - surface does not support input");
139 }138 }
140139
141 m_inputAreas.push_back(area);140 m_inputAreas.insert(area);
142 m_mirInputAreas.push_back(area->m_mirInputArea);141 updateMirInputRegion();
143142}
143
144bool MirSurface::removeInputArea(const InputArea* area)
145{
146 const bool res = m_inputAreas.remove(area);
147 updateMirInputRegion();
148 return res;
149}
150
151bool MirSurface::enableInputArea(const InputArea* area, bool enable)
152{
153 bool res;
154 if (enable) {
155 m_inputAreas.insert(area);
156 res = true;
157 } else {
158 res = m_inputAreas.remove(area);
159 }
160 updateMirInputRegion();
161 return res;
162}
163
164void MirSurface::updateMirInputRegion()
165{
144 /* WARNING: by default, a surface has an input region covering the whole surface.166 /* WARNING: by default, a surface has an input region covering the whole surface.
145 Once the surface input region is set, the default will *not* be restored when167 Once the surface input region is set, the default will *not* be restored when
146 all input regions are removed/disabled */168 all input regions are removed/disabled */
147 m_surface->set_input_region(m_mirInputAreas);169 std::vector<mir::geometry::Rectangle> mirInputAreas;
148}170 for (auto const& area : m_inputAreas) {
149171 mirInputAreas.push_back(area->m_mirInputArea);
150bool MirSurface::removeInputArea(const InputArea* area)172 }
151{173 m_surface->set_input_region(mirInputAreas);
152 int index = m_inputAreas.indexOf(area);174}
153 if (index < 0) return false;
154
155 disableMirInputArea(area->m_mirInputArea);
156
157 m_inputAreas.remove(index);
158 return true;
159}
160
161bool MirSurface::enableInputArea(const InputArea* area, bool enable)
162{
163 if (m_inputAreas.contains(area)) return false;
164
165 if (enable) {
166 m_mirInputAreas.push_back(area->m_mirInputArea);
167 return true;
168 } else {
169 return disableMirInputArea(area->m_mirInputArea);
170 }
171}
172
173bool MirSurface::disableMirInputArea(const mir::geometry::Rectangle& rect)
174{
175 for (auto it = m_mirInputAreas.begin(); it != m_mirInputAreas.end(); it++) {
176 if (it->size == rect.size && it->top_left == rect.top_left) {
177 m_mirInputAreas.erase(it);
178 return true;
179 }
180 }
181 return false;
182}
183
184175
=== modified file 'src/modules/Unity/SurfaceManager/mirsurface.h'
--- src/modules/Unity/SurfaceManager/mirsurface.h 2013-07-25 13:51:47 +0000
+++ src/modules/Unity/SurfaceManager/mirsurface.h 2013-07-30 15:59:58 +0000
@@ -3,7 +3,7 @@
33
4// Qt4// Qt
5#include <QQuickItem>5#include <QQuickItem>
6#include <QVector>6#include <QSet>
77
8// mir8// mir
9#include <mir/shell/surface.h>9#include <mir/shell/surface.h>
@@ -85,16 +85,17 @@
85 std::shared_ptr<mir::shell::Surface> m_surface;85 std::shared_ptr<mir::shell::Surface> m_surface;
8686
87private:87private:
88 // start of methods used by InputFilter88 // start of methods used by InputArea
89 void installInputArea(const InputArea* area);89 void installInputArea(const InputArea* area);
90 bool removeInputArea(const InputArea* area);90 bool removeInputArea(const InputArea* area);
91 bool enableInputArea(const InputArea* area, bool enable = true);91 bool enableInputArea(const InputArea* area, bool enable = true);
92 // end of methods used by InputFilter92 // end of methods used by InputArea
93
94 void updateMirInputRegion();
9395
94 bool disableMirInputArea(const mir::geometry::Rectangle& rect);96 bool disableMirInputArea(const mir::geometry::Rectangle& rect);
9597
96 QVector<const InputArea*> m_inputAreas;98 QSet<const InputArea*> m_inputAreas;
97 std::vector<mir::geometry::Rectangle> m_mirInputAreas;
9899
99 bool m_visible:true; //FIXME(greyback) state should be in Mir::Shell::Surface, not here100 bool m_visible:true; //FIXME(greyback) state should be in Mir::Shell::Surface, not here
100101
101102
=== modified file 'src/modules/Unity/SurfaceManager/mirsurfacemanager.cpp'
--- src/modules/Unity/SurfaceManager/mirsurfacemanager.cpp 2013-07-24 17:22:08 +0000
+++ src/modules/Unity/SurfaceManager/mirsurfacemanager.cpp 2013-07-30 15:59:58 +0000
@@ -14,8 +14,19 @@
1414
15namespace msh = mir::shell;15namespace msh = mir::shell;
1616
17MirSurfaceManager *MirSurfaceManager::the_surface_manager = nullptr;
18
19MirSurfaceManager* MirSurfaceManager::singleton()
20{
21 if (!the_surface_manager) {
22 the_surface_manager = new MirSurfaceManager();
23 }
24 return the_surface_manager;
25}
26
17MirSurfaceManager::MirSurfaceManager(QObject *parent)27MirSurfaceManager::MirSurfaceManager(QObject *parent)
18 : QObject(parent)28 : QObject(parent)
29 , m_shellSurface(nullptr)
19{30{
20 DLOG("MirSurfaceManager::MirSurfaceManager (this=%p)", this);31 DLOG("MirSurfaceManager::MirSurfaceManager (this=%p)", this);
2132
@@ -42,12 +53,29 @@
42 m_surfaces.clear();53 m_surfaces.clear();
43}54}
4455
56MirSurface *MirSurfaceManager::surfaceFor(std::shared_ptr<mir::shell::Surface> surface, QQuickItem *parent)
57{
58 auto it = m_surfaces.find(surface.get());
59 if (it != m_surfaces.end()) {
60 return *it;
61 }
62 if (!m_shellSurface) {
63 // If sessionCreatedSurface was not called assume it is the shell surface
64 m_shellSurface = new MirSurface(surface, parent);
65 m_surfaces.insert(surface.get(), m_shellSurface);
66 return m_shellSurface;
67 } else {
68 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());
69 return nullptr;
70 }
71}
72
45void MirSurfaceManager::sessionCreatedSurface(mir::shell::ApplicationSession const*, std::shared_ptr<mir::shell::Surface> const& surface)73void MirSurfaceManager::sessionCreatedSurface(mir::shell::ApplicationSession const*, std::shared_ptr<mir::shell::Surface> const& surface)
46{74{
47 DLOG("MirSurfaceManager::sessionCreatedSurface (this=%p) with surface name '%s'", this, surface->name().c_str());75 DLOG("MirSurfaceManager::sessionCreatedSurface (this=%p) with surface name '%s'", this, surface->name().c_str());
48 auto qmlSurface = new MirSurface(surface);76 auto qmlSurface = new MirSurface(surface);
4977
50 m_surfaces.prepend(qmlSurface);78 m_surfaces.insert(surface.get(), qmlSurface);
51 Q_EMIT surfaceCreated(qmlSurface);79 Q_EMIT surfaceCreated(qmlSurface);
52}80}
5381
@@ -55,12 +83,11 @@
55{83{
56 DLOG("MirSurfaceManager::sessionDestroyingSurface (this=%p) with surface name '%s'", this, surface->name().c_str());84 DLOG("MirSurfaceManager::sessionDestroyingSurface (this=%p) with surface name '%s'", this, surface->name().c_str());
5785
58 Q_FOREACH(MirSurface* s, m_surfaces) {86 auto it = m_surfaces.find(surface.get());
59 if (s->m_surface == surface) {87 if (it != m_surfaces.end()) {
60 m_surfaces.removeOne(s);88 m_surfaces.erase(it);
61 Q_EMIT surfaceDestroyed(s);89 Q_EMIT surfaceDestroyed(*it);
62 return;90 delete *it;
63 }
64 }91 }
6592
66 DLOG("MirSurfaceManager::sessionDestroyingSurface: unable to find MirSurface corresponding to surface '%s'", surface->name().c_str());93 DLOG("MirSurfaceManager::sessionDestroyingSurface: unable to find MirSurface corresponding to surface '%s'", surface->name().c_str());
6794
=== modified file 'src/modules/Unity/SurfaceManager/mirsurfacemanager.h'
--- src/modules/Unity/SurfaceManager/mirsurfacemanager.h 2013-07-24 17:22:08 +0000
+++ src/modules/Unity/SurfaceManager/mirsurfacemanager.h 2013-07-30 15:59:58 +0000
@@ -17,11 +17,15 @@
17 Q_OBJECT17 Q_OBJECT
1818
19public:19public:
20 static MirSurfaceManager* singleton();
21
20 MirSurfaceManager(QObject *parent = 0);22 MirSurfaceManager(QObject *parent = 0);
21 ~MirSurfaceManager();23 ~MirSurfaceManager();
2224
23 MirSurface* shellSurface() const;25 MirSurface* shellSurface() const;
2426
27 MirSurface *surfaceFor(std::shared_ptr<mir::shell::Surface> surface, QQuickItem *parent = 0);
28
25Q_SIGNALS:29Q_SIGNALS:
26 void surfaceCreated(MirSurface* surface);30 void surfaceCreated(MirSurface* surface);
27 void surfaceDestroyed(MirSurface* surface);31 void surfaceDestroyed(MirSurface* surface);
@@ -33,8 +37,10 @@
33 void sessionDestroyingSurface(mir::shell::ApplicationSession const*, std::shared_ptr<mir::shell::Surface> const&);37 void sessionDestroyingSurface(mir::shell::ApplicationSession const*, std::shared_ptr<mir::shell::Surface> const&);
3438
35private:39private:
36 QList<MirSurface*> m_surfaces;40 QHash<mir::shell::Surface *, MirSurface *> m_surfaces;
41 MirSurface* m_shellSurface;
37 ShellServerConfiguration* m_mirServer;42 ShellServerConfiguration* m_mirServer;
43 static MirSurfaceManager *the_surface_manager;
38};44};
3945
40#endif // MIR_SURFACE_MANAGER_H46#endif // MIR_SURFACE_MANAGER_H
4147
=== modified file 'src/modules/Unity/SurfaceManager/plugin.cpp'
--- src/modules/Unity/SurfaceManager/plugin.cpp 2013-07-19 17:29:44 +0000
+++ src/modules/Unity/SurfaceManager/plugin.cpp 2013-07-30 15:59:58 +0000
@@ -8,7 +8,7 @@
8 Q_UNUSED(engine);8 Q_UNUSED(engine);
9 Q_UNUSED(scriptEngine);9 Q_UNUSED(scriptEngine);
10 DLOG("surfaceManagerSingleton (engine=%p, scriptEngine=%p)", engine, scriptEngine);10 DLOG("surfaceManagerSingleton (engine=%p, scriptEngine=%p)", engine, scriptEngine);
11 return new MirSurfaceManager();11 return MirSurfaceManager::singleton();
12}12}
1313
14class UbuntuApplicationPlugin : public QQmlExtensionPlugin {14class UbuntuApplicationPlugin : public QQmlExtensionPlugin {

Subscribers

People subscribed via source and target branches