11#include "phosphorplacement_export.h"
80 QObject* parent =
nullptr);
194 std::optional<PhosphorEngine::WindowPlacement>
203 const QString& recordedScreenId,
const QString& closeScreenId);
207 const QString& recordedScreenId,
208 const QString& closeScreenId);
229 int virtualDesktop)
override;
239 int virtualDesktop)
override;
270 QString
screenForWindow(
const QString& windowId,
const QString& defaultScreen)
const override;
316 const QString& currentScreenId)
const;
353 return geometryOverlapsScreen(geometry, screenId);
368 bool overwrite)
override;
608 int virtualDesktop)
override;
664 QRect
zoneGeometry(
const QString& zoneId,
const QString& screenId)
const override;
687 const QSet<QString>& includeScreens = {},
int desktopFilter = 0);
813 QVector<PhosphorEngine::ZoneAssignmentEntry>
narrowed;
861 void setLastUsedZone(
const QString& zoneId,
const QString& screenId,
const QString& zoneClass,
int desktop);
942 static constexpr int MinVisibleWidth = 100;
943 static constexpr int MinVisibleHeight = 100;
951 bool isGeometryOnScreen(
const QRect& geometry)
const;
973 bool geometryOverlapsScreen(
const QRect& geometry,
const QString& screenId)
const;
974 QRect adjustGeometryToScreen(
const QRect& geometry)
const;
978 template<
typename Func>
979 auto preFloatLookup(
const QString& windowId, Func&& getter)
const
980 ->
decltype(getter(std::declval<PhosphorSnapEngine::SnapState*>(), windowId));
985 void validateLastUsedZone(
const QString& targetScreen);
996 static QString findNearestVirtualScreen(
const QStringList& vsIds,
int oldIndex);
1000 struct ZoneLookupResult
1005 ZoneLookupResult findZoneInAllLayouts(
const QUuid& zoneUuid)
const;
1017 int desktopFilter = 0)
const override;
1072 bool clearGlobalLastUsedIfRemoved(
const QStringList& removedZones,
1082 bool pruneMigratedWindows(
const QList<QPair<QString, PhosphorSnapEngine::SnapState*>>& visits);
1084 bool holdsAnyZone(
const QString& windowId)
const;
1088 QList<PhosphorSnapEngine::SnapState*> snapAllStates()
const;
1100 void forEachZoneAssignedWindow(
1101 const std::function<
void(
const QString& windowId,
const QStringList& zoneIds,
const QString& screenId,
1107 void flushPendingUserSnappedClasses();
1113 std::optional<QSet<QString>> m_pendingUserSnappedClasses;
1121 QPointer<PhosphorEngine::WindowRegistry> m_windowRegistry;
1122 QPointer<PhosphorScreens::ScreenManager> m_screenManager;
1123 QPointer<PhosphorEngine::PlacementEngineBase> m_snapEngine;
1125 EngineTiledPredicate m_engineTiledPredicate{};
1126 ModeEngineIdResolver m_modeEngineIdResolver{};
1130 QSet<QString> m_floatingWindows;
1135 QSet<QString> m_suspensionFloats;
1138 EngineFloatResolver m_engineFloatResolver{};
1139 EngineFloatWriter m_engineFloatWriter{};
1140 EngineFloatLister m_engineFloatLister{};
1143 QHash<QString, bool> m_windowStickyStates;
1145 QVector<ResnapEntry> m_resnapBuffer;
1148 DirtyMask m_dirtyMask = DirtyAll;
1151 ManagedFramePredicate m_managedFramePredicate{};
1153 struct PendingLastUsedZone
1155 QString zoneId, screenId, zoneClass;
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;
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
QObject * asQObject() override
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 ¤tScreenId) 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
~WindowTrackingService() override
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