Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
WindowTrackingService.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4// WindowTrackingService is the engine-agnostic facade every placement engine
5// and the daemon share. The implementation is split by concern across src/
6// (WindowTrackingService.cpp and its _sticky part, snap, resnap, navigation,
7// virtualscreenmigration, lifecycle), and the member ordering here encodes which of those owns what.
8
9#pragma once
10
11#include "phosphorplacement_export.h"
12
22
23#include <QHash>
24#include <QObject>
25#include <QPointer>
26#include <QRect>
27#include <QSet>
28#include <QString>
29#include <QStringList>
30#include <QUuid>
31
32#include <functional>
33#include <optional>
34#include <utility>
35
36namespace PhosphorZones {
37class Layout;
38class LayoutRegistry;
39class Zone;
40}
41
42namespace PhosphorSnapEngine {
43class SnapState;
44}
45
49
50namespace PhosphorScreens {
51class ScreenManager;
52struct PhysicalScreen;
53}
54
55namespace PhosphorPlacement {
56
71class PHOSPHORPLACEMENT_EXPORT WindowTrackingService : public QObject, public PhosphorEngine::IWindowTrackingService
72{
73 Q_OBJECT
74
75public:
79 IGeometryResolver* geometryResolver = nullptr, PlacementConfig config = {},
80 QObject* parent = nullptr);
81
84 const PlacementConfig& config() const
85 {
86 return m_config;
87 }
89 {
90 m_config = config;
91 }
92
93 QObject* asQObject() override;
95
105
111
113
118
123
133
135
143 using AutotileModePredicate = std::function<bool(const QString& windowId)>;
145
148 bool isWindowInAutotileMode(const QString& windowId) const;
149
157 using EngineTiledPredicate = std::function<bool(const QString& windowId)>;
159
162 bool isWindowEngineTiled(const QString& windowId) const;
163
177 using ModeEngineIdResolver = std::function<QString(const QString& windowId, const QString& screenId)>;
179
187 QString owningModeEngineId(const QString& windowId, const QString& screenId) const;
188
194 std::optional<PhosphorEngine::WindowPlacement>
195 claimPlacementForOpen(const QString& windowId, const QString& openingScreenId, const QString& openingEngineId);
196
203 const QString& recordedScreenId, const QString& closeScreenId);
206 static QList<QPair<QString, int>> mismatchedDesktopZones(const PhosphorEngine::WindowPlacement& placement,
207 const QString& recordedScreenId,
208 const QString& closeScreenId);
209
213
215 QRect screenAvailableGeometry(const QString& screenId) const override;
216
217 // ═══════════════════════════════════════════════════════════════════════════
218 // PhosphorZones::Zone Assignment Management
219 // ═══════════════════════════════════════════════════════════════════════════
220
228 void assignWindowToZone(const QString& windowId, const QString& zoneId, const QString& screenId,
229 int virtualDesktop) override;
230
238 void assignWindowToZones(const QString& windowId, const QStringList& zoneIds, const QString& screenId,
239 int virtualDesktop) override;
240
245 void unassignWindow(const QString& windowId) override;
246
252 QString zoneForWindow(const QString& windowId) const override;
253
259 QStringList zonesForWindow(const QString& windowId) const override;
260
266 QString screenForWindow(const QString& windowId) const override;
267
270 QString screenForWindow(const QString& windowId, const QString& defaultScreen) const override;
271
277 QStringList windowsInZone(const QString& zoneId) const override;
278
283 QStringList snappedWindows() const;
284
289 int pruneStaleAssignments(const QSet<QString>& aliveWindowIds);
290
294 bool isWindowSnapped(const QString& windowId) const override;
295
296 // ═══════════════════════════════════════════════════════════════════════════
297 // Geometry Validation Utility
298 // ═══════════════════════════════════════════════════════════════════════════
299
315 std::optional<QRect> validateGeometryForScreen(const QRect& geo, const QString& savedScreen,
316 const QString& currentScreenId) const;
317
344 std::optional<QRect> validatedUnmanagedGeometry(const QString& windowId, const QString& screenId) const override;
345
351 bool geometryBelongsToScreen(const QRect& geometry, const QString& screenId) const override
352 {
353 return geometryOverlapsScreen(geometry, screenId);
354 }
355
358 std::optional<QPoint> outputOrigin(const QString& screenId) const;
359
367 void recordFreeGeometry(const QString& windowId, const QString& screenId, const QRect& geometry,
368 bool overwrite) override;
374 void recordFloatingClose(const QString& windowId, const QString& screenId, const QRect& geometry);
379 using ManagedFramePredicate = std::function<bool(const QString& windowId, const QRect& frame)>;
381 bool isManagedFrame(const QString& windowId, const QRect& frame) const;
383 bool occupiesZoneInView(const QString& windowId) const;
384
387 void clearFreeGeometry(const QString& windowId) override;
388 void clearFreeGeometry(const QString& windowId, const QString& screenId) override;
389
396 void releaseEngineSlot(const QString& windowId, const QString& engineId) override;
398 void forgetDesktopZones(const QString& windowId, const QString& engineId, int desktop) override;
403 void renumberDesktopZones(int removedDesktop) override;
405
406 // ═══════════════════════════════════════════════════════════════════════════
407 // Floating Window State
408 // ═══════════════════════════════════════════════════════════════════════════
409
425 using EngineFloatResolver = std::function<bool(const QString& windowId)>;
426 using EngineFloatWriter = std::function<void(const QString& windowId, bool floating)>;
427 using EngineFloatLister = std::function<QStringList()>;
428
434
441 bool isWindowFloating(const QString& windowId) const override;
442
458 bool isSuspensionFloat(const QString& windowId) const override;
459 void markSuspensionFloat(const QString& windowId);
460 void clearSuspensionFloat(const QString& windowId) override;
461
472 void setWindowFloating(const QString& windowId, bool floating) override;
473
477 QStringList floatingWindows() const;
478
483 void unsnapForFloat(const QString& windowId) override;
484
491 QString preFloatZone(const QString& windowId) const;
492
499 QStringList preFloatZones(const QString& windowId) const override;
500
507 QString preFloatScreen(const QString& windowId) const override;
508
510 void clearPreFloatZone(const QString& windowId) override;
511
521 void clearPreFloatZoneExceptHiddenContexts(const QString& windowId, const QString& screenId);
522
531 bool hasSnapState() const;
532
543 bool clearFloatingForSnap(const QString& windowId) override;
544
545 // ═══════════════════════════════════════════════════════════════════════════
546 // Sticky Window Handling
547 // ═══════════════════════════════════════════════════════════════════════════
548
552 void setWindowSticky(const QString& windowId, bool sticky);
553
556 bool isWindowSticky(const QString& windowId) const override;
557
558 // ═══════════════════════════════════════════════════════════════════════════
559 // Auto-Snap Logic
560 // ═══════════════════════════════════════════════════════════════════════════
561
567 void recordSnapIntent(const QString& windowId, bool wasUserInitiated) override;
568
572 QString lastUsedZoneId() const;
573
580 QString lastUsedZoneClass() const;
581
588 QString lastUsedScreenName() const;
589
593 int lastUsedDesktop() const;
594
602 void retagLastUsedZoneClass(const QString& newClass);
603
607 void updateLastUsedZone(const QString& zoneId, const QString& screenId, const QString& windowClass,
608 int virtualDesktop) override;
609
619 void markAsAutoSnapped(const QString& windowId);
620
626 bool isAutoSnapped(const QString& windowId) const;
627
633 bool clearAutoSnapped(const QString& windowId) override;
634
635 // ═══════════════════════════════════════════════════════════════════════════
636 // Navigation Helpers
637 // ═══════════════════════════════════════════════════════════════════════════
638
644 QString findEmptyZone(const QString& screenId = QString()) const override;
645
651 PhosphorProtocol::EmptyZoneList getEmptyZones(const QString& screenId) const;
652
664 QRect zoneGeometry(const QString& zoneId, const QString& screenId) const override;
665
672 QRect multiZoneGeometry(const QStringList& zoneIds, const QString& screenId) const;
673
686 void populateResnapBufferForAllScreens(const QSet<QString>& excludeScreens = {},
687 const QSet<QString>& includeScreens = {}, int desktopFilter = 0);
688
696
700 QStringList buildZoneOrderedWindowList(const QString& screenId) const;
701
706
707 // ═══════════════════════════════════════════════════════════════════════════
708 // Virtual Screen Migration
709 // ═══════════════════════════════════════════════════════════════════════════
710
729 void migrateScreenAssignmentsToVirtual(const QString& physicalScreenId, const QStringList& virtualScreenIds,
731
741 void migrateScreenAssignmentsFromVirtual(const QString& physicalScreenId);
742
766 QSet<QString> physicalScreensWithStaleVirtualAssignments(const QSet<QString>& subdividedPhysicalIds) const;
767
768 // ═══════════════════════════════════════════════════════════════════════════
769 // Resolution Change Handling
770 // ═══════════════════════════════════════════════════════════════════════════
771
774 QHash<QString, QRect> updatedWindowGeometries() const;
775
781 {
782 QRect geometry;
783 QString screenId;
784 QString windowId;
785 };
786
793 QHash<QString, QList<PendingRestoreTarget>> pendingRestoreGeometries() const;
794
795 // ═══════════════════════════════════════════════════════════════════════════
796 // Window Lifecycle
797 // ═══════════════════════════════════════════════════════════════════════════
798
807
811 {
812 QVector<PhosphorEngine::ZoneAssignmentEntry> unsnapped;
813 QVector<PhosphorEngine::ZoneAssignmentEntry> narrowed;
814 };
815
823
824 // ═══════════════════════════════════════════════════════════════════════════
825 // State Access
826 // ═══════════════════════════════════════════════════════════════════════════
827
832 QStringList recordedSnapZones(const QString& windowId) const override;
836 QStringList snapZonesOnDesktopInView(const PhosphorEngine::EngineSlot& slot, const QString& screenId) const;
837
839
840 QVector<ResnapEntry> takeResnapBuffer() override;
841 void markLastUsedZoneDirty() override;
842
844 const QSet<QString>& userSnappedClasses() const;
845
856 void setUserSnappedClasses(const QSet<QString>& classes);
857
861 void setLastUsedZone(const QString& zoneId, const QString& screenId, const QString& zoneClass, int desktop);
862
870 void setFloatingWindows(const QSet<QString>& windows);
871
872 // ═══════════════════════════════════════════════════════════════════════
873 // Dirty field tracking
874 //
875 // A bitfield of which persisted state changed. WindowTrackingAdaptor::
876 // saveState() snapshots and clears it in one step (takeDirty) and writes
877 // only the keys its bits name; a write that fails re-marks the bits it
878 // carried, so the next tick retries them. The mask starts at DirtyAll, but
879 // the adaptor's constructor load ends with clearDirty(), so the first save
880 // writes only what changed after the load.
881 // ═══════════════════════════════════════════════════════════════════════
882 // NOTE: several bits below (DirtyZoneAssignments,
883 // DirtyPreTileGeometries, DirtyPreFloatZones, DirtyPreFloatScreens,
884 // DirtyAutotileOrders, DirtyAutotilePending) no longer have a dedicated save
885 // block — their legacy keys were collapsed into DirtyWindowPlacements. The
886 // runtime mutators that still OR them in are retained because the act of
887 // marking ANY bit schedules a save, and saveState()'s refreshOpenWindowPlacements()
888 // re-derives the affected per-window state into the placement record. They are
889 // therefore "schedule a save" triggers, not independent persisted fields; only DirtyActiveLayoutId /
890 // DirtyKnownDesktops / DirtyLastUsedZone / DirtyUserSnapped / DirtyWindowPlacements / DirtyScrollStrips /
891 // DirtyScreenPixelSizes map to their own on-disk key.
892 enum DirtyField : uint32_t {
895 DirtyZoneAssignments = 1u << 1, // legacy save-trigger → DirtyWindowPlacements
897 DirtyPreTileGeometries = 1u << 3, // legacy save-trigger → DirtyWindowPlacements
899 DirtyPreFloatZones = 1u << 5, // legacy save-trigger → DirtyWindowPlacements
900 DirtyPreFloatScreens = 1u << 6, // legacy save-trigger → DirtyWindowPlacements
902 DirtyAutotileOrders = 1u << 8, // legacy save-trigger → DirtyWindowPlacements
903 DirtyAutotilePending = 1u << 9, // legacy save-trigger → DirtyWindowPlacements
904 // bit 10 reserved (was DirtyFloatRestores, removed with the FloatRestoreQueues key)
906 DirtyScrollStrips = 1u << 12,
908 DirtyAll = 0x3FFFu, // covers bits 0-13 incl. the reserved bit 10
909 };
910 using DirtyMask = uint32_t;
911
917 void markDirty(DirtyMask fields);
918
922
926
931
932Q_SIGNALS:
935 void windowZoneChanged(const QString& windowId, const QString& zoneId);
936
939
940private:
941 // Minimum visible area for geometry validation
942 static constexpr int MinVisibleWidth = 100;
943 static constexpr int MinVisibleHeight = 100;
944
945 // Helpers
946 //
947 // scheduleSaveState() wraps markDirty(DirtyAll), for a mutator that does
948 // not name the fields it touched (windowClosed, the VS migrations). The
949 // rest call markDirty with a narrow mask.
950 void scheduleSaveState(DirtyMask fields = DirtyAll);
951 bool isGeometryOnScreen(const QRect& geometry) const;
952
973 bool geometryOverlapsScreen(const QRect& geometry, const QString& screenId) const;
974 QRect adjustGeometryToScreen(const QRect& geometry) const;
975 PhosphorZones::Zone* findZoneById(const QString& zoneId) const;
976
978 template<typename Func>
979 auto preFloatLookup(const QString& windowId, Func&& getter) const
980 -> decltype(getter(std::declval<PhosphorSnapEngine::SnapState*>(), windowId));
981
985 void validateLastUsedZone(const QString& targetScreen);
988 PhosphorZones::Layout* lastUsedLayoutFor(const PhosphorSnapEngine::SnapState* state, const QString& screenId) const;
992 std::pair<int, QString> storeContextFor(const PhosphorSnapEngine::SnapState* state, const QString& screenId) const;
993
996 static QString findNearestVirtualScreen(const QStringList& vsIds, int oldIndex);
997
1000 struct ZoneLookupResult
1001 {
1002 PhosphorZones::Zone* zone = nullptr;
1003 PhosphorZones::Layout* layout = nullptr;
1004 };
1005 ZoneLookupResult findZoneInAllLayouts(const QUuid& zoneUuid) const;
1006
1007public:
1010 QString resolveEffectiveScreenId(const QString& screenId) const override;
1011
1014 QRect resolveZoneGeometry(const QStringList& zoneIds, const QString& screenId) const override;
1015
1016 QString findEmptyZoneInLayout(PhosphorZones::Layout* layout, const QString& screenId,
1017 int desktopFilter = 0) const override;
1018
1019 // Zone sort / position-map helpers now live in PhosphorZones::LayoutUtils.
1020 // Call PhosphorZones::LayoutUtils::sortZonesByNumber / buildZonePositionMap directly.
1021
1030 QSet<QUuid> buildOccupiedZoneSet(const QString& screenFilter = QString(), int desktopFilter = 0) const override;
1031
1040 QString currentAppIdFor(const QString& anyWindowId) const override;
1041
1048 QString canonicalizeForLookup(const QString& rawWindowId) const;
1049
1050private:
1051 // ── Snap-state resolution helpers (wrap the injected resolver) ───────────
1052 // Each returns nullptr / empty when the resolver is unwired, preserving the
1053 // historical "no SnapState" no-op guards at the call sites.
1054 PhosphorSnapEngine::SnapState* snapForWindow(const QString& windowId) const;
1057 bool snapHoldsWindow(const QString& windowId, const PhosphorSnapEngine::SnapState* state) const;
1058 PhosphorSnapEngine::SnapState* snapForWindowOnScreen(const QString& windowId, const QString& screenId,
1059 int desktop = 0);
1060 PhosphorSnapEngine::SnapState* snapForScreen(const QString& screenId) const;
1066 PhosphorSnapEngine::SnapState* snapRepresentativeLastUsed() const;
1072 bool clearGlobalLastUsedIfRemoved(const QStringList& removedZones,
1073 const PhosphorSnapEngine::SnapState* owningStore);
1075 bool unassignFromStore(const QString& windowId, PhosphorSnapEngine::SnapState* store);
1076
1082 bool pruneMigratedWindows(const QList<QPair<QString, PhosphorSnapEngine::SnapState*>>& visits);
1084 bool holdsAnyZone(const QString& windowId) const;
1085 PhosphorSnapEngine::SnapState* snapGlobals() const;
1088 QList<PhosphorSnapEngine::SnapState*> snapAllStates() const;
1100 void forEachZoneAssignedWindow(
1101 const std::function<void(const QString& windowId, const QStringList& zoneIds, const QString& screenId,
1102 int desktop, const QString& activity, PhosphorSnapEngine::SnapState* store)>& fn)
1103 const;
1104
1107 void flushPendingUserSnappedClasses();
1108
1109 // Dependencies
1110 PhosphorZones::LayoutRegistry* m_layoutManager;
1111 SnapStateResolver m_snapResolver;
1113 std::optional<QSet<QString>> m_pendingUserSnappedClasses;
1114 PhosphorEngine::WindowPlacementStore m_placementStore;
1115 IGeometryResolver* m_geometryResolver;
1116 PlacementConfig m_config;
1117 PhosphorWorkspaces::VirtualDesktopManager* m_virtualDesktopManager;
1118 // Shared registry for current-class queries and canonical key translation; not owned, null in unit tests.
1119 // Daemon::stop() clears it, and the QPointer (as for the screen manager) covers the destruction order: both
1120 // are Daemon unique_ptr members, destroyed before ~QObject deletes the adaptor and this service.
1121 QPointer<PhosphorEngine::WindowRegistry> m_windowRegistry;
1122 QPointer<PhosphorScreens::ScreenManager> m_screenManager;
1123 QPointer<PhosphorEngine::PlacementEngineBase> m_snapEngine;
1124 AutotileModePredicate m_autotileModePredicate{};
1125 EngineTiledPredicate m_engineTiledPredicate{};
1126 ModeEngineIdResolver m_modeEngineIdResolver{};
1127
1128 // Floating windows, read and written only while no per-engine float
1129 // resolver/writer is wired (unit tests, early init).
1130 QSet<QString> m_floatingWindows;
1131
1132 // Suspension-float classification (see isSuspensionFloat), canonical-keyed, never persisted. After a
1133 // restart only a tiling screen's minimize floats are re-marked (the effect re-asserts them); a snap
1134 // screen's are not, so that window's unminimize unfloat runs as a user toggle.
1135 QSet<QString> m_suspensionFloats;
1136
1137 // Daemon-injected per-engine float reader/writer/lister. See setEngineFloatResolver.
1138 EngineFloatResolver m_engineFloatResolver{};
1139 EngineFloatWriter m_engineFloatWriter{};
1140 EngineFloatLister m_engineFloatLister{};
1141
1142 // Sticky window states
1143 QHash<QString, bool> m_windowStickyStates;
1144
1145 QVector<ResnapEntry> m_resnapBuffer;
1146
1147 // Delta-persistence dirty mask (see markDirty). Starts at DirtyAll; the adaptor's constructor load clears it.
1148 DirtyMask m_dirtyMask = DirtyAll;
1149
1150 // Appended last (installed class).
1151 ManagedFramePredicate m_managedFramePredicate{};
1153 struct PendingLastUsedZone
1154 {
1155 QString zoneId, screenId, zoneClass;
1156 int desktop = 0;
1157 };
1158 std::optional<PendingLastUsedZone> m_pendingLastUsedZone{};
1159 void flushPendingLastUsedZone();
1162 QHash<QString, QRect> m_outputGeometry;
1163 void followOutputGeometry(const PhosphorScreens::PhysicalScreen& screen);
1164 void renameScreen(const QString& oldPhysicalId, const QString& newPhysicalId);
1167 void reslotSuspendedPreFloats(const QHash<QString, int>& positions);
1168 QHash<QString, int> m_removedLayoutPositions;
1169 // No save timer: persistence is the WindowTrackingAdaptor's debounced save, driven by stateChanged().
1170};
1171
1172} // namespace PhosphorPlacement
How KWin's desktop positions moved in one change of its desktop list: for each 1-based position in th...
Definition DesktopRemap.h:29
Definition IWindowTrackingService.h:35
Abstract base class for placement engines.
Definition PlacementEngineBase.h:36
The single source of truth for window restore state in the unified model.
Definition WindowPlacementStore.h:38
Definition WindowRegistry.h:113
Definition IGeometryResolver.h:17
void recordFreeGeometry(const QString &windowId, const QString &screenId, const QRect &geometry, bool overwrite) override
Float-back writes.
void setPlacementConfig(const PlacementConfig &config)
Definition WindowTrackingService.h:88
static QList< QPair< QString, int > > mismatchedDesktopZones(const PhosphorEngine::WindowPlacement &placement, const QString &recordedScreenId, const QString &closeScreenId)
The (engine id, desktop) entries that downgrade clears from the per-desktop maps, read before it runs...
std::optional< QRect > validatedUnmanagedGeometry(const QString &windowId, const QString &screenId) const override
Look up a window's free (unmanaged) geometry from the unified WindowPlacementStore and validate it.
void markLastUsedZoneDirty() override
An engine cleared a last-used zone in one of its stores: persist it.
QString zoneForWindow(const QString &windowId) const override
Get the primary zone ID for a window.
bool isWindowInAutotileMode(const QString &windowId) const
The AutotileModePredicate's answer for windowId; false when unwired (snap-only tests / early init).
void markDirty(DirtyMask fields)
OR the given fields into the dirty mask AND emit stateChanged.
void clearSuspensionFloat(const QString &windowId) override
Drop the suspension classification.
QRect screenAvailableGeometry(const QString &screenId) const override
The area of screenId a window may occupy (the output minus panels and struts), or an invalid rect whe...
PhosphorProtocol::EmptyZoneList getEmptyZones(const QString &screenId) const
Get typed list of all empty zones for Snap Assist continuation.
bool isWindowSnapped(const QString &windowId) const override
Whether the window holds a zone in its primary store (the context in view when it is a member there).
void assignWindowToZone(const QString &windowId, const QString &zoneId, const QString &screenId, int virtualDesktop) override
Assign a window to a zone.
void clearResnapBuffer()
Clear the resnap buffer.
void clearPreFloatZoneExceptHiddenContexts(const QString &windowId, const QString &screenId)
Clear the window's pre-float zone in every snap store except the hidden contexts of screenId: a store...
QString screenForWindow(const QString &windowId, const QString &defaultScreen) const override
Same, but returns defaultScreen when the window has no screen assignment — the canonicalizing with-de...
void recordSnapIntent(const QString &windowId, bool wasUserInitiated) override
Record that a window class was user-snapped.
QVector< ResnapEntry > takeResnapBuffer() override
bool isWindowFloating(const QString &windowId) const override
Whether the engine running the window's current screen mode floats it.
QString findEmptyZoneInLayout(PhosphorZones::Layout *layout, const QString &screenId, int desktopFilter=0) const override
void setFloatingWindows(const QSet< QString > &windows)
Set floating windows (test / bulk-seed entry point).
void clearFreeGeometry(const QString &windowId, const QString &screenId) override
Screen-scoped consume-once variant: clears only screenId's remembered float-back, preserving other mo...
QString preFloatScreen(const QString &windowId) const override
Get the screen id where the window was snapped before floating, from the window's primary snap store.
QStringList buildZoneOrderedWindowList(const QString &screenId) const
The windows snapped (not floating) on screenId in the context in view, sorted by their primary zone's...
bool isWindowSticky(const QString &windowId) const override
Whether the window is on all desktops: the compositor's setWindowSticky report when one arrived,...
bool geometryBelongsToScreen(const QRect &geometry, const QString &screenId) const override
Does geometry plausibly belong to the coordinate space screenId names?
Definition WindowTrackingService.h:351
ZonePruneResult pruneStaleZoneAssignments()
Drop stale zones in the store holding each: an id no layout holds, in every context,...
std::optional< QPoint > outputOrigin(const QString &screenId) const
The top-left of screenId's output (its monitor, for a virtual screen) that float-back rects are measu...
uint32_t DirtyMask
Definition WindowTrackingService.h:910
QRect multiZoneGeometry(const QStringList &zoneIds, const QString &screenId) const
Get combined geometry for multiple zones on a specific screen.
DirtyMask peekDirty() const
Return the current dirty mask without clearing.
const PhosphorEngine::WindowPlacementStore & placementStore() const
bool hasSnapState() const
True while the resolver's globals store resolves: wired, and (for the engine resolver,...
void setSnapEngine(PhosphorEngine::PlacementEngineBase *engine)
Wire the snap-mode placement engine.
QString currentAppIdFor(const QString &anyWindowId) const override
Current app class for a windowId, preferring the live registry.
void markSuspensionFloat(const QString &windowId)
static void downgradeMismatchedManagedSlots(PhosphorEngine::WindowPlacement &placement, const QString &recordedScreenId, const QString &closeScreenId)
Downgrade managed slots recorded against a different screen: when recordedScreenId does not match clo...
QSet< QString > physicalScreensWithStaleVirtualAssignments(const QSet< QString > &subdividedPhysicalIds) const
Find physical screens whose state still references virtual ids, excluding screens the caller knows ar...
bool isAutoSnapped(const QString &windowId) const
Check if a window was auto-snapped.
void unassignWindow(const QString &windowId) override
Remove window from its assigned zone.
std::function< bool(const QString &windowId, const QRect &frame)> ManagedFramePredicate
(M): frame equals a rect a snap membership of the window resolves to (its zones and pre-float zones,...
Definition WindowTrackingService.h:379
void migrateScreenAssignmentsToVirtual(const QString &physicalScreenId, const QStringList &virtualScreenIds, PhosphorScreens::ScreenManager *mgr)
Migrate window screen assignments from physical to virtual screen IDs.
void bufferWindowsOfRemovedLayout(PhosphorZones::Layout *layout)
Replace the resnap buffer with the windows in view on a snapping screen whose primary zone layout (be...
PhosphorScreens::ScreenManager * screenManager() const override
QString preFloatZone(const QString &windowId) const
Get primary zone to restore to when unfloating, from the window's own entry in its primary snap store...
void setEngineFloatResolver(EngineFloatResolver resolver)
QHash< QString, QRect > updatedWindowGeometries() const
windowId -> its zone rect in the context in view (else its primary's), for the work-area re-apply.
bool clearAutoSnapped(const QString &windowId) override
Clear auto-snapped flag for a window.
std::function< QString(const QString &windowId, const QString &screenId)> ModeEngineIdResolver
Resolver: which engine id owns windowId's mode on screenId?
Definition WindowTrackingService.h:177
void clearPreFloatZone(const QString &windowId) override
Clear the window's pre-float zone in every snap store.
QString lastUsedScreenName() const
Screen name companion of the last-used-zone tracking.
int pruneStaleAssignments(const QSet< QString > &aliveWindowIds)
Drop per-window state for windows not in the alive set: every snap store's assignments,...
void populateResnapBufferForAllScreens(const QSet< QString > &excludeScreens={}, const QSet< QString > &includeScreens={}, int desktopFilter=0)
Populate the resnap buffer: each window's primary zone position, read from a map over every loaded la...
std::function< void(const QString &windowId, bool floating)> EngineFloatWriter
Definition WindowTrackingService.h:426
bool isWindowEngineTiled(const QString &windowId) const
True if a tiling-family engine (autotile / scrolling) reports the window actively tiled.
QStringList snappedWindows() const
Get all snapped windows.
void setManagedFramePredicate(ManagedFramePredicate predicate)
QString lastUsedZoneId() const
Get last used zone ID.
bool clearFloatingForSnap(const QString &windowId) override
Clear the float when a floating window is snapped.
void releaseEngineSlot(const QString &windowId, const QString &engineId) override
Downgrade engineId's slot to released on windowId's record(s) and mark the placements dirty — the dir...
void assignWindowToZones(const QString &windowId, const QStringList &zoneIds, const QString &screenId, int virtualDesktop) override
Assign a window to multiple zones (multi-zone snap).
void recordFloatingClose(const QString &windowId, const QString &screenId, const QRect &geometry)
The close-time capture of an engine-orphaned window: the float geometry (P, M, S as above) and screen...
QStringList recordedSnapZones(const QString &windowId) const override
Live snap zones if present, else the durable placement-record snap slot.
QStringList preFloatZones(const QString &windowId) const override
Get all zones to restore to when unfloating (multi-zone support), from the window's primary snap stor...
void setEngineFloatLister(EngineFloatLister lister)
Aggregates every engine's floating windows for the engine-agnostic floatingWindows() enumeration.
PhosphorEngine::ResnapEntry ResnapEntry
Definition WindowTrackingService.h:838
DirtyField
Definition WindowTrackingService.h:892
@ DirtyPreTileGeometries
Definition WindowTrackingService.h:897
@ DirtyPreFloatZones
Definition WindowTrackingService.h:899
@ DirtyAutotileOrders
Definition WindowTrackingService.h:902
@ DirtyScreenPixelSizes
each monitor's last compositor-reported pixel size (WTA-provided)
Definition WindowTrackingService.h:907
@ DirtyScrollStrips
scrolling strip-structure snapshots (WTA-provided blob)
Definition WindowTrackingService.h:906
@ DirtyLastUsedZone
Definition WindowTrackingService.h:898
@ DirtyKnownDesktops
the virtual desktop ids the session last saw (was DirtyPendingRestores)
Definition WindowTrackingService.h:896
@ DirtyNone
Definition WindowTrackingService.h:893
@ DirtyAutotilePending
Definition WindowTrackingService.h:903
@ DirtyZoneAssignments
Definition WindowTrackingService.h:895
@ DirtyPreFloatScreens
Definition WindowTrackingService.h:900
@ DirtyWindowPlacements
unified WindowPlacementStore (sole per-window restore state)
Definition WindowTrackingService.h:905
@ DirtyActiveLayoutId
Definition WindowTrackingService.h:894
@ DirtyUserSnapped
Definition WindowTrackingService.h:901
@ DirtyAll
Definition WindowTrackingService.h:908
bool isManagedFrame(const QString &windowId, const QRect &frame) const
PhosphorPlacement::SnapStateResolver SnapStateResolver
The injectable SnapState-resolver seam.
Definition WindowTrackingService.h:110
void clearDirty()
Clear every dirty bit.
void windowZoneChanged(const QString &windowId, const QString &zoneId)
The window's primary zone changed (empty: it left every zone).
QRect resolveZoneGeometry(const QStringList &zoneIds, const QString &screenId) const override
Resolve zone geometry: combined geometry for multi-zone, single for single zone.
PhosphorEngine::WindowPlacementStore & placementStore() override
The unified, engine-agnostic placement store (one WindowPlacement record per window).
void migrateScreenAssignmentsFromVirtual(const QString &physicalScreenId)
Reverse migration: virtual screen IDs → physical screen ID.
int lastUsedDesktop() const
Virtual-desktop companion of the last-used-zone tracking.
bool occupiesZoneInView(const QString &windowId) const
(O): the window is snapped, not floating, in the store its screen shows, on a screen snap runs.
QHash< QString, QList< PendingRestoreTarget > > pendingRestoreGeometries() const
appId -> list of {geometry, screenId, windowId}, newest first: the snapped records of closed windows ...
void setModeEngineIdResolver(ModeEngineIdResolver resolver)
QStringList floatingWindows() const
Get all floating window IDs.
PhosphorEngine::WindowRegistry * windowRegistry() const
The wired registry, or null.
void setLastUsedZone(const QString &zoneId, const QString &screenId, const QString &zoneClass, int desktop)
Set last used zone info (the adaptor's session load; held until a store is wired).
void setAutotileModePredicate(AutotileModePredicate predicate)
std::optional< QRect > validateGeometryForScreen(const QRect &geo, const QString &savedScreen, const QString &currentScreenId) const
Validate and adjust a saved geometry for screen-aware restore.
QString canonicalizeForLookup(const QString &rawWindowId) const
Canonicalize for read-only callers (no map mutation).
QRect zoneGeometry(const QString &zoneId, const QString &screenId) const override
Get geometry for a zone on a specific screen.
void forgetDesktopZones(const QString &windowId, const QString &engineId, int desktop) override
Dirty-marking wrapper for WindowPlacementStore::forgetDesktopZones.
void unsnapForFloat(const QString &windowId) override
Unsnap window for floating (saves zone for later restore).
std::optional< PhosphorEngine::WindowPlacement > claimPlacementForOpen(const QString &windowId, const QString &openingScreenId, const QString &openingEngineId)
The reopen contract's claim (the store's screen-aware claimForOpen) for windowId opening on openingSc...
QString findEmptyZone(const QString &screenId=QString()) const override
Find the first empty zone in the layout for a screen.
DirtyMask takeDirty()
Return the current dirty mask, clearing it atomically.
void setEngineTiledPredicate(EngineTiledPredicate predicate)
void setSnapStateResolver(SnapStateResolver resolver)
QString screenForWindow(const QString &windowId) const override
The screen a window is assigned to, or empty when it has none.
std::function< QStringList()> EngineFloatLister
Definition WindowTrackingService.h:427
void setWindowFloating(const QString &windowId, bool floating) override
Set window floating state.
QSet< QUuid > buildOccupiedZoneSet(const QString &screenFilter=QString(), int desktopFilter=0) const override
Build set of occupied zone UUIDs, optionally filtered by screen and virtual desktop.
void updateLastUsedZone(const QString &zoneId, const QString &screenId, const QString &windowClass, int virtualDesktop) override
Update last used zone tracking.
void onLayoutChanged()
The prune alone; the adaptor calls pruneStaleZoneAssignments to relay.
std::function< bool(const QString &windowId)> EngineTiledPredicate
Predicate: is the window ACTIVELY TILED by a tiling-family engine (autotile / scrolling) in the conte...
Definition WindowTrackingService.h:157
QStringList snapZonesOnDesktopInView(const PhosphorEngine::EngineSlot &slot, const QString &screenId) const
slot's zones for the desktop screenId shows: the per-desktop map's entry when the slot carries one (e...
void setWindowSticky(const QString &windowId, bool sticky)
Record whether a window is sticky (on all desktops).
QString owningModeEngineId(const QString &windowId, const QString &screenId) const
The owning engine id for windowId on screenId per the resolver; snap's engine id when the resolver is...
void clearFreeGeometry(const QString &windowId) override
Clear a window's shared free/float geometry from the record.
void setWindowRegistry(PhosphorEngine::WindowRegistry *registry)
Wire the shared WindowRegistry.
void setUserSnappedClasses(const QSet< QString > &classes)
Set user-snapped classes (loaded from the persisted state by the adaptor).
void stateChanged()
Emitted when state needs to be saved.
QStringList windowsInZone(const QString &zoneId) const override
Every window holding a zone in any context, each once.
void remapDesktopZones(const PhosphorEngine::DesktopRemap &remap) override
renumberDesktopZones for any change of KWin's desktop list (F763): move every persisted per-desktop z...
void windowClosed(const QString &windowId, PhosphorEngine::WindowKind kind=PhosphorEngine::WindowKind::Unknown)
Clean up all tracking data for a closed window.
std::function< bool(const QString &windowId)> AutotileModePredicate
Predicate: is the window's CURRENT screen in Autotile mode?
Definition WindowTrackingService.h:143
std::function< bool(const QString &windowId)> EngineFloatResolver
Per-engine float resolver/writer.
Definition WindowTrackingService.h:425
void setSnapState(PhosphorSnapEngine::SnapState *state)
Convenience wiring for a SINGLE snap store (unit tests).
const QSet< QString > & userSnappedClasses() const
The user-snapped classes.
QStringList zonesForWindow(const QString &windowId) const override
Get all zone IDs for a window (multi-zone support).
void renumberDesktopZones(int removedDesktop) override
Dirty-marking wrapper for WindowPlacementStore::renumberDesktopZones that also shifts the buffered re...
const PlacementConfig & config() const
The placement config.
Definition WindowTrackingService.h:84
void markAsAutoSnapped(const QString &windowId)
Mark a window as auto-snapped.
void retagLastUsedZoneClass(const QString &newClass)
Update the last-used-zone class tag without touching zone/screen.
bool isSuspensionFloat(const QString &windowId) const override
Suspension-float classification (minimize-floats).
PhosphorEngine::PlacementEngineBase * snapEngine() const
QString lastUsedZoneClass() const
App class string stamped on the last-used-zone tracking.
QString resolveEffectiveScreenId(const QString &screenId) const override
A live or non-virtual id comes back as is; a virtual screen that no longer exists resolves to the nea...
void setEngineFloatWriter(EngineFloatWriter writer)
WindowTrackingService(PhosphorZones::LayoutRegistry *layoutManager, PhosphorScreens::ScreenManager *screenManager, PhosphorWorkspaces::VirtualDesktopManager *vdm, IGeometryResolver *geometryResolver=nullptr, PlacementConfig config={}, QObject *parent=nullptr)
Centralized screen-topology service.
Definition Manager.h:86
Per-screen snap placement state.
Definition SnapState.h:36
The compositor's virtual desktops, and every rule about them.
Definition VirtualDesktopManager.h:30
Manual zone-layout registry + per-context assignment store.
Definition LayoutRegistry.h:87
Represents a collection of zones that form a layout.
Definition Layout.h:42
Represents a single zone within a layout.
Definition Zone.h:47
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
Definition IGeometryResolver.h:14
QList< EmptyZoneEntry > EmptyZoneList
Definition ZoneTypes.h:58
Definition IWindowTrackingService.h:28
Definition SnapStateResolver.h:16
Definition WindowTrackingService.h:46
Definition IWindowTrackingService.h:24
One engine's view of a window: which managed slot it occupies (or that it is floating / unmanaged) in...
Definition WindowPlacement.h:41
Definition EngineTypes.h:159
One window's single, authoritative placement record — the unit of the unified, engine-agnostic restor...
Definition WindowPlacement.h:96
Definition PlacementConfig.h:11
Seam onto the snap engine's per-(screen,desktop,activity) SnapState stores.
Definition SnapStateResolver.h:33
A pre-computed snap restore target for the effect's instant-restore cache: zone geometry,...
Definition WindowTrackingService.h:781
QString screenId
Definition WindowTrackingService.h:783
QRect geometry
Definition WindowTrackingService.h:782
QString windowId
Definition WindowTrackingService.h:784
unsnapped: windows left in no zone in view (windowId, targetScreenId).
Definition WindowTrackingService.h:811
QVector< PhosphorEngine::ZoneAssignmentEntry > narrowed
Definition WindowTrackingService.h:813
QVector< PhosphorEngine::ZoneAssignmentEntry > unsnapped
Definition WindowTrackingService.h:812