Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ShellGlobal.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
8// Qt's MOC needs fully-defined types for Q_PROPERTY pointer types
9// (qmetatype.h's `checkTypeIsSuitableForMetaType` static-asserts
10// `is_complete<T>`). Forward declarations compile in older Qt but
11// fail with Qt ≥ 6.10. ScreenModel and WallpaperService are both
12// part of this library and don't transitively pull ShellGlobal back
13// in, so the includes are cycle-free.
16
17#include <QHash>
18#include <QObject>
19#include <QPointer>
20#include <QString>
21
22namespace PhosphorShell {
23
24class PersistentProperties;
25
26// Exposed to QML as a context property (`PhosphorShell`) by ShellEngine —
27// not registered as a QML singleton. Q_INVOKABLE methods and Q_PROPERTYs
28// are still accessible through the context-property reference.
29class PHOSPHORSHELL_EXPORT ShellGlobal : public QObject
30{
31 Q_OBJECT
32
33 // NOTIFY (not CONSTANT) — `screens` is set lazily by ShellEngine after
34 // engine construction (setScreenModel). A CONSTANT property would let
35 // QML cache the initial nullptr forever even after the model arrives.
36 Q_PROPERTY(ScreenModel* screens READ screens NOTIFY screensChanged)
37
38
42 Q_PROPERTY(WallpaperService* wallpaper READ wallpaper CONSTANT)
43
44public:
45 explicit ShellGlobal(QObject* parent = nullptr);
46 ~ShellGlobal() override;
47
48 [[nodiscard]] ScreenModel* screens() const;
50
51 [[nodiscard]] WallpaperService* wallpaper() const;
52
53 Q_INVOKABLE [[nodiscard]] QObject* singleton(const QString& reloadId) const;
54 void registerSingleton(const QString& reloadId, PersistentProperties* props);
56
57Q_SIGNALS:
59
60private:
61 // QPointer so external destruction (engine reload) doesn't leave us
62 // dangling.
63 QPointer<ScreenModel> m_screens;
64 QHash<QString, QPointer<PersistentProperties>> m_singletons;
65 // Owned by `this` — process-wide info but conveniently scoped to
66 // the engine's lifetime so a hot-reload cleanly tears down the
67 // file watcher and pending async loads with the rest of the shell.
68 WallpaperService* m_wallpaper = nullptr;
69};
70
71} // namespace PhosphorShell
Definition PersistentProperties.h:14
Definition ScreenModel.h:25
Definition ShellGlobal.h:30
QObject * singleton(const QString &reloadId) const
ScreenModel * screens() const
void registerSingleton(const QString &reloadId, PersistentProperties *props)
void setScreenModel(ScreenModel *model)
ShellGlobal(QObject *parent=nullptr)
Desktop wallpaper image source for shader backgrounds.
WallpaperService * wallpaper() const
Asynchronous wallpaper-image source for shader backgrounds.
Definition WallpaperService.h:51
Definition Environment.h:11