2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#ifndef TOPLEVELSURFACELIST_H
18#define TOPLEVELSURFACELIST_H
20#include <QAbstractListModel>
22#include <QLoggingCategory>
24Q_DECLARE_LOGGING_CATEGORY(UNITY_TOPSURFACELIST)
28 namespace application {
29 class ApplicationInfoInterface;
30 class MirSurfaceInterface;
36 * @brief A model of top-level surfaces
38 * It's an abstraction of top-level application windows.
40 * When an entry first appears, it normaly doesn't have a surface yet, meaning that the application is
41 * still starting up. A shell should then display a splash screen or saved screenshot of the application
42 * until its surface comes up.
44 * As applications can have multiple surfaces and you can also have entries without surfaces at all,
45 * the only way to unambiguously refer to an entry in this model is through its id.
47class TopLevelSurfaceList : public QAbstractListModel
53 * @brief A list model of applications.
55 * It's expected to have a role called "application" which returns a ApplicationInfoInterface
57 Q_PROPERTY(QAbstractListModel* applicationsModel READ applicationsModel
58 WRITE setApplicationsModel
59 NOTIFY applicationsModelChanged)
62 * @brief Number of top-level surfaces in this model
64 * This is the same as rowCount, added in order to keep compatibility with QML ListModels.
66 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
69 The id to be used on the next entry created
72 Q_PROPERTY(int nextId READ nextId NOTIFY nextIdChanged)
76 * @brief The Roles supported by the model
78 * SurfaceRole - A MirSurfaceInterface. It will be null if the application is still starting up
79 * ApplicationRole - An ApplicationInfoInterface
80 * IdRole - A unique identifier for this entry. Useful to unambiguosly track elements as they move around in the list
83 SurfaceRole = Qt::UserRole,
84 ApplicationRole = Qt::UserRole + 1,
85 IdRole = Qt::UserRole + 2,
88 explicit TopLevelSurfaceList(QObject *parent = nullptr);
89 virtual ~TopLevelSurfaceList();
91 // QAbstractItemModel methods
92 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
93 QVariant data(const QModelIndex& index, int role) const override;
94 QHash<int, QByteArray> roleNames() const override {
95 QHash<int, QByteArray> roleNames { {SurfaceRole, "surface"},
96 {ApplicationRole, "application"},
101 int nextId() const { return m_nextId; }
103 QAbstractListModel *applicationsModel() const;
104 void setApplicationsModel(QAbstractListModel*);
108 * @brief Returns the surface at the given index
110 * It will be a nullptr if the application is still starting up and thus hasn't yet created
111 * and drawn into a surface.
113 unity::shell::application::MirSurfaceInterface *surfaceAt(int index) const;
116 * @brief Returns the application at the given index
118 unity::shell::application::ApplicationInfoInterface *applicationAt(int index) const;
121 * @brief Returns the unique id of the element at the given index
123 int idAt(int index) const;
126 * @brief Returns the index where the row with the given id is located
128 * Returns -1 if there's no row with the given id.
130 int indexForId(int id) const;
133 * @brief Raises the row with the given id to index 0
135 void raiseId(int id);
137 void doRaiseId(int id);
143 * @brief Emitted when the list changes
145 * Emitted when model gains an element, loses an element or when elements exchange positions.
149 void nextIdChanged();
151 void applicationsModelChanged();
154 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
155 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
157 int indexOf(unity::shell::application::MirSurfaceInterface *surface);
158 void raise(unity::shell::application::MirSurfaceInterface *surface);
159 void move(int from, int to);
160 void appendSurfaceHelper(unity::shell::application::MirSurfaceInterface *surface,
161 unity::shell::application::ApplicationInfoInterface *application);
162 void connectSurface(unity::shell::application::MirSurfaceInterface *surface);
164 int nextFreeId(int candidateId);
166 void onSurfaceDestroyed(unity::shell::application::MirSurfaceInterface *surface);
167 void onSurfaceDied(unity::shell::application::MirSurfaceInterface *surface);
168 void removeAt(int index);
169 void findApplicationRole();
171 unity::shell::application::ApplicationInfoInterface *getApplicationFromModelAt(int index);
174 Placeholder for a future surface from a starting or running application.
175 Enables shell to give immediate feedback to the user by showing, eg,
178 It's a model row containing a null surface and the given application.
180 void appendPlaceholder(unity::shell::application::ApplicationInfoInterface *application);
183 Adds a model row with the given surface and application
185 Alternatively, if a placeholder exists for the given application it's
186 filled with the given surface instead.
188 void appendSurface(unity::shell::application::MirSurfaceInterface *surface,
189 unity::shell::application::ApplicationInfoInterface *application);
192 ModelEntry(unity::shell::application::MirSurfaceInterface *surface, unity::shell::application::ApplicationInfoInterface *application, int id)
193 : surface(surface), application(application), id(id) {}
194 unity::shell::application::MirSurfaceInterface *surface;
195 unity::shell::application::ApplicationInfoInterface *application;
197 bool removeOnceSurfaceDestroyed{false};
200 QList<ModelEntry> m_surfaceList;
202 static const int m_maxId{1000000};
204 // applications that are being monitored
205 QList<unity::shell::application::ApplicationInfoInterface *> m_applications;
207 QAbstractListModel* m_applicationsModel{nullptr};
208 int m_applicationRole{-1};
217 ModelState m_modelState{IdleState};
220Q_DECLARE_METATYPE(TopLevelSurfaceList*)
221Q_DECLARE_METATYPE(QAbstractListModel*)
223#endif // TOPLEVELSURFACELIST_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