2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#ifndef TOPLEVELWINDOWMODEL_H
18#define TOPLEVELWINDOWMODEL_H
20#include <QAbstractListModel>
21#include <QLoggingCategory>
25Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
30namespace miral { class Workspace; }
34 namespace application {
35 class ApplicationInfoInterface;
36 class ApplicationManagerInterface;
37 class MirSurfaceInterface;
38 class SurfaceManagerInterface;
44 * @brief A model of top-level surfaces
46 * It's an abstraction of top-level application windows.
48 * When an entry first appears, it normaly doesn't have a surface yet, meaning that the application is
49 * still starting up. A shell should then display a splash screen or saved screenshot of the application
50 * until its surface comes up.
52 * As applications can have multiple surfaces and you can also have entries without surfaces at all,
53 * the only way to unambiguously refer to an entry in this model is through its id.
55class TopLevelWindowModel : public QAbstractListModel
60 * @brief Number of top-level surfaces in this model
62 * This is the same as rowCount, added in order to keep compatibility with QML ListModels.
64 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
67 * @brief The input method surface, if any
69 * The surface of a onscreen keyboard (akak "virtual keyboard") would be kept here and not in the model itself.
71 Q_PROPERTY(unity::shell::application::MirSurfaceInterface* inputMethodSurface READ inputMethodSurface NOTIFY inputMethodSurfaceChanged)
74 * @brief The currently focused window, if any
76 Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
79 The id to be used on the next entry created
82 Q_PROPERTY(int nextId READ nextId NOTIFY nextIdChanged)
86 * @brief The Roles supported by the model
88 * WindowRole - A Window.
89 * ApplicationRole - An ApplicationInfoInterface
92 WindowRole = Qt::UserRole,
93 ApplicationRole = Qt::UserRole + 1,
96 TopLevelWindowModel(Workspace* workspace);
98 // From QAbstractItemModel
99 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
100 QVariant data(const QModelIndex& index, int role) const override;
101 QHash<int, QByteArray> roleNames() const override {
102 QHash<int, QByteArray> roleNames { {WindowRole, "window"},
103 {ApplicationRole, "application"} };
109 unity::shell::application::MirSurfaceInterface* inputMethodSurface() const;
110 Window* focusedWindow() const;
112 int nextId() const { return m_nextId; }
116 * @brief Returns the surface at the given index
118 * It will be a nullptr if the application is still starting up and thus hasn't yet created
119 * and drawn into a surface.
121 * Same as windowAt(index).surface()
123 Q_INVOKABLE unity::shell::application::MirSurfaceInterface *surfaceAt(int index) const;
126 * @brief Returns the window at the given index
128 * Will always be valid
130 Q_INVOKABLE Window *windowAt(int index) const;
133 * @brief Returns the application at the given index
135 Q_INVOKABLE unity::shell::application::ApplicationInfoInterface *applicationAt(int index) const;
138 * @brief Returns the unique id of the element at the given index
140 Q_INVOKABLE int idAt(int index) const;
143 * @brief Returns the index where the row with the given id is located
145 * Returns -1 if there's no row with the given id.
147 Q_INVOKABLE int indexForId(int id) const;
150 * @brief Raises the row with the given id to the top of the window stack (index == count-1)
152 Q_INVOKABLE void raiseId(int id);
156 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
157 void focusedWindowChanged(Window *focusedWindow);
160 * @brief Emitted when the list changes
162 * Emitted when model gains an element, loses an element or when elements exchange positions.
166 void nextIdChanged();
169 void setApplicationManager(unity::shell::application::ApplicationManagerInterface*);
170 void setSurfaceManager(unity::shell::application::SurfaceManagerInterface*);
172 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
173 void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
174 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
175 void onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
176 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
177 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
179 void onModificationsStarted();
180 void onModificationsEnded();
183 void doRaiseId(int id);
185 int nextFreeId(int candidateId, const int latestId);
186 int nextId(int id) const;
188 int indexOf(unity::shell::application::MirSurfaceInterface *surface);
190 void setInputMethodWindow(Window *window);
191 void setFocusedWindow(Window *window);
192 void removeInputMethodWindow();
193 int findIndexOf(const unity::shell::application::MirSurfaceInterface *surface) const;
194 void removeAt(int index);
196 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
197 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
199 void prependPlaceholder(unity::shell::application::ApplicationInfoInterface *application);
200 void prependSurface(unity::shell::application::MirSurfaceInterface *surface,
201 unity::shell::application::ApplicationInfoInterface *application);
202 void prependSurfaceHelper(unity::shell::application::MirSurfaceInterface *surface,
203 unity::shell::application::ApplicationInfoInterface *application);
205 void connectWindow(Window *window);
206 void connectSurface(unity::shell::application::MirSurfaceInterface *surface);
208 void onSurfaceDied(unity::shell::application::MirSurfaceInterface *surface);
209 void onSurfaceDestroyed(unity::shell::application::MirSurfaceInterface *surface);
211 void move(int from, int to);
213 void activateEmptyWindow(Window *window);
215 void activateTopMostWindowWithoutId(int forbiddenId);
216 void refreshWindows();
219 Window *createWindow(unity::shell::application::MirSurfaceInterface *surface);
223 ModelEntry(Window *window,
224 unity::shell::application::ApplicationInfoInterface *application)
225 : window(window), application(application) {}
226 Window *window{nullptr};
227 unity::shell::application::ApplicationInfoInterface *application{nullptr};
228 bool removeOnceSurfaceDestroyed{false};
231 QVector<ModelEntry> m_windowModel;
232 Window* m_inputMethodWindow{nullptr};
233 Window* m_focusedWindow{nullptr};
234 Workspace* m_workspace{nullptr};
235 // track all the surfaces we've been told about.
236 QSet<unity::shell::application::MirSurfaceInterface*> m_allSurfaces;
239 // Just something big enough that we don't risk running out of unused id numbers.
240 // Not sure if QML int type supports something close to std::numeric_limits<int>::max() and
241 // there's no reason to try out its limits.
242 static const int m_maxId{1000000};
244 unity::shell::application::ApplicationManagerInterface* m_applicationManager{nullptr};
245 unity::shell::application::SurfaceManagerInterface *m_surfaceManager{nullptr};
254 ModelState m_modelState{IdleState};
256 // Valid between modificationsStarted and modificationsEnded
257 bool m_focusedWindowCleared{false};
260#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