Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
SurfaceFactory.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
8#include <PhosphorLayer/phosphorlayer_export.h>
9
10#include <QObject>
11#include <QString>
12
13#include <optional>
14#include <type_traits>
15
16namespace PhosphorLayer {
17
18class ILayerShellTransport;
19class IQmlEngineProvider;
20class IScreenProvider;
21class ISurfaceAnimator;
22
34class PHOSPHORLAYER_EXPORT SurfaceFactory : public QObject
35{
36 Q_OBJECT
37public:
48 struct Deps
49 {
51 ILayerShellTransport* transport = nullptr;
52
54 IScreenProvider* screens = nullptr;
55
59 IQmlEngineProvider* engineProvider = nullptr;
60
76 ISurfaceAnimator* animator = nullptr;
77
80 };
81
82 explicit SurfaceFactory(Deps deps, QObject* parent = nullptr);
83 ~SurfaceFactory() override;
84
97 [[nodiscard]] Surface* create(SurfaceConfig cfg, QObject* parent = nullptr);
98
124 template<typename T>
125 [[nodiscard]] T* createAs(SurfaceConfig cfg, QObject* parent = nullptr)
126 {
127 static_assert(std::is_base_of_v<Surface, T>, "T must derive from PhosphorLayer::Surface");
128 auto sdeps = validateAndPrepareDeps(cfg);
129 if (!sdeps) {
130 return nullptr;
131 }
132 return new T(Surface::CtorToken{}, std::move(cfg), std::move(*sdeps), parent ? parent : this);
133 }
134
135 const Deps& deps() const noexcept;
136
147 [[nodiscard]] std::optional<SurfaceDeps> validateAndPrepareDeps(SurfaceConfig& cfg);
148
149private:
150 class Impl;
151 std::unique_ptr<Impl> m_impl;
152};
153
154} // namespace PhosphorLayer
Abstracts the layer-shell protocol binding.
Definition ILayerShellTransport.h:111
Hook point for consumer-controlled QQmlEngine ownership policy.
Definition IQmlEngineProvider.h:32
Source-of-truth interface for the available QScreen set.
Definition IScreenProvider.h:62
Hook point for show/hide transitions on Surfaces.
Definition ISurfaceAnimator.h:50
Stateless constructor for Surfaces.
Definition SurfaceFactory.h:35
const Deps & deps() const noexcept
SurfaceFactory(Deps deps, QObject *parent=nullptr)
T * createAs(SurfaceConfig cfg, QObject *parent=nullptr)
Create a Surface subclass from a config.
Definition SurfaceFactory.h:125
Surface * create(SurfaceConfig cfg, QObject *parent=nullptr)
Create a Surface from a config.
Opaque construction token — only SurfaceFactory can create instances of it.
Definition Surface.h:222
One layer-shell surface with a managed lifecycle.
Definition Surface.h:99
Definition SurfaceAnimator.h:26
Immutable per-surface configuration passed to SurfaceFactory::create().
Definition SurfaceConfig.h:46
Bundle of dependencies the Surface inherits from the factory.
Definition Surface.h:42
Dependency bundle for SurfaceFactory.
Definition SurfaceFactory.h:49
QString loggingCategory
Logging category name for internal diagnostics. Empty → "phosphorlayer".
Definition SurfaceFactory.h:79