Lomiri
Loading...
Searching...
No Matches
TopLevelWindowModel.h
1/*
2 * Copyright (C) 2016-2017 Canonical Ltd.
3 * Copyright 2019 UBports Foundation
4 *
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 3, as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TOPLEVELWINDOWMODEL_H
19#define TOPLEVELWINDOWMODEL_H
20
21#include <QAbstractListModel>
22#include <QAtomicInteger>
23#include <QLoggingCategory>
24
25#include <memory>
26
27#include "WindowManagerGlobal.h"
28
29Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
30
31class Window;
32class Workspace;
33
34namespace miral { class Workspace; }
35
36namespace lomiri {
37 namespace shell {
38 namespace application {
39 class ApplicationInfoInterface;
40 class ApplicationManagerInterface;
41 class MirSurfaceInterface;
42 class SurfaceManagerInterface;
43 }
44 }
45}
46
59class WINDOWMANAGERQML_EXPORT TopLevelWindowModel : public QAbstractListModel
60{
61 Q_OBJECT
62
68 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
69
70
75 Q_PROPERTY(lomiri::shell::application::MirSurfaceInterface* inputMethodSurface READ inputMethodSurface NOTIFY inputMethodSurfaceChanged)
76
80 Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
81
86 Q_PROPERTY(int nextId READ nextId)
87
88
107 Q_PROPERTY(bool rootFocus READ rootFocus WRITE setRootFocus NOTIFY rootFocusChanged)
108
109public:
116 enum Roles {
117 WindowRole = Qt::UserRole,
118 ApplicationRole = Qt::UserRole + 1,
119 };
120
121 TopLevelWindowModel(Workspace* workspace);
123
124 // From QAbstractItemModel
125 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
126 QVariant data(const QModelIndex& index, int role) const override;
127 QHash<int, QByteArray> roleNames() const override {
128 QHash<int, QByteArray> roleNames { {WindowRole, "window"},
129 {ApplicationRole, "application"} };
130 return roleNames;
131 }
132
133 // Own API;
134
135 lomiri::shell::application::MirSurfaceInterface* inputMethodSurface() const;
136 Window* focusedWindow() const;
137
138#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
139 int nextId() const { return m_nextId.loadRelaxed(); }
140#else
141 int nextId() const { return m_nextId.load(); }
142#endif
143
144public:
153 Q_INVOKABLE lomiri::shell::application::MirSurfaceInterface *surfaceAt(int index) const;
154
160 Q_INVOKABLE Window *windowAt(int index) const;
161
165 Q_INVOKABLE void removeAt(int index);
166
170 Q_INVOKABLE lomiri::shell::application::ApplicationInfoInterface *applicationAt(int index) const;
171
175 Q_INVOKABLE int idAt(int index) const;
176
182 Q_INVOKABLE int indexForId(int id) const;
183
187 Q_INVOKABLE void raiseId(int id);
188
192 Q_INVOKABLE void closeAllWindows();
193
197 Q_INVOKABLE void pendingActivation();
198
199 void setApplicationManager(lomiri::shell::application::ApplicationManagerInterface*);
200 void setSurfaceManager(lomiri::shell::application::SurfaceManagerInterface*);
201 void setRootFocus(bool focus);
202 bool rootFocus();
203
204Q_SIGNALS:
205 void countChanged();
206 void inputMethodSurfaceChanged(lomiri::shell::application::MirSurfaceInterface* inputMethodSurface);
207 void focusedWindowChanged(Window *focusedWindow);
208
215
216 void closedAllWindows();
217
218 void rootFocusChanged();
219
220private Q_SLOTS:
221 void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
222 const QVector<lomiri::shell::application::MirSurfaceInterface*> surfaces);
223 void onSurfacesRaised(const QVector<lomiri::shell::application::MirSurfaceInterface*> &surfaces);
224
225 void onModificationsStarted();
226 void onModificationsEnded();
227
228private:
229 void doRaiseId(int id);
230 int generateId();
231 int nextFreeId(int candidateId, const int latestId);
232 int nextId(int id) const;
233 QString toString();
234 int indexOf(lomiri::shell::application::MirSurfaceInterface *surface);
235
236 void setInputMethodWindow(Window *window);
237 void setFocusedWindow(Window *window);
238 void removeInputMethodWindow();
239 void deleteAt(int index);
240 void removeSurfaces(const QVector<lomiri::shell::application::MirSurfaceInterface *> surfaces);
241
242 void addApplication(lomiri::shell::application::ApplicationInfoInterface *application);
243 void removeApplication(lomiri::shell::application::ApplicationInfoInterface *application);
244
245 void prependPlaceholder(lomiri::shell::application::ApplicationInfoInterface *application);
246 void prependSurface(lomiri::shell::application::MirSurfaceInterface *surface,
247 lomiri::shell::application::ApplicationInfoInterface *application);
248 void prependSurfaceHelper(lomiri::shell::application::MirSurfaceInterface *surface,
249 lomiri::shell::application::ApplicationInfoInterface *application);
250 void prependWindow(Window *window, lomiri::shell::application::ApplicationInfoInterface *application);
251
252 void connectWindow(Window *window);
253 void connectSurface(lomiri::shell::application::MirSurfaceInterface *surface);
254
255 void onSurfaceDied(lomiri::shell::application::MirSurfaceInterface *surface);
256 void onSurfaceDestroyed(lomiri::shell::application::MirSurfaceInterface *surface);
257
258 void move(int from, int to);
259
260 void activateEmptyWindow(Window *window);
261
262 void activateTopMostWindowWithoutId(int forbiddenId);
263 void refreshWindows();
264 void clear();
265
266 Window *createWindow(lomiri::shell::application::MirSurfaceInterface *surface);
267 Window *createWindowWithId(lomiri::shell::application::MirSurfaceInterface *surface, int id);
268 Window *createNullWindow();
269
270 struct ModelEntry {
271 ModelEntry() {}
272 ModelEntry(Window *window,
273 lomiri::shell::application::ApplicationInfoInterface *application)
274 : window(window), application(application) {}
275 Window *window{nullptr};
276 lomiri::shell::application::ApplicationInfoInterface *application{nullptr};
277 bool removeOnceSurfaceDestroyed{false};
278 };
279
280 QVector<ModelEntry> m_windowModel;
281 Window* m_inputMethodWindow{nullptr};
282 Window* m_focusedWindow{nullptr};
283 Window* m_nullWindow;
284 Workspace* m_workspace{nullptr};
285 // track all the surfaces we've been told about.
286 QSet<lomiri::shell::application::MirSurfaceInterface*> m_allSurfaces;
287 Window* m_previousWindow{nullptr};
288 bool m_pendingActivation;
289
290 QAtomicInteger<int> m_nextId{1};
291
292 lomiri::shell::application::ApplicationManagerInterface* m_applicationManager{nullptr};
293 lomiri::shell::application::SurfaceManagerInterface *m_surfaceManager{nullptr};
294 bool m_surfaceManagerBusy;
295
296 enum ModelState {
297 IdleState,
298 InsertingState,
299 RemovingState,
300 MovingState,
301 ResettingState
302 };
303 ModelState m_modelState{IdleState};
304
305 // Valid between modificationsStarted and modificationsEnded
306 bool m_focusedWindowCleared{false};
307
308 bool m_closingAllApps{false};
309};
310
311#endif // TOPLEVELWINDOWMODEL_H
A model of top-level surfaces.
Roles
The Roles supported by the model.
void listChanged()
Emitted when the list changes.
A slightly higher concept than MirSurface.
Definition Window.h:48