Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ShellHost.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// ShellHost - owns the per-screen layer-shell shell-state map and the
7// lifecycle bookkeeping (create / destroy / rekey / sync) that any
8// multi-slot overlay consumer needs.
9//
10// Phase 2 foundation: the type holds a `QHash<QString, ShellState>`
11// keyed by effective screen id plus a sticky creation-failure set
12// (spam-guard for compositors that refuse a shell on a given screen).
13// Method moves from OverlayService land in subsequent Phase 2 commits;
14// this commit pins the shape of the public type and its accessors so
15// the daemon can construct a ShellHost as a member alongside its
16// existing per-screen state.
17
19#include <PhosphorOverlay/phosphoroverlay_export.h>
20
22#include <PhosphorLayer/Role.h>
23
24#include <QHash>
25#include <QObject>
26#include <QSet>
27#include <QString>
28#include <QStringList>
29#include <QStringView>
30
31#include <functional>
32
33class QScreen;
34
35namespace PhosphorLayer {
36class Surface;
37} // namespace PhosphorLayer
38
39namespace PhosphorOverlay {
40
58[[nodiscard]] PHOSPHOROVERLAY_EXPORT PhosphorLayer::Role makePerInstanceRole(const PhosphorLayer::Role& base,
59 QStringView screenId, quint64 generation);
60
61class PHOSPHOROVERLAY_EXPORT ShellHost : public QObject
62{
63 Q_OBJECT
64
65public:
70 using SurfaceFactory = std::function<PhosphorLayer::Surface*(const QString& screenId, QScreen* physScreen)>;
71
77 using PostCreateCallback = std::function<void(const QString& screenId, ShellState& state)>;
78
90 using PreDestroyCallback = std::function<void(const QString& screenId)>;
91
92 explicit ShellHost(QObject* parent = nullptr);
93 ~ShellHost() override;
94
99
102
105
111
130 ShellState* ensureShell(const QString& screenId, QScreen* physScreen);
131
137 void destroyShell(const QString& screenId);
138
163 void syncSurfaceState(const QString& screenId, bool anyVisible, bool anyInputGrabbing);
164
185 bool rekey(const QString& oldKey, const QString& newKey);
186
193
209 void hideSlot(const QString& screenId, const QString& slotKey, std::function<void()> completion = {});
210
214 ShellState& stateFor(const QString& screenId);
215
219 const ShellState* stateFor(const QString& screenId) const;
220
222 bool hasState(const QString& screenId) const;
223
227 void removeState(const QString& screenId);
228
231 QStringList screenIds() const;
232
237 void markFailure(const QString& screenId);
238 void clearFailure(const QString& screenId);
239 bool hasFailure(const QString& screenId) const;
240
246 QStringList failureScreenIds() const;
247
248private:
261 QHash<QString, ShellState*> m_states;
262 QSet<QString> m_creationFailed;
263 SurfaceFactory m_surfaceFactory;
264 PostCreateCallback m_postCreateCallback;
265 PreDestroyCallback m_preDestroyCallback;
266 PhosphorAnimationLayer::SurfaceAnimator* m_surfaceAnimator = nullptr;
267};
268
269} // namespace PhosphorOverlay
Concrete PhosphorLayer::ISurfaceAnimator driving show/hide via phosphor-animation Profiles.
Definition SurfaceAnimator.h:121
One layer-shell surface with a managed lifecycle.
Definition Surface.h:99
Definition ShellHost.h:62
std::function< void(const QString &screenId)> PreDestroyCallback
Hook fired before the library deletes the shell surface.
Definition ShellHost.h:90
QStringList failureScreenIds() const
Snapshot of every screen id currently flagged as failed.
const ShellState * stateFor(const QString &screenId) const
Read-only accessor.
void markFailure(const QString &screenId)
Sticky per-screen creation-failure flag.
ShellHost(QObject *parent=nullptr)
void hideSlot(const QString &screenId, const QString &slotKey, std::function< void()> completion={})
Animator-driven slot hide for the slot keyed by slotKey on the shell for screenId.
ShellState & stateFor(const QString &screenId)
Read-write accessor.
void destroyShell(const QString &screenId)
Tear down the shell for screenId.
void registerConfigForRole(const PhosphorLayer::Role &role, PhosphorAnimationLayer::SurfaceAnimator::Config config)
Register an animator config under role.
std::function< PhosphorLayer::Surface *(const QString &screenId, QScreen *physScreen)> SurfaceFactory
Consumer-provided factory for the per-screen layer-shell surface.
Definition ShellHost.h:70
bool hasFailure(const QString &screenId) const
void setPostCreateCallback(PostCreateCallback callback)
Inject the post-create hook (optional but typically used).
void removeState(const QString &screenId)
Remove the ShellState for screenId entirely.
ShellState * ensureShell(const QString &screenId, QScreen *physScreen)
Idempotent: bring up (or return) the per-screen shell for screenId on physScreen.
bool hasState(const QString &screenId) const
True if a ShellState exists (live or zeroed) for screenId.
QStringList screenIds() const
Enumerate every screen id with a ShellState entry (in arbitrary QHash iteration order).
void setSurfaceFactory(SurfaceFactory factory)
Inject the per-screen surface factory.
void setPreDestroyCallback(PreDestroyCallback callback)
Inject the pre-destroy hook (optional).
bool rekey(const QString &oldKey, const QString &newKey)
Move the ShellState entry from oldKey to newKey, preserving the underlying heap-allocated state objec...
std::function< void(const QString &screenId, ShellState &state)> PostCreateCallback
Hook fired after a fresh shell surface + window are recorded in the ShellState.
Definition ShellHost.h:77
void clearFailure(const QString &screenId)
void syncSurfaceState(const QString &screenId, bool anyVisible, bool anyInputGrabbing)
Reconcile the shell's mapped state + pointer-input region with the consumer's view of what's live on ...
void setSurfaceAnimator(PhosphorAnimationLayer::SurfaceAnimator *animator)
Inject the SurfaceAnimator that drives every slot's show/hide leg.
Definition ShellState.h:40
Definition SurfaceAnimator.h:26
Definition ShellHost.h:39
PHOSPHOROVERLAY_EXPORT PhosphorLayer::Role makePerInstanceRole(const PhosphorLayer::Role &base, QStringView screenId, quint64 generation)
Build a per-instance PhosphorLayer::Role by appending -{screenId}-{generation} to base's scope prefix...
constexpr const char * Surface
Definition LayerSurface.h:21
Per-role profile + scale tuning bundle.
Definition SurfaceAnimator.h:155
Value type describing a surface's protocol-level configuration.
Definition Role.h:77