Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
DecorationManager.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 <phosphorcompositor_export.h>
7
9
10#include <QHash>
11#include <QObject>
12#include <QPointer>
13#include <QSet>
14#include <QString>
15#include <QVector>
16
17#include <functional>
18#include <memory>
19#include <optional>
20
21class QTimer;
22
23namespace PhosphorCompositor {
24
56class PHOSPHORCOMPOSITOR_EXPORT DecorationManager : public QObject
57{
58 Q_OBJECT
59
60public:
61 enum class OwnerKind {
62 Autotile,
63 Snap,
64 Rule
65 };
66
71 struct Owner
72 {
74 QString screenId;
75 bool operator==(const Owner&) const = default;
76 };
77 static Owner autotile(const QString& screenId)
78 {
79 return {OwnerKind::Autotile, screenId};
80 }
81 static Owner snap(const QString& screenId)
82 {
83 return {OwnerKind::Snap, screenId};
84 }
85 static Owner rule()
86 {
87 return {OwnerKind::Rule, QString()};
88 }
89
91 enum class Placement {
95 CallerWillPlace,
100 AlreadyPlaced,
101 };
102
103 enum class Restore {
104 Immediate,
105 Deferred,
106 };
107
111 explicit DecorationManager(ICompositorBridge& bridge, QObject* parent = nullptr);
117
118 // ── Ownership ──────────────────────────────────────────────────────
119 void acquire(const QString& windowId, const Owner& owner, Placement placement = Placement::AlreadyPlaced);
120 void release(const QString& windowId, const Owner& owner, Restore restore = Restore::Immediate);
123 void releaseKind(const QString& windowId, OwnerKind kind, Restore restore = Restore::Immediate);
128 void releaseOthersOfKind(const QString& windowId, OwnerKind kind, const QString& keepScreenId);
129
130 // ── Bulk operations ────────────────────────────────────────────────
136 void releaseAllOfKind(OwnerKind kind, Restore restore = Restore::Immediate);
146 void forgetWindow(const QString& windowId);
147
148 // ── Window-rule layer (tri-state) ──────────────────────────────────
155 void setRuleOverride(const QString& windowId, std::optional<bool> ruleValue);
159
160 // ── Deferred restore drain ─────────────────────────────────────────
182 void setRestoreVeto(std::function<bool(const QString& windowId)> veto);
183
184 // ── External-reset resync ──────────────────────────────────────────
188 void resyncWindow(const QString& windowId);
189
190 // ── Queries ────────────────────────────────────────────────────────
191 // The state-observation surface: production code expresses everything
192 // through the ownership calls above, so these exist for the behavioral
193 // test spec (and future render-layer integration) to assert manager
194 // state without reaching into internals.
196 bool isBorderless(const QString& windowId) const;
197 bool isOwned(const QString& windowId) const;
198 bool isOwnedBy(const QString& windowId, const Owner& owner) const;
199 bool isVetoed(const QString& windowId) const;
200
201Q_SIGNALS:
206 void windowDecorationRestored(const QString& windowId);
212
213private:
214 struct Entry
215 {
216 QVector<Owner> owners; // small-N linear scan
217 bool vetoed = false;
218 bool evaluated = false;
219 bool eligible = false;
220 bool priorNoBorder = false;
221 bool physicallyHidden = false;
222 bool pendingRestore = false;
230 int vetoRetries = 0;
231 };
232
235 void reconcile(const QString& windowId, Entry& entry, Placement placement);
238 void finishRelease(const QString& windowId, Entry& entry, Restore restore);
241 void cancelPendingRestore(const QString& windowId, Entry& entry);
244 void drainPendingRestoresInternal(bool fromFallback);
249 WindowHandle resolveExact(const QString& windowId) const;
250 void hideNow(WindowHandle w, Placement placement);
256 bool restoreNow(const QString& windowId, Entry& entry, bool reassertGeometry);
258 void pruneIfEmpty(const QString& windowId);
261 void armFallbackTimer();
263 void cancelFallbackTimer();
264
265 QHash<QString, Entry> m_windows;
266 QSet<QString> m_pendingRestore;
267 QPointer<QTimer> m_pendingFallback;
268 int m_fallbackIntervalMs; // FallbackDrainMs unless shrunk for tests
269 std::function<bool(const QString&)> m_restoreVeto;
273 QVector<std::shared_ptr<std::function<void()>>> m_liveDrainChains;
274 ICompositorBridge& m_bridge;
275};
276
277} // namespace PhosphorCompositor
The single owner of server-side decoration (title-bar) state.
Definition DecorationManager.h:57
void setRestoreVeto(std::function< bool(const QString &windowId)> veto)
Extra authoritative re-check evaluated per window at drain-step time (in addition to the built-in "wi...
Restore
Definition DecorationManager.h:103
~DecorationManager() override
Breaks any in-flight drain chains' self-reference cycles — a chain interrupted by manager destruction...
void resyncWindow(const QString &windowId)
The compositor can silently reset noBorder (KWin does on desktop switches).
void clearAllRuleOverrides()
Rules went away wholesale (rule set emptied / teardown): clear every Rule owner and veto,...
void releaseAllOfKind(OwnerKind kind, Restore restore=Restore::Immediate)
Per-mode hide-title-bars toggle OFF / whole-mode teardown.
void forgetWindow(const QString &windowId)
Window destroyed: drop all state for it.
bool isOwned(const QString &windowId) const
void windowDecorationRestored(const QString &windowId)
Emitted after a physical decoration restore (the effect refreshes border overlays for the window).
bool isOwnedBy(const QString &windowId, const Owner &owner) const
void acquire(const QString &windowId, const Owner &owner, Placement placement=Placement::AlreadyPlaced)
void setFallbackIntervalForTesting(int ms)
Test seam: shrink the fallback-retry interval (default 500 ms) so timer-interplay tests run in millis...
void releaseOthersOfKind(const QString &windowId, OwnerKind kind, const QString &keepScreenId)
Cross-screen transfer: drop kind owners on every screen EXCEPT keepScreenId.
DecorationManager(ICompositorBridge &bridge, QObject *parent=nullptr)
bridge must outlive the manager (the KWin effect owns both, with the bridge destroyed after the manag...
void drainPendingRestores()
Drain queued restores, one decoration toggle per event-loop tick.
void restoreAll()
Daemon loss / effect teardown: synchronously restore every window we hid to its prior state,...
static Owner autotile(const QString &screenId)
Definition DecorationManager.h:77
OwnerKind
Definition DecorationManager.h:61
bool isVetoed(const QString &windowId) const
void setRuleOverride(const QString &windowId, std::optional< bool > ruleValue)
nullopt: rule has no opinion — clear Rule owner and veto.
static Owner rule()
Definition DecorationManager.h:85
static Owner snap(const QString &screenId)
Definition DecorationManager.h:81
void release(const QString &windowId, const Owner &owner, Restore restore=Restore::Immediate)
Placement
How the physical hide coordinates with geometry application.
Definition DecorationManager.h:91
bool isBorderless(const QString &windowId) const
True when we physically suppressed the window's decoration.
void releaseKind(const QString &windowId, OwnerKind kind, Restore restore=Restore::Immediate)
Release every owner of kind regardless of screen (float, fullscreen, window leaving the mode entirely...
void drainFinished()
Emitted when a drain chain completes having processed at least one restore (the effect rebuilds all b...
Abstract interface bridging compositor-agnostic logic to compositor-specific APIs.
Definition ICompositorBridge.h:88
Definition AutotileState.h:17
void * WindowHandle
Opaque handle to a compositor window.
Definition ICompositorBridge.h:31
An owner is a (kind, screen) pair.
Definition DecorationManager.h:72
bool operator==(const Owner &) const =default
QString screenId
Definition DecorationManager.h:74
OwnerKind kind
Definition DecorationManager.h:73