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
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:
47 explicit ShellGlobal(const QString& wallpaperStorePath, QObject* parent = nullptr);
48 ~ShellGlobal() override;
49
50 [[nodiscard]] ScreenModel* screens() const;
52
53 [[nodiscard]] WallpaperService* wallpaper() const;
54
55 Q_INVOKABLE [[nodiscard]] QObject* singleton(const QString& reloadId) const;
56 void registerSingleton(const QString& reloadId, PersistentProperties* props);
58
59Q_SIGNALS:
61
62private:
63 // QPointer so external destruction (engine reload) doesn't leave us
64 // dangling.
65 QPointer<ScreenModel> m_screens;
66 QHash<QString, QPointer<PersistentProperties>> m_singletons;
67 // Owned by `this` — process-wide info but conveniently scoped to
68 // the engine's lifetime so a hot-reload cleanly tears down the
69 // file watcher and pending async loads with the rest of the shell.
70 WallpaperService* m_wallpaper = nullptr;
71};
72
73} // namespace PhosphorShell
Definition PersistentProperties.h:14
Definition ScreenModel.h:25
QObject * singleton(const QString &reloadId) const
ScreenModel * screens() const
void registerSingleton(const QString &reloadId, PersistentProperties *props)
void setScreenModel(ScreenModel *model)
WallpaperService * wallpaper() const
ShellGlobal(const QString &wallpaperStorePath, QObject *parent=nullptr)
Desktop wallpaper image source for shader backgrounds.
The shell's own wallpaper: which image each output shows.
Definition WallpaperService.h:69
Definition Environment.h:11