2 * Copyright (C) 2016-2017 Canonical, Ltd.
3 * Copyright 2019 UBports Foundation
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.
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.
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/>.
18#ifndef TOPLEVELWINDOWMODEL_H
19#define TOPLEVELWINDOWMODEL_H
21#include <QAbstractListModel>
22#include <QAtomicInteger>
23#include <QLoggingCategory>
25#include "WindowManagerGlobal.h"
27Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
33 namespace application {
34 class ApplicationInfoInterface;
35 class ApplicationManagerInterface;
36 class MirSurfaceInterface;
37 class SurfaceManagerInterface;
43 * @brief A model of top-level surfaces
45 * It's an abstraction of top-level application windows.
47 * When an entry first appears, it normaly doesn't have a surface yet, meaning that the application is
48 * still starting up. A shell should then display a splash screen or saved screenshot of the application
49 * until its surface comes up.
51 * As applications can have multiple surfaces and you can also have entries without surfaces at all,
52 * the only way to unambiguously refer to an entry in this model is through its id.
54class WINDOWMANAGERQML_EXPORT TopLevelWindowModel : public QAbstractListModel
59 * @brief Number of top-level surfaces in this model
61 * This is the same as rowCount, added in order to keep compatibility with QML ListModels.
63 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
66 * @brief The input method surface, if any
68 * The surface of a onscreen keyboard (akak "virtual keyboard") would be kept here and not in the model itself.
70 Q_PROPERTY(unity::shell::application::MirSurfaceInterface* inputMethodSurface READ inputMethodSurface NOTIFY inputMethodSurfaceChanged)
73 * @brief The currently focused window, if any
75 Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
77 Q_PROPERTY(unity::shell::application::SurfaceManagerInterface* surfaceManager
79 WRITE setSurfaceManager
80 NOTIFY surfaceManagerChanged)
82 Q_PROPERTY(unity::shell::application::ApplicationManagerInterface* applicationManager
83 READ applicationManager
84 WRITE setApplicationManager
85 NOTIFY applicationManagerChanged)
88 The id to be used on the next entry created
91 Q_PROPERTY(int nextId READ nextId)
95 * @brief Sets whether a user Window or "nothing" should be focused
97 * This implementation of TLWM must have something focused. However, the
98 * user may wish to have nothing in some cases - for example, when they
99 * minimize all their windows on the desktop or unfocus the app they're
100 * using by clicking the background or indicators.
102 * Unsetting rootFocus effectively focuses "nothing" by setting up a Window
103 * that has no displayable Surfaces and bringing it into focus.
105 * Setting rootFocus attempts to focus the Window which was focused last -
106 * unless another app is attempting to gain focus (as determined by
107 * pendingActivation) and that's why we got rootFocus.
109 * If the previously-focused Window was closed before rootFocus was set,
110 * the next available window will be focused.
112 Q_PROPERTY(bool rootFocus READ rootFocus WRITE setRootFocus NOTIFY rootFocusChanged)
116 * @brief The Roles supported by the model
118 * WindowRole - A Window.
119 * ApplicationRole - An ApplicationInfoInterface
122 WindowRole = Qt::UserRole,
123 ApplicationRole = Qt::UserRole + 1,
126 TopLevelWindowModel();
128 // From QAbstractItemModel
129 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
130 QVariant data(const QModelIndex& index, int role) const override;
131 QHash<int, QByteArray> roleNames() const override {
132 QHash<int, QByteArray> roleNames { {WindowRole, "window"},
133 {ApplicationRole, "application"} };
139 unity::shell::application::MirSurfaceInterface* inputMethodSurface() const;
140 Window* focusedWindow() const;
142 unity::shell::application::ApplicationManagerInterface *applicationManager() const { return m_applicationManager; }
143 void setApplicationManager(unity::shell::application::ApplicationManagerInterface*);
145 unity::shell::application::SurfaceManagerInterface *surfaceManager() const { return m_surfaceManager; }
146 void setSurfaceManager(unity::shell::application::SurfaceManagerInterface*);
148 int nextId() const { return m_nextId.load(); }
152 * @brief Returns the surface at the given index
154 * It will be a nullptr if the application is still starting up and thus hasn't yet created
155 * and drawn into a surface.
157 * Same as windowAt(index).surface()
159 Q_INVOKABLE unity::shell::application::MirSurfaceInterface *surfaceAt(int index) const;
162 * @brief Returns the window at the given index
164 * Will always be valid
166 Q_INVOKABLE Window *windowAt(int index) const;
169 * @brief Returns the application at the given index
171 Q_INVOKABLE unity::shell::application::ApplicationInfoInterface *applicationAt(int index) const;
174 * @brief Returns the unique id of the element at the given index
176 Q_INVOKABLE int idAt(int index) const;
179 * @brief Returns the index where the row with the given id is located
181 * Returns -1 if there's no row with the given id.
183 Q_INVOKABLE int indexForId(int id) const;
186 * @brief Raises the row with the given id to the top of the window stack (index == count-1)
188 Q_INVOKABLE void raiseId(int id);
191 * @brief Closes all windows, emits closedAllWindows when done
193 Q_INVOKABLE void closeAllWindows();
196 * @brief Sets pending activation flag
198 Q_INVOKABLE void pendingActivation();
200 void setRootFocus(bool focus);
205 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
206 void focusedWindowChanged(Window *focusedWindow);
207 void applicationManagerChanged(unity::shell::application::ApplicationManagerInterface*);
208 void surfaceManagerChanged(unity::shell::application::SurfaceManagerInterface*);
211 * @brief Emitted when the list changes
213 * Emitted when model gains an element, loses an element or when elements exchange positions.
217 void closedAllWindows();
219 void rootFocusChanged();
222 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
223 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
225 void onModificationsStarted();
226 void onModificationsEnded();
229 void doRaiseId(int id);
231 int nextFreeId(int candidateId, const int latestId);
232 int nextId(int id) const;
234 int indexOf(unity::shell::application::MirSurfaceInterface *surface);
236 void setInputMethodWindow(Window *window);
237 void setFocusedWindow(Window *window);
238 void removeInputMethodWindow();
239 int findIndexOf(const unity::shell::application::MirSurfaceInterface *surface) const;
240 void deleteAt(int index);
241 void removeAt(int index);
243 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
244 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
246 void prependPlaceholder(unity::shell::application::ApplicationInfoInterface *application);
247 void prependSurface(unity::shell::application::MirSurfaceInterface *surface,
248 unity::shell::application::ApplicationInfoInterface *application);
249 void prependSurfaceHelper(unity::shell::application::MirSurfaceInterface *surface,
250 unity::shell::application::ApplicationInfoInterface *application);
251 void prependWindow(Window *window, unity::shell::application::ApplicationInfoInterface *application);
253 void connectWindow(Window *window);
254 void connectSurface(unity::shell::application::MirSurfaceInterface *surface);
256 void onSurfaceDied(unity::shell::application::MirSurfaceInterface *surface);
257 void onSurfaceDestroyed(unity::shell::application::MirSurfaceInterface *surface);
259 void move(int from, int to);
261 void activateEmptyWindow(Window *window);
263 void activateTopMostWindowWithoutId(int forbiddenId);
265 Window *createWindow(unity::shell::application::MirSurfaceInterface *surface);
266 Window *createWindowWithId(unity::shell::application::MirSurfaceInterface *surface, int id);
267 Window *createNullWindow();
271 ModelEntry(Window *window,
272 unity::shell::application::ApplicationInfoInterface *application)
273 : window(window), application(application) {}
274 Window *window{nullptr};
275 unity::shell::application::ApplicationInfoInterface *application{nullptr};
276 bool removeOnceSurfaceDestroyed{false};
279 QVector<ModelEntry> m_windowModel;
280 Window* m_inputMethodWindow{nullptr};
281 Window* m_focusedWindow{nullptr};
282 Window* m_nullWindow;
283 Window* m_previousWindow{nullptr};
284 bool m_pendingActivation;
286 QAtomicInteger<int> m_nextId{1};
288 unity::shell::application::ApplicationManagerInterface* m_applicationManager{nullptr};
289 unity::shell::application::SurfaceManagerInterface *m_surfaceManager{nullptr};
290 bool m_surfaceManagerBusy;
299 ModelState m_modelState{IdleState};
301 // Valid between modificationsStarted and modificationsEnded
302 bool m_focusedWindowChanged{false};
303 Window *m_newlyFocusedWindow{nullptr};
305 bool m_closingAllApps{false};
308#endif // TOPLEVELWINDOWMODEL_H
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list