Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
ScrollState.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
9#include "phosphorscrollengine_export.h"
10
11#include <QObject>
12#include <QRect>
13#include <QSet>
14#include <QString>
15#include <QStringList>
16#include <QVariant>
17
18namespace PhosphorScrollEngine {
19
29class PHOSPHORSCROLLENGINE_EXPORT ScrollState : public QObject, public PhosphorEngine::IPlacementState
30{
31 Q_OBJECT
32
33public:
34 explicit ScrollState(const QString& screenId, QObject* parent = nullptr)
35 : QObject(parent)
36 , m_screenId(screenId)
37 {
38 }
39
41 {
42 return m_strip;
43 }
44 const ScrollStrip& strip() const
45 {
46 return m_strip;
47 }
48
49 void addFloating(const QString& windowId)
50 {
51 m_floating.insert(windowId);
52 }
53
57 bool hasFloating() const
58 {
59 return !m_floating.isEmpty();
60 }
61 bool removeFloating(const QString& windowId)
62 {
63 // The two focus-memory fields move together: a state must never claim
64 // "the float layer holds focus" while naming nobody. Every caller that
65 // needs the pre-teardown verdict (unfloatWindowInternal) reads
66 // floatingHasFocus() BEFORE calling this, per its own comment.
67 if (m_lastFloatingFocus == windowId) {
68 m_lastFloatingFocus.clear();
69 m_floatingHasFocus = false;
70 }
71 return m_floating.remove(windowId);
72 }
73
92 QString lastFloatingFocus() const
93 {
94 return m_lastFloatingFocus;
95 }
96 void setLastFloatingFocus(const QString& windowId)
97 {
98 m_lastFloatingFocus = windowId;
99 }
100 bool floatingHasFocus() const
101 {
102 return m_floatingHasFocus;
103 }
104 void setFloatingHasFocus(bool hasFocus)
105 {
106 m_floatingHasFocus = hasFocus;
107 }
108
142 {
143 return m_hasLastAppliedViewOffset;
144 }
146 {
147 return m_lastAppliedViewOffset;
148 }
150 {
151 return m_lastAppliedWorkArea;
152 }
153
157 {
158 return m_lastAppliedAxis;
159 }
160
170 bool hasResolvedAxis() const
171 {
172 return m_hasResolvedAxis;
173 }
175 {
176 return m_resolvedAxis;
177 }
179 {
180 m_resolvedAxis = axis;
181 m_hasResolvedAxis = true;
182 }
183 void setLastAppliedViewOffset(int viewOffset, const QRect& workArea, StripAxis axis)
184 {
185 m_lastAppliedViewOffset = viewOffset;
186 m_lastAppliedWorkArea = workArea;
187 m_lastAppliedAxis = axis;
188 m_hasLastAppliedViewOffset = true;
189 }
190
197 {
198 m_lastAppliedViewOffset = 0;
199 m_lastAppliedWorkArea = QRect();
200 m_lastAppliedAxis = StripAxis::horizontal();
201 m_hasLastAppliedViewOffset = false;
202 }
203
246 int blueprintCursor() const
247 {
248 return m_blueprintCursor;
249 }
250 void setBlueprintCursor(int cursor)
251 {
252 m_blueprintCursor = qMax(0, cursor);
253 }
255 {
256 m_blueprintCursor = 0;
257 }
258
271 QVariant blueprintIdentity() const
272 {
273 return m_blueprintIdentity;
274 }
275
277 void setBlueprintIdentity(const QVariant& blueprint)
278 {
279 m_blueprintIdentity = blueprint;
280 m_hasBlueprintIdentity = true;
281 }
282
292 {
293 return m_hasBlueprintIdentity;
294 }
295
296 // ── IPlacementState ─────────────────────────────────────────────────────
297 QString screenId() const override
298 {
299 return m_screenId;
300 }
301 int windowCount() const override
302 {
303 // The two sets are disjoint by intent but not by construction — the
304 // engine explicitly tolerates a window transiently in both (see
305 // windowClosed's both-sets handling). Count the union, not the sum.
306 int overlap = 0;
307 for (const QString& id : m_floating) {
308 if (m_strip.containsWindow(id)) {
309 ++overlap;
310 }
311 }
312 return m_strip.windowCount() + m_floating.size() - overlap;
313 }
314 QStringList managedWindows() const override
315 {
316 QStringList all = m_strip.windowsInOrder();
317 all += floatingWindows();
318 // Same union-not-sum rule as windowCount.
319 all.removeDuplicates();
320 return all;
321 }
322 bool containsWindow(const QString& windowId) const override
323 {
324 return m_strip.containsWindow(windowId) || m_floating.contains(windowId);
325 }
326 bool isFloating(const QString& windowId) const override
327 {
328 return m_floating.contains(windowId);
329 }
330 QStringList floatingWindows() const override
331 {
332 QStringList out(m_floating.cbegin(), m_floating.cend());
333 out.sort();
334 return out;
335 }
336
342 QString placementIdForWindow(const QString& windowId) const override
343 {
344 const int idx = m_strip.windowsInOrder().indexOf(windowId);
345 return idx >= 0 ? QString::number(idx) : QString();
346 }
347 int tiledWindowCount() const override
348 {
349 return m_strip.windowCount();
350 }
351
352private:
353 QString m_screenId;
354 ScrollStrip m_strip;
355 QSet<QString> m_floating;
356 QString m_lastFloatingFocus;
357 bool m_floatingHasFocus = false;
358 int m_lastAppliedViewOffset = 0;
359 QRect m_lastAppliedWorkArea;
360 StripAxis m_lastAppliedAxis;
361 StripAxis m_resolvedAxis;
362 bool m_hasResolvedAxis = false;
363 bool m_hasLastAppliedViewOffset = false;
364 int m_blueprintCursor = 0;
365 QVariant m_blueprintIdentity;
366 bool m_hasBlueprintIdentity = false;
367};
368
369} // namespace PhosphorScrollEngine
Per-screen placement state contract.
Definition IPlacementState.h:28
QRect lastAppliedWorkArea() const
Definition ScrollState.h:149
bool hasBlueprintIdentity() const
Whether an identity has been ESTABLISHED, which is a different question from whether the stored value...
Definition ScrollState.h:291
ScrollState(const QString &screenId, QObject *parent=nullptr)
Definition ScrollState.h:34
int lastAppliedViewOffset() const
Definition ScrollState.h:145
int windowCount() const override
Total number of managed windows (tiled + floating).
Definition ScrollState.h:301
void clearLastAppliedViewOffset()
Invalidate the baseline entirely: the next emitted batch takes the first-batch path (zero delta,...
Definition ScrollState.h:196
const ScrollStrip & strip() const
Definition ScrollState.h:44
QStringList floatingWindows() const override
All currently-floating windows.
Definition ScrollState.h:330
void setBlueprintIdentity(const QVariant &blueprint)
Stamps the value AND marks it established — there is deliberately no way to store one without establi...
Definition ScrollState.h:277
ScrollStrip & strip()
Definition ScrollState.h:40
void setBlueprintCursor(int cursor)
Definition ScrollState.h:250
void addFloating(const QString &windowId)
Definition ScrollState.h:49
void setFloatingHasFocus(bool hasFocus)
Definition ScrollState.h:104
QStringList managedWindows() const override
All windows managed by this state (tiled + floating).
Definition ScrollState.h:314
int tiledWindowCount() const override
Number of tiled (non-floating) windows in the managed set.
Definition ScrollState.h:347
QVariant blueprintIdentity() const
The blueprint value the cursor is counting against.
Definition ScrollState.h:271
bool hasResolvedAxis() const
The axis this state was last RESOLVED against, which is a different question from lastAppliedAxis abo...
Definition ScrollState.h:170
bool floatingHasFocus() const
Definition ScrollState.h:100
QString lastFloatingFocus() const
Focus-side memory for switch-focus-between-floating-and-tiling: the float most recently reported focu...
Definition ScrollState.h:92
void setResolvedAxis(StripAxis axis)
Definition ScrollState.h:178
int blueprintCursor() const
How many entries this strip has taken from the context template's seed blueprint since it was last em...
Definition ScrollState.h:246
bool removeFloating(const QString &windowId)
Definition ScrollState.h:61
bool containsWindow(const QString &windowId) const override
Whether the window is in this state's managed set.
Definition ScrollState.h:322
bool isFloating(const QString &windowId) const override
Whether the window is floating (excluded from placement).
Definition ScrollState.h:326
StripAxis lastAppliedAxis() const
The AXIS the baseline was measured along.
Definition ScrollState.h:156
void resetBlueprintCursor()
Definition ScrollState.h:254
QString screenId() const override
Screen this state object manages.
Definition ScrollState.h:297
void setLastFloatingFocus(const QString &windowId)
Definition ScrollState.h:96
bool hasLastAppliedViewOffset() const
The strip viewOffset carried by the last geometry batch this state actually emitted,...
Definition ScrollState.h:141
void setLastAppliedViewOffset(int viewOffset, const QRect &workArea, StripAxis axis)
Definition ScrollState.h:183
StripAxis resolvedAxis() const
Definition ScrollState.h:174
bool hasFloating() const
Whether anything floats out of this strip, without building the sorted list floatingWindows() returns...
Definition ScrollState.h:57
QString placementIdForWindow(const QString &windowId) const override
Opaque slot id: the window's index in strip order, matching the autotile convention (order index as s...
Definition ScrollState.h:342
The pure scrolling-strip model: an ordered list of columns on an unbounded strip, viewed through a vi...
Definition ScrollStrip.h:100
Coordinate mapping for one strip orientation: a pure value type, trivially copyable,...
Definition StripAxis.h:35
static constexpr StripAxis horizontal()
Definition StripAxis.h:43
Definition ScrollEngine.h:46