Merge lp:~dandrader/qtmir/miral-surfacemanager into lp:~unity-team/qtmir/miral-qt-integration
- miral-surfacemanager
- Merge into miral-qt-integration
Proposed by
Daniel d'Andrada
Status: | Merged |
---|---|
Approved by: | Gerry Boland |
Approved revision: | 579 |
Merged at revision: | 581 |
Proposed branch: | lp:~dandrader/qtmir/miral-surfacemanager |
Merge into: | lp:~unity-team/qtmir/miral-qt-integration |
Diff against target: |
1582 lines (+261/-1156) 13 files modified
src/modules/Unity/Application/CMakeLists.txt (+2/-4) src/modules/Unity/Application/application.h (+1/-2) src/modules/Unity/Application/application_manager.cpp (+11/-0) src/modules/Unity/Application/application_manager.h (+6/-5) src/modules/Unity/Application/applicationmanagerinterface.h (+0/-35) src/modules/Unity/Application/mirsurfaceinterface.h (+0/-1) src/modules/Unity/Application/plugin.cpp (+3/-4) src/modules/Unity/Application/surfacemanager.cpp (+166/-0) src/modules/Unity/Application/surfacemanager.h (+72/-0) src/modules/Unity/Application/toplevelwindowmodel.cpp (+0/-691) src/modules/Unity/Application/toplevelwindowmodel.h (+0/-161) src/modules/Unity/Application/window.cpp (+0/-186) src/modules/Unity/Application/window.h (+0/-67) |
To merge this branch: | bzr merge lp:~dandrader/qtmir/miral-surfacemanager |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gerry Boland (community) | Approve | ||
Review via email: mp+310909@code.launchpad.net |
Commit message
Move TopLevelWindowModel out of qtmir. Export a SurfaceManager instead
Description of the change
Dramatically improves the interface between qtmir and unity8
Needs:
https:/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/modules/Unity/Application/CMakeLists.txt' | |||
2 | --- src/modules/Unity/Application/CMakeLists.txt 2016-11-03 20:17:46 +0000 | |||
3 | +++ src/modules/Unity/Application/CMakeLists.txt 2016-11-15 17:55:38 +0000 | |||
4 | @@ -45,14 +45,13 @@ | |||
5 | 45 | session.cpp | 45 | session.cpp |
6 | 46 | sessionmanager.cpp | 46 | sessionmanager.cpp |
7 | 47 | sharedwakelock.cpp | 47 | sharedwakelock.cpp |
8 | 48 | surfacemanager.cpp | ||
9 | 48 | upstart/applicationinfo.cpp | 49 | upstart/applicationinfo.cpp |
10 | 49 | upstart/taskcontroller.cpp | 50 | upstart/taskcontroller.cpp |
11 | 50 | timer.cpp | 51 | timer.cpp |
12 | 51 | timesource.cpp | 52 | timesource.cpp |
13 | 52 | toplevelwindowmodel.cpp | ||
14 | 53 | tracepoints.c | 53 | tracepoints.c |
15 | 54 | settings.cpp | 54 | settings.cpp |
16 | 55 | window.cpp | ||
17 | 56 | windowmodel.cpp | 55 | windowmodel.cpp |
18 | 57 | # We need to run moc on these headers | 56 | # We need to run moc on these headers |
19 | 58 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h | 57 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h |
20 | @@ -61,8 +60,7 @@ | |||
21 | 61 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h | 60 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h |
22 | 62 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceItemInterface.h | 61 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceItemInterface.h |
23 | 63 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h | 62 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h |
26 | 64 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/TopLevelWindowModelInterface.h | 63 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/SurfaceManagerInterface.h |
25 | 65 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/WindowInterface.h | ||
27 | 66 | # Feed the automoc monster | 64 | # Feed the automoc monster |
28 | 67 | session_interface.h | 65 | session_interface.h |
29 | 68 | applicationinfo.h | 66 | applicationinfo.h |
30 | 69 | 67 | ||
31 | === modified file 'src/modules/Unity/Application/application.h' | |||
32 | --- src/modules/Unity/Application/application.h 2016-11-03 20:17:46 +0000 | |||
33 | +++ src/modules/Unity/Application/application.h 2016-11-15 17:55:38 +0000 | |||
34 | @@ -103,6 +103,7 @@ | |||
35 | 103 | unity::shell::application::MirSurfaceListInterface* surfaceList() const override; | 103 | unity::shell::application::MirSurfaceListInterface* surfaceList() const override; |
36 | 104 | unity::shell::application::MirSurfaceListInterface* promptSurfaceList() const override; | 104 | unity::shell::application::MirSurfaceListInterface* promptSurfaceList() const override; |
37 | 105 | int surfaceCount() const override { return surfaceList()->count(); } | 105 | int surfaceCount() const override { return surfaceList()->count(); } |
38 | 106 | void close() override; | ||
39 | 106 | 107 | ||
40 | 107 | ProcessState processState() const { return m_processState; } | 108 | ProcessState processState() const { return m_processState; } |
41 | 108 | void setProcessState(ProcessState value); | 109 | void setProcessState(ProcessState value); |
42 | @@ -119,8 +120,6 @@ | |||
43 | 119 | 120 | ||
44 | 120 | pid_t pid() const; | 121 | pid_t pid() const; |
45 | 121 | 122 | ||
46 | 122 | void close(); | ||
47 | 123 | |||
48 | 124 | // internal as in "not exposed in unity-api", so qtmir-internal. | 123 | // internal as in "not exposed in unity-api", so qtmir-internal. |
49 | 125 | InternalState internalState() const { return m_state; } | 124 | InternalState internalState() const { return m_state; } |
50 | 126 | 125 | ||
51 | 127 | 126 | ||
52 | === modified file 'src/modules/Unity/Application/application_manager.cpp' | |||
53 | --- src/modules/Unity/Application/application_manager.cpp 2016-11-03 20:17:46 +0000 | |||
54 | +++ src/modules/Unity/Application/application_manager.cpp 2016-11-15 17:55:38 +0000 | |||
55 | @@ -577,6 +577,17 @@ | |||
56 | 577 | authorized = true; | 577 | authorized = true; |
57 | 578 | } | 578 | } |
58 | 579 | 579 | ||
59 | 580 | |||
60 | 581 | unityapi::ApplicationInfoInterface *ApplicationManager::findApplicationWithSurface(unityapi::MirSurfaceInterface* surface) | ||
61 | 582 | { | ||
62 | 583 | if (!surface) | ||
63 | 584 | return nullptr; | ||
64 | 585 | |||
65 | 586 | auto qtmirSurface = static_cast<qtmir::MirSurfaceInterface*>(surface); | ||
66 | 587 | |||
67 | 588 | return findApplicationWithPid(miral::pid_of(qtmirSurface->session()->session())); | ||
68 | 589 | } | ||
69 | 590 | |||
70 | 580 | Application* ApplicationManager::findApplicationWithSession(const std::shared_ptr<ms::Session> &session) | 591 | Application* ApplicationManager::findApplicationWithSession(const std::shared_ptr<ms::Session> &session) |
71 | 581 | { | 592 | { |
72 | 582 | if (!session) | 593 | if (!session) |
73 | 583 | 594 | ||
74 | === modified file 'src/modules/Unity/Application/application_manager.h' | |||
75 | --- src/modules/Unity/Application/application_manager.h 2016-11-03 20:17:46 +0000 | |||
76 | +++ src/modules/Unity/Application/application_manager.h 2016-11-15 17:55:38 +0000 | |||
77 | @@ -26,9 +26,11 @@ | |||
78 | 26 | 26 | ||
79 | 27 | // local | 27 | // local |
80 | 28 | #include "application.h" | 28 | #include "application.h" |
81 | 29 | #include "applicationmanagerinterface.h" | ||
82 | 30 | #include "taskcontroller.h" | 29 | #include "taskcontroller.h" |
83 | 31 | 30 | ||
84 | 31 | // Unity API | ||
85 | 32 | #include <unity/shell/application/ApplicationManagerInterface.h> | ||
86 | 33 | |||
87 | 32 | namespace mir { | 34 | namespace mir { |
88 | 33 | namespace scene { | 35 | namespace scene { |
89 | 34 | class Session; | 36 | class Session; |
90 | @@ -53,7 +55,7 @@ | |||
91 | 53 | class SharedWakelock; | 55 | class SharedWakelock; |
92 | 54 | class SettingsInterface; | 56 | class SettingsInterface; |
93 | 55 | 57 | ||
95 | 56 | class ApplicationManager : public ApplicationManagerInterface | 58 | class ApplicationManager : public unity::shell::application::ApplicationManagerInterface |
96 | 57 | { | 59 | { |
97 | 58 | Q_OBJECT | 60 | Q_OBJECT |
98 | 59 | 61 | ||
99 | @@ -81,13 +83,11 @@ | |||
100 | 81 | QString focusedApplicationId() const override; | 83 | QString focusedApplicationId() const override; |
101 | 82 | Q_INVOKABLE qtmir::Application* get(int index) const override; | 84 | Q_INVOKABLE qtmir::Application* get(int index) const override; |
102 | 83 | Q_INVOKABLE qtmir::Application* findApplication(const QString &appId) const override; | 85 | Q_INVOKABLE qtmir::Application* findApplication(const QString &appId) const override; |
103 | 86 | unity::shell::application::ApplicationInfoInterface *findApplicationWithSurface(unity::shell::application::MirSurfaceInterface* surface) override; | ||
104 | 84 | Q_INVOKABLE bool requestFocusApplication(const QString &appId) override; | 87 | Q_INVOKABLE bool requestFocusApplication(const QString &appId) override; |
105 | 85 | Q_INVOKABLE qtmir::Application* startApplication(const QString &appId, const QStringList &arguments = QStringList()) override; | 88 | Q_INVOKABLE qtmir::Application* startApplication(const QString &appId, const QStringList &arguments = QStringList()) override; |
106 | 86 | Q_INVOKABLE bool stopApplication(const QString &appId) override; | 89 | Q_INVOKABLE bool stopApplication(const QString &appId) override; |
107 | 87 | 90 | ||
108 | 88 | // qtmir::ApplicationManagerInterface | ||
109 | 89 | Application* findApplicationWithSession(const std::shared_ptr<mir::scene::Session> &session) override; | ||
110 | 90 | |||
111 | 91 | // QAbstractListModel | 91 | // QAbstractListModel |
112 | 92 | int rowCount(const QModelIndex & parent = QModelIndex()) const override; | 92 | int rowCount(const QModelIndex & parent = QModelIndex()) const override; |
113 | 93 | QVariant data(const QModelIndex & index, int role) const override; | 93 | QVariant data(const QModelIndex & index, int role) const override; |
114 | @@ -119,6 +119,7 @@ | |||
115 | 119 | void onApplicationClosing(Application *application); | 119 | void onApplicationClosing(Application *application); |
116 | 120 | 120 | ||
117 | 121 | private: | 121 | private: |
118 | 122 | Application* findApplicationWithSession(const std::shared_ptr<mir::scene::Session> &session); | ||
119 | 122 | void setFocused(Application *application); | 123 | void setFocused(Application *application); |
120 | 123 | void add(Application *application); | 124 | void add(Application *application); |
121 | 124 | void remove(Application* application); | 125 | void remove(Application* application); |
122 | 125 | 126 | ||
123 | === removed file 'src/modules/Unity/Application/applicationmanagerinterface.h' | |||
124 | --- src/modules/Unity/Application/applicationmanagerinterface.h 2016-11-03 20:17:46 +0000 | |||
125 | +++ src/modules/Unity/Application/applicationmanagerinterface.h 1970-01-01 00:00:00 +0000 | |||
126 | @@ -1,35 +0,0 @@ | |||
127 | 1 | /* | ||
128 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
129 | 3 | * | ||
130 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
131 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
132 | 6 | * the Free Software Foundation. | ||
133 | 7 | * | ||
134 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
135 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
136 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
137 | 11 | * Lesser General Public License for more details. | ||
138 | 12 | * | ||
139 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
140 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
141 | 15 | */ | ||
142 | 16 | |||
143 | 17 | #ifndef QTMIR_APPLICATION_MANAGER_INTERFACE_H | ||
144 | 18 | #define QTMIR_APPLICATION_MANAGER_INTERFACE_H | ||
145 | 19 | |||
146 | 20 | // Unity API | ||
147 | 21 | #include <unity/shell/application/ApplicationManagerInterface.h> | ||
148 | 22 | |||
149 | 23 | namespace qtmir { | ||
150 | 24 | |||
151 | 25 | class ApplicationManagerInterface : public unity::shell::application::ApplicationManagerInterface | ||
152 | 26 | { | ||
153 | 27 | public: | ||
154 | 28 | ApplicationManagerInterface(QObject *parent) : unity::shell::application::ApplicationManagerInterface(parent) {} | ||
155 | 29 | |||
156 | 30 | virtual Application* findApplicationWithSession(const std::shared_ptr<mir::scene::Session> &session) = 0; | ||
157 | 31 | }; | ||
158 | 32 | |||
159 | 33 | } // namespace qtmir | ||
160 | 34 | |||
161 | 35 | #endif // QTMIR_APPLICATION_MANAGER_INTERFACE_H | ||
162 | 36 | 0 | ||
163 | === modified file 'src/modules/Unity/Application/mirsurfaceinterface.h' | |||
164 | --- src/modules/Unity/Application/mirsurfaceinterface.h 2016-11-03 20:17:46 +0000 | |||
165 | +++ src/modules/Unity/Application/mirsurfaceinterface.h 2016-11-15 17:55:38 +0000 | |||
166 | @@ -116,7 +116,6 @@ | |||
167 | 116 | void ready(); | 116 | void ready(); |
168 | 117 | void cursorChanged(const QCursor &cursor); | 117 | void cursorChanged(const QCursor &cursor); |
169 | 118 | void raiseRequested(); | 118 | void raiseRequested(); |
170 | 119 | void closeRequested(); | ||
171 | 120 | void framesPosted(); | 119 | void framesPosted(); |
172 | 121 | void isBeingDisplayedChanged(); | 120 | void isBeingDisplayedChanged(); |
173 | 122 | void frameDropped(); | 121 | void frameDropped(); |
174 | 123 | 122 | ||
175 | === modified file 'src/modules/Unity/Application/plugin.cpp' | |||
176 | --- src/modules/Unity/Application/plugin.cpp 2016-11-03 20:17:46 +0000 | |||
177 | +++ src/modules/Unity/Application/plugin.cpp 2016-11-15 17:55:38 +0000 | |||
178 | @@ -23,9 +23,8 @@ | |||
179 | 23 | #include "mirsurfaceinterface.h" | 23 | #include "mirsurfaceinterface.h" |
180 | 24 | #include "mirsurfaceitem.h" | 24 | #include "mirsurfaceitem.h" |
181 | 25 | #include "mirsurfacelistmodel.h" | 25 | #include "mirsurfacelistmodel.h" |
182 | 26 | #include "toplevelwindowmodel.h" | ||
183 | 27 | #include "window.h" | ||
184 | 28 | #include "windowmodel.h" | 26 | #include "windowmodel.h" |
185 | 27 | #include "surfacemanager.h" | ||
186 | 29 | 28 | ||
187 | 30 | // platforms/mirserver | 29 | // platforms/mirserver |
188 | 31 | #include <mirsingleton.h> | 30 | #include <mirsingleton.h> |
189 | @@ -65,8 +64,8 @@ | |||
190 | 65 | qRegisterMetaType<qtmir::Application*>("Application*"); | 64 | qRegisterMetaType<qtmir::Application*>("Application*"); |
191 | 66 | qRegisterMetaType<unity::shell::application::MirSurfaceInterface*>("MirSurfaceInterface*"); | 65 | qRegisterMetaType<unity::shell::application::MirSurfaceInterface*>("MirSurfaceInterface*"); |
192 | 67 | qRegisterMetaType<unity::shell::application::MirSurfaceListInterface*>("unity::shell::application::MirSurfaceListInterface*"); | 66 | qRegisterMetaType<unity::shell::application::MirSurfaceListInterface*>("unity::shell::application::MirSurfaceListInterface*"); |
193 | 67 | qRegisterMetaType<unity::shell::application::SurfaceManagerInterface*>("unity::shell::application::SurfaceManagerInterface*"); | ||
194 | 68 | qRegisterMetaType<MirSurfaceAttrib>("MirSurfaceAttrib"); | 68 | qRegisterMetaType<MirSurfaceAttrib>("MirSurfaceAttrib"); |
195 | 69 | qRegisterMetaType<unity::shell::application::WindowInterface*>("unity::shell::application::WindowInterface*"); | ||
196 | 70 | 69 | ||
197 | 71 | qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>( | 70 | qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>( |
198 | 72 | uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML"); | 71 | uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML"); |
199 | @@ -80,9 +79,9 @@ | |||
200 | 80 | uri, 0, 1, "MirSurface", "MirSurface can't be instantiated from QML"); | 79 | uri, 0, 1, "MirSurface", "MirSurface can't be instantiated from QML"); |
201 | 81 | qmlRegisterType<qtmir::MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem"); | 80 | qmlRegisterType<qtmir::MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem"); |
202 | 82 | qmlRegisterSingletonType<qtmir::Mir>(uri, 0, 1, "Mir", mirSingleton); | 81 | qmlRegisterSingletonType<qtmir::Mir>(uri, 0, 1, "Mir", mirSingleton); |
203 | 82 | qmlRegisterType<qtmir::SurfaceManager>(uri, 0, 1, "SurfaceManager"); | ||
204 | 83 | 83 | ||
205 | 84 | qmlRegisterType<qtmir::WindowModel>(uri, 0, 1, "WindowModel"); | 84 | qmlRegisterType<qtmir::WindowModel>(uri, 0, 1, "WindowModel"); |
206 | 85 | qmlRegisterType<qtmir::TopLevelWindowModel>(uri, 0, 1, "TopLevelWindowModel"); | ||
207 | 86 | } | 85 | } |
208 | 87 | 86 | ||
209 | 88 | virtual void initializeEngine(QQmlEngine *engine, const char *uri) | 87 | virtual void initializeEngine(QQmlEngine *engine, const char *uri) |
210 | 89 | 88 | ||
211 | === added file 'src/modules/Unity/Application/surfacemanager.cpp' | |||
212 | --- src/modules/Unity/Application/surfacemanager.cpp 1970-01-01 00:00:00 +0000 | |||
213 | +++ src/modules/Unity/Application/surfacemanager.cpp 2016-11-15 17:55:38 +0000 | |||
214 | @@ -0,0 +1,166 @@ | |||
215 | 1 | /* | ||
216 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
217 | 3 | * | ||
218 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
219 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
220 | 6 | * the Free Software Foundation. | ||
221 | 7 | * | ||
222 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
223 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
224 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
225 | 11 | * Lesser General Public License for more details. | ||
226 | 12 | * | ||
227 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
228 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
229 | 15 | */ | ||
230 | 16 | |||
231 | 17 | #include "surfacemanager.h" | ||
232 | 18 | |||
233 | 19 | #include "mirsurface.h" | ||
234 | 20 | #include "sessionmanager.h" | ||
235 | 21 | |||
236 | 22 | // mirserver | ||
237 | 23 | #include "nativeinterface.h" | ||
238 | 24 | |||
239 | 25 | // Qt | ||
240 | 26 | #include <QGuiApplication> | ||
241 | 27 | |||
242 | 28 | Q_LOGGING_CATEGORY(QTMIR_SURFACEMANAGER, "qtmir.surfacemanager", QtDebugMsg) | ||
243 | 29 | |||
244 | 30 | #define DEBUG_MSG qCDebug(QTMIR_SURFACEMANAGER).nospace().noquote() << __func__ | ||
245 | 31 | |||
246 | 32 | using namespace qtmir; | ||
247 | 33 | namespace unityapi = unity::shell::application; | ||
248 | 34 | |||
249 | 35 | SurfaceManager::SurfaceManager(QObject *) | ||
250 | 36 | { | ||
251 | 37 | DEBUG_MSG << "()"; | ||
252 | 38 | |||
253 | 39 | auto nativeInterface = dynamic_cast<NativeInterface*>(QGuiApplication::platformNativeInterface()); | ||
254 | 40 | |||
255 | 41 | if (!nativeInterface) { | ||
256 | 42 | qFatal("ERROR: Unity.Application QML plugin requires use of the 'mirserver' QPA plugin"); | ||
257 | 43 | } | ||
258 | 44 | |||
259 | 45 | m_windowController = static_cast<WindowControllerInterface*>(nativeInterface->nativeResourceForIntegration("WindowController")); | ||
260 | 46 | |||
261 | 47 | auto windowModel = static_cast<WindowModelNotifier*>(nativeInterface->nativeResourceForIntegration("WindowModelNotifier")); | ||
262 | 48 | connectToWindowModelNotifier(windowModel); | ||
263 | 49 | |||
264 | 50 | m_sessionManager = SessionManager::singleton(); | ||
265 | 51 | } | ||
266 | 52 | |||
267 | 53 | void SurfaceManager::connectToWindowModelNotifier(WindowModelNotifier *notifier) | ||
268 | 54 | { | ||
269 | 55 | connect(notifier, &WindowModelNotifier::windowAdded, this, &SurfaceManager::onWindowAdded, Qt::QueuedConnection); | ||
270 | 56 | connect(notifier, &WindowModelNotifier::windowRemoved, this, &SurfaceManager::onWindowRemoved, Qt::QueuedConnection); | ||
271 | 57 | connect(notifier, &WindowModelNotifier::windowReady, this, &SurfaceManager::onWindowReady, Qt::QueuedConnection); | ||
272 | 58 | connect(notifier, &WindowModelNotifier::windowMoved, this, &SurfaceManager::onWindowMoved, Qt::QueuedConnection); | ||
273 | 59 | connect(notifier, &WindowModelNotifier::windowStateChanged, this, &SurfaceManager::onWindowStateChanged, Qt::QueuedConnection); | ||
274 | 60 | connect(notifier, &WindowModelNotifier::windowFocusChanged, this, &SurfaceManager::onWindowFocusChanged, Qt::QueuedConnection); | ||
275 | 61 | connect(notifier, &WindowModelNotifier::windowsRaised, this, &SurfaceManager::onWindowsRaised, Qt::QueuedConnection); | ||
276 | 62 | connect(notifier, &WindowModelNotifier::modificationsStarted, this, &SurfaceManager::modificationsStarted, Qt::QueuedConnection); | ||
277 | 63 | connect(notifier, &WindowModelNotifier::modificationsEnded, this, &SurfaceManager::modificationsEnded, Qt::QueuedConnection); | ||
278 | 64 | } | ||
279 | 65 | |||
280 | 66 | void SurfaceManager::rememberMirSurface(MirSurface *surface) | ||
281 | 67 | { | ||
282 | 68 | m_allSurfaces.append(surface); | ||
283 | 69 | } | ||
284 | 70 | |||
285 | 71 | void SurfaceManager::forgetMirSurface(const miral::Window &window) | ||
286 | 72 | { | ||
287 | 73 | for (int i = 0; i < m_allSurfaces.count(); ++i) { | ||
288 | 74 | if (m_allSurfaces[i]->window() == window) { | ||
289 | 75 | m_allSurfaces.removeAt(i); | ||
290 | 76 | return; | ||
291 | 77 | } | ||
292 | 78 | } | ||
293 | 79 | } | ||
294 | 80 | void SurfaceManager::onWindowAdded(const NewWindow &window) | ||
295 | 81 | { | ||
296 | 82 | auto mirSession = window.windowInfo.window().application(); | ||
297 | 83 | SessionInterface* session = m_sessionManager->findSession(mirSession.get()); | ||
298 | 84 | |||
299 | 85 | auto surface = new MirSurface(window, m_windowController, session); | ||
300 | 86 | rememberMirSurface(surface); | ||
301 | 87 | |||
302 | 88 | if (session) | ||
303 | 89 | session->registerSurface(surface); | ||
304 | 90 | |||
305 | 91 | Q_EMIT surfaceCreated(surface); | ||
306 | 92 | } | ||
307 | 93 | |||
308 | 94 | void SurfaceManager::onWindowRemoved(const miral::WindowInfo &windowInfo) | ||
309 | 95 | { | ||
310 | 96 | MirSurface *surface = find(windowInfo); | ||
311 | 97 | forgetMirSurface(windowInfo.window()); | ||
312 | 98 | surface->setLive(false); | ||
313 | 99 | } | ||
314 | 100 | |||
315 | 101 | MirSurface *SurfaceManager::find(const miral::WindowInfo &needle) const | ||
316 | 102 | { | ||
317 | 103 | return find(needle.window()); | ||
318 | 104 | } | ||
319 | 105 | |||
320 | 106 | MirSurface *SurfaceManager::find(const miral::Window &window) const | ||
321 | 107 | { | ||
322 | 108 | Q_FOREACH(const auto surface, m_allSurfaces) { | ||
323 | 109 | if (surface->window() == window) { | ||
324 | 110 | return surface; | ||
325 | 111 | } | ||
326 | 112 | } | ||
327 | 113 | return nullptr; | ||
328 | 114 | } | ||
329 | 115 | |||
330 | 116 | void SurfaceManager::onWindowReady(const miral::WindowInfo &windowInfo) | ||
331 | 117 | { | ||
332 | 118 | if (auto mirSurface = find(windowInfo)) { | ||
333 | 119 | mirSurface->setReady(); | ||
334 | 120 | } | ||
335 | 121 | } | ||
336 | 122 | |||
337 | 123 | void SurfaceManager::onWindowMoved(const miral::WindowInfo &windowInfo, const QPoint topLeft) | ||
338 | 124 | { | ||
339 | 125 | if (auto mirSurface = find(windowInfo)) { | ||
340 | 126 | mirSurface->setPosition(topLeft); | ||
341 | 127 | } | ||
342 | 128 | } | ||
343 | 129 | |||
344 | 130 | void SurfaceManager::onWindowFocusChanged(const miral::WindowInfo &windowInfo, bool focused) | ||
345 | 131 | { | ||
346 | 132 | if (auto mirSurface = find(windowInfo)) { | ||
347 | 133 | mirSurface->setFocused(focused); | ||
348 | 134 | } | ||
349 | 135 | } | ||
350 | 136 | |||
351 | 137 | void SurfaceManager::onWindowStateChanged(const miral::WindowInfo &windowInfo, Mir::State state) | ||
352 | 138 | { | ||
353 | 139 | if (auto mirSurface = find(windowInfo)) { | ||
354 | 140 | mirSurface->updateState(state); | ||
355 | 141 | } | ||
356 | 142 | } | ||
357 | 143 | |||
358 | 144 | void SurfaceManager::onWindowsRaised(const std::vector<miral::Window> &windows) | ||
359 | 145 | { | ||
360 | 146 | // sad inefficiency when crossing API boundaries (from miral to qt) | ||
361 | 147 | const int raiseCount = windows.size(); | ||
362 | 148 | QVector<unityapi::MirSurfaceInterface*> surfaces(raiseCount); | ||
363 | 149 | for (int i = 0; i < raiseCount; i++) { | ||
364 | 150 | auto mirSurface = find(windows[i]); | ||
365 | 151 | surfaces.append(mirSurface); | ||
366 | 152 | } | ||
367 | 153 | Q_EMIT surfacesRaised(surfaces); | ||
368 | 154 | } | ||
369 | 155 | |||
370 | 156 | void SurfaceManager::raise(unityapi::MirSurfaceInterface *surface) | ||
371 | 157 | { | ||
372 | 158 | auto qtmirSurface = static_cast<qtmir::MirSurface*>(surface); | ||
373 | 159 | m_windowController->raise(qtmirSurface->window()); | ||
374 | 160 | } | ||
375 | 161 | |||
376 | 162 | void SurfaceManager::activate(unityapi::MirSurfaceInterface *surface) | ||
377 | 163 | { | ||
378 | 164 | auto qtmirSurface = static_cast<qtmir::MirSurface*>(surface); | ||
379 | 165 | m_windowController->activate(qtmirSurface ? qtmirSurface->window() : miral::Window()); | ||
380 | 166 | } | ||
381 | 0 | 167 | ||
382 | === added file 'src/modules/Unity/Application/surfacemanager.h' | |||
383 | --- src/modules/Unity/Application/surfacemanager.h 1970-01-01 00:00:00 +0000 | |||
384 | +++ src/modules/Unity/Application/surfacemanager.h 2016-11-15 17:55:38 +0000 | |||
385 | @@ -0,0 +1,72 @@ | |||
386 | 1 | /* | ||
387 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
388 | 3 | * | ||
389 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
390 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
391 | 6 | * the Free Software Foundation. | ||
392 | 7 | * | ||
393 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
394 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
395 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
396 | 11 | * Lesser General Public License for more details. | ||
397 | 12 | * | ||
398 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
399 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
400 | 15 | */ | ||
401 | 16 | |||
402 | 17 | #ifndef QTMIR_SURFACEMANAGER_H | ||
403 | 18 | #define QTMIR_SURFACEMANAGER_H | ||
404 | 19 | |||
405 | 20 | // common | ||
406 | 21 | #include "windowmodelnotifier.h" | ||
407 | 22 | |||
408 | 23 | // Unity API | ||
409 | 24 | #include <unity/shell/application/SurfaceManagerInterface.h> | ||
410 | 25 | |||
411 | 26 | #include <QVector> | ||
412 | 27 | #include <QLoggingCategory> | ||
413 | 28 | |||
414 | 29 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_SURFACEMANAGER) | ||
415 | 30 | |||
416 | 31 | namespace qtmir { | ||
417 | 32 | |||
418 | 33 | class MirSurface; | ||
419 | 34 | class SessionManager; | ||
420 | 35 | class WindowControllerInterface; | ||
421 | 36 | |||
422 | 37 | class SurfaceManager : public unity::shell::application::SurfaceManagerInterface | ||
423 | 38 | { | ||
424 | 39 | Q_OBJECT | ||
425 | 40 | |||
426 | 41 | public: | ||
427 | 42 | explicit SurfaceManager(QObject *parent = 0); | ||
428 | 43 | virtual ~SurfaceManager() {} | ||
429 | 44 | |||
430 | 45 | void raise(unity::shell::application::MirSurfaceInterface *surface) override; | ||
431 | 46 | void activate(unity::shell::application::MirSurfaceInterface *surface) override; | ||
432 | 47 | |||
433 | 48 | private Q_SLOTS: | ||
434 | 49 | void onWindowAdded(const qtmir::NewWindow &windowInfo); | ||
435 | 50 | void onWindowRemoved(const miral::WindowInfo &windowInfo); | ||
436 | 51 | void onWindowReady(const miral::WindowInfo &windowInfo); | ||
437 | 52 | void onWindowMoved(const miral::WindowInfo &windowInfo, const QPoint topLeft); | ||
438 | 53 | void onWindowStateChanged(const miral::WindowInfo &windowInfo, Mir::State state); | ||
439 | 54 | void onWindowFocusChanged(const miral::WindowInfo &windowInfo, bool focused); | ||
440 | 55 | void onWindowsRaised(const std::vector<miral::Window> &windows); | ||
441 | 56 | |||
442 | 57 | private: | ||
443 | 58 | void connectToWindowModelNotifier(WindowModelNotifier *notifier); | ||
444 | 59 | void rememberMirSurface(MirSurface *surface); | ||
445 | 60 | void forgetMirSurface(const miral::Window &window); | ||
446 | 61 | MirSurface* find(const miral::WindowInfo &needle) const; | ||
447 | 62 | MirSurface* find(const miral::Window &needle) const; | ||
448 | 63 | |||
449 | 64 | QVector<MirSurface*> m_allSurfaces; | ||
450 | 65 | |||
451 | 66 | WindowControllerInterface *m_windowController; | ||
452 | 67 | SessionManager* m_sessionManager; | ||
453 | 68 | }; | ||
454 | 69 | |||
455 | 70 | } // namespace qtmir | ||
456 | 71 | |||
457 | 72 | #endif // QTMIR_SURFACEMANAGER_H | ||
458 | 0 | 73 | ||
459 | === removed file 'src/modules/Unity/Application/toplevelwindowmodel.cpp' | |||
460 | --- src/modules/Unity/Application/toplevelwindowmodel.cpp 2016-11-09 14:18:17 +0000 | |||
461 | +++ src/modules/Unity/Application/toplevelwindowmodel.cpp 1970-01-01 00:00:00 +0000 | |||
462 | @@ -1,691 +0,0 @@ | |||
463 | 1 | /* | ||
464 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
465 | 3 | * | ||
466 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
467 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
468 | 6 | * the Free Software Foundation. | ||
469 | 7 | * | ||
470 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
471 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
472 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
473 | 11 | * Lesser General Public License for more details. | ||
474 | 12 | * | ||
475 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
476 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
477 | 15 | */ | ||
478 | 16 | |||
479 | 17 | #include "toplevelwindowmodel.h" | ||
480 | 18 | |||
481 | 19 | #include "application.h" | ||
482 | 20 | #include "application_manager.h" | ||
483 | 21 | #include "mirsurface.h" | ||
484 | 22 | #include "sessionmanager.h" | ||
485 | 23 | |||
486 | 24 | // mirserver | ||
487 | 25 | #include "nativeinterface.h" | ||
488 | 26 | |||
489 | 27 | // Qt | ||
490 | 28 | #include <QGuiApplication> | ||
491 | 29 | #include <QDebug> | ||
492 | 30 | |||
493 | 31 | Q_LOGGING_CATEGORY(QTMIR_TOPLEVELWINDOWMODEL, "qtmir.toplevelwindowmodel", QtDebugMsg) | ||
494 | 32 | |||
495 | 33 | #define DEBUG_MSG qCDebug(QTMIR_TOPLEVELWINDOWMODEL).nospace().noquote() << __func__ | ||
496 | 34 | |||
497 | 35 | using namespace qtmir; | ||
498 | 36 | namespace unityapi = unity::shell::application; | ||
499 | 37 | |||
500 | 38 | TopLevelWindowModel::TopLevelWindowModel() | ||
501 | 39 | { | ||
502 | 40 | auto nativeInterface = dynamic_cast<NativeInterface*>(QGuiApplication::platformNativeInterface()); | ||
503 | 41 | |||
504 | 42 | if (!nativeInterface) { | ||
505 | 43 | qFatal("ERROR: Unity.Application QML plugin requires use of the 'mirserver' QPA plugin"); | ||
506 | 44 | } | ||
507 | 45 | |||
508 | 46 | m_windowController = static_cast<WindowControllerInterface*>(nativeInterface->nativeResourceForIntegration("WindowController")); | ||
509 | 47 | |||
510 | 48 | auto windowModel = static_cast<WindowModelNotifier*>(nativeInterface->nativeResourceForIntegration("WindowModelNotifier")); | ||
511 | 49 | connectToWindowModelNotifier(windowModel); | ||
512 | 50 | |||
513 | 51 | setApplicationManager(ApplicationManager::singleton()); | ||
514 | 52 | |||
515 | 53 | m_sessionManager = SessionManager::singleton(); | ||
516 | 54 | } | ||
517 | 55 | |||
518 | 56 | TopLevelWindowModel::TopLevelWindowModel(WindowModelNotifier *notifier, | ||
519 | 57 | WindowControllerInterface *controller) | ||
520 | 58 | : m_windowController(controller) | ||
521 | 59 | { | ||
522 | 60 | connectToWindowModelNotifier(notifier); | ||
523 | 61 | } | ||
524 | 62 | |||
525 | 63 | void TopLevelWindowModel::setApplicationManager(ApplicationManagerInterface* value) | ||
526 | 64 | { | ||
527 | 65 | if (m_applicationManager == value) { | ||
528 | 66 | return; | ||
529 | 67 | } | ||
530 | 68 | |||
531 | 69 | Q_ASSERT(m_modelState == IdleState); | ||
532 | 70 | m_modelState = ResettingState; | ||
533 | 71 | |||
534 | 72 | beginResetModel(); | ||
535 | 73 | |||
536 | 74 | if (m_applicationManager) { | ||
537 | 75 | m_windowModel.clear(); | ||
538 | 76 | disconnect(m_applicationManager, 0, this, 0); | ||
539 | 77 | } | ||
540 | 78 | |||
541 | 79 | m_applicationManager = value; | ||
542 | 80 | |||
543 | 81 | if (m_applicationManager) { | ||
544 | 82 | connect(m_applicationManager, &QAbstractItemModel::rowsInserted, | ||
545 | 83 | this, [this](const QModelIndex &/*parent*/, int first, int last) { | ||
546 | 84 | for (int i = first; i <= last; ++i) { | ||
547 | 85 | auto application = m_applicationManager->get(i); | ||
548 | 86 | addApplication(static_cast<Application*>(application)); | ||
549 | 87 | } | ||
550 | 88 | }); | ||
551 | 89 | |||
552 | 90 | connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved, | ||
553 | 91 | this, [this](const QModelIndex &/*parent*/, int first, int last) { | ||
554 | 92 | for (int i = first; i <= last; ++i) { | ||
555 | 93 | auto application = m_applicationManager->get(i); | ||
556 | 94 | removeApplication(static_cast<Application*>(application)); | ||
557 | 95 | } | ||
558 | 96 | }); | ||
559 | 97 | |||
560 | 98 | for (int i = 0; i < m_applicationManager->rowCount(); ++i) { | ||
561 | 99 | auto application = m_applicationManager->get(i); | ||
562 | 100 | addApplication(static_cast<Application*>(application)); | ||
563 | 101 | } | ||
564 | 102 | } | ||
565 | 103 | |||
566 | 104 | endResetModel(); | ||
567 | 105 | m_modelState = IdleState; | ||
568 | 106 | } | ||
569 | 107 | |||
570 | 108 | void TopLevelWindowModel::addApplication(Application *application) | ||
571 | 109 | { | ||
572 | 110 | DEBUG_MSG << "(" << application->appId() << ")"; | ||
573 | 111 | |||
574 | 112 | if (application->state() != unityapi::ApplicationInfoInterface::Stopped && application->surfaceList()->count() == 0) { | ||
575 | 113 | prependPlaceholder(application); | ||
576 | 114 | } | ||
577 | 115 | } | ||
578 | 116 | |||
579 | 117 | void TopLevelWindowModel::removeApplication(Application *application) | ||
580 | 118 | { | ||
581 | 119 | DEBUG_MSG << "(" << application->appId() << ")"; | ||
582 | 120 | |||
583 | 121 | Q_ASSERT(m_modelState == IdleState); | ||
584 | 122 | |||
585 | 123 | int i = 0; | ||
586 | 124 | while (i < m_windowModel.count()) { | ||
587 | 125 | if (m_windowModel.at(i).application == application) { | ||
588 | 126 | removeAt(i); | ||
589 | 127 | } else { | ||
590 | 128 | ++i; | ||
591 | 129 | } | ||
592 | 130 | } | ||
593 | 131 | } | ||
594 | 132 | |||
595 | 133 | void TopLevelWindowModel::prependPlaceholder(Application *application) | ||
596 | 134 | { | ||
597 | 135 | DEBUG_MSG << "(" << application->appId() << ")"; | ||
598 | 136 | |||
599 | 137 | prependSurfaceHelper(nullptr, application); | ||
600 | 138 | } | ||
601 | 139 | |||
602 | 140 | void TopLevelWindowModel::prependSurface(MirSurface *surface, Application *application) | ||
603 | 141 | { | ||
604 | 142 | Q_ASSERT(surface != nullptr); | ||
605 | 143 | |||
606 | 144 | bool filledPlaceholder = false; | ||
607 | 145 | for (int i = 0; i < m_windowModel.count() && !filledPlaceholder; ++i) { | ||
608 | 146 | ModelEntry &entry = m_windowModel[i]; | ||
609 | 147 | if (entry.application == application && entry.window->surface() == nullptr) { | ||
610 | 148 | entry.window->setSurface(surface); | ||
611 | 149 | connectSurface(surface); | ||
612 | 150 | DEBUG_MSG << " appId=" << application->appId() << " surface=" << surface | ||
613 | 151 | << ", filling out placeholder. after: " << toString(); | ||
614 | 152 | filledPlaceholder = true; | ||
615 | 153 | } | ||
616 | 154 | } | ||
617 | 155 | |||
618 | 156 | if (!filledPlaceholder) { | ||
619 | 157 | DEBUG_MSG << " appId=" << application->appId() << " surface=" << surface << ", adding new row"; | ||
620 | 158 | prependSurfaceHelper(surface, application); | ||
621 | 159 | } | ||
622 | 160 | } | ||
623 | 161 | |||
624 | 162 | void TopLevelWindowModel::prependSurfaceHelper(MirSurface *surface, Application *application) | ||
625 | 163 | { | ||
626 | 164 | if (m_modelState == IdleState) { | ||
627 | 165 | m_modelState = InsertingState; | ||
628 | 166 | beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/); | ||
629 | 167 | } else { | ||
630 | 168 | Q_ASSERT(m_modelState == ResettingState); | ||
631 | 169 | // No point in signaling anything if we're resetting the whole model | ||
632 | 170 | } | ||
633 | 171 | |||
634 | 172 | int id = generateId(); | ||
635 | 173 | Window *window = new Window(id); | ||
636 | 174 | if (surface) { | ||
637 | 175 | window->setSurface(surface); | ||
638 | 176 | } | ||
639 | 177 | m_windowModel.prepend(ModelEntry(window, application)); | ||
640 | 178 | if (surface) { | ||
641 | 179 | connectSurface(surface); | ||
642 | 180 | } | ||
643 | 181 | |||
644 | 182 | connectWindow(window); | ||
645 | 183 | |||
646 | 184 | if (m_modelState == InsertingState) { | ||
647 | 185 | endInsertRows(); | ||
648 | 186 | Q_EMIT countChanged(); | ||
649 | 187 | Q_EMIT listChanged(); | ||
650 | 188 | m_modelState = IdleState; | ||
651 | 189 | } | ||
652 | 190 | |||
653 | 191 | if (!surface) { | ||
654 | 192 | // focus the newly added window. miral can't help with that as it doesn't know about it. | ||
655 | 193 | window->setFocused(true); | ||
656 | 194 | if (m_focusedWindow && m_focusedWindow->surface()) { | ||
657 | 195 | m_windowController->activate(miral::Window()); | ||
658 | 196 | } | ||
659 | 197 | } | ||
660 | 198 | |||
661 | 199 | DEBUG_MSG << " after " << toString(); | ||
662 | 200 | } | ||
663 | 201 | |||
664 | 202 | void TopLevelWindowModel::connectWindow(Window *window) | ||
665 | 203 | { | ||
666 | 204 | connect(window, &unityapi::WindowInterface::focusRequested, this, [this, window]() { | ||
667 | 205 | if (!window->surface()) { | ||
668 | 206 | // miral doesn't know about this window, so we have to do it ourselves | ||
669 | 207 | window->setFocused(true); | ||
670 | 208 | raiseId(window->id()); | ||
671 | 209 | Window *previousWindow = m_focusedWindow; | ||
672 | 210 | setFocusedWindow(window); | ||
673 | 211 | if (previousWindow && previousWindow->surface() && previousWindow->surface()->focused()) { | ||
674 | 212 | m_windowController->activate(miral::Window()); | ||
675 | 213 | } | ||
676 | 214 | } | ||
677 | 215 | }); | ||
678 | 216 | |||
679 | 217 | connect(window, &unityapi::WindowInterface::focusedChanged, this, [this, window](bool focused) { | ||
680 | 218 | if (window->surface()) { | ||
681 | 219 | // Condense changes to the focused window | ||
682 | 220 | // eg: Do focusedWindow=A to focusedWindow=B instead of | ||
683 | 221 | // focusedWindow=A to focusedWindow=null to focusedWindow=B | ||
684 | 222 | m_focusedWindowChanged = true; | ||
685 | 223 | if (focused) { | ||
686 | 224 | Q_ASSERT(m_newlyFocusedWindow == nullptr); | ||
687 | 225 | m_newlyFocusedWindow = window; | ||
688 | 226 | } | ||
689 | 227 | } | ||
690 | 228 | }); | ||
691 | 229 | |||
692 | 230 | connect(window, &Window::closeRequested, this, [this, window]() { | ||
693 | 231 | if (!window->surface()) { | ||
694 | 232 | int index = indexForId(window->id()); | ||
695 | 233 | Q_ASSERT(index >= 0); | ||
696 | 234 | m_windowModel[index].application->close(); | ||
697 | 235 | } | ||
698 | 236 | }); | ||
699 | 237 | } | ||
700 | 238 | |||
701 | 239 | void TopLevelWindowModel::connectSurface(MirSurfaceInterface *surface) | ||
702 | 240 | { | ||
703 | 241 | connect(surface, &MirSurfaceInterface::liveChanged, this, [this, surface](bool live){ | ||
704 | 242 | if (!live) { | ||
705 | 243 | onSurfaceDied(surface); | ||
706 | 244 | } | ||
707 | 245 | }); | ||
708 | 246 | connect(surface, &QObject::destroyed, this, [this, surface](){ this->onSurfaceDestroyed(surface); }); | ||
709 | 247 | } | ||
710 | 248 | |||
711 | 249 | void TopLevelWindowModel::onSurfaceDied(MirSurfaceInterface *surface) | ||
712 | 250 | { | ||
713 | 251 | int i = indexOf(surface); | ||
714 | 252 | if (i == -1) { | ||
715 | 253 | return; | ||
716 | 254 | } | ||
717 | 255 | |||
718 | 256 | auto application = m_windowModel[i].application; | ||
719 | 257 | |||
720 | 258 | // can't be starting if it already has a surface | ||
721 | 259 | Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting); | ||
722 | 260 | |||
723 | 261 | if (application->state() == unityapi::ApplicationInfoInterface::Running) { | ||
724 | 262 | m_windowModel[i].removeOnceSurfaceDestroyed = true; | ||
725 | 263 | } else { | ||
726 | 264 | // assume it got killed by the out-of-memory daemon. | ||
727 | 265 | // | ||
728 | 266 | // So leave entry in the model and only remove its surface, so shell can display a screenshot | ||
729 | 267 | // in its place. | ||
730 | 268 | m_windowModel[i].removeOnceSurfaceDestroyed = false; | ||
731 | 269 | } | ||
732 | 270 | } | ||
733 | 271 | |||
734 | 272 | void TopLevelWindowModel::onSurfaceDestroyed(MirSurfaceInterface *surface) | ||
735 | 273 | { | ||
736 | 274 | int i = indexOf(surface); | ||
737 | 275 | if (i == -1) { | ||
738 | 276 | return; | ||
739 | 277 | } | ||
740 | 278 | |||
741 | 279 | if (m_windowModel[i].removeOnceSurfaceDestroyed) { | ||
742 | 280 | removeAt(i); | ||
743 | 281 | } else { | ||
744 | 282 | auto window = m_windowModel[i].window; | ||
745 | 283 | window->setSurface(nullptr); | ||
746 | 284 | window->setFocused(false); | ||
747 | 285 | DEBUG_MSG << " Removed surface from entry. After: " << toString(); | ||
748 | 286 | } | ||
749 | 287 | } | ||
750 | 288 | |||
751 | 289 | void TopLevelWindowModel::connectToWindowModelNotifier(WindowModelNotifier *notifier) | ||
752 | 290 | { | ||
753 | 291 | connect(notifier, &WindowModelNotifier::windowAdded, this, &TopLevelWindowModel::onWindowAdded, Qt::QueuedConnection); | ||
754 | 292 | connect(notifier, &WindowModelNotifier::windowRemoved, this, &TopLevelWindowModel::onWindowRemoved, Qt::QueuedConnection); | ||
755 | 293 | connect(notifier, &WindowModelNotifier::windowReady, this, &TopLevelWindowModel::onWindowReady, Qt::QueuedConnection); | ||
756 | 294 | connect(notifier, &WindowModelNotifier::windowMoved, this, &TopLevelWindowModel::onWindowMoved, Qt::QueuedConnection); | ||
757 | 295 | connect(notifier, &WindowModelNotifier::windowStateChanged, this, &TopLevelWindowModel::onWindowStateChanged, Qt::QueuedConnection); | ||
758 | 296 | connect(notifier, &WindowModelNotifier::windowFocusChanged, this, &TopLevelWindowModel::onWindowFocusChanged, Qt::QueuedConnection); | ||
759 | 297 | connect(notifier, &WindowModelNotifier::windowsRaised, this, &TopLevelWindowModel::onWindowsRaised, Qt::QueuedConnection); | ||
760 | 298 | connect(notifier, &WindowModelNotifier::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted, Qt::QueuedConnection); | ||
761 | 299 | connect(notifier, &WindowModelNotifier::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded, Qt::QueuedConnection); | ||
762 | 300 | } | ||
763 | 301 | |||
764 | 302 | void TopLevelWindowModel::onWindowAdded(const NewWindow &window) | ||
765 | 303 | { | ||
766 | 304 | auto mirSession = window.windowInfo.window().application(); | ||
767 | 305 | SessionInterface* session = m_sessionManager->findSession(mirSession.get()); | ||
768 | 306 | |||
769 | 307 | auto surface = new MirSurface(window, m_windowController, session); | ||
770 | 308 | rememberMirSurface(surface); | ||
771 | 309 | |||
772 | 310 | if (session) | ||
773 | 311 | session->registerSurface(surface); | ||
774 | 312 | |||
775 | 313 | if (window.windowInfo.type() == mir_surface_type_inputmethod) { | ||
776 | 314 | int id = generateId(); | ||
777 | 315 | Window *qmlWindow = new Window(id); | ||
778 | 316 | connectWindow(qmlWindow); | ||
779 | 317 | qmlWindow->setSurface(surface); | ||
780 | 318 | setInputMethodWindow(qmlWindow); | ||
781 | 319 | } else { | ||
782 | 320 | Application *application = m_applicationManager->findApplicationWithSession(mirSession); | ||
783 | 321 | if (application) { | ||
784 | 322 | prependSurface(surface, application); | ||
785 | 323 | } else { | ||
786 | 324 | // Must be a prompt session. No need to do anything about it here as a prompt surface is not top-level. | ||
787 | 325 | // It will show up in the qtmir::Application::promptSurfaceList of some application. | ||
788 | 326 | } | ||
789 | 327 | } | ||
790 | 328 | // TODO: handle surfaces that are neither top-level windows nor input method. eg: child dialogs, popups, menus | ||
791 | 329 | } | ||
792 | 330 | |||
793 | 331 | void TopLevelWindowModel::onWindowRemoved(const miral::WindowInfo &windowInfo) | ||
794 | 332 | { | ||
795 | 333 | forgetMirSurface(windowInfo.window()); | ||
796 | 334 | |||
797 | 335 | if (windowInfo.type() == mir_surface_type_inputmethod) { | ||
798 | 336 | removeInputMethodWindow(); | ||
799 | 337 | return; | ||
800 | 338 | } | ||
801 | 339 | |||
802 | 340 | const int index = findIndexOf(windowInfo.window()); | ||
803 | 341 | if (index >= 0) { | ||
804 | 342 | auto surface = static_cast<MirSurface*>(m_windowModel[index].window->surface()); | ||
805 | 343 | surface->setLive(false); | ||
806 | 344 | } | ||
807 | 345 | } | ||
808 | 346 | |||
809 | 347 | void TopLevelWindowModel::rememberMirSurface(MirSurface *surface) | ||
810 | 348 | { | ||
811 | 349 | m_allSurfaces.append(surface); | ||
812 | 350 | } | ||
813 | 351 | |||
814 | 352 | void TopLevelWindowModel::forgetMirSurface(const miral::Window &window) | ||
815 | 353 | { | ||
816 | 354 | for (int i = 0; i < m_allSurfaces.count(); ++i) { | ||
817 | 355 | if (m_allSurfaces[i]->window() == window) { | ||
818 | 356 | m_allSurfaces.removeAt(i); | ||
819 | 357 | return; | ||
820 | 358 | } | ||
821 | 359 | } | ||
822 | 360 | } | ||
823 | 361 | |||
824 | 362 | void TopLevelWindowModel::removeAt(int index) | ||
825 | 363 | { | ||
826 | 364 | if (m_modelState == IdleState) { | ||
827 | 365 | beginRemoveRows(QModelIndex(), index, index); | ||
828 | 366 | m_modelState = RemovingState; | ||
829 | 367 | } else { | ||
830 | 368 | Q_ASSERT(m_modelState == ResettingState); | ||
831 | 369 | // No point in signaling anything if we're resetting the whole model | ||
832 | 370 | } | ||
833 | 371 | |||
834 | 372 | auto window = m_windowModel[index].window; | ||
835 | 373 | |||
836 | 374 | window->setSurface(nullptr); | ||
837 | 375 | window->setFocused(false); | ||
838 | 376 | |||
839 | 377 | m_windowModel.removeAt(index); | ||
840 | 378 | |||
841 | 379 | if (m_modelState == RemovingState) { | ||
842 | 380 | endRemoveRows(); | ||
843 | 381 | Q_EMIT countChanged(); | ||
844 | 382 | Q_EMIT listChanged(); | ||
845 | 383 | m_modelState = IdleState; | ||
846 | 384 | } | ||
847 | 385 | |||
848 | 386 | disconnect(window, 0, this, 0); | ||
849 | 387 | if (m_focusedWindow == window) { | ||
850 | 388 | setFocusedWindow(nullptr); | ||
851 | 389 | } | ||
852 | 390 | delete window; | ||
853 | 391 | |||
854 | 392 | DEBUG_MSG << " after " << toString(); | ||
855 | 393 | } | ||
856 | 394 | |||
857 | 395 | void TopLevelWindowModel::onWindowReady(const miral::WindowInfo &windowInfo) | ||
858 | 396 | { | ||
859 | 397 | if (auto mirSurface = find(windowInfo)) { | ||
860 | 398 | mirSurface->setReady(); | ||
861 | 399 | } | ||
862 | 400 | } | ||
863 | 401 | |||
864 | 402 | void TopLevelWindowModel::onWindowMoved(const miral::WindowInfo &windowInfo, const QPoint topLeft) | ||
865 | 403 | { | ||
866 | 404 | if (auto mirSurface = find(windowInfo)) { | ||
867 | 405 | mirSurface->setPosition(topLeft); | ||
868 | 406 | } | ||
869 | 407 | } | ||
870 | 408 | |||
871 | 409 | void TopLevelWindowModel::onWindowFocusChanged(const miral::WindowInfo &windowInfo, bool focused) | ||
872 | 410 | { | ||
873 | 411 | if (auto mirSurface = find(windowInfo)) { | ||
874 | 412 | mirSurface->setFocused(focused); | ||
875 | 413 | } | ||
876 | 414 | } | ||
877 | 415 | |||
878 | 416 | void TopLevelWindowModel::onWindowStateChanged(const miral::WindowInfo &windowInfo, Mir::State state) | ||
879 | 417 | { | ||
880 | 418 | if (auto mirSurface = find(windowInfo)) { | ||
881 | 419 | mirSurface->updateState(state); | ||
882 | 420 | } | ||
883 | 421 | } | ||
884 | 422 | |||
885 | 423 | void TopLevelWindowModel::setInputMethodWindow(Window *window) | ||
886 | 424 | { | ||
887 | 425 | if (m_inputMethodWindow) { | ||
888 | 426 | qWarning("Multiple Input Method Surfaces created, removing the old one!"); | ||
889 | 427 | delete m_inputMethodWindow; | ||
890 | 428 | } | ||
891 | 429 | m_inputMethodWindow = window; | ||
892 | 430 | Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface()); | ||
893 | 431 | } | ||
894 | 432 | |||
895 | 433 | void TopLevelWindowModel::removeInputMethodWindow() | ||
896 | 434 | { | ||
897 | 435 | if (m_inputMethodWindow) { | ||
898 | 436 | delete m_inputMethodWindow; | ||
899 | 437 | m_inputMethodWindow = nullptr; | ||
900 | 438 | Q_EMIT inputMethodSurfaceChanged(nullptr); | ||
901 | 439 | } | ||
902 | 440 | } | ||
903 | 441 | |||
904 | 442 | void TopLevelWindowModel::onWindowsRaised(const std::vector<miral::Window> &windows) | ||
905 | 443 | { | ||
906 | 444 | const int raiseCount = windows.size(); | ||
907 | 445 | for (int i = 0; i < raiseCount; i++) { | ||
908 | 446 | int fromIndex = findIndexOf(windows[i]); | ||
909 | 447 | if (fromIndex != -1) { | ||
910 | 448 | move(fromIndex, 0); | ||
911 | 449 | } | ||
912 | 450 | } | ||
913 | 451 | } | ||
914 | 452 | |||
915 | 453 | int TopLevelWindowModel::rowCount(const QModelIndex &/*parent*/) const | ||
916 | 454 | { | ||
917 | 455 | return m_windowModel.count(); | ||
918 | 456 | } | ||
919 | 457 | |||
920 | 458 | QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const | ||
921 | 459 | { | ||
922 | 460 | if (index.row() < 0 || index.row() >= m_windowModel.size()) | ||
923 | 461 | return QVariant(); | ||
924 | 462 | |||
925 | 463 | if (role == WindowRole) { | ||
926 | 464 | unityapi::WindowInterface *window = m_windowModel.at(index.row()).window; | ||
927 | 465 | return QVariant::fromValue(window); | ||
928 | 466 | } else if (role == ApplicationRole) { | ||
929 | 467 | return QVariant::fromValue(m_windowModel.at(index.row()).application); | ||
930 | 468 | } else { | ||
931 | 469 | return QVariant(); | ||
932 | 470 | } | ||
933 | 471 | } | ||
934 | 472 | |||
935 | 473 | MirSurface *TopLevelWindowModel::find(const miral::WindowInfo &needle) const | ||
936 | 474 | { | ||
937 | 475 | auto window = needle.window(); | ||
938 | 476 | Q_FOREACH(const auto surface, m_allSurfaces) { | ||
939 | 477 | if (surface->window() == window) { | ||
940 | 478 | return surface; | ||
941 | 479 | } | ||
942 | 480 | } | ||
943 | 481 | return nullptr; | ||
944 | 482 | } | ||
945 | 483 | |||
946 | 484 | int TopLevelWindowModel::findIndexOf(const miral::Window &needle) const | ||
947 | 485 | { | ||
948 | 486 | for (int i=0; i<m_windowModel.count(); i++) { | ||
949 | 487 | auto surface = static_cast<MirSurface*>(m_windowModel[i].window->surface()); | ||
950 | 488 | if (surface && surface->window() == needle) { | ||
951 | 489 | return i; | ||
952 | 490 | } | ||
953 | 491 | } | ||
954 | 492 | return -1; | ||
955 | 493 | } | ||
956 | 494 | |||
957 | 495 | int TopLevelWindowModel::generateId() | ||
958 | 496 | { | ||
959 | 497 | int id = m_nextId; | ||
960 | 498 | m_nextId = nextFreeId(m_nextId + 1); | ||
961 | 499 | return id; | ||
962 | 500 | } | ||
963 | 501 | |||
964 | 502 | int TopLevelWindowModel::nextFreeId(int candidateId) | ||
965 | 503 | { | ||
966 | 504 | if (candidateId > m_maxId) { | ||
967 | 505 | return nextFreeId(1); | ||
968 | 506 | } else { | ||
969 | 507 | if (indexForId(candidateId) == -1) { | ||
970 | 508 | // it's indeed free | ||
971 | 509 | return candidateId; | ||
972 | 510 | } else { | ||
973 | 511 | return nextFreeId(candidateId + 1); | ||
974 | 512 | } | ||
975 | 513 | } | ||
976 | 514 | } | ||
977 | 515 | |||
978 | 516 | QString TopLevelWindowModel::toString() | ||
979 | 517 | { | ||
980 | 518 | QString str; | ||
981 | 519 | for (int i = 0; i < m_windowModel.count(); ++i) { | ||
982 | 520 | auto item = m_windowModel.at(i); | ||
983 | 521 | |||
984 | 522 | QString itemStr = QString("(index=%1,appId=%2,surface=0x%3,id=%4)") | ||
985 | 523 | .arg(i) | ||
986 | 524 | .arg(item.application->appId()) | ||
987 | 525 | .arg((qintptr)item.window->surface(), 0, 16) | ||
988 | 526 | .arg(item.window->id()); | ||
989 | 527 | |||
990 | 528 | if (i > 0) { | ||
991 | 529 | str.append(","); | ||
992 | 530 | } | ||
993 | 531 | str.append(itemStr); | ||
994 | 532 | } | ||
995 | 533 | return str; | ||
996 | 534 | } | ||
997 | 535 | |||
998 | 536 | int TopLevelWindowModel::indexOf(MirSurfaceInterface *surface) | ||
999 | 537 | { | ||
1000 | 538 | for (int i = 0; i < m_windowModel.count(); ++i) { | ||
1001 | 539 | if (m_windowModel.at(i).window->surface() == surface) { | ||
1002 | 540 | return i; | ||
1003 | 541 | } | ||
1004 | 542 | } | ||
1005 | 543 | return -1; | ||
1006 | 544 | } | ||
1007 | 545 | |||
1008 | 546 | int TopLevelWindowModel::indexForId(int id) const | ||
1009 | 547 | { | ||
1010 | 548 | for (int i = 0; i < m_windowModel.count(); ++i) { | ||
1011 | 549 | if (m_windowModel[i].window->id() == id) { | ||
1012 | 550 | return i; | ||
1013 | 551 | } | ||
1014 | 552 | } | ||
1015 | 553 | return -1; | ||
1016 | 554 | } | ||
1017 | 555 | |||
1018 | 556 | unityapi::WindowInterface *TopLevelWindowModel::windowAt(int index) const | ||
1019 | 557 | { | ||
1020 | 558 | if (index >=0 && index < m_windowModel.count()) { | ||
1021 | 559 | return m_windowModel[index].window; | ||
1022 | 560 | } else { | ||
1023 | 561 | return nullptr; | ||
1024 | 562 | } | ||
1025 | 563 | } | ||
1026 | 564 | |||
1027 | 565 | unityapi::MirSurfaceInterface *TopLevelWindowModel::surfaceAt(int index) const | ||
1028 | 566 | { | ||
1029 | 567 | if (index >=0 && index < m_windowModel.count()) { | ||
1030 | 568 | return m_windowModel[index].window->surface(); | ||
1031 | 569 | } else { | ||
1032 | 570 | return nullptr; | ||
1033 | 571 | } | ||
1034 | 572 | } | ||
1035 | 573 | |||
1036 | 574 | unityapi::ApplicationInfoInterface *TopLevelWindowModel::applicationAt(int index) const | ||
1037 | 575 | { | ||
1038 | 576 | if (index >=0 && index < m_windowModel.count()) { | ||
1039 | 577 | return m_windowModel[index].application; | ||
1040 | 578 | } else { | ||
1041 | 579 | return nullptr; | ||
1042 | 580 | } | ||
1043 | 581 | } | ||
1044 | 582 | |||
1045 | 583 | int TopLevelWindowModel::idAt(int index) const | ||
1046 | 584 | { | ||
1047 | 585 | if (index >=0 && index < m_windowModel.count()) { | ||
1048 | 586 | return m_windowModel[index].window->id(); | ||
1049 | 587 | } else { | ||
1050 | 588 | return 0; | ||
1051 | 589 | } | ||
1052 | 590 | } | ||
1053 | 591 | |||
1054 | 592 | void TopLevelWindowModel::raiseId(int id) | ||
1055 | 593 | { | ||
1056 | 594 | if (m_modelState == IdleState) { | ||
1057 | 595 | DEBUG_MSG << "(id=" << id << ") - do it now."; | ||
1058 | 596 | doRaiseId(id); | ||
1059 | 597 | } else { | ||
1060 | 598 | DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop."; | ||
1061 | 599 | // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts | ||
1062 | 600 | // if we perform yet another model change straight away. | ||
1063 | 601 | // | ||
1064 | 602 | // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says | ||
1065 | 603 | // the index is definitely within bounds. | ||
1066 | 604 | QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id)); | ||
1067 | 605 | } | ||
1068 | 606 | } | ||
1069 | 607 | |||
1070 | 608 | void TopLevelWindowModel::doRaiseId(int id) | ||
1071 | 609 | { | ||
1072 | 610 | int fromIndex = indexForId(id); | ||
1073 | 611 | if (fromIndex != -1) { | ||
1074 | 612 | auto surface = static_cast<MirSurface*>(m_windowModel[fromIndex].window->surface()); | ||
1075 | 613 | if (surface) { | ||
1076 | 614 | m_windowController->raise(surface->window()); | ||
1077 | 615 | } else { | ||
1078 | 616 | // move it ourselves. Since there's no mir::scene::Surface/miral::Window, there's nothing | ||
1079 | 617 | // miral can do about it. | ||
1080 | 618 | move(fromIndex, 0); | ||
1081 | 619 | } | ||
1082 | 620 | } | ||
1083 | 621 | } | ||
1084 | 622 | |||
1085 | 623 | void TopLevelWindowModel::setFocusedWindow(Window *window) | ||
1086 | 624 | { | ||
1087 | 625 | if (window != m_focusedWindow) { | ||
1088 | 626 | DEBUG_MSG << "(" << window << ")"; | ||
1089 | 627 | |||
1090 | 628 | Window* previousWindow = m_focusedWindow; | ||
1091 | 629 | |||
1092 | 630 | m_focusedWindow = window; | ||
1093 | 631 | Q_EMIT focusedWindowChanged(m_focusedWindow); | ||
1094 | 632 | |||
1095 | 633 | if (previousWindow && previousWindow->focused() && !previousWindow->surface()) { | ||
1096 | 634 | // do it ourselves. miral doesn't know about this window | ||
1097 | 635 | previousWindow->setFocused(false); | ||
1098 | 636 | } | ||
1099 | 637 | } | ||
1100 | 638 | } | ||
1101 | 639 | |||
1102 | 640 | unityapi::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface() const | ||
1103 | 641 | { | ||
1104 | 642 | return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr; | ||
1105 | 643 | } | ||
1106 | 644 | |||
1107 | 645 | unityapi::WindowInterface* TopLevelWindowModel::focusedWindow() const | ||
1108 | 646 | { | ||
1109 | 647 | return m_focusedWindow; | ||
1110 | 648 | } | ||
1111 | 649 | |||
1112 | 650 | void TopLevelWindowModel::move(int from, int to) | ||
1113 | 651 | { | ||
1114 | 652 | if (from == to) return; | ||
1115 | 653 | DEBUG_MSG << " from=" << from << " to=" << to; | ||
1116 | 654 | |||
1117 | 655 | if (from >= 0 && from < m_windowModel.size() && to >= 0 && to < m_windowModel.size()) { | ||
1118 | 656 | QModelIndex parent; | ||
1119 | 657 | /* When moving an item down, the destination index needs to be incremented | ||
1120 | 658 | by one, as explained in the documentation: | ||
1121 | 659 | http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */ | ||
1122 | 660 | |||
1123 | 661 | Q_ASSERT(m_modelState == IdleState); | ||
1124 | 662 | m_modelState = MovingState; | ||
1125 | 663 | |||
1126 | 664 | beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0)); | ||
1127 | 665 | #if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) | ||
1128 | 666 | const auto &window = m_windowModel.takeAt(from); | ||
1129 | 667 | m_windowModel.insert(to, window); | ||
1130 | 668 | #else | ||
1131 | 669 | m_windowModel.move(from, to); | ||
1132 | 670 | #endif | ||
1133 | 671 | endMoveRows(); | ||
1134 | 672 | |||
1135 | 673 | Q_EMIT listChanged(); | ||
1136 | 674 | m_modelState = IdleState; | ||
1137 | 675 | |||
1138 | 676 | DEBUG_MSG << " after " << toString(); | ||
1139 | 677 | } | ||
1140 | 678 | } | ||
1141 | 679 | void TopLevelWindowModel::onModificationsStarted() | ||
1142 | 680 | { | ||
1143 | 681 | } | ||
1144 | 682 | |||
1145 | 683 | void TopLevelWindowModel::onModificationsEnded() | ||
1146 | 684 | { | ||
1147 | 685 | if (m_focusedWindowChanged) { | ||
1148 | 686 | setFocusedWindow(m_newlyFocusedWindow); | ||
1149 | 687 | } | ||
1150 | 688 | // reset | ||
1151 | 689 | m_focusedWindowChanged = false; | ||
1152 | 690 | m_newlyFocusedWindow = nullptr; | ||
1153 | 691 | } | ||
1154 | 692 | 0 | ||
1155 | === removed file 'src/modules/Unity/Application/toplevelwindowmodel.h' | |||
1156 | --- src/modules/Unity/Application/toplevelwindowmodel.h 2016-11-04 11:06:15 +0000 | |||
1157 | +++ src/modules/Unity/Application/toplevelwindowmodel.h 1970-01-01 00:00:00 +0000 | |||
1158 | @@ -1,161 +0,0 @@ | |||
1159 | 1 | /* | ||
1160 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1161 | 3 | * | ||
1162 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
1163 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
1164 | 6 | * the Free Software Foundation. | ||
1165 | 7 | * | ||
1166 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
1167 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
1168 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1169 | 11 | * Lesser General Public License for more details. | ||
1170 | 12 | * | ||
1171 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1172 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1173 | 15 | */ | ||
1174 | 16 | |||
1175 | 17 | #ifndef TOPLEVELWINDOWMODEL_H | ||
1176 | 18 | #define TOPLEVELWINDOWMODEL_H | ||
1177 | 19 | |||
1178 | 20 | #include <QLoggingCategory> | ||
1179 | 21 | |||
1180 | 22 | #include "mirsurface.h" | ||
1181 | 23 | #include "window.h" | ||
1182 | 24 | #include "windowmodelnotifier.h" | ||
1183 | 25 | |||
1184 | 26 | // Unity API | ||
1185 | 27 | #include <unity/shell/application/TopLevelWindowModelInterface.h> | ||
1186 | 28 | |||
1187 | 29 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_TOPLEVELWINDOWMODEL) | ||
1188 | 30 | |||
1189 | 31 | namespace unity { | ||
1190 | 32 | namespace shell { | ||
1191 | 33 | namespace application { | ||
1192 | 34 | class ApplicationInfoInterface; | ||
1193 | 35 | class ApplicationManagerInterface; | ||
1194 | 36 | class MirSurfaceInterface; | ||
1195 | 37 | } | ||
1196 | 38 | } | ||
1197 | 39 | } | ||
1198 | 40 | |||
1199 | 41 | namespace qtmir { | ||
1200 | 42 | |||
1201 | 43 | class Application; | ||
1202 | 44 | class ApplicationManagerInterface; | ||
1203 | 45 | class SessionManager; | ||
1204 | 46 | class WindowControllerInterface; | ||
1205 | 47 | |||
1206 | 48 | class TopLevelWindowModel : public unity::shell::application::TopLevelWindowModelInterface | ||
1207 | 49 | { | ||
1208 | 50 | Q_OBJECT | ||
1209 | 51 | |||
1210 | 52 | public: | ||
1211 | 53 | TopLevelWindowModel(); | ||
1212 | 54 | explicit TopLevelWindowModel(WindowModelNotifier *notifier, | ||
1213 | 55 | WindowControllerInterface *controller); // For testing | ||
1214 | 56 | |||
1215 | 57 | // From unity::shell::application::TopLevelWindowModelInterface | ||
1216 | 58 | unity::shell::application::MirSurfaceInterface* inputMethodSurface() const override; | ||
1217 | 59 | unity::shell::application::WindowInterface* focusedWindow() const override; | ||
1218 | 60 | |||
1219 | 61 | // From QAbstractItemModel | ||
1220 | 62 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
1221 | 63 | QVariant data(const QModelIndex& index, int role) const override; | ||
1222 | 64 | |||
1223 | 65 | // Own API | ||
1224 | 66 | void setApplicationManager(ApplicationManagerInterface*); | ||
1225 | 67 | |||
1226 | 68 | public Q_SLOTS: | ||
1227 | 69 | // From unity::shell::application::TopLevelWindowModelInterface | ||
1228 | 70 | unity::shell::application::MirSurfaceInterface *surfaceAt(int index) const override; | ||
1229 | 71 | unity::shell::application::WindowInterface *windowAt(int index) const override; | ||
1230 | 72 | unity::shell::application::ApplicationInfoInterface *applicationAt(int index) const override; | ||
1231 | 73 | int idAt(int index) const override; | ||
1232 | 74 | int indexForId(int id) const override; | ||
1233 | 75 | void raiseId(int id) override; | ||
1234 | 76 | |||
1235 | 77 | private Q_SLOTS: | ||
1236 | 78 | void onWindowAdded(const qtmir::NewWindow &windowInfo); | ||
1237 | 79 | void onWindowRemoved(const miral::WindowInfo &windowInfo); | ||
1238 | 80 | void onWindowReady(const miral::WindowInfo &windowInfo); | ||
1239 | 81 | void onWindowMoved(const miral::WindowInfo &windowInfo, const QPoint topLeft); | ||
1240 | 82 | void onWindowStateChanged(const miral::WindowInfo &windowInfo, Mir::State state); | ||
1241 | 83 | void onWindowFocusChanged(const miral::WindowInfo &windowInfo, bool focused); | ||
1242 | 84 | void onWindowsRaised(const std::vector<miral::Window> &windows); | ||
1243 | 85 | void onModificationsStarted(); | ||
1244 | 86 | void onModificationsEnded(); | ||
1245 | 87 | |||
1246 | 88 | private: | ||
1247 | 89 | void doRaiseId(int id); | ||
1248 | 90 | int generateId(); | ||
1249 | 91 | int nextFreeId(int candidateId); | ||
1250 | 92 | void connectToWindowModelNotifier(WindowModelNotifier *notifier); | ||
1251 | 93 | QString toString(); | ||
1252 | 94 | int indexOf(MirSurfaceInterface *surface); | ||
1253 | 95 | |||
1254 | 96 | void setInputMethodWindow(Window *window); | ||
1255 | 97 | void setFocusedWindow(Window *window); | ||
1256 | 98 | void removeInputMethodWindow(); | ||
1257 | 99 | MirSurface* find(const miral::WindowInfo &needle) const; | ||
1258 | 100 | int findIndexOf(const miral::Window &needle) const; | ||
1259 | 101 | void removeAt(int index); | ||
1260 | 102 | |||
1261 | 103 | void addApplication(Application *application); | ||
1262 | 104 | void removeApplication(Application *application); | ||
1263 | 105 | |||
1264 | 106 | void prependPlaceholder(Application *application); | ||
1265 | 107 | void prependSurface(MirSurface *surface, Application *application); | ||
1266 | 108 | void prependSurfaceHelper(MirSurface *surface, Application *application); | ||
1267 | 109 | |||
1268 | 110 | void connectWindow(Window *window); | ||
1269 | 111 | void connectSurface(MirSurfaceInterface *surface); | ||
1270 | 112 | |||
1271 | 113 | void onSurfaceDied(MirSurfaceInterface *surface); | ||
1272 | 114 | void onSurfaceDestroyed(MirSurfaceInterface *surface); | ||
1273 | 115 | |||
1274 | 116 | void move(int from, int to); | ||
1275 | 117 | |||
1276 | 118 | void rememberMirSurface(MirSurface *surface); | ||
1277 | 119 | void forgetMirSurface(const miral::Window &window); | ||
1278 | 120 | |||
1279 | 121 | struct ModelEntry { | ||
1280 | 122 | ModelEntry() {} | ||
1281 | 123 | ModelEntry(Window *window, | ||
1282 | 124 | Application *application) | ||
1283 | 125 | : window(window), application(application) {} | ||
1284 | 126 | Window *window{nullptr}; | ||
1285 | 127 | Application *application{nullptr}; | ||
1286 | 128 | bool removeOnceSurfaceDestroyed{false}; | ||
1287 | 129 | }; | ||
1288 | 130 | |||
1289 | 131 | QVector<ModelEntry> m_windowModel; | ||
1290 | 132 | WindowControllerInterface *m_windowController; | ||
1291 | 133 | SessionManager* m_sessionManager; | ||
1292 | 134 | Window* m_inputMethodWindow{nullptr}; | ||
1293 | 135 | Window* m_focusedWindow{nullptr}; | ||
1294 | 136 | QVector<MirSurface*> m_allSurfaces; | ||
1295 | 137 | |||
1296 | 138 | int m_nextId{1}; | ||
1297 | 139 | // Just something big enough that we don't risk running out of unused id numbers. | ||
1298 | 140 | // Not sure if QML int type supports something close to std::numeric_limits<int>::max() and | ||
1299 | 141 | // there's no reason to try out its limits. | ||
1300 | 142 | static const int m_maxId{1000000}; | ||
1301 | 143 | |||
1302 | 144 | ApplicationManagerInterface* m_applicationManager{nullptr}; | ||
1303 | 145 | |||
1304 | 146 | enum ModelState { | ||
1305 | 147 | IdleState, | ||
1306 | 148 | InsertingState, | ||
1307 | 149 | RemovingState, | ||
1308 | 150 | MovingState, | ||
1309 | 151 | ResettingState | ||
1310 | 152 | }; | ||
1311 | 153 | ModelState m_modelState{IdleState}; | ||
1312 | 154 | |||
1313 | 155 | // Valid between modificationsStarted and modificationsEnded | ||
1314 | 156 | bool m_focusedWindowChanged{false}; | ||
1315 | 157 | Window *m_newlyFocusedWindow{nullptr}; | ||
1316 | 158 | }; | ||
1317 | 159 | |||
1318 | 160 | } // namespace qtmir | ||
1319 | 161 | #endif // TOPLEVELWINDOWMODEL_H | ||
1320 | 162 | 0 | ||
1321 | === removed file 'src/modules/Unity/Application/window.cpp' | |||
1322 | --- src/modules/Unity/Application/window.cpp 2016-11-07 11:44:55 +0000 | |||
1323 | +++ src/modules/Unity/Application/window.cpp 1970-01-01 00:00:00 +0000 | |||
1324 | @@ -1,186 +0,0 @@ | |||
1325 | 1 | /* | ||
1326 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1327 | 3 | * | ||
1328 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1329 | 5 | * it under the terms of the GNU General Public License as published by | ||
1330 | 6 | * the Free Software Foundation; version 3. | ||
1331 | 7 | * | ||
1332 | 8 | * This program is distributed in the hope that it will be useful, | ||
1333 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1334 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1335 | 11 | * GNU General Public License for more details. | ||
1336 | 12 | * | ||
1337 | 13 | * You should have received a copy of the GNU General Public License | ||
1338 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1339 | 15 | */ | ||
1340 | 16 | |||
1341 | 17 | #include "window.h" | ||
1342 | 18 | #include "mirsurface.h" | ||
1343 | 19 | |||
1344 | 20 | #include <QQmlEngine> | ||
1345 | 21 | |||
1346 | 22 | namespace unityapi = unity::shell::application; | ||
1347 | 23 | using namespace qtmir; | ||
1348 | 24 | |||
1349 | 25 | Window::Window(int id) | ||
1350 | 26 | : WindowInterface(nullptr) | ||
1351 | 27 | , m_id(id) | ||
1352 | 28 | { | ||
1353 | 29 | QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); | ||
1354 | 30 | } | ||
1355 | 31 | |||
1356 | 32 | QPoint Window::position() const | ||
1357 | 33 | { | ||
1358 | 34 | return m_position; | ||
1359 | 35 | } | ||
1360 | 36 | |||
1361 | 37 | QPoint Window::requestedPosition() const | ||
1362 | 38 | { | ||
1363 | 39 | return m_requestedPosition; | ||
1364 | 40 | } | ||
1365 | 41 | |||
1366 | 42 | void Window::setRequestedPosition(const QPoint &value) | ||
1367 | 43 | { | ||
1368 | 44 | if (value != m_requestedPosition) { | ||
1369 | 45 | m_requestedPosition = value; | ||
1370 | 46 | Q_EMIT requestedPositionChanged(m_requestedPosition); | ||
1371 | 47 | if (m_surface) { | ||
1372 | 48 | m_surface->setRequestedPosition(value); | ||
1373 | 49 | } else { | ||
1374 | 50 | // fake-miral: always comply | ||
1375 | 51 | m_position = m_requestedPosition; | ||
1376 | 52 | Q_EMIT positionChanged(m_position); | ||
1377 | 53 | } | ||
1378 | 54 | } | ||
1379 | 55 | } | ||
1380 | 56 | |||
1381 | 57 | Mir::State Window::state() const | ||
1382 | 58 | { | ||
1383 | 59 | return m_state; | ||
1384 | 60 | } | ||
1385 | 61 | |||
1386 | 62 | bool Window::focused() const | ||
1387 | 63 | { | ||
1388 | 64 | return m_focused; | ||
1389 | 65 | } | ||
1390 | 66 | |||
1391 | 67 | bool Window::confinesMousePointer() const | ||
1392 | 68 | { | ||
1393 | 69 | if (m_surface) { | ||
1394 | 70 | return m_surface->confinesMousePointer(); | ||
1395 | 71 | } else { | ||
1396 | 72 | return false; | ||
1397 | 73 | } | ||
1398 | 74 | } | ||
1399 | 75 | |||
1400 | 76 | int Window::id() const | ||
1401 | 77 | { | ||
1402 | 78 | return m_id; | ||
1403 | 79 | } | ||
1404 | 80 | |||
1405 | 81 | unityapi::MirSurfaceInterface* Window::surface() const | ||
1406 | 82 | { | ||
1407 | 83 | return m_surface; | ||
1408 | 84 | } | ||
1409 | 85 | |||
1410 | 86 | void Window::requestState(Mir::State state) | ||
1411 | 87 | { | ||
1412 | 88 | if (m_surface) { | ||
1413 | 89 | m_surface->requestState(state); | ||
1414 | 90 | } else if (m_state != state) { | ||
1415 | 91 | m_state = state; | ||
1416 | 92 | Q_EMIT stateChanged(m_state); | ||
1417 | 93 | } | ||
1418 | 94 | } | ||
1419 | 95 | |||
1420 | 96 | void Window::requestFocus() | ||
1421 | 97 | { | ||
1422 | 98 | if (m_surface) { | ||
1423 | 99 | m_surface->requestFocus(); | ||
1424 | 100 | } else { | ||
1425 | 101 | Q_EMIT focusRequested(); | ||
1426 | 102 | } | ||
1427 | 103 | } | ||
1428 | 104 | |||
1429 | 105 | void Window::close() | ||
1430 | 106 | { | ||
1431 | 107 | if (m_surface) { | ||
1432 | 108 | m_surface->close(); | ||
1433 | 109 | } else { | ||
1434 | 110 | Q_EMIT closeRequested(); | ||
1435 | 111 | } | ||
1436 | 112 | } | ||
1437 | 113 | |||
1438 | 114 | void Window::setSurface(MirSurface *surface) | ||
1439 | 115 | { | ||
1440 | 116 | if (m_surface) { | ||
1441 | 117 | disconnect(m_surface, 0, this, 0); | ||
1442 | 118 | } | ||
1443 | 119 | |||
1444 | 120 | m_surface = surface; | ||
1445 | 121 | |||
1446 | 122 | if (m_surface) { | ||
1447 | 123 | connect(surface, &MirSurfaceInterface::focusRequested, this, [this]() { | ||
1448 | 124 | Q_EMIT focusRequested(); | ||
1449 | 125 | }); | ||
1450 | 126 | |||
1451 | 127 | connect(surface, &MirSurfaceInterface::closeRequested, this, &Window::closeRequested); | ||
1452 | 128 | |||
1453 | 129 | connect(surface, &MirSurfaceInterface::positionChanged, this, [this]() { | ||
1454 | 130 | updatePosition(); | ||
1455 | 131 | }); | ||
1456 | 132 | |||
1457 | 133 | connect(surface, &MirSurfaceInterface::stateChanged, this, [this]() { | ||
1458 | 134 | updateState(); | ||
1459 | 135 | }); | ||
1460 | 136 | |||
1461 | 137 | connect(surface, &MirSurfaceInterface::focusedChanged, this, [this]() { | ||
1462 | 138 | updateFocused(); | ||
1463 | 139 | }); | ||
1464 | 140 | |||
1465 | 141 | // bring it up to speed | ||
1466 | 142 | m_surface->setRequestedPosition(m_requestedPosition); | ||
1467 | 143 | m_surface->requestState(m_state); | ||
1468 | 144 | |||
1469 | 145 | // and sync with surface | ||
1470 | 146 | updatePosition(); | ||
1471 | 147 | updateState(); | ||
1472 | 148 | updateFocused(); | ||
1473 | 149 | } | ||
1474 | 150 | |||
1475 | 151 | Q_EMIT surfaceChanged(surface); | ||
1476 | 152 | } | ||
1477 | 153 | |||
1478 | 154 | void Window::updatePosition() | ||
1479 | 155 | { | ||
1480 | 156 | if (m_surface->position() != m_position) { | ||
1481 | 157 | m_position = m_surface->position(); | ||
1482 | 158 | Q_EMIT positionChanged(m_position); | ||
1483 | 159 | } | ||
1484 | 160 | } | ||
1485 | 161 | |||
1486 | 162 | void Window::updateState() | ||
1487 | 163 | { | ||
1488 | 164 | if (m_surface->state() != m_state) { | ||
1489 | 165 | m_state = m_surface->state(); | ||
1490 | 166 | Q_EMIT stateChanged(m_state); | ||
1491 | 167 | } | ||
1492 | 168 | } | ||
1493 | 169 | |||
1494 | 170 | void Window::updateFocused() | ||
1495 | 171 | { | ||
1496 | 172 | if (m_surface->focused() != m_focused) { | ||
1497 | 173 | m_focused = m_surface->focused(); | ||
1498 | 174 | Q_EMIT focusedChanged(m_focused); | ||
1499 | 175 | } | ||
1500 | 176 | } | ||
1501 | 177 | |||
1502 | 178 | void Window::setFocused(bool value) | ||
1503 | 179 | { | ||
1504 | 180 | if (value != m_focused) { | ||
1505 | 181 | m_focused = value; | ||
1506 | 182 | Q_EMIT focusedChanged(m_focused); | ||
1507 | 183 | // when we have a surface we get focus changes from updateFocused() instead | ||
1508 | 184 | Q_ASSERT(!m_surface); | ||
1509 | 185 | } | ||
1510 | 186 | } | ||
1511 | 187 | 0 | ||
1512 | === removed file 'src/modules/Unity/Application/window.h' | |||
1513 | --- src/modules/Unity/Application/window.h 2016-11-03 20:17:46 +0000 | |||
1514 | +++ src/modules/Unity/Application/window.h 1970-01-01 00:00:00 +0000 | |||
1515 | @@ -1,67 +0,0 @@ | |||
1516 | 1 | /* | ||
1517 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1518 | 3 | * | ||
1519 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1520 | 5 | * it under the terms of the GNU General Public License as published by | ||
1521 | 6 | * the Free Software Foundation; version 3. | ||
1522 | 7 | * | ||
1523 | 8 | * This program is distributed in the hope that it will be useful, | ||
1524 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1525 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1526 | 11 | * GNU General Public License for more details. | ||
1527 | 12 | * | ||
1528 | 13 | * You should have received a copy of the GNU General Public License | ||
1529 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1530 | 15 | */ | ||
1531 | 16 | |||
1532 | 17 | #ifndef QTMIR_WINDOW_H | ||
1533 | 18 | #define QTMIR_WINDOW_H | ||
1534 | 19 | |||
1535 | 20 | // unity-api | ||
1536 | 21 | #include <unity/shell/application/WindowInterface.h> | ||
1537 | 22 | |||
1538 | 23 | namespace qtmir { | ||
1539 | 24 | |||
1540 | 25 | class MirSurface; | ||
1541 | 26 | |||
1542 | 27 | class Window : public unity::shell::application::WindowInterface | ||
1543 | 28 | { | ||
1544 | 29 | Q_OBJECT | ||
1545 | 30 | |||
1546 | 31 | public: | ||
1547 | 32 | Window(int id); | ||
1548 | 33 | QPoint position() const override; | ||
1549 | 34 | QPoint requestedPosition() const override; | ||
1550 | 35 | void setRequestedPosition(const QPoint &) override; | ||
1551 | 36 | Mir::State state() const override; | ||
1552 | 37 | bool focused() const override; | ||
1553 | 38 | bool confinesMousePointer() const override; | ||
1554 | 39 | int id() const override; | ||
1555 | 40 | unity::shell::application::MirSurfaceInterface* surface() const override; | ||
1556 | 41 | |||
1557 | 42 | void setSurface(MirSurface *surface); | ||
1558 | 43 | void setFocused(bool value); | ||
1559 | 44 | |||
1560 | 45 | public Q_SLOTS: | ||
1561 | 46 | void requestState(Mir::State state) override; | ||
1562 | 47 | void requestFocus() override; | ||
1563 | 48 | void close() override; | ||
1564 | 49 | |||
1565 | 50 | Q_SIGNALS: | ||
1566 | 51 | void closeRequested(); | ||
1567 | 52 | |||
1568 | 53 | private: | ||
1569 | 54 | void updatePosition(); | ||
1570 | 55 | void updateState(); | ||
1571 | 56 | void updateFocused(); | ||
1572 | 57 | |||
1573 | 58 | QPoint m_position; | ||
1574 | 59 | QPoint m_requestedPosition; | ||
1575 | 60 | bool m_focused{false}; | ||
1576 | 61 | int m_id; | ||
1577 | 62 | Mir::State m_state{Mir::RestoredState}; | ||
1578 | 63 | MirSurface *m_surface{nullptr}; | ||
1579 | 64 | }; | ||
1580 | 65 | |||
1581 | 66 | } // namespace qtmir { | ||
1582 | 67 | #endif // QTMIR_WINDOW_H |
Smaller API is cleaner.