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
15// `create()` below names both of these. Every existing consumer happened
16// to pull them in first, so the omission only surfaced once a translation
17// unit included this header on its own — the usual way a unity build
18// hides a missing declaration.
19QT_BEGIN_NAMESPACE
20class QQmlEngine;
21class QJSEngine;
22QT_END_NAMESPACE
23
24namespace PhosphorShell {
25
49class PHOSPHORSHELL_EXPORT ToplevelListModel : public QAbstractListModel
50{
51 Q_OBJECT
52
53public:
54 enum Role {
55 ToplevelRole = Qt::UserRole + 1
56 };
57 Q_ENUM(Role)
58
59 explicit ToplevelListModel(PhosphorWayland::ForeignToplevelManager* manager, QObject* parent = nullptr);
60 ~ToplevelListModel() override;
61
62 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
63 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
64 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
65
66private Q_SLOTS:
67 void onToplevelAdded(PhosphorWayland::ForeignToplevel* toplevel);
68 void onToplevelRemoved(PhosphorWayland::ForeignToplevel* toplevel);
69
70private:
71 QPointer<PhosphorWayland::ForeignToplevelManager> m_manager;
72 // QPointer rows — a toplevel can be deleteLater'd between `closed`
73 // and the actual delete; storing QPointer means a stale row never
74 // returns a dangling pointer to a delegate's `var` property.
75 QList<QPointer<PhosphorWayland::ForeignToplevel>> m_rows;
76};
77
108// Registered as a QML singleton imperatively in ShellEngine::load() via
109// `qmlRegisterSingletonType<Toplevels>(..., &Toplevels::create)`. The
110// QML_NAMED_ELEMENT / QML_SINGLETON macros would only be honoured by
111// `qt_add_qml_module`, which the build doesn't use.
112class PHOSPHORSHELL_EXPORT Toplevels : public QObject
113{
114 Q_OBJECT
115
122 Q_PROPERTY(QList<PhosphorWayland::ForeignToplevel*> toplevels READ toplevels NOTIFY toplevelsChanged)
126 Q_PROPERTY(QAbstractListModel* model READ model CONSTANT)
127 Q_PROPERTY(bool supported READ isSupported CONSTANT)
139
140public:
141 explicit Toplevels(QObject* parent = nullptr);
142 ~Toplevels() override;
143
145 [[nodiscard]] static Toplevels* create(QQmlEngine* engine, QJSEngine* scriptEngine);
146
147 [[nodiscard]] QList<PhosphorWayland::ForeignToplevel*> toplevels() const;
148 [[nodiscard]] QAbstractListModel* model() const;
149 [[nodiscard]] bool isSupported() const;
151
152Q_SIGNALS:
155
156private:
159 void subscribeToplevel(PhosphorWayland::ForeignToplevel* toplevel);
162 void watchToplevel(PhosphorWayland::ForeignToplevel* toplevel);
164 void recomputeActive();
170 static PhosphorWayland::ForeignToplevelManager* sharedManager();
171
172 // Per-engine model owned by this Toplevels wrapper. Reads from the
173 // shared manager but provides a fresh QAbstractListModel for each
174 // QML engine, so engine teardown cleanly tears down its own model
175 // without disturbing siblings.
176 ToplevelListModel* m_model = nullptr;
177
178 // The last-published active toplevel. QPointer because a toplevel can
179 // be destroyed without a preceding state change, and the getter is
180 // read from arbitrary binding evaluations; a raw pointer would hand
181 // QML a dangling ForeignToplevel* in that window.
182 QPointer<PhosphorWayland::ForeignToplevel> m_active;
183 // The pointer VALUE last published through activeToplevelChanged. Raw
184 // and never dereferenced: it exists purely so the change gate compares
185 // published state rather than a handle that can clear itself out from
186 // under the comparison.
187 PhosphorWayland::ForeignToplevel* m_publishedActive = nullptr;
188};
189
190} // namespace PhosphorShell
QAbstractListModel view of the live toplevel set.
Definition Toplevels.h:50
ToplevelListModel(PhosphorWayland::ForeignToplevelManager *manager, QObject *parent=nullptr)
QVariant data(const QModelIndex &index, int role) const override
Role
Definition Toplevels.h:54
@ ToplevelRole
Definition Toplevels.h:55
int rowCount(const QModelIndex &parent={}) const override
QHash< int, QByteArray > roleNames() const override
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
PhosphorWayland::ForeignToplevel * activeToplevel() 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 BackgroundEffect.h:15