Merge lp:~gerboland/miral/add-input-method-to-window-model into lp:miral

Proposed by Gerry Boland
Status: Merged
Merged at revision: 322
Proposed branch: lp:~gerboland/miral/add-input-method-to-window-model
Merge into: lp:miral
Prerequisite: lp:~gerboland/miral/fix-windowmanager-tests
Diff against target: 216 lines (+114/-2)
5 files modified
miral-qt/src/common/windowmodelnotifierinterface.h (+4/-0)
miral-qt/src/modules/Unity/Application/windowmodel.cpp (+23/-1)
miral-qt/src/modules/Unity/Application/windowmodel.h (+10/-1)
miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp (+11/-0)
miral-qt/tests/modules/WindowManager/windowmodel_test.cpp (+66/-0)
To merge this branch: bzr merge lp:~gerboland/miral/add-input-method-to-window-model
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+305285@code.launchpad.net

Commit message

[miral-qt] Add inputMethodSurface property to WindowManager

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

Looks good (modulo discussion in prerequisite)

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-09-08 14:00:59 +0000
3+++ miral-qt/src/common/windowmodelnotifierinterface.h 2016-09-08 23:46:50 +0000
4@@ -91,6 +91,10 @@
5 void windowInfoChanged(const qtmir::WindowInfo, const int index);
6 void windowsRaised(const QVector<int> indices);
7
8+ // Assuming only 1 input method surface for now
9+ void inputMethodWindowAdded(const qtmir::NewWindow);
10+ void inputMethodWindowRemoved();
11+
12 private:
13 Q_DISABLE_COPY(WindowModelNotifierInterface)
14 };
15
16=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.cpp'
17--- miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-09-08 14:00:59 +0000
18+++ miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-09-08 23:46:50 +0000
19@@ -30,7 +30,6 @@
20 using namespace qtmir;
21
22 WindowModel::WindowModel()
23- : m_focusedWindow(nullptr)
24 {
25 auto nativeInterface = dynamic_cast<NativeInterface*>(QGuiApplication::platformNativeInterface());
26
27@@ -60,6 +59,10 @@
28 connect(notifier, &WindowModelNotifierInterface::windowFocused, this, &WindowModel::onWindowFocused, Qt::QueuedConnection);
29 connect(notifier, &WindowModelNotifierInterface::windowInfoChanged, this, &WindowModel::onWindowInfoChanged, Qt::QueuedConnection);
30 connect(notifier, &WindowModelNotifierInterface::windowsRaised, this, &WindowModel::onWindowsRaised, Qt::QueuedConnection);
31+ connect(notifier, &WindowModelNotifierInterface::inputMethodWindowAdded,
32+ this, &WindowModel::onInputMethodWindowAdded, Qt::QueuedConnection);
33+ connect(notifier, &WindowModelNotifierInterface::inputMethodWindowRemoved,
34+ this, &WindowModel::onInputMethodWindowRemoved, Qt::QueuedConnection);
35 }
36
37 QHash<int, QByteArray> WindowModel::roleNames() const
38@@ -120,6 +123,25 @@
39 Q_EMIT dataChanged(row, row, QVector<int>() << SurfaceRole);
40 }
41
42+void WindowModel::onInputMethodWindowAdded(const NewWindow windowInfo)
43+{
44+ if (m_inputMethodSurface) {
45+ qDebug("Multiple Input Method Surfaces created, removing the old one!");
46+ delete m_inputMethodSurface;
47+ }
48+ m_inputMethodSurface = new MirSurface(windowInfo, m_windowController);
49+ Q_EMIT inputMethodSurfaceChanged(m_inputMethodSurface);
50+}
51+
52+void WindowModel::onInputMethodWindowRemoved()
53+{
54+ if (m_inputMethodSurface) {
55+ delete m_inputMethodSurface;
56+ m_inputMethodSurface = nullptr;
57+ Q_EMIT inputMethodSurfaceChanged(m_inputMethodSurface);
58+ }
59+}
60+
61 void WindowModel::onWindowsRaised(QVector<int> indices)
62 {
63 const int modelCount = m_windowModel.count();
64
65=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.h'
66--- miral-qt/src/modules/Unity/Application/windowmodel.h 2016-09-08 14:00:59 +0000
67+++ miral-qt/src/modules/Unity/Application/windowmodel.h 2016-09-08 23:46:50 +0000
68@@ -32,6 +32,8 @@
69
70 Q_PROPERTY(int count READ count NOTIFY countChanged)
71
72+ Q_PROPERTY(MirSurfaceInterface* inputMethodSurface READ inputMethodSurface NOTIFY inputMethodSurfaceChanged)
73+
74 public:
75 enum Roles {
76 SurfaceRole = Qt::UserRole
77@@ -49,8 +51,11 @@
78
79 int count() const { return rowCount(); }
80
81+ MirSurfaceInterface* inputMethodSurface() const { return m_inputMethodSurface; }
82+
83 Q_SIGNALS:
84 void countChanged();
85+ void inputMethodSurfaceChanged(MirSurfaceInterface* inputMethodSurface);
86
87 private Q_SLOTS:
88 void onWindowAdded(const NewWindow windowInfo, const int index);
89@@ -61,12 +66,16 @@
90 void onWindowInfoChanged(const WindowInfo windowInfo, const int index);
91 void onWindowsRaised(const QVector<int> indices);
92
93+ void onInputMethodWindowAdded(const NewWindow windowInfo);
94+ void onInputMethodWindowRemoved();
95+
96 private:
97 void connectToWindowModelNotifier(WindowModelNotifierInterface *notifier);
98
99 QVector<MirSurfaceInterface *> m_windowModel;
100 WindowControllerInterface *m_windowController;
101- MirSurfaceInterface* m_focusedWindow;
102+ MirSurfaceInterface* m_focusedWindow{nullptr};
103+ MirSurfaceInterface* m_inputMethodSurface{nullptr};
104 };
105
106 } // namespace qtmir
107
108=== modified file 'miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp'
109--- miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp 2016-09-08 14:00:59 +0000
110+++ miral-qt/src/platforms/mirserver/windowmodelnotifier.cpp 2016-09-08 23:46:50 +0000
111@@ -43,6 +43,12 @@
112
113 void WindowModelNotifier::addWindow(const miral::WindowInfo &windowInfo, const std::string &persistentId)
114 {
115+ if (windowInfo.type() == mir_surface_type_inputmethod) {
116+ NewWindow newWindowInfo{windowInfo};
117+ Q_EMIT inputMethodWindowAdded(newWindowInfo);
118+ return;
119+ }
120+
121 auto stackPosition = m_windowStack.count();
122 m_windowStack.push_back(windowInfo.window()); // ASSUMPTION: Mir should tell us where in stack
123
124@@ -52,6 +58,11 @@
125
126 void WindowModelNotifier::removeWindow(const miral::WindowInfo &windowInfo)
127 {
128+ if (windowInfo.type() == mir_surface_type_inputmethod) {
129+ Q_EMIT inputMethodWindowRemoved();
130+ return;
131+ }
132+
133 const int pos = m_windowStack.indexOf(windowInfo.window());
134 if (pos < 0) {
135 qDebug("Unknown window removed");
136
137=== modified file 'miral-qt/tests/modules/WindowManager/windowmodel_test.cpp'
138--- miral-qt/tests/modules/WindowManager/windowmodel_test.cpp 2016-09-08 23:46:50 +0000
139+++ miral-qt/tests/modules/WindowManager/windowmodel_test.cpp 2016-09-08 23:46:50 +0000
140@@ -69,6 +69,16 @@
141 return miral::WindowInfo{window, windowSpec};
142 }
143
144+ miral::WindowInfo createMirALWindowInfoForInputMethod()
145+ {
146+ const miral::Application app{stubSession};
147+ const miral::Window window{app, stubSurface};
148+
149+ ms::SurfaceCreationParameters windowSpec;
150+ windowSpec.of_type(mir_surface_type_inputmethod);
151+ return miral::WindowInfo{window, windowSpec};
152+ }
153+
154 MirSurface *getMirSurfaceFromModel(const WindowModel &model, int index)
155 {
156 flushEvents();
157@@ -672,3 +682,59 @@
158 // Ensure other window untouched
159 EXPECT_EQ(fixedSize, surface->size());
160 }
161+
162+/*
163+ * Test: that the WindowModelNotifier.addWindow for an Input Method Window causes
164+ * the Qt-side WindowModel to register the input method surface
165+ */
166+TEST_F(WindowModelTest, WhenAddInputMethodWindowNotifiedModelEmitsInputMethodChangedSignal)
167+{
168+ WindowModelNotifier notifier;
169+ WindowModel model(&notifier, nullptr); // no need for controller in this testcase
170+
171+ auto mirWindowInfo = createMirALWindowInfoForInputMethod();
172+
173+ QSignalSpy spyCountChanged(&model, SIGNAL(inputMethodSurfaceChanged(MirSurfaceInterface*)));
174+
175+ notifier.addWindow(mirWindowInfo);
176+ flushEvents();
177+
178+ EXPECT_EQ(1, spyCountChanged.count());
179+}
180+
181+/*
182+ * Test: that the WindowModelNotifier.addWindow for an Input Method Window causes
183+ * the Qt-side WindowModel::inputMethodSurface property to be correctly set
184+ */
185+TEST_F(WindowModelTest, WhenAddInputMethodWindowNotifiedModelPropertyHasCorrectWindow)
186+{
187+ WindowModelNotifier notifier;
188+ WindowModel model(&notifier, nullptr); // no need for controller in this testcase
189+
190+ auto mirWindowInfo = createMirALWindowInfoForInputMethod();
191+
192+ notifier.addWindow(mirWindowInfo);
193+ flushEvents();
194+
195+ auto miralWindow = static_cast<MirSurface*>(model.inputMethodSurface())->window();
196+ EXPECT_EQ(mirWindowInfo.window(), miralWindow);
197+}
198+
199+/*
200+ * Test: that the WindowModelNotifier.removeWindow for an Input Method Window causes
201+ * the Qt-side WindowModel to reset the WindowModel::inputMethodSurface property to null
202+ */
203+TEST_F(WindowModelTest, WhenRemoveInputMethodWindowNotifiedModelPropertyReset)
204+{
205+ WindowModelNotifier notifier;
206+ WindowModel model(&notifier, nullptr); // no need for controller in this testcase
207+
208+ auto mirWindowInfo = createMirALWindowInfoForInputMethod();
209+ notifier.addWindow(mirWindowInfo);
210+
211+ // Test removing the window
212+ notifier.removeWindow(mirWindowInfo);
213+ flushEvents();
214+
215+ EXPECT_EQ(nullptr, model.inputMethodSurface());
216+}

Subscribers

People subscribed via source and target branches