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>
23Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
29 namespace application {
30 class ApplicationInfoInterface;
31 class ApplicationManagerInterface;
32 class MirSurfaceInterface;
33 class SurfaceManagerInterface;
39 * @brief A model of top-level surfaces
41 * It's an abstraction of top-level application windows.
43 * When an entry first appears, it normaly doesn't have a surface yet, meaning that the application is
44 * still starting up. A shell should then display a splash screen or saved screenshot of the application
45 * until its surface comes up.
47 * As applications can have multiple surfaces and you can also have entries without surfaces at all,
48 * the only way to unambiguously refer to an entry in this model is through its id.
50class TopLevelWindowModel : public QAbstractListModel
55 * @brief Number of top-level surfaces in this model
57 * This is the same as rowCount, added in order to keep compatibility with QML ListModels.
59 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
62 * @brief The input method surface, if any
64 * The surface of a onscreen keyboard (akak "virtual keyboard") would be kept here and not in the model itself.
66 Q_PROPERTY(unity::shell::application::MirSurfaceInterface* inputMethodSurface READ inputMethodSurface NOTIFY inputMethodSurfaceChanged)
69 * @brief The currently focused window, if any
71 Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
73 Q_PROPERTY(unity::shell::application::SurfaceManagerInterface* surfaceManager
75 WRITE setSurfaceManager
76 NOTIFY surfaceManagerChanged)
78 Q_PROPERTY(unity::shell::application::ApplicationManagerInterface* applicationManager
79 READ applicationManager
80 WRITE setApplicationManager
81 NOTIFY applicationManagerChanged)
84 The id to be used on the next entry created
87 Q_PROPERTY(int nextId READ nextId NOTIFY nextIdChanged)
91 * @brief The Roles supported by the model
93 * WindowRole - A Window.
94 * ApplicationRole - An ApplicationInfoInterface
97 WindowRole = Qt::UserRole,
98 ApplicationRole = Qt::UserRole + 1,
101 TopLevelWindowModel();
103 // From QAbstractItemModel
104 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
105 QVariant data(const QModelIndex& index, int role) const override;
106 QHash<int, QByteArray> roleNames() const override {
107 QHash<int, QByteArray> roleNames { {WindowRole, "window"},
108 {ApplicationRole, "application"} };
114 unity::shell::application::MirSurfaceInterface* inputMethodSurface() const;
115 Window* focusedWindow() const;
117 unity::shell::application::ApplicationManagerInterface *applicationManager() const { return m_applicationManager; }
118 void setApplicationManager(unity::shell::application::ApplicationManagerInterface*);
120 unity::shell::application::SurfaceManagerInterface *surfaceManager() const { return m_surfaceManager; }
121 void setSurfaceManager(unity::shell::application::SurfaceManagerInterface*);
123 int nextId() const { return m_nextId; }
127 * @brief Returns the surface at the given index
129 * It will be a nullptr if the application is still starting up and thus hasn't yet created
130 * and drawn into a surface.
132 * Same as windowAt(index).surface()
134 Q_INVOKABLE unity::shell::application::MirSurfaceInterface *surfaceAt(int index) const;
137 * @brief Returns the window at the given index
139 * Will always be valid
141 Q_INVOKABLE Window *windowAt(int index) const;
144 * @brief Returns the application at the given index
146 Q_INVOKABLE unity::shell::application::ApplicationInfoInterface *applicationAt(int index) const;
149 * @brief Returns the unique id of the element at the given index
151 Q_INVOKABLE int idAt(int index) const;
154 * @brief Returns the index where the row with the given id is located
156 * Returns -1 if there's no row with the given id.
158 Q_INVOKABLE int indexForId(int id) const;
161 * @brief Raises the row with the given id to the top of the window stack (index == count-1)
163 Q_INVOKABLE void raiseId(int id);
167 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
168 void focusedWindowChanged(Window *focusedWindow);
169 void applicationManagerChanged(unity::shell::application::ApplicationManagerInterface*);
170 void surfaceManagerChanged(unity::shell::application::SurfaceManagerInterface*);
173 * @brief Emitted when the list changes
175 * Emitted when model gains an element, loses an element or when elements exchange positions.
179 void nextIdChanged();
182 void onSurfaceCreated(unity::shell::application::MirSurfaceInterface *surface);
183 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
185 void onModificationsStarted();
186 void onModificationsEnded();
189 void doRaiseId(int id);
191 int nextFreeId(int candidateId, const int latestId);
192 int nextId(int id) const;
194 int indexOf(unity::shell::application::MirSurfaceInterface *surface);
196 void setInputMethodWindow(Window *window);
197 void setFocusedWindow(Window *window);
198 void removeInputMethodWindow();
199 int findIndexOf(const unity::shell::application::MirSurfaceInterface *surface) const;
200 void removeAt(int index);
202 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
203 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
205 void prependPlaceholder(unity::shell::application::ApplicationInfoInterface *application);
206 void prependSurface(unity::shell::application::MirSurfaceInterface *surface,
207 unity::shell::application::ApplicationInfoInterface *application);
208 void prependSurfaceHelper(unity::shell::application::MirSurfaceInterface *surface,
209 unity::shell::application::ApplicationInfoInterface *application);
211 void connectWindow(Window *window);
212 void connectSurface(unity::shell::application::MirSurfaceInterface *surface);
214 void onSurfaceDied(unity::shell::application::MirSurfaceInterface *surface);
215 void onSurfaceDestroyed(unity::shell::application::MirSurfaceInterface *surface);
217 void move(int from, int to);
219 void activateEmptyWindow(Window *window);
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};
236 // Just something big enough that we don't risk running out of unused id numbers.
237 // Not sure if QML int type supports something close to std::numeric_limits<int>::max() and
238 // there's no reason to try out its limits.
239 static const int m_maxId{1000000};
241 unity::shell::application::ApplicationManagerInterface* m_applicationManager{nullptr};
242 unity::shell::application::SurfaceManagerInterface *m_surfaceManager{nullptr};
251 ModelState m_modelState{IdleState};
253 // Valid between modificationsStarted and modificationsEnded
254 bool m_focusedWindowChanged{false};
255 Window *m_newlyFocusedWindow{nullptr};
258#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