Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
Toplevels.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorShell/phosphorshell_export.h>
7
9
10#include <QAbstractListModel>
11#include <QList>
12#include <QObject>
13#include <QPointer>
14#include <QtQml/qqmlregistration.h>
15
16namespace PhosphorShell {
17
41class PHOSPHORSHELL_EXPORT ToplevelListModel : public QAbstractListModel
42{
43 Q_OBJECT
44
45public:
46 enum Role {
47 ToplevelRole = Qt::UserRole + 1
48 };
49 Q_ENUM(Role)
50
51 explicit ToplevelListModel(PhosphorWayland::ForeignToplevelManager* manager, QObject* parent = nullptr);
52 ~ToplevelListModel() override;
53
54 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
55 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
56 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
57
58private Q_SLOTS:
59 void onToplevelAdded(PhosphorWayland::ForeignToplevel* toplevel);
60 void onToplevelRemoved(PhosphorWayland::ForeignToplevel* toplevel);
61
62private:
63 QPointer<PhosphorWayland::ForeignToplevelManager> m_manager;
64 // QPointer rows — a toplevel can be deleteLater'd between `closed`
65 // and the actual delete; storing QPointer means a stale row never
66 // returns a dangling pointer to a delegate's `var` property.
67 QList<QPointer<PhosphorWayland::ForeignToplevel>> m_rows;
68};
69
99// Registered as a QML singleton imperatively in ShellEngine::load() via
100// `qmlRegisterSingletonType<Toplevels>(..., &Toplevels::create)`. The
101// QML_NAMED_ELEMENT / QML_SINGLETON macros would only be honoured by
102// `qt_add_qml_module`, which the build doesn't use.
103class PHOSPHORSHELL_EXPORT Toplevels : public QObject
104{
105 Q_OBJECT
106
113 Q_PROPERTY(QList<PhosphorWayland::ForeignToplevel*> toplevels READ toplevels NOTIFY toplevelsChanged)
117 Q_PROPERTY(QAbstractListModel* model READ model CONSTANT)
118 Q_PROPERTY(bool supported READ isSupported CONSTANT)
119
120public:
121 explicit Toplevels(QObject* parent = nullptr);
122 ~Toplevels() override;
123
125 [[nodiscard]] static Toplevels* create(QQmlEngine* engine, QJSEngine* scriptEngine);
126
127 [[nodiscard]] QList<PhosphorWayland::ForeignToplevel*> toplevels() const;
128 [[nodiscard]] QAbstractListModel* model() const;
129 [[nodiscard]] bool isSupported() const;
130
131Q_SIGNALS:
133
134private:
140 static PhosphorWayland::ForeignToplevelManager* sharedManager();
141
142 // Per-engine model owned by this Toplevels wrapper. Reads from the
143 // shared manager but provides a fresh QAbstractListModel for each
144 // QML engine, so engine teardown cleanly tears down its own model
145 // without disturbing siblings.
146 ToplevelListModel* m_model = nullptr;
147};
148
149} // namespace PhosphorShell
QAbstractListModel view of the live toplevel set.
Definition Toplevels.h:42
QVariant data(const QModelIndex &index, int role) const override
Role
Definition Toplevels.h:46
QHash< int, QByteArray > roleNames() const override
QML singleton exposing the live list of toplevel windows for taskbars.
Definition Toplevels.h:104
Toplevels(QObject *parent=nullptr)
Snapshot list of currently-live toplevels.
static Toplevels * create(QQmlEngine *engine, QJSEngine *scriptEngine)
QML-singleton factory hook.
QAbstractListModel * model() const
QList< PhosphorWayland::ForeignToplevel * > toplevels() const
Client-side wrapper around zwlr_foreign_toplevel_manager_v1.
Definition ForeignToplevel.h:44
A single toplevel window owned by some other Wayland client.
Definition ForeignToplevel.h:91
Definition Environment.h:11
Definition CompositorLost.h:11