2 * Copyright (C) 2016-2017 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>
25#include "WindowManagerGlobal.h"
27Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
32namespace miral { class Workspace; }
36 namespace application {
37 class ApplicationInfoInterface;
38 class ApplicationManagerInterface;
39 class MirSurfaceInterface;
40 class SurfaceManagerInterface;
46 * @brief A model of top-level surfaces
48 * It's an abstraction of top-level application windows.
50 * When an entry first appears, it normaly doesn't have a surface yet, meaning that the application is
51 * still starting up. A shell should then display a splash screen or saved screenshot of the application
52 * until its surface comes up.
54 * As applications can have multiple surfaces and you can also have entries without surfaces at all,
55 * the only way to unambiguously refer to an entry in this model is through its id.
57class WINDOWMANAGERQML_EXPORT TopLevelWindowModel : public QAbstractListModel
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 * @brief The input method surface, if any
71 * The surface of a onscreen keyboard (akak "virtual keyboard") would be kept here and not in the model itself.
73 Q_PROPERTY(unity::shell::application::MirSurfaceInterface* inputMethodSurface READ inputMethodSurface NOTIFY inputMethodSurfaceChanged)
76 * @brief The currently focused window, if any
78 Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
81 The id to be used on the next entry created
84 Q_PROPERTY(int nextId READ nextId NOTIFY nextIdChanged)
88 * @brief The Roles supported by the model
90 * WindowRole - A Window.
91 * ApplicationRole - An ApplicationInfoInterface
94 WindowRole = Qt::UserRole,
95 ApplicationRole = Qt::UserRole + 1,
98 TopLevelWindowModel(Workspace* workspace);
99 ~TopLevelWindowModel();
101 // From QAbstractItemModel
102 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
103 QVariant data(const QModelIndex& index, int role) const override;
104 QHash<int, QByteArray> roleNames() const override {
105 QHash<int, QByteArray> roleNames { {WindowRole, "window"},
106 {ApplicationRole, "application"} };
112 unity::shell::application::MirSurfaceInterface* inputMethodSurface() const;
113 Window* focusedWindow() const;
115 int nextId() const { return m_nextId; }
119 * @brief Returns the surface at the given index
121 * It will be a nullptr if the application is still starting up and thus hasn't yet created
122 * and drawn into a surface.
124 * Same as windowAt(index).surface()
126 Q_INVOKABLE unity::shell::application::MirSurfaceInterface *surfaceAt(int index) const;
129 * @brief Returns the window at the given index
131 * Will always be valid
133 Q_INVOKABLE Window *windowAt(int index) const;
136 * @brief Returns the application at the given index
138 Q_INVOKABLE unity::shell::application::ApplicationInfoInterface *applicationAt(int index) const;
141 * @brief Returns the unique id of the element at the given index
143 Q_INVOKABLE int idAt(int index) const;
146 * @brief Returns the index where the row with the given id is located
148 * Returns -1 if there's no row with the given id.
150 Q_INVOKABLE int indexForId(int id) const;
153 * @brief Raises the row with the given id to the top of the window stack (index == count-1)
155 Q_INVOKABLE void raiseId(int id);
157 void setApplicationManager(unity::shell::application::ApplicationManagerInterface*);
158 void setSurfaceManager(unity::shell::application::SurfaceManagerInterface*);
162 void inputMethodSurfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
163 void focusedWindowChanged(Window *focusedWindow);
166 * @brief Emitted when the list changes
168 * Emitted when model gains an element, loses an element or when elements exchange positions.
172 void nextIdChanged();
175 void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
176 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
177 void onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
178 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
179 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
181 void onModificationsStarted();
182 void onModificationsEnded();
185 void doRaiseId(int id);
187 int nextFreeId(int candidateId, const int latestId);
188 int nextId(int id) const;
190 int indexOf(unity::shell::application::MirSurfaceInterface *surface);
192 void setInputMethodWindow(Window *window);
193 void setFocusedWindow(Window *window);
194 void removeInputMethodWindow();
195 int findIndexOf(const unity::shell::application::MirSurfaceInterface *surface) const;
196 void deleteAt(int index);
197 void removeAt(int index);
199 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
200 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
202 void prependPlaceholder(unity::shell::application::ApplicationInfoInterface *application);
203 void prependSurface(unity::shell::application::MirSurfaceInterface *surface,
204 unity::shell::application::ApplicationInfoInterface *application);
205 void prependSurfaceHelper(unity::shell::application::MirSurfaceInterface *surface,
206 unity::shell::application::ApplicationInfoInterface *application);
207 void prependWindow(Window *window, unity::shell::application::ApplicationInfoInterface *application);
209 void connectWindow(Window *window);
210 void connectSurface(unity::shell::application::MirSurfaceInterface *surface);
212 void onSurfaceDied(unity::shell::application::MirSurfaceInterface *surface);
213 void onSurfaceDestroyed(unity::shell::application::MirSurfaceInterface *surface);
215 void move(int from, int to);
217 void activateEmptyWindow(Window *window);
219 void activateTopMostWindowWithoutId(int forbiddenId);
220 void refreshWindows();
223 Window *createWindow(unity::shell::application::MirSurfaceInterface *surface);
227 ModelEntry(Window *window,
228 unity::shell::application::ApplicationInfoInterface *application)
229 : window(window), application(application) {}
230 Window *window{nullptr};
231 unity::shell::application::ApplicationInfoInterface *application{nullptr};
232 bool removeOnceSurfaceDestroyed{false};
235 QVector<ModelEntry> m_windowModel;
236 Window* m_inputMethodWindow{nullptr};
237 Window* m_focusedWindow{nullptr};
238 Workspace* m_workspace{nullptr};
239 // track all the surfaces we've been told about.
240 QSet<unity::shell::application::MirSurfaceInterface*> m_allSurfaces;
243 // Just something big enough that we don't risk running out of unused id numbers.
244 // Not sure if QML int type supports something close to std::numeric_limits<int>::max() and
245 // there's no reason to try out its limits.
246 static const int m_maxId{1000000};
248 unity::shell::application::ApplicationManagerInterface* m_applicationManager{nullptr};
249 unity::shell::application::SurfaceManagerInterface *m_surfaceManager{nullptr};
258 ModelState m_modelState{IdleState};
260 // Valid between modificationsStarted and modificationsEnded
261 bool m_focusedWindowCleared{false};
264#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