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
20class IScreenProvider;
22
34class PHOSPHORLAYER_EXPORT SurfaceFactory : public QObject
35{
36 Q_OBJECT
37public:
48 struct Deps
49 {
52
55
66
83 };
84
85 explicit SurfaceFactory(Deps deps, QObject* parent = nullptr);
86 ~SurfaceFactory() override;
87
102 [[nodiscard]] Surface* create(SurfaceConfig cfg, QObject* parent = nullptr);
103
129 template<typename T>
130 [[nodiscard]] T* createAs(SurfaceConfig cfg, QObject* parent = nullptr)
131 {
132 static_assert(std::is_base_of_v<Surface, T>, "T must derive from PhosphorLayer::Surface");
133 auto sdeps = validateAndPrepareDeps(cfg);
134 if (!sdeps) {
135 return nullptr;
136 }
137 return new T(Surface::CtorToken{}, std::move(cfg), std::move(*sdeps), parent ? parent : this);
138 }
139
140 const Deps& deps() const noexcept;
141
152 [[nodiscard]] std::optional<SurfaceDeps> validateAndPrepareDeps(SurfaceConfig& cfg);
153
154private:
155 class Impl;
156 std::unique_ptr<Impl> m_impl;
157};
158
159} // namespace PhosphorLayer
Abstracts the layer-shell protocol binding.
Definition ILayerShellTransport.h:111
Hook point for consumer-controlled QQmlEngine ownership policy.
Definition IQmlEngineProvider.h:40
Source-of-truth interface for the available QScreen set.
Definition IScreenProvider.h:62
Hook point for show/hide transitions on Surfaces.
Definition ISurfaceAnimator.h:51
std::optional< SurfaceDeps > validateAndPrepareDeps(SurfaceConfig &cfg)
Run the factory's validation and produce a SurfaceDeps ready for Surface construction.
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:130
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:257
One layer-shell surface with a managed lifecycle.
Definition Surface.h:105
Definition SurfaceAnimator.h:26
Immutable per-surface configuration passed to SurfaceFactory::create().
Definition SurfaceConfig.h:47
Bundle of dependencies the Surface inherits from the factory.
Definition Surface.h:42
Dependency bundle for SurfaceFactory.
Definition SurfaceFactory.h:49
ISurfaceAnimator * animator
Optional.
Definition SurfaceFactory.h:82
IQmlEngineProvider * engineProvider
Optional.
Definition SurfaceFactory.h:65
IScreenProvider * screens
Required. Source of truth for the QScreen set.
Definition SurfaceFactory.h:54
ILayerShellTransport * transport
Required. Concrete transport implementation (e.g. PhosphorWaylandTransport).
Definition SurfaceFactory.h:51