Loading...
Searching...
No Matches
TopLevelWindowModel.h
/*
* Copyright (C) 2016-2017 Canonical Ltd.
* Copyright 2019 UBports Foundation
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOPLEVELWINDOWMODEL_H
#define TOPLEVELWINDOWMODEL_H
#include <QAbstractListModel>
#include <QAtomicInteger>
#include <QLoggingCategory>
#include <memory>
#include "WindowManagerGlobal.h"
Q_DECLARE_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL)
class Window;
class Workspace;
namespace miral { class Workspace; }
namespace lomiri {
namespace shell {
namespace application {
class ApplicationInfoInterface;
class ApplicationManagerInterface;
class MirSurfaceInterface;
class SurfaceManagerInterface;
}
}
}
class WINDOWMANAGERQML_EXPORT TopLevelWindowModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(lomiri::shell::application::MirSurfaceInterface* inputMethodSurface READ inputMethodSurface NOTIFY inputMethodSurfaceChanged)
Q_PROPERTY(Window* focusedWindow READ focusedWindow NOTIFY focusedWindowChanged)
Q_PROPERTY(int nextId READ nextId)
Q_PROPERTY(bool rootFocus READ rootFocus WRITE setRootFocus NOTIFY rootFocusChanged)
public:
enum Roles {
WindowRole = Qt::UserRole,
ApplicationRole = Qt::UserRole + 1,
};
TopLevelWindowModel(Workspace* workspace);
~TopLevelWindowModel();
// From QAbstractItemModel
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role) const override;
QHash<int, QByteArray> roleNames() const override {
QHash<int, QByteArray> roleNames { {WindowRole, "window"},
{ApplicationRole, "application"} };
return roleNames;
}
// Own API;
lomiri::shell::application::MirSurfaceInterface* inputMethodSurface() const;
Window* focusedWindow() const;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
int nextId() const { return m_nextId.loadRelaxed(); }
#else
int nextId() const { return m_nextId.load(); }
#endif
public:
Q_INVOKABLE lomiri::shell::application::MirSurfaceInterface *surfaceAt(int index) const;
Q_INVOKABLE Window *windowAt(int index) const;
Q_INVOKABLE lomiri::shell::application::ApplicationInfoInterface *applicationAt(int index) const;
Q_INVOKABLE int idAt(int index) const;
Q_INVOKABLE int indexForId(int id) const;
Q_INVOKABLE void raiseId(int id);
Q_INVOKABLE void closeAllWindows();
Q_INVOKABLE void pendingActivation();
void setApplicationManager(lomiri::shell::application::ApplicationManagerInterface*);
void setSurfaceManager(lomiri::shell::application::SurfaceManagerInterface*);
void setRootFocus(bool focus);
bool rootFocus();
Q_SIGNALS:
void countChanged();
void inputMethodSurfaceChanged(lomiri::shell::application::MirSurfaceInterface* inputMethodSurface);
void focusedWindowChanged(Window *focusedWindow);
void listChanged();
void closedAllWindows();
void rootFocusChanged();
private Q_SLOTS:
void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
const QVector<lomiri::shell::application::MirSurfaceInterface*> surfaces);
void onSurfacesRaised(const QVector<lomiri::shell::application::MirSurfaceInterface*> &surfaces);
void onModificationsStarted();
void onModificationsEnded();
private:
void doRaiseId(int id);
int generateId();
int nextFreeId(int candidateId, const int latestId);
int nextId(int id) const;
QString toString();
int indexOf(lomiri::shell::application::MirSurfaceInterface *surface);
void setInputMethodWindow(Window *window);
void setFocusedWindow(Window *window);
void removeInputMethodWindow();
void deleteAt(int index);
void removeAt(int index);
void removeSurfaces(const QVector<lomiri::shell::application::MirSurfaceInterface *> surfaces);
void addApplication(lomiri::shell::application::ApplicationInfoInterface *application);
void removeApplication(lomiri::shell::application::ApplicationInfoInterface *application);
void prependPlaceholder(lomiri::shell::application::ApplicationInfoInterface *application);
void prependSurface(lomiri::shell::application::MirSurfaceInterface *surface,
lomiri::shell::application::ApplicationInfoInterface *application);
void prependSurfaceHelper(lomiri::shell::application::MirSurfaceInterface *surface,
lomiri::shell::application::ApplicationInfoInterface *application);
void prependWindow(Window *window, lomiri::shell::application::ApplicationInfoInterface *application);
void connectWindow(Window *window);
void connectSurface(lomiri::shell::application::MirSurfaceInterface *surface);
int countWindowsWithApplication(lomiri::shell::application::ApplicationInfoInterface *application);
void onSurfaceDied(lomiri::shell::application::MirSurfaceInterface *surface);
void onSurfaceDestroyed(lomiri::shell::application::MirSurfaceInterface *surface);
void move(int from, int to);
void activateEmptyWindow(Window *window);
void activateTopMostWindowWithoutId(int forbiddenId);
void refreshWindows();
void clear();
Window *createWindow(lomiri::shell::application::MirSurfaceInterface *surface);
Window *createWindowWithId(lomiri::shell::application::MirSurfaceInterface *surface, int id);
Window *createNullWindow();
struct ModelEntry {
ModelEntry() {}
ModelEntry(Window *window,
lomiri::shell::application::ApplicationInfoInterface *application)
: window(window), application(application) {}
Window *window{nullptr};
lomiri::shell::application::ApplicationInfoInterface *application{nullptr};
bool removeOnceSurfaceDestroyed{false};
};
QVector<ModelEntry> m_windowModel;
Window* m_inputMethodWindow{nullptr};
Window* m_focusedWindow{nullptr};
Window* m_nullWindow;
Workspace* m_workspace{nullptr};
// track all the surfaces we've been told about.
QSet<lomiri::shell::application::MirSurfaceInterface*> m_allSurfaces;
Window* m_previousWindow{nullptr};
bool m_pendingActivation;
QAtomicInteger<int> m_nextId{1};
lomiri::shell::application::ApplicationManagerInterface* m_applicationManager{nullptr};
lomiri::shell::application::SurfaceManagerInterface *m_surfaceManager{nullptr};
bool m_surfaceManagerBusy;
enum ModelState {
IdleState,
InsertingState,
RemovingState,
MovingState,
ResettingState
};
ModelState m_modelState{IdleState};
// Valid between modificationsStarted and modificationsEnded
bool m_focusedWindowCleared{false};
bool m_closingAllApps{false};
};
#endif // TOPLEVELWINDOWMODEL_H
TopLevelWindowModel
A model of top-level surfaces.
Definition TopLevelWindowModel.h:60
TopLevelWindowModel::rootFocus
bool rootFocus
Sets whether a user Window or "nothing" should be focused.
Definition TopLevelWindowModel.h:107
TopLevelWindowModel::nextId
int nextId
Definition TopLevelWindowModel.h:86
TopLevelWindowModel::inputMethodSurface
lomiri::shell::application::MirSurfaceInterface * inputMethodSurface
The input method surface, if any.
Definition TopLevelWindowModel.h:75
TopLevelWindowModel::Roles
Roles
The Roles supported by the model.
Definition TopLevelWindowModel.h:116
TopLevelWindowModel::count
int count
Number of top-level surfaces in this model.
Definition TopLevelWindowModel.h:68
TopLevelWindowModel::listChanged
void listChanged()
Emitted when the list changes.
TopLevelWindowModel::focusedWindow
Window * focusedWindow
The currently focused window, if any.
Definition TopLevelWindowModel.h:80
Window
A slightly higher concept than MirSurface.
Definition Window.h:48
lomiri::shell
Definition applicationsfiltermodel.h:23
lomiri
Definition applicationsfiltermodel.h:22