Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ShellEngine.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#include <QHash>
9#include <QObject>
10#include <QPointer>
11#include <QSize>
12#include <QUrl>
13#include <QVariantMap>
14
15#include <functional>
16#include <memory>
17#include <vector>
18
19QT_BEGIN_NAMESPACE
20class QFileSystemWatcher;
21class QQmlEngine;
22class QTimer;
23QT_END_NAMESPACE
24
25namespace PhosphorLayer {
26class IScreenProvider;
27class Surface;
28class SurfaceFactory;
29} // namespace PhosphorLayer
30
31namespace PhosphorShell {
32
33class PanelWindow;
34class ScreenModel;
35class ShellGlobal;
36
37class PHOSPHORSHELL_EXPORT ShellEngine : public QObject
38{
39 Q_OBJECT
40public:
41 struct Deps
42 {
43 PhosphorLayer::SurfaceFactory* surfaceFactory = nullptr;
44 PhosphorLayer::IScreenProvider* screenProvider = nullptr;
45 };
46
47 explicit ShellEngine(Deps deps, QObject* parent = nullptr);
48 ~ShellEngine() override;
49
50 bool load(const QUrl& shellUrl);
51 [[nodiscard]] QQmlEngine* engine() const;
52
61 using EngineHook = std::function<void(QQmlEngine*)>;
63
64Q_SIGNALS:
65 void loaded();
66 void reloaded();
67 void failed(const QString& reason);
68
69private Q_SLOTS:
70 void onFileChanged();
71 void onScreensChanged();
72
73private:
78 [[nodiscard]] bool buildAndMaterialize();
79 void materializePanels();
80 void installDynamicAutoFit(PanelWindow* panel, PhosphorLayer::Surface* surface, QSize screenSize);
81 void teardown();
82 void setupWatcher();
83 void savePersistentState();
84 void restorePersistentState();
85
86 QUrl m_shellUrl;
87 std::unique_ptr<QQmlEngine> m_engine;
88 std::unique_ptr<QObject> m_rootObject;
89 // Non-owning observer of the QML root. When the root is a PanelWindow,
90 // ownership transfers to a Surface and m_rootObject is released — but
91 // findChildren scans (PersistentProperties save/restore) still need a
92 // pointer to walk the tree. QPointer auto-clears when the wrapper
93 // window destroys the root.
94 QPointer<QObject> m_rootRef;
95 Deps m_deps;
96 std::vector<std::unique_ptr<PhosphorLayer::Surface>> m_surfaces;
97 QFileSystemWatcher* m_watcher = nullptr;
98 QTimer* m_reloadTimer = nullptr;
99 ScreenModel* m_screenModel = nullptr;
100 ShellGlobal* m_shellGlobal = nullptr;
101 QHash<QString, QVariantMap> m_persistentState;
102 std::vector<EngineHook> m_engineHooks;
103};
104
105} // namespace PhosphorShell
Source-of-truth interface for the available QScreen set.
Definition IScreenProvider.h:62
Stateless constructor for Surfaces.
Definition SurfaceFactory.h:35
One layer-shell surface with a managed lifecycle.
Definition Surface.h:99
Definition PanelWindow.h:19
Definition ScreenModel.h:25
Definition ShellEngine.h:38
void addEngineHook(EngineHook hook)
std::function< void(QQmlEngine *)> EngineHook
Register a callback that fires whenever a fresh QQmlEngine is created — at startup AND on hot-reload ...
Definition ShellEngine.h:61
bool load(const QUrl &shellUrl)
QQmlEngine * engine() const
void failed(const QString &reason)
ShellEngine(Deps deps, QObject *parent=nullptr)
Definition ShellGlobal.h:30
Definition SurfaceAnimator.h:26
Definition Environment.h:11
constexpr const char * Surface
Definition LayerSurface.h:21
Definition ShellEngine.h:42