Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
EngineTypes.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 <QHashFunctions>
7#include <QLatin1StringView>
8#include <QList>
9#include <QRect>
10#include <QSet>
11#include <QString>
12#include <QStringList>
13
14#include <functional>
15#include <utility>
16
17namespace PhosphorEngine {
18
25{
26 QString screenId;
27 int desktop = 1;
28 QString activity;
29
30 bool operator==(const PlacementStateKey& other) const
31 {
32 return screenId == other.screenId && desktop == other.desktop && activity == other.activity;
33 }
34};
35
36inline size_t qHash(const PlacementStateKey& key, size_t seed = 0)
37{
38 return qHashMulti(seed, key.screenId, key.desktop, key.activity);
39}
40
41} // namespace PhosphorEngine
42
46template<>
47struct std::hash<PhosphorEngine::PlacementStateKey>
48{
49 size_t operator()(const PhosphorEngine::PlacementStateKey& key) const noexcept
50 {
51 return qHash(key);
52 }
53};
54
55namespace PhosphorEngine {
56
61
72
77enum class WindowKind : int {
79 Normal = 1,
81};
82
90{
91 switch (wire) {
92 case static_cast<int>(WindowKind::Normal):
93 return WindowKind::Normal;
94 case static_cast<int>(WindowKind::Transient):
96 default:
98 }
99}
100
129
141{
142 switch (wire) {
143 case static_cast<int>(RestoreReason::Unminimize):
145 case static_cast<int>(RestoreReason::PendingSweep):
147 case static_cast<int>(RestoreReason::DesktopArrival):
149 case static_cast<int>(RestoreReason::DaemonRestartSweep):
151 case static_cast<int>(RestoreReason::DesktopReapply):
153 default:
154 return RestoreReason::Open;
155 }
156}
157
159{
160 QString windowId;
162 QString screenId;
167 bool fromRemovedLayout = false;
172 QStringList zoneIds{};
173};
174
176{
177 bool shouldSnap = false;
178 QRect geometry;
179 QString zoneId;
180 QStringList zoneIds;
181 QString screenId;
194
195 bool isValid() const
196 {
197 return shouldSnap && geometry.isValid() && !zoneId.isEmpty();
198 }
199
201 {
202 // Value-initialize so every field takes its in-class default; a
203 // positional initializer here would silently stop covering fields
204 // added to the struct later.
205 return SnapResult{};
206 }
207};
208
210{
211 bool found = false;
212 QStringList zoneIds;
213 QRect geometry;
214 QString screenId;
215};
216
218{
219 QString windowId;
222 QStringList targetZoneIds;
235 bool restatement = false;
236};
237
243
247using StickyPredicate = std::function<bool(const QString&)>;
248
258{
259 bool known = false;
260 bool sticky = false;
261 QSet<int> desktops;
262 QString activity;
265 QStringList activities{};
266
268 bool coversDesktop(int desktop) const
269 {
270 return known && (sticky || desktops.contains(desktop));
271 }
272
275 bool coversActivity(const QString& other) const
276 {
277 if (activity.isEmpty() || other.isEmpty()) {
278 return true;
279 }
280 return activities.size() > 1 ? activities.contains(other) : activity == other;
281 }
282
283 bool coversKey(const PlacementStateKey& key) const
284 {
285 return coversDesktop(key.desktop) && coversActivity(key.activity);
286 }
287};
288
292using DesktopSpanQuery = std::function<DesktopSpan(const QString&)>;
293
299{
302 QList<std::pair<QString, PlacementStateKey>> released;
304 QList<std::pair<QString, PlacementStateKey>> adopted;
305
306 bool isEmpty() const
307 {
308 return released.isEmpty() && adopted.isEmpty();
309 }
310};
311
327
328inline constexpr QLatin1StringView RestoreSentinel("__restore__");
329
330} // namespace PhosphorEngine
Definition DesktopRemap.h:12
StickyWindowHandling
Definition EngineTypes.h:238
@ IgnoreAll
Definition EngineTypes.h:241
@ TreatAsNormal
Definition EngineTypes.h:239
@ RestoreOnly
Definition EngineTypes.h:240
PlacementStateKey TilingStateKey
Backwards-compatible spelling for autotile's existing sources.
Definition EngineTypes.h:60
StickyPinPhase
Which half of the sticky-screen pin pass to run.
Definition EngineTypes.h:323
@ Acquire
Definition EngineTypes.h:324
@ Release
Definition EngineTypes.h:325
RestoreReason clampRestoreReasonFromWire(int wire)
Clamp an integer wire value to a valid RestoreReason.
Definition EngineTypes.h:140
WindowKind clampWindowKindFromWire(int wire)
Clamp an integer wire value to a valid WindowKind.
Definition EngineTypes.h:89
SnapIntent
Definition EngineTypes.h:62
@ UserInitiated
Definition EngineTypes.h:63
@ AutoReplaced
The same automatic placement for a window that did NOT just open (a restart or pending sweep,...
Definition EngineTypes.h:70
@ AutoRestored
An automatic placement of a window that genuinely opened: may take focus under "Focus new windows".
Definition EngineTypes.h:66
RestoreReason
Why a snap restore is being resolved.
Definition EngineTypes.h:119
@ DesktopArrival
re-drive after the daemon moved the window to another desktop
Definition EngineTypes.h:123
@ PendingSweep
the pending-restores sweep, once the daemon is ready
Definition EngineTypes.h:122
@ DesktopReapply
re-apply the zone a window already holds in the context it arrived in; places nothing new
Definition EngineTypes.h:127
@ Open
a window OPEN: session restore, deferred-routing flush
Definition EngineTypes.h:120
@ DaemonRestartSweep
the bring-up stacking-restore sweep
Definition EngineTypes.h:124
@ Unminimize
unminimize of a window orphaned by a daemon restart
Definition EngineTypes.h:121
constexpr QLatin1StringView RestoreSentinel("__restore__")
WindowKind
Coarse structural classification of a window, carried on the open and close wire calls and on the pla...
Definition EngineTypes.h:77
@ Unknown
Definition EngineTypes.h:78
@ Normal
Definition EngineTypes.h:79
@ Transient
Definition EngineTypes.h:80
size_t qHash(const PlacementStateKey &key, size_t seed=0)
Definition EngineTypes.h:36
std::function< bool(const QString &)> StickyPredicate
Answers whether a window is on all desktops.
Definition EngineTypes.h:247
std::function< DesktopSpan(const QString &)> DesktopSpanQuery
Answers a window's DesktopSpan.
Definition EngineTypes.h:292
The contexts a window occupies, as the per-desktop membership pass reads them: which desktops (x11 nu...
Definition EngineTypes.h:258
QSet< int > desktops
when !sticky: the desktops it occupies (a span such as {1,2})
Definition EngineTypes.h:261
bool sticky
on every desktop
Definition EngineTypes.h:260
bool coversKey(const PlacementStateKey &key) const
Whether the span reaches the context key names.
Definition EngineTypes.h:283
QStringList activities
When the window is on several (but not all) activities, all of them; empty otherwise.
Definition EngineTypes.h:265
bool coversDesktop(int desktop) const
Whether the span reaches desktop desktop.
Definition EngineTypes.h:268
bool coversActivity(const QString &other) const
Whether the span reaches activity other.
Definition EngineTypes.h:275
bool known
false: no desktop information yet — leave memberships alone
Definition EngineTypes.h:259
QString activity
empty: every activity, or unknown
Definition EngineTypes.h:262
What a membership pass did, so the caller can drive the bookkeeping the engines cannot reach: the pla...
Definition EngineTypes.h:299
QList< std::pair< QString, PlacementStateKey > > adopted
(windowId, key) memberships granted.
Definition EngineTypes.h:304
QList< std::pair< QString, PlacementStateKey > > released
(windowId, key) memberships taken back because the span stopped covering them.
Definition EngineTypes.h:302
bool isEmpty() const
Definition EngineTypes.h:306
Identity of a per-screen placement state: a window's placement is scoped to the (screen,...
Definition EngineTypes.h:25
bool operator==(const PlacementStateKey &other) const
Definition EngineTypes.h:30
int desktop
Definition EngineTypes.h:27
QString screenId
Definition EngineTypes.h:26
QString activity
Definition EngineTypes.h:28
Definition EngineTypes.h:159
int virtualDesktop
Definition EngineTypes.h:163
QString windowId
Definition EngineTypes.h:160
QStringList zoneIds
Every zone the window held, primary first.
Definition EngineTypes.h:172
QString screenId
Definition EngineTypes.h:162
bool fromRemovedLayout
The entry holds a zone of a layout being deleted (bufferWindowsOfRemovedLayout).
Definition EngineTypes.h:167
int zonePosition
Definition EngineTypes.h:161
Definition EngineTypes.h:176
static SnapResult noSnap()
Definition EngineTypes.h:200
bool shouldSnap
Definition EngineTypes.h:177
QString zoneId
Definition EngineTypes.h:179
QStringList zoneIds
Definition EngineTypes.h:180
QRect geometry
Definition EngineTypes.h:178
bool deferredToTilingEngine
INERT, kept for ABI layout: snap's resolve once set it when it stood down for a record that homed the...
Definition EngineTypes.h:187
QString screenId
Definition EngineTypes.h:181
int virtualDesktop
Target virtual desktop the snap should be committed in (1-based).
Definition EngineTypes.h:193
bool isValid() const
Definition EngineTypes.h:195
Definition EngineTypes.h:210
QStringList zoneIds
Definition EngineTypes.h:212
QRect geometry
Definition EngineTypes.h:213
QString screenId
Definition EngineTypes.h:214
bool found
Definition EngineTypes.h:211
Definition EngineTypes.h:218
QString windowId
Definition EngineTypes.h:219
QRect targetGeometry
Definition EngineTypes.h:223
QString targetScreenId
Definition EngineTypes.h:224
QStringList targetZoneIds
Definition EngineTypes.h:222
bool restatement
The entry re-states a placement the window already has (a carry to the desktop it moved to,...
Definition EngineTypes.h:235
QString targetZoneId
Definition EngineTypes.h:221
QString sourceZoneId
Definition EngineTypes.h:220
int virtualDesktop
Virtual desktop to record the assignment on (1-based).
Definition EngineTypes.h:230
size_t operator()(const PhosphorEngine::PlacementStateKey &key) const noexcept
Definition EngineTypes.h:49