Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
WindowPlacementStore.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <phosphorengine_export.h>
8
9#include <QHash>
10#include <QJsonObject>
11#include <QList>
12#include <QString>
13
14#include <functional>
15#include <optional>
16
17namespace PhosphorEngine {
18
33class PHOSPHORENGINE_EXPORT WindowPlacementStore
34{
35public:
37
48 bool record(WindowPlacement placement);
49
62 std::optional<WindowPlacement> take(const QString& windowId, const QString& appId,
63 const std::function<bool(const WindowPlacement&)>& accept = {},
64 const std::function<bool(const WindowPlacement&)>& preferred = {});
65
70 std::optional<WindowPlacement> peek(const QString& windowId, const QString& appId,
71 const std::function<bool(const WindowPlacement&)>& accept = {}) const;
72
75 bool contains(const QString& windowId, const QString& appId = QString()) const;
76
96 bool collapsePureFloatSiblings(const QString& appId, const QString& keepWindowId);
97
100 bool clear(const QString& windowId);
101
105 bool clearFreeGeometry(const QString& windowId);
106
111 int transform(const std::function<bool(WindowPlacement&)>& fn);
112
114 int removeIf(const std::function<bool(const WindowPlacement&)>& pred);
115
118 QList<WindowPlacement> records() const;
119
122 QJsonObject serialize(const std::function<bool(const WindowPlacement&)>& keep = {}) const;
123 void deserialize(const QJsonObject& obj);
124
125 int size() const;
126
127private:
129 QHash<QString, QList<WindowPlacement>> m_byApp;
130 quint64 m_sequence = 0;
131
132 static constexpr int MaxPerApp = 16;
133};
134
135} // namespace PhosphorEngine
The single source of truth for window restore state in the unified model.
Definition WindowPlacementStore.h:34
bool clear(const QString &windowId)
Drop any record for the exact windowId (and prune the empty bucket).
bool collapsePureFloatSiblings(const QString &appId, const QString &keepWindowId)
Collapse stale pure-float duplicates for an app, keeping keepWindowId.
bool contains(const QString &windowId, const QString &appId=QString()) const
True if a record exists for the exact windowId, or (if appId non-empty) any record in that appId buck...
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.
std::optional< WindowPlacement > peek(const QString &windowId, const QString &appId, const std::function< bool(const WindowPlacement &)> &accept={}) const
Non-consuming lookup (unlike take): the record for the exact windowId, else the NEWEST record in the ...
QList< WindowPlacement > records() const
All records, in no particular order.
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 exact-windowId match befor...
bool clearFreeGeometry(const QString &windowId)
Clear ONLY the shared free/float geometry for the exact windowId, leaving the engine slots and contex...
QJsonObject serialize(const std::function< bool(const WindowPlacement &)> &keep={}) const
JSON shape: { appId: [ record, ... ] }.
void deserialize(const QJsonObject &obj)
bool record(WindowPlacement placement)
Record / MERGE this window's placement.
Definition EngineTypes.h:13
One window's single, authoritative placement record — the unit of the unified, engine-agnostic restor...
Definition WindowPlacement.h:66