The single source of truth for window restore state in the unified model. More...
#include <PhosphorEngine/WindowPlacementStore.h>
Public Types | |
| using | OutputOrigin = std::function<std::optional<QPoint>(const QString& screenId)> |
| The top-left of the output a free-geometry key (a screen id, virtual or not) lies on, which its rect is measured from on disk; nullopt for an output the caller does not know. | |
Public Member Functions | |
| WindowPlacementStore ()=default | |
| bool | record (WindowPlacement placement) |
| Record / MERGE this window's placement. | |
| std::optional< WindowPlacement > | take (const QString &windowId, const QString &appId, const std::function< bool(const WindowPlacement &)> &accept={}, const std::function< bool(const WindowPlacement &)> &preferred={}) |
| Restore lookup: the first record whose accept predicate passes, trying the same-instance match before the appId FIFO (oldest first). | |
| std::optional< WindowPlacement > | peekLiveSibling (const QString &windowId, const QString &appId, const std::function< bool(const WindowPlacement &)> &accept={}) const |
The EARLIEST-RECORDED record in appId's bucket that is bound to a live window OTHER than windowId's instance and passes accept, or nullopt. | |
| std::optional< WindowPlacement > | takeForReopen (const QString &engineId, const QString &windowId, const QString &appId, const QString &screenId) |
| Reopen resolve: the shared consumption pattern the TILING engines' open-time restores use (SnapEngine::resolveWindowRestore keeps its own take + re-bind with take()'s oldest-first ORDER and its preferred ranking pass, and since #1106 shares the live-instance exclusion below) — take() wrapped in the accept predicate both tiling engines share and the two rules that make a close/reopen (fresh uuid, appId-FIFO match) behave correctly. | |
| std::optional< WindowPlacement > | peek (const QString &windowId, const QString &appId, const std::function< bool(const WindowPlacement &)> &accept={}, bool excludeLiveSiblings=false) const |
| Non-consuming lookup (unlike take): the record for the same live instance, else the NEWEST record in the appId bucket whose accept passes. | |
| std::optional< WindowPlacement > | peekExact (const QString &windowId) const |
| Same-instance peek: branch 1 of peek() only, never the appId-FIFO fallback. | |
| std::optional< WindowPlacement > | peekForReclaim (const QString &windowId, const QString &appId, const std::function< bool(const WindowPlacement &)> &accept={}) const |
| Non-consuming lookup for the tiling engines' reopen claim (IPlacementEngine::claimCrossScreenReopen), which restores a window on the output it opens on, onto another virtual screen there. | |
| bool | contains (const QString &windowId, const QString &appId=QString()) const |
True if a record exists for the same live instance, or (if appId non-empty) any record in that appId bucket. | |
| bool | markInstanceClosed (const QString &windowId, bool graceEligible=true) |
| The window CLOSED: drop its open claim (releaseOpenClaim). | |
| void | markInstanceMovedLive (const QString &windowId) |
| INERT, kept for ABI. | |
| bool | burnReclaimCredit (const QString &windowId, const QString &appId) |
| INERT, kept for ABI. | |
| std::optional< WindowPlacement > | claimForOpen (const QString &windowId, const QString &appId) |
| Reserve, once per opening window instance, the record that instance owns. | |
| void | releaseOpenClaim (const QString &windowId) |
Drop windowId's open claim, so a claim never outlives the instance that made it. | |
| std::optional< WindowPlacement > | claimForOpen (const QString &windowId, const QString &appId, const QString &openingScreenId, const std::function< bool(const WindowPlacement &)> &restorableHere) |
| The reopen-contract claim: claimForOpen restricted to what the opening screen can restore. | |
| int | releaseOpenClaimsExcept (const QSet< QString > &aliveInstanceIds) |
Drop every open claim whose instance is not in aliveInstanceIds (instance ids, as PhosphorIdentity::WindowId::extractInstanceId gives them), so a claimer that died without a close signal stops reserving a record another instance could restore from. | |
| void | setLiveInstanceProbe (std::function< bool(const QString &windowId)> probe) |
| Inject the live-window probe behind every live-sibling exclusion in the store (take, takeForReopen, claimForOpen, peekForReclaim, peekLiveSibling, peek's opt-in, the eviction and collapse tiers). | |
| bool | isLiveInstance (const QString &windowId) const |
Whether the probe reports windowId's instance as a still-open window. | |
| bool | collapsePureFloatSiblings (const QString &appId, const QString &keepWindowId) |
Collapse stale pure-float duplicates for an app, keeping keepWindowId. | |
| bool | clear (const QString &windowId) |
| Drop any record for the same live instance (and prune the empty bucket). | |
| bool | clearFreeGeometry (const QString &windowId) |
| Clear ONLY the shared free/float geometry for the same live instance, leaving the engine slots and context intact. | |
| bool | clearFreeGeometry (const QString &windowId, const QString &screenId) |
| bool | releaseEngineSlot (const QString &windowId, const QString &engineId) |
| DOWNGRADE one engine's slot to WindowPlacement::stateReleased() on every record for the same live instance, leaving the other engines' slots, the context and the shared geometry intact. | |
| bool | forgetDesktopZones (const QString &windowId, const QString &engineId, int desktop) |
| Drop one desktop's entry from an engine slot's zonesByDesktop map. | |
| int | renumberDesktopZones (int removedDesktop) |
Drop removedDesktop from every slot's zonesByDesktop map and shift the entries above it down by one, and shift the record-level desktop the same way (a record ON the removed desktop reads as unknown), because Plasma renumbers x11 desktops when one in the middle is deleted. | |
| int | remapDesktopZones (const DesktopRemap &remap) |
Move every slot's zonesByDesktop entries and the record-level desktop through remap, for any change of KWin's desktop list: a removed desktop's entry goes and a record on it reads as unknown (0). | |
| int | remapRestoredDesktopZones (const DesktopRemap &remap, quint64 restoredUpTo) |
remapDesktopZones for the start-up renumber that KWin's first desktop list brings when it lands after windows did (F1045): only the records restored from disk that no live window has touched move, which are the ones stamped at or below restoredUpTo (a sequence() read before any window opened) that no downgrade (releaseEngineSlot, clearFreeGeometry) changed this session, no open claim names and no live window owns. | |
| quint64 | sequence () const |
| The stamp of the newest record. | |
| int | transform (const std::function< bool(WindowPlacement &)> &fn) |
Apply an in-place mutation to every record; fn returns true when it changed the record. | |
| int | removeIf (const std::function< bool(const WindowPlacement &)> &pred) |
Remove every record matching pred. Returns the count removed. | |
| QList< WindowPlacement > | records () const |
| All records, in no particular order. | |
| QJsonObject | serialize (const std::function< bool(const WindowPlacement &)> &keep={}) const |
| JSON shape: { "_version": FormatVersion, appId: [ record, ... ] }. | |
| void | deserialize (const QJsonObject &obj) |
| QJsonObject | serialize (const std::function< bool(const WindowPlacement &)> &keep, const OutputOrigin &originFor) const |
| The on-disk form keeps each float-back RELATIVE to its output, so a spot survives a rearrangement of the monitors between sessions (F814). | |
| void | deserialize (const QJsonObject &obj, const OutputOrigin &originFor) |
| int | size () const |
Static Public Member Functions | |
| static int | formatVersionOf (const QJsonObject &stored) |
The version stored was written in (1 when unstamped). | |
Static Public Attributes | |
| static constexpr int | MaxPerApp = 16 |
| Per-app record cap (public so tests can pin the eviction contract). | |
| static constexpr qint64 | ShutdownCloseGraceMs = 30000 |
| INERT, kept for source compatibility: the shutdown-close grace serialize() once applied to the reclaim credit, which is gone. | |
| static constexpr int | FormatVersion = 2 |
| The serialized format's version, stamped as "_version". | |
The single source of truth for window restore state in the unified model.
Holds AT MOST ONE WindowPlacement record PER WINDOW INSTANCE (not per engine), captured live by the engines. Records are keyed two ways so they survive both a daemon restart (the instance component is stable while the window stays open) and a close→reopen (uuid changes, so the appId FIFO carries it).
The core invariant — record() MERGES into the single record for the same instance — gives per-mode state independence with a shared free/float geometry: each engine updates only its OWN slot (in engines, keyed by engineId()) plus any free-geometry change, so a window may be snapped in the snap engine AND floating in the autotile engine at once, each engine remembering the window's state in its own mode, while the un-managed position lives once in freeGeometryByScreen (shared across modes, keyed per screen).
| using PhosphorEngine::WindowPlacementStore::OutputOrigin = std::function<std::optional<QPoint>(const QString& screenId)> |
The top-left of the output a free-geometry key (a screen id, virtual or not) lies on, which its rect is measured from on disk; nullopt for an output the caller does not know.
|
default |
| bool PhosphorEngine::WindowPlacementStore::burnReclaimCredit | ( | const QString & | windowId, |
| const QString & | appId ) |
INERT, kept for ABI.
It retired one reclaim credit per open, and the credit is gone. Always returns false.
| std::optional< WindowPlacement > PhosphorEngine::WindowPlacementStore::claimForOpen | ( | const QString & | windowId, |
| const QString & | appId ) |
Reserve, once per opening window instance, the record that instance owns.
WHY THIS EXISTS. The two open channels both select a record for the same opening window: the snap channel through SnapAdaptor::resolveWindowRestore and the tiling channel through TilingAdaptor::dispatchWindowOpened, which reaches take() / takeForReopen(). At login every uuid is fresh, so both always fall to their appId branch, and their orders differ. Without a reservation an already-home window could consume a SIBLING's record, leaving that sibling with nothing to restore from, and a window's later re-drives could answer from a different record than its own open used.
The fix has to be a RESERVATION, never a predicate. "Skip non-same-instance records" looks right and destroys the behaviour: after a logout NO record is same-instance, so such a predicate refuses the whole bucket. Instead the first daemon-side touch of an opening window claims one record, and every later reader honours that claim.
Non-consuming and idempotent: repeat calls for the same instance return the same record for the life of the claim. Selection is the same-instance record when one carries restorable content (the daemon-restart shape, uuid intact — never the slot-less geometry stub every open writes), else the NEWEST unclaimed record in the appId bucket that is not bound to a still-live sibling. Newest matches peek() and takeForReopen(); take()'s oldest-first is a starvation order, not a claim about ownership, and with N windows the SET consumed is the same either way.
Returns the claimed record, or nullopt when nothing is claimable.
| std::optional< WindowPlacement > PhosphorEngine::WindowPlacementStore::claimForOpen | ( | const QString & | windowId, |
| const QString & | appId, | ||
| const QString & | openingScreenId, | ||
| const std::function< bool(const WindowPlacement &)> & | restorableHere ) |
The reopen-contract claim: claimForOpen restricted to what the opening screen can restore.
The window's OWN record (same instance) is final: when an engine has ever captured it, it is claimed if it carries restorable content and nothing is claimed otherwise, never a sibling's. Without one, the newest record that passes claimForOpen's sibling rules AND sits on the opening KWin output (or has no screen) AND satisfies restorableHere (the opening engine's "can I restore this here", unset meaning any) is claimed. An empty openingScreenId applies no output filter. Same idempotence as claimForOpen.
| bool PhosphorEngine::WindowPlacementStore::clear | ( | const QString & | windowId | ) |
Drop any record for the same live instance (and prune the empty bucket).
Returns true if a record was actually removed.
| bool PhosphorEngine::WindowPlacementStore::clearFreeGeometry | ( | const QString & | windowId | ) |
Clear ONLY the shared free/float geometry for the same live instance, leaving the engine slots and context intact.
Returns true if anything was cleared. The all-screens form is for wholesale invalidation (virtual-screen remap); the screen-scoped overload is for consume-once paths (drag-out, drop-snap), which must not destroy the float-back remembered for other monitors.
| bool PhosphorEngine::WindowPlacementStore::clearFreeGeometry | ( | const QString & | windowId, |
| const QString & | screenId ) |
| bool PhosphorEngine::WindowPlacementStore::collapsePureFloatSiblings | ( | const QString & | appId, |
| const QString & | keepWindowId ) |
Collapse stale pure-float duplicates for an app, keeping keepWindowId.
A "pure-float" record carries float-back geometry but NO managed (snapped/tiled) engine slot. When keepWindowId names a pure-float record, every OTHER pure-float record in the same appId bucket that remembers a float position on a screen keepWindowId also covers is removed. Records carrying a snapped/tiled slot are never touched (managed placements whose multi-instance distribution must survive). No-op when the kept record is absent or itself managed.
Called ONLY from close-capture paths: a window closing floating is the freshest authority for its app's float-back on that screen, so duplicate siblings (left by rapid open/close or overlapping short-lived instances) are stale. Records bound to a still-OPEN window (per the live-instance probe) are never pruned. PRECONDITION: call this only from a close capture, where keepWindowId is the closing window. Every current call site enforces that by gating on a non-empty authoritative close screen. A pruned sibling's engine slots and other-screen geometry are absorbed fill-gaps-only. Without the collapse, a consuming reopen — take()'s live-excluded oldest-first for snap, or takeForReopen's live-excluded newest-first tail for the tiling engines — can rotate a reopening window between the duplicates: it "opens in a different spot each time."
Returns true if at least one sibling was removed, so the caller can mark its persistence dirty: the preceding record() may have been a content-identical no-op, in which case this prune is the only mutation and would otherwise not reach disk until an incidental save.
| bool PhosphorEngine::WindowPlacementStore::contains | ( | const QString & | windowId, |
| const QString & | appId = QString() ) const |
True if a record exists for the same live instance, or (if appId non-empty) any record in that appId bucket.
| void PhosphorEngine::WindowPlacementStore::deserialize | ( | const QJsonObject & | obj | ) |
| void PhosphorEngine::WindowPlacementStore::deserialize | ( | const QJsonObject & | obj, |
| const OutputOrigin & | originFor ) |
| bool PhosphorEngine::WindowPlacementStore::forgetDesktopZones | ( | const QString & | windowId, |
| const QString & | engineId, | ||
| int | desktop ) |
Drop one desktop's entry from an engine slot's zonesByDesktop map.
The counterpart to that map being MERGED by record(): a capture that stops naming a desktop does not forget it, so a window that genuinely left one has to say so here. Without this the stale zone survives every later save and a restart puts the window back on a desktop it no longer occupies. Returns true when an entry was actually removed.
|
static |
The version stored was written in (1 when unstamped).
A caller that read an older one writes the migrated form back once.
|
inline |
Whether the probe reports windowId's instance as a still-open window.
False without a probe. For callers outside the store that enumerate records and must skip the ones describing a live window (the effect's instant-restore cache, which otherwise teleports a fresh second instance into its open sibling's zone).
| bool PhosphorEngine::WindowPlacementStore::markInstanceClosed | ( | const QString & | windowId, |
| bool | graceEligible = true ) |
The window CLOSED: drop its open claim (releaseOpenClaim).
The rest of the old contract retired with the cross-screen reclaim, so the records are left untouched and the answer is always false. graceEligible is ignored; both stay for ABI.
| void PhosphorEngine::WindowPlacementStore::markInstanceMovedLive | ( | const QString & | windowId | ) |
INERT, kept for ABI.
It excused a live move from the reclaim-credit burn, and the credit is gone.
| std::optional< WindowPlacement > PhosphorEngine::WindowPlacementStore::peek | ( | const QString & | windowId, |
| const QString & | appId, | ||
| const std::function< bool(const WindowPlacement &)> & | accept = {}, | ||
| bool | excludeLiveSiblings = false ) const |
Non-consuming lookup (unlike take): the record for the same live instance, else the NEWEST record in the appId bucket whose accept passes.
Leaves the store unchanged — for live reads such as the float-back geometry lookup, where the record must stay put for the eventual restore/capture.
excludeLiveSiblings makes the appId branch skip records bound to a still-open sibling, exactly as take() does. A caller that peeks to decide whether a later take() will find something (the snap engine's cross-screen ownership gate) must pass true, or the gate and the consume disagree on a live sibling's record. Off by default because float-back geometry reads legitimately consult a live sibling's record.
|
inline |
Same-instance peek: branch 1 of peek() only, never the appId-FIFO fallback.
The instance component remains stable if a live window's appId prefix changes, while still distinguishing same-app siblings. The appId fallback exists for close/reopen paths where the instance changes.
| std::optional< WindowPlacement > PhosphorEngine::WindowPlacementStore::peekForReclaim | ( | const QString & | windowId, |
| const QString & | appId, | ||
| const std::function< bool(const WindowPlacement &)> & | accept = {} ) const |
Non-consuming lookup for the tiling engines' reopen claim (IPlacementEngine::claimCrossScreenReopen), which restores a window on the output it opens on, onto another virtual screen there.
Differs from peek() in three ways:
appId bucket (the window's own record included — a same-instance match wins outright, live or not, since the window's own record IS its history). The narrowing is safe because record() RE-BUCKETS on an appId change, so a record follows the window's current appId. A miss means no claim, never a wrong one. Returns nullopt when appId is empty, since a bare id has no bucket. | std::optional< WindowPlacement > PhosphorEngine::WindowPlacementStore::peekLiveSibling | ( | const QString & | windowId, |
| const QString & | appId, | ||
| const std::function< bool(const WindowPlacement &)> & | accept = {} ) const |
The EARLIEST-RECORDED record in appId's bucket that is bound to a live window OTHER than windowId's instance and passes accept, or nullopt.
Non-consuming. This is the record a fresh same-app window inherits its free SIZE from when nothing places it: KDE apps write their window size to their own config on every resize, a snap is a resize, so a second instance opened beside a snapped sibling comes up at the zone's size (discussion #1106). The sibling's record still carries the free geometry the sibling had before its snap.
Earliest by bucket POSITION, not newest by sequence, and filtered by accept, which carries the real discrimination: the caller skips records with no usable rect for its screen (including a rect of a zone's size, the spawn frame of a sibling the auto-snap chain placed at open) instead of settling for the first live sibling. Position is only the tie-break: first-recorded order mid-session, the persisted bucket order for saved records after a restart, and re-announce order for anything the save missed, so it cannot be trusted on its own. Answers nullopt on an empty windowId or appId, without a live-instance probe, and for the window opened in the daemon-restart gap before the effect has re-announced its siblings: the production probe reads the registry, so until then no sibling reads as live. The last is unknowable from inside the store and is accepted.
| bool PhosphorEngine::WindowPlacementStore::record | ( | WindowPlacement | placement | ) |
Record / MERGE this window's placement.
The incoming record supplies only the calling engine's slot (in engines) and any free-geometry update; if a record for the same live instance already exists (in any appId bucket) the incoming engine slot(s) and free-geometry screen(s) are merged in, leaving the other engine's slot and other screens' free geometry intact. Otherwise the record is appended to its appId's FIFO. No-op on an invalid record. Returns true if the store actually changed — false when the merge produced a content-identical record, so callers can skip marking state dirty and avoid a self-perpetuating save loop. Stamps a fresh monotonic sequence whenever it changes anything (the content-identical short-circuit leaves the existing record, sequence included, untouched).
| QList< WindowPlacement > PhosphorEngine::WindowPlacementStore::records | ( | ) | const |
All records, in no particular order.
For read-only sweeps (e.g. building the effect's instant-restore cache from the snapped records).
| bool PhosphorEngine::WindowPlacementStore::releaseEngineSlot | ( | const QString & | windowId, |
| const QString & | engineId ) |
DOWNGRADE one engine's slot to WindowPlacement::stateReleased() on every record for the same live instance, leaving the other engines' slots, the context and the shared geometry intact.
Returns true if any record changed.
This is the release-path counterpart of record()'s merge-never-clear: slots accumulate as cross-mode memory, and for RESTORE that is right — but a slot on a window an engine has knowingly GIVEN UP (cross-mode handoff, or a window that left the screen it was managed on) is not memory, it is a stale ownership claim. The reopen claim (pendingCrossScreenManagedRestore) reads a managed slot plus the record-level screenId as a restorable home, so a stale slot that outlives its engine's ownership would read as one.
DOWNGRADE, not remove, and the difference is load-bearing on both sides — see stateReleased()'s contract. Removing the slot would also risk emptying the engines map, which record()'s merge reads as "no managed context to adopt", freezing the record's screenId against every later geometry-only write.
Sweeps ALL records matching the instance rather than stopping at the first: appId drift (the Electron/CEF case this codebase canonicalizes for) can leave records for one instance in two buckets, and the one carrying the stale slot is not necessarily the one QHash order reaches first.
Callers go through WindowTrackingService::releaseEngineSlot (which marks the store dirty): a handoffRelease, and a window leaving the screen, desktop or activity an engine held it on. NOT called on ordinary close: a window that CLOSED placed keeps its slot, which login restore reads.
| void PhosphorEngine::WindowPlacementStore::releaseOpenClaim | ( | const QString & | windowId | ) |
Drop windowId's open claim, so a claim never outlives the instance that made it.
The daemon calls it from the observed close, and the alive-set prune drops the claims of windows that died without one through releaseOpenClaimsExcept; the store calls it itself from clear(). Consumption through take() / takeForReopen() releases it too — after the re-bind the record IS the window's own, and the claim is redundant identity.
| int PhosphorEngine::WindowPlacementStore::releaseOpenClaimsExcept | ( | const QSet< QString > & | aliveInstanceIds | ) |
Drop every open claim whose instance is not in aliveInstanceIds (instance ids, as PhosphorIdentity::WindowId::extractInstanceId gives them), so a claimer that died without a close signal stops reserving a record another instance could restore from.
Returns how many went.
| int PhosphorEngine::WindowPlacementStore::remapDesktopZones | ( | const DesktopRemap & | remap | ) |
Move every slot's zonesByDesktop entries and the record-level desktop through remap, for any change of KWin's desktop list: a removed desktop's entry goes and a record on it reads as unknown (0).
Returns the number of records changed (F763).
| int PhosphorEngine::WindowPlacementStore::remapRestoredDesktopZones | ( | const DesktopRemap & | remap, |
| quint64 | restoredUpTo ) |
remapDesktopZones for the start-up renumber that KWin's first desktop list brings when it lands after windows did (F1045): only the records restored from disk that no live window has touched move, which are the ones stamped at or below restoredUpTo (a sequence() read before any window opened) that no downgrade (releaseEngineSlot, clearFreeGeometry) changed this session, no open claim names and no live window owns.
Each keeps its sequence, so a moved record still ranks below every capture made since. Returns the number of records changed.
| int PhosphorEngine::WindowPlacementStore::removeIf | ( | const std::function< bool(const WindowPlacement &)> & | pred | ) |
Remove every record matching pred. Returns the count removed.
| int PhosphorEngine::WindowPlacementStore::renumberDesktopZones | ( | int | removedDesktop | ) |
Drop removedDesktop from every slot's zonesByDesktop map and shift the entries above it down by one, and shift the record-level desktop the same way (a record ON the removed desktop reads as unknown), because Plasma renumbers x11 desktops when one in the middle is deleted.
The persisted fields have to follow the same renumbering the engines apply to their live stores, or a restart seeds a zone under a number that now belongs to another desktop. Returns the number of records changed. The single-removal form of remapDesktopZones.
|
inline |
The stamp of the newest record.
Every later capture, forget or renumber stamps above it.
| QJsonObject PhosphorEngine::WindowPlacementStore::serialize | ( | const std::function< bool(const WindowPlacement &)> & | keep, |
| const OutputOrigin & | originFor ) const |
The on-disk form keeps each float-back RELATIVE to its output, so a spot survives a rearrangement of the monitors between sessions (F814).
The write subtracts originFor's answer and the read adds it back, an unknown output counting as (0,0) both ways. The read first runs the format migrations up to FormatVersion; see migrateV1ToV2 in the serializer.
| QJsonObject PhosphorEngine::WindowPlacementStore::serialize | ( | const std::function< bool(const WindowPlacement &)> & | keep = {} | ) | const |
JSON shape: { "_version": FormatVersion, appId: [ record, ... ] }.
keep filters out entries that should not persist (e.g. disabled-context). Empty buckets are dropped. Each record persists as WindowPlacement::toJson writes it, with every free-geometry rect relative to its output (below). These two measure every output from (0,0), so the rects round-trip unchanged.
|
inline |
Inject the live-window probe behind every live-sibling exclusion in the store (take, takeForReopen, claimForOpen, peekForReclaim, peekLiveSibling, peek's opt-in, the eviction and collapse tiers).
Answers per full windowId; evaluated at lookup time. Unwired (tests) means no exclusion.
| int PhosphorEngine::WindowPlacementStore::size | ( | ) | const |
| std::optional< WindowPlacement > PhosphorEngine::WindowPlacementStore::take | ( | const QString & | windowId, |
| const QString & | appId, | ||
| const std::function< bool(const WindowPlacement &)> & | accept = {}, | ||
| const std::function< bool(const WindowPlacement &)> & | preferred = {} ) |
Restore lookup: the first record whose accept predicate passes, trying the same-instance match before the appId FIFO (oldest first).
The matched record is REMOVED (consumed) and returned. accept lets the caller reject cross-screen / disabled-context / wrong-kind candidates.
preferred (optional) ranks the appId-FIFO branch ONLY: when supplied, the oldest entry satisfying BOTH accept and preferred is consumed first, and only if none qualifies does the oldest merely-accepted entry win. The same-instance match is unaffected — a window's own record is always used in whatever state it holds. Lets a caller restore the most meaningful record (e.g. a snapped placement) ahead of a contentless free/floating sibling that is merely older in the FIFO.
The appId branch never consumes a record bound to a still-LIVE sibling (per the live-instance probe), the same exclusion takeForReopen and claimForOpen apply. Such a record describes a different, open window, never this one's history: a second Dolphin opened beside a snapped first one used to take the first's record, snap-restore into the same zone and re-bind the record under its own id, stripping the live sibling of its float-back. Unwired (tests) means no exclusion.
| std::optional< WindowPlacement > PhosphorEngine::WindowPlacementStore::takeForReopen | ( | const QString & | engineId, |
| const QString & | windowId, | ||
| const QString & | appId, | ||
| const QString & | screenId ) |
Reopen resolve: the shared consumption pattern the TILING engines' open-time restores use (SnapEngine::resolveWindowRestore keeps its own take + re-bind with take()'s oldest-first ORDER and its preferred ranking pass, and since #1106 shares the live-instance exclusion below) — take() wrapped in the accept predicate both tiling engines share and the two rules that make a close/reopen (fresh uuid, appId-FIFO match) behave correctly.
The accept predicate, hoisted here so the two engines cannot drift: a record whose engineId slot is FLOATING restores when its screen matches screenId (or is empty), and FIFO consumption by a DIFFERENT instance additionally requires a valid anyFreeGeometry (a geometry-less floating record is meaningful only same-instance — consumed by a sibling it floats a fresh window at its spawn rect for no reason while burning a FIFO slot). FLOATING slots only, deliberately: a TILED record is never consumed and restores no position — its role is the exact-final verdict below (the window closed tiled, so the reopen must not float it).
windowId and re-recorded, so the other engines' slots + per-screen free/float geometry survive the reopen.The appId fallback consumes the NEWEST accepted record — matching peek()'s "the most recent placement is current truth" — and never one whose window instance is still LIVE (per the live-instance probe): the last close is the state the user expects back, and consuming oldest first handed a reopen whichever stale record had sat unconsumed longest (the octopi graveyard: eleven leftover tiled records shadowing the fresh floating one, and colliding months-old column ranks on a compositor-restart restore). The live exclusion is what makes newest-first safe for multi-instance apps: a record just re-bound to an OPEN sibling is the newest in the bucket, and without the probe the next reopen would steal it, leaving the sibling recordless.
Returns the consumed record (already re-recorded), or nullopt when no record passed. It has no other side effect.
| int PhosphorEngine::WindowPlacementStore::transform | ( | const std::function< bool(WindowPlacement &)> & | fn | ) |
Apply an in-place mutation to every record; fn returns true when it changed the record.
Returns the number changed. For bulk rewrites that keep the appId bucketing (e.g. virtual-screen id remap of freeGeometryByScreen keys). Does NOT move records between buckets — only mutate fields other than appId.
|
staticconstexpr |
The serialized format's version, stamped as "_version".
1 (no stamp): absolute float-back rects. 2: rects relative to their output.
|
staticconstexpr |
Per-app record cap (public so tests can pin the eviction contract).
|
staticconstexpr |
INERT, kept for source compatibility: the shutdown-close grace serialize() once applied to the reclaim credit, which is gone.