Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
LayerSurface.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 "phosphorwayland_export.h"
7
8#include <utility>
9
10#include <QMargins>
11#include <QObject>
12#include <QPointer>
13#include <QScreen>
14#include <QWindow>
15
16namespace PhosphorWayland {
17
20inline constexpr const char* IsLayerShell = "_ps_layer_shell";
21inline constexpr const char* Surface = "_ps_layer_shell_surface";
22inline constexpr const char* Layer = "_ps_layer";
23inline constexpr const char* Anchors = "_ps_anchors";
24inline constexpr const char* ExclusiveZone = "_ps_exclusive_zone";
25inline constexpr const char* Keyboard = "_ps_keyboard";
26inline constexpr const char* Scope = "_ps_scope";
27inline constexpr const char* MarginsLeft = "_ps_margins_left";
28inline constexpr const char* MarginsTop = "_ps_margins_top";
29inline constexpr const char* MarginsRight = "_ps_margins_right";
30inline constexpr const char* MarginsBottom = "_ps_margins_bottom";
31inline constexpr const char* ExclusiveEdge = "_ps_exclusive_edge";
32inline constexpr const char* DesiredWidth = "_ps_desired_width";
33inline constexpr const char* DesiredHeight = "_ps_desired_height";
34} // namespace LayerSurfaceProps
35
38class PHOSPHORWAYLAND_EXPORT LayerSurface : public QObject
39{
40 Q_OBJECT
41 Q_DISABLE_COPY_MOVE(LayerSurface)
42
43 Q_PROPERTY(Layer layer READ layer WRITE setLayer NOTIFY layerChanged)
44 Q_PROPERTY(Anchors anchors READ anchors WRITE setAnchors NOTIFY anchorsChanged)
45 Q_PROPERTY(int32_t exclusiveZone READ exclusiveZone WRITE setExclusiveZone NOTIFY exclusiveZoneChanged)
48 Q_PROPERTY(QString scope READ scope WRITE setScope NOTIFY scopeChanged)
49 Q_PROPERTY(QScreen* screen READ screen WRITE setScreen NOTIFY screenChanged)
50 Q_PROPERTY(QMargins margins READ margins WRITE setMargins NOTIFY marginsChanged)
51 Q_PROPERTY(Anchors exclusiveEdge READ exclusiveEdge WRITE setExclusiveEdge NOTIFY exclusiveEdgeChanged)
52
53public:
54 ~LayerSurface() override;
55
62 Q_ENUM(Layer)
63
69 Q_ENUM(KeyboardInteractivity)
70
78 Q_DECLARE_FLAGS(Anchors, Anchor)
79 Q_FLAG(Anchors)
80
81 static constexpr Anchors AnchorAll = Anchors(AnchorTop | AnchorBottom | AnchorLeft | AnchorRight);
82
83 // ── Mutable properties (can be changed after show()) ─────────────
85 Layer layer() const;
86
87 void setAnchors(Anchors anchors);
88 Anchors anchors() const;
89
90 void setExclusiveZone(int32_t zone);
91 int32_t exclusiveZone() const;
92
95
96 void setMargins(const QMargins& margins);
97 QMargins margins() const;
98
99 void setExclusiveEdge(Anchors edge);
100 Anchors exclusiveEdge() const;
101
109 void setDesiredSize(const QSize& size);
110 QSize desiredSize() const;
111
112 // ── Immutable properties (must set before show()) ────────────────
113 void setScope(const QString& scope);
114 QString scope() const;
115
116 void setScreen(QScreen* screen);
117 QScreen* screen() const;
118
120 static LayerSurface* get(QWindow* window);
121
123 static LayerSurface* find(QWindow* window);
124
126 static bool isSupported();
127
129 static std::pair<uint32_t, uint32_t> computeLayerSize(Anchors anchors, const QSize& windowSize);
130
131Q_SIGNALS:
142
143public:
146 {
147 public:
148 explicit BatchGuard(LayerSurface* surface)
149 : m_surface(surface)
150 {
151 if (m_surface) {
152 ++m_surface->m_batchDepth;
153 }
154 }
156 {
157 if (m_surface) {
158 Q_ASSERT(m_surface->m_batchDepth > 0);
159 if (--m_surface->m_batchDepth == 0 && m_surface->m_batchDirty) {
160 m_surface->m_batchDirty = false;
161 Q_EMIT m_surface->propertiesChanged();
162 }
163 }
164 }
165 BatchGuard(const BatchGuard&) = delete;
166 BatchGuard& operator=(const BatchGuard&) = delete;
167 BatchGuard(BatchGuard&& other) noexcept
168 : m_surface(std::exchange(other.m_surface, nullptr))
169 {
170 }
172
173 private:
174 QPointer<LayerSurface> m_surface;
175 };
176
177private:
178 friend class BatchGuard;
179 explicit LayerSurface(QWindow* window);
180
181 void emitPropertiesChanged();
182
183 QPointer<QWindow> m_window;
184 int m_batchDepth = 0;
185 bool m_batchDirty = false;
186 Layer m_layer = LayerTop;
187 Anchors m_anchors;
188 int32_t m_exclusiveZone = -1;
190 QString m_scope;
191 QPointer<QScreen> m_screen;
192 QMargins m_margins;
193 Anchors m_exclusiveEdge;
194 QSize m_desiredSize;
195 QMetaObject::Connection m_destroyedConnection;
196};
197
198Q_DECLARE_OPERATORS_FOR_FLAGS(LayerSurface::Anchors)
199
200} // namespace PhosphorWayland
201
202Q_DECLARE_METATYPE(PhosphorWayland::LayerSurface*)
RAII guard: suppresses propertiesChanged() until destroyed.
Definition LayerSurface.h:146
BatchGuard & operator=(BatchGuard &&)=delete
BatchGuard(LayerSurface *surface)
Definition LayerSurface.h:148
BatchGuard(BatchGuard &&other) noexcept
Definition LayerSurface.h:167
~BatchGuard()
Definition LayerSurface.h:155
BatchGuard & operator=(const BatchGuard &)=delete
BatchGuard(const BatchGuard &)=delete
Wayland layer-shell surface backed by zwlr_layer_shell_v1.
Definition LayerSurface.h:39
static LayerSurface * find(QWindow *window)
Retrieve existing LayerSurface for the window, or nullptr.
static LayerSurface * get(QWindow *window)
Get or create a LayerSurface for the given window (call before first show()).
static std::pair< uint32_t, uint32_t > computeLayerSize(Anchors anchors, const QSize &windowSize)
Compute layer-shell size: 0 for axes anchored to both edges.
Anchor
Definition LayerSurface.h:71
@ AnchorTop
Definition LayerSurface.h:73
@ AnchorBottom
Definition LayerSurface.h:74
@ AnchorLeft
Definition LayerSurface.h:75
@ AnchorNone
Definition LayerSurface.h:72
@ AnchorRight
Definition LayerSurface.h:76
Layer
Definition LayerSurface.h:56
@ LayerBackground
Definition LayerSurface.h:57
@ LayerTop
Definition LayerSurface.h:59
@ LayerBottom
Definition LayerSurface.h:58
@ LayerOverlay
Definition LayerSurface.h:60
KeyboardInteractivity
Definition LayerSurface.h:64
@ KeyboardInteractivityOnDemand
Definition LayerSurface.h:67
@ KeyboardInteractivityExclusive
Definition LayerSurface.h:66
@ KeyboardInteractivityNone
Definition LayerSurface.h:65
void setLayer(Layer layer)
void setMargins(const QMargins &margins)
void setExclusiveZone(int32_t zone)
void setDesiredSize(const QSize &size)
Override the layer-shell set_size value sent on the next configure- triggering commit,...
void setScreen(QScreen *screen)
KeyboardInteractivity keyboardInteractivity() const
void setExclusiveEdge(Anchors edge)
void setKeyboardInteractivity(KeyboardInteractivity interactivity)
static bool isSupported()
True if the compositor supports zwlr_layer_shell_v1.
static constexpr Anchors AnchorAll
Definition LayerSurface.h:81
void setAnchors(Anchors anchors)
void setScope(const QString &scope)
Property keys used by LayerSurface ↔ QPA plugin communication.
Definition LayerSurface.h:19
constexpr const char * MarginsRight
Definition LayerSurface.h:29
constexpr const char * MarginsLeft
Definition LayerSurface.h:27
constexpr const char * Keyboard
Definition LayerSurface.h:25
constexpr const char * DesiredWidth
Definition LayerSurface.h:32
constexpr const char * IsLayerShell
Definition LayerSurface.h:20
constexpr const char * ExclusiveZone
Definition LayerSurface.h:24
constexpr const char * Anchors
Definition LayerSurface.h:23
constexpr const char * Surface
Definition LayerSurface.h:21
constexpr const char * MarginsTop
Definition LayerSurface.h:28
constexpr const char * DesiredHeight
Definition LayerSurface.h:33
constexpr const char * Scope
Definition LayerSurface.h:26
constexpr const char * MarginsBottom
Definition LayerSurface.h:30
constexpr const char * Layer
Definition LayerSurface.h:22
constexpr const char * ExclusiveEdge
Definition LayerSurface.h:31
Definition BackgroundEffect.h:15