Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
AutotileState.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
7
8#include <QColor>
9#include <QHash>
10#include <QPair>
11#include <QRect>
12#include <QRectF>
13#include <QSet>
14#include <QString>
15#include <QVector>
16
18
30{
36 QHash<QString, QSet<QString>> tiledWindowsByScreen;
37 // Defaults shared with the daemon's ConfigDefaults via DecorationDefaults
38 // so the effect's pre-settings-load rendering can't drift from what the
39 // daemon would persist.
44 QColor color;
46};
47
54namespace AutotileStateHelpers {
55
56// ═══════════════════════════════════════════════════════════════════════════════
57// Border state accessors (pure data queries)
58// ═══════════════════════════════════════════════════════════════════════════════
59
60inline bool isTiledWindow(const BorderState& border, const QString& windowId)
61{
62 for (auto it = border.tiledWindowsByScreen.constBegin(); it != border.tiledWindowsByScreen.constEnd(); ++it) {
63 if (it.value().contains(windowId)) {
64 return true;
65 }
66 }
67 return false;
68}
69
70inline bool shouldShowBorderForWindow(const BorderState& border, const QString& windowId)
71{
72 return border.showBorder && isTiledWindow(border, windowId);
73}
74
75// ═══════════════════════════════════════════════════════════════════════════════
76// Window closed cleanup (pure state bookkeeping)
77// ═══════════════════════════════════════════════════════════════════════════════
78
86{
87 QSet<QString>& notifiedWindows;
88 QHash<QString, QString>& notifiedWindowScreens;
89 QSet<QString>& minimizeFloatedWindows;
90 QHash<QString, QRect>& autotileTargetZones;
91 QHash<QString, QRect>& centeredWaylandZones;
93 QHash<QString, QHash<QString, QRectF>>& preAutotileGeometries;
94};
95
102inline void cleanupClosedWindowState(const QString& windowId, BorderState& border, AutotileWindowState& state)
103{
104 state.notifiedWindows.remove(windowId);
105 state.notifiedWindowScreens.remove(windowId);
106 state.minimizeFloatedWindows.remove(windowId);
107 state.autotileTargetZones.remove(windowId);
108 state.centeredWaylandZones.remove(windowId);
109 state.monocleMaximizedWindows.remove(windowId);
110 // Closed windows must be removed from every screen bucket — the effect
111 // may have stale entries if the window crossed screens before closing.
112 for (auto it = border.tiledWindowsByScreen.begin(); it != border.tiledWindowsByScreen.end();) {
113 it.value().remove(windowId);
114 if (it.value().isEmpty()) {
115 it = border.tiledWindowsByScreen.erase(it);
116 } else {
117 ++it;
118 }
119 }
120
121 // Sweep the pre-autotile geometry out of EVERY screen bucket — the same
122 // cross-screen-stale scenario the tiled sweep above defends against
123 // (the window crossed screens before closing) would otherwise leak a
124 // geometry entry in the old screen's bucket forever.
125 for (auto it = state.preAutotileGeometries.begin(); it != state.preAutotileGeometries.end();) {
126 it->remove(windowId);
127 if (it->isEmpty()) {
128 it = state.preAutotileGeometries.erase(it);
129 } else {
130 ++it;
131 }
132 }
133}
134
135// ═══════════════════════════════════════════════════════════════════════════════
136// Per-screen BorderState mutators
137// ═══════════════════════════════════════════════════════════════════════════════
138
140inline void addTiledOnScreen(BorderState& border, const QString& screenId, const QString& windowId)
141{
142 border.tiledWindowsByScreen[screenId].insert(windowId);
143}
144
147inline bool removeTiledOnScreen(BorderState& border, const QString& screenId, const QString& windowId)
148{
149 auto it = border.tiledWindowsByScreen.find(screenId);
150 if (it == border.tiledWindowsByScreen.end()) {
151 return false;
152 }
153 const bool removed = it.value().remove(windowId);
154 if (it.value().isEmpty()) {
155 border.tiledWindowsByScreen.erase(it);
156 }
157 return removed;
158}
159
163inline void removeFromOtherScreens(BorderState& border, const QString& windowId, const QString& keepScreenId)
164{
165 for (auto it = border.tiledWindowsByScreen.begin(); it != border.tiledWindowsByScreen.end();) {
166 if (it.key() != keepScreenId) {
167 it.value().remove(windowId);
168 }
169 // The keep-bucket exclusion below is defensive symmetry only: this
170 // function never mutates the keep bucket, so an empty keep bucket
171 // could only pre-exist (and every other mutator erases empty
172 // buckets on the way out).
173 if (it.value().isEmpty() && it.key() != keepScreenId) {
174 it = border.tiledWindowsByScreen.erase(it);
175 } else {
176 ++it;
177 }
178 }
179}
180
183inline bool removeFromAllScreens(BorderState& border, const QString& windowId)
184{
185 bool any = false;
186 for (auto it = border.tiledWindowsByScreen.begin(); it != border.tiledWindowsByScreen.end();) {
187 if (it.value().remove(windowId)) {
188 any = true;
189 }
190 if (it.value().isEmpty()) {
191 it = border.tiledWindowsByScreen.erase(it);
192 } else {
193 ++it;
194 }
195 }
196 return any;
197}
198
201inline QSet<QString> tiledOnScreen(const BorderState& border, const QString& screenId)
202{
203 return border.tiledWindowsByScreen.value(screenId);
204}
205
209inline QVector<QPair<QString, QString>> allTiledPairs(const BorderState& border)
210{
211 QVector<QPair<QString, QString>> result;
212 for (auto it = border.tiledWindowsByScreen.constBegin(); it != border.tiledWindowsByScreen.constEnd(); ++it) {
213 for (const QString& wid : it.value()) {
214 result.append({wid, it.key()});
215 }
216 }
217 return result;
218}
219
220} // namespace AutotileStateHelpers
221} // namespace PhosphorCompositor
QSet< QString > tiledOnScreen(const BorderState &border, const QString &screenId)
Detached copy of the set of tiled windows on a given screen (QHash::value copy, not a reference).
Definition AutotileState.h:201
void cleanupClosedWindowState(const QString &windowId, BorderState &border, AutotileWindowState &state)
Clean up all state tracking for a closed window.
Definition AutotileState.h:102
void removeFromOtherScreens(BorderState &border, const QString &windowId, const QString &keepScreenId)
Remove a window from every screen's tiled bucket EXCEPT keepScreenId (cross-screen transfer: a window...
Definition AutotileState.h:163
bool removeFromAllScreens(BorderState &border, const QString &windowId)
Remove a window from every screen's tiled bucket.
Definition AutotileState.h:183
bool shouldShowBorderForWindow(const BorderState &border, const QString &windowId)
Definition AutotileState.h:70
void addTiledOnScreen(BorderState &border, const QString &screenId, const QString &windowId)
Add a window to a screen's tiled bucket. Idempotent.
Definition AutotileState.h:140
bool isTiledWindow(const BorderState &border, const QString &windowId)
Definition AutotileState.h:60
QVector< QPair< QString, QString > > allTiledPairs(const BorderState &border)
Collect every tiled (windowId, screenId) pair for bulk operations (hide-titlebars toggle on).
Definition AutotileState.h:209
bool removeTiledOnScreen(BorderState &border, const QString &screenId, const QString &windowId)
Remove a window from a specific screen's tiled bucket.
Definition AutotileState.h:147
constexpr int BorderRadius
Definition DecorationDefaults.h:29
constexpr int BorderWidth
Definition DecorationDefaults.h:25
constexpr bool ShowBorder
Definition DecorationDefaults.h:23
constexpr bool HideTitleBars
Definition DecorationDefaults.h:22
Definition AutotileState.h:17
Bundles per-window state maps for cleanup operations.
Definition AutotileState.h:86
QSet< QString > & minimizeFloatedWindows
Definition AutotileState.h:89
QHash< QString, QString > & notifiedWindowScreens
Definition AutotileState.h:88
QHash< QString, QHash< QString, QRectF > > & preAutotileGeometries
Definition AutotileState.h:93
QSet< QString > & notifiedWindows
Definition AutotileState.h:87
QHash< QString, QRect > & centeredWaylandZones
Definition AutotileState.h:91
QHash< QString, QRect > & autotileTargetZones
Definition AutotileState.h:90
QSet< QString > & monocleMaximizedWindows
Definition AutotileState.h:92
Compositor-agnostic autotile border state.
Definition AutotileState.h:30
bool hideTitleBars
Definition AutotileState.h:40
bool showBorder
Definition AutotileState.h:41
QColor inactiveColor
Definition AutotileState.h:45
int width
Definition AutotileState.h:42
QColor color
Definition AutotileState.h:44
QHash< QString, QSet< QString > > tiledWindowsByScreen
windowId → screen bucket of tile-managed windows (drives border RENDERING).
Definition AutotileState.h:36
int radius
Definition AutotileState.h:43