Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
WindowRegistry.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
8#include "phosphorengine_export.h"
9#include <QHash>
10#include <QMultiHash>
11#include <QObject>
12#include <QSet>
13#include <QString>
14#include <QStringList>
15#include <optional>
16
17namespace PhosphorEngine {
18
19class DesktopRemap;
20
22{
23 QString appId;
24 QString desktopFile;
25 QString title;
26 QString windowRole{};
27 int pid = 0;
34 QList<int> virtualDesktops{};
35 QString activity{};
37
38 // ── Extended window properties. The kwin-effect snapshots these at metadata-push
39 // time so the daemon's window-rule resolvers (shouldFloatByRule /
40 // shouldRestoreFloatedPosition) can match the same KWin-property / geometry
41 // fields the effect path resolves live. std::optional so an absent value (the
42 // compositor could not report it — e.g. no underlying KWin::Window) leaves the
43 // corresponding WindowQuery field disengaged, keeping a predicate over it inert,
44 // mirroring window_query.cpp's engage-only-when-known contract. ──
45 std::optional<bool> isMinimized{};
51 std::optional<bool> isDemandingAttention{};
57 std::optional<bool> isFullscreen{};
58 std::optional<bool> isSticky{};
59 std::optional<bool> isMaximized{};
60 std::optional<bool> isFocused{};
65 std::optional<bool> isTransient{};
66 std::optional<bool> isNotification{};
67 std::optional<bool> keepAbove{};
68 std::optional<bool> keepBelow{};
69 std::optional<bool> skipTaskbar{};
70 std::optional<bool> skipPager{};
71 std::optional<bool> skipSwitcher{};
72 std::optional<bool> isModal{};
73 std::optional<bool> hasDecoration{};
74 std::optional<bool> isResizable{};
75 std::optional<bool> isMovable{};
76 std::optional<bool> isMaximizable{};
77 std::optional<int> width{};
78 std::optional<int> height{};
79 std::optional<int> positionX{};
80 std::optional<int> positionY{};
81 std::optional<QString> captionNormal{};
85 QStringList activities{};
88 std::optional<bool> isAxisMaximized{};
89
90 bool operator==(const WindowMetadata& other) const
91 {
92 return appId == other.appId && desktopFile == other.desktopFile && title == other.title
93 && windowRole == other.windowRole && pid == other.pid && virtualDesktop == other.virtualDesktop
94 && virtualDesktops == other.virtualDesktops && activity == other.activity && windowType == other.windowType
96 && isFullscreen == other.isFullscreen && isSticky == other.isSticky && isMaximized == other.isMaximized
97 && isFocused == other.isFocused && isTransient == other.isTransient
98 && isNotification == other.isNotification && keepAbove == other.keepAbove && keepBelow == other.keepBelow
99 && skipTaskbar == other.skipTaskbar && skipPager == other.skipPager && skipSwitcher == other.skipSwitcher
100 && isModal == other.isModal && hasDecoration == other.hasDecoration && isResizable == other.isResizable
101 && isMovable == other.isMovable && isMaximizable == other.isMaximizable && width == other.width
102 && height == other.height && positionX == other.positionX && positionY == other.positionY
103 && captionNormal == other.captionNormal && activities == other.activities
105 }
106 bool operator!=(const WindowMetadata& other) const
107 {
108 return !(*this == other);
109 }
110};
111
112class PHOSPHORENGINE_EXPORT WindowRegistry : public QObject, public IWindowRegistry
113{
114 Q_OBJECT
115
116public:
117 explicit WindowRegistry(QObject* parent = nullptr);
118 ~WindowRegistry() override;
119
120 void upsert(const QString& instanceId, const WindowMetadata& metadata);
125 void remove(const QString& instanceId);
126
127 std::optional<WindowMetadata> metadata(const QString& instanceId) const;
134 {
136 QList<int> virtualDesktops;
137 QString activity;
138 QStringList activities;
139
149 int effectiveDesktop(int screenCurrentDesktop) const
150 {
151 if (virtualDesktops.size() > 1 && virtualDesktops.contains(screenCurrentDesktop)) {
152 return screenCurrentDesktop;
153 }
154 return virtualDesktop > 0 ? virtualDesktop : screenCurrentDesktop;
155 }
156
161 QString effectiveActivity(const QString& currentActivity) const
162 {
163 if (activities.size() > 1 && activities.contains(currentActivity)) {
164 return currentActivity;
165 }
166 return activity.isEmpty() ? currentActivity : activity;
167 }
168 };
169 std::optional<WindowContext> windowContext(const QString& instanceId) const;
170 Q_INVOKABLE QString appIdFor(const QString& instanceId) const override;
175 bool isMinimized(const QString& windowId) const;
180 std::optional<bool> minimizedState(const QString& windowId) const override;
183 std::optional<bool> fillsOutputState(const QString& windowId) const override;
184 std::optional<WindowDesktopContext> desktopContext(const QString& windowId) const override;
189 QStringList instancesWithAppId(const QString& appId) const;
196 QStringList instanceIds() const;
197 bool contains(const QString& instanceId) const;
198 int size() const;
203 void clear();
204
205 Q_INVOKABLE QString canonicalizeWindowId(const QString& rawWindowId) override;
206 Q_INVOKABLE QString canonicalizeForLookup(const QString& rawWindowId) const override;
207
219 int pruneStaleInstances(const QSet<QString>& aliveInstanceIds);
220
237 int remapDesktops(const DesktopRemap& remap);
244
245Q_SIGNALS:
246 void windowAppeared(const QString& instanceId);
247 void metadataChanged(const QString& instanceId, const WindowMetadata& oldMetadata,
248 const WindowMetadata& newMetadata);
249 void windowDisappeared(const QString& instanceId);
250
251private:
252 QHash<QString, WindowMetadata> m_records;
253 QMultiHash<QString, QString> m_appIdIndex;
254 QHash<QString, QString> m_canonicalByInstance;
258 QSet<QString> m_disappearingInstances;
259 QHash<QString, WindowMetadata> m_pendingUpserts;
268 int m_clearing = 0;
270 QSet<QString> m_desktopRenumberPending;
271
272 void indexInsert(const QString& instanceId, const QString& appId);
273 void indexRemove(const QString& instanceId, const QString& appId);
274};
275
276} // namespace PhosphorEngine
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 IWindowRegistry.h:49
int remapDesktops(const DesktopRemap &remap)
Move the desktop fields of every instance still in the snapshot through remap the way KWin moves the ...
void clear()
Remove every record and canonical mapping, firing windowDisappeared for each.
bool isMinimized(const QString &windowId) const
Live compositor minimize state, collapsed to a bool: unknown reads as false.
std::optional< WindowContext > windowContext(const QString &instanceId) const
void windowDisappeared(const QString &instanceId)
int pruneStaleInstances(const QSet< QString > &aliveInstanceIds)
Defensive cleanup for windows that died WITHOUT a close signal reaching the registry (compositor cras...
QStringList instanceIds() const
Every instance holding a METADATA RECORD, unordered.
void beginDesktopRenumber()
Snapshot the recorded instances as the ones a coming desktop renumber applies to.
WindowRegistry(QObject *parent=nullptr)
void metadataChanged(const QString &instanceId, const WindowMetadata &oldMetadata, const WindowMetadata &newMetadata)
QString appIdFor(const QString &instanceId) const override
The app identity recorded for instanceId, or empty when the instance is unknown.
std::optional< WindowMetadata > metadata(const QString &instanceId) const
std::optional< bool > fillsOutputState(const QString &windowId) const override
IWindowRegistry::fillsOutputState over the reported maximize (either axis) and fullscreen fields.
QStringList instancesWithAppId(const QString &appId) const
Every instance currently recorded under appId, most recently indexed first (QMultiHash::values(key)).
void remove(const QString &instanceId)
Remove metadata and canonical state, emitting windowDisappeared exactly once while the canonical mapp...
std::optional< WindowDesktopContext > desktopContext(const QString &windowId) const override
The desktop set and activity last reported for windowId (bare instance id or composite appId|instance...
void endDesktopRenumber()
End the snapshot without moving anything.
void upsert(const QString &instanceId, const WindowMetadata &metadata)
bool contains(const QString &instanceId) const
QString canonicalizeForLookup(const QString &rawWindowId) const override
void windowAppeared(const QString &instanceId)
std::optional< bool > minimizedState(const QString &windowId) const override
Tri-state minimize state (IWindowRegistry contract): engaged when a record exists AND the compositor ...
QString canonicalizeWindowId(const QString &rawWindowId) override
Freeze (on first contact) and return the canonical id for rawWindowId's instance.
Definition DesktopRemap.h:12
WindowType
Window-type vocabulary shared by the compositor effect, the daemon's WindowRegistry,...
Definition WindowTypeEnum.h:23
@ Unknown
type could not be determined
Definition WindowTypeEnum.h:24
Definition WindowRegistry.h:22
std::optional< bool > isFocused
focused at metadata-push time (point-in-time, NOT refreshed on focus change) — the open-path Float / ...
Definition WindowRegistry.h:60
bool operator!=(const WindowMetadata &other) const
Definition WindowRegistry.h:106
std::optional< bool > isTransient
dialog/utility/popup/menu/tooltip/splash family or has a transient parent
Definition WindowRegistry.h:65
std::optional< int > positionY
frame top edge Y in px
Definition WindowRegistry.h:80
QString activity
activity UUID; empty = all activities / unknown
Definition WindowRegistry.h:35
std::optional< bool > skipPager
Definition WindowRegistry.h:70
std::optional< bool > isSticky
on all virtual desktops
Definition WindowRegistry.h:58
std::optional< bool > keepBelow
Definition WindowRegistry.h:68
QStringList activities
Full activity list when the window is on SEVERAL (but not all) activities; empty otherwise.
Definition WindowRegistry.h:85
std::optional< bool > isDemandingAttention
Urgency (KWin's demandsAttention).
Definition WindowRegistry.h:51
std::optional< bool > isFullscreen
Definition WindowRegistry.h:57
std::optional< bool > isMinimized
Kept current as of the LAST DELIVERED push, unlike isFocused: the effect re-pushes full metadata on e...
Definition WindowRegistry.h:45
std::optional< bool > keepAbove
Definition WindowRegistry.h:67
std::optional< int > width
frame width in px
Definition WindowRegistry.h:77
std::optional< bool > isMaximizable
window can be maximized
Definition WindowRegistry.h:76
std::optional< bool > isAxisMaximized
Maximized on ONE axis (vertical or horizontal).
Definition WindowRegistry.h:88
std::optional< bool > isResizable
Definition WindowRegistry.h:74
std::optional< int > height
frame height in px
Definition WindowRegistry.h:78
int virtualDesktop
1-based x11 desktop number; 0 = all desktops / unknown.
Definition WindowRegistry.h:30
QString appId
Definition WindowRegistry.h:23
std::optional< bool > hasDecoration
server-side title-bar / border
Definition WindowRegistry.h:73
QString windowRole
X11 WM_WINDOW_ROLE; empty for Wayland-native windows.
Definition WindowRegistry.h:26
std::optional< bool > skipSwitcher
Definition WindowRegistry.h:71
std::optional< int > positionX
frame left edge X in px
Definition WindowRegistry.h:79
QList< int > virtualDesktops
Full desktop list when the window spans SEVERAL (but not all) desktops; empty for the common single-d...
Definition WindowRegistry.h:34
QString title
Definition WindowRegistry.h:25
bool operator==(const WindowMetadata &other) const
Definition WindowRegistry.h:90
std::optional< bool > isMaximized
MaximizeFull (both axes).
Definition WindowRegistry.h:59
std::optional< bool > isNotification
notification / critical-notification / on-screen-display
Definition WindowRegistry.h:66
int pid
process id; 0 = unknown
Definition WindowRegistry.h:27
std::optional< bool > isModal
Definition WindowRegistry.h:72
std::optional< QString > captionNormal
title without the WM-added app-name suffix
Definition WindowRegistry.h:81
std::optional< bool > skipTaskbar
Definition WindowRegistry.h:69
std::optional< bool > isMovable
window can be moved
Definition WindowRegistry.h:75
PhosphorProtocol::WindowType windowType
Definition WindowRegistry.h:36
QString desktopFile
Definition WindowRegistry.h:24
The window's own context for per-window mode resolution: its virtual desktop (0 = all/unknown),...
Definition WindowRegistry.h:134
QStringList activities
full list when on several activities (appended last)
Definition WindowRegistry.h:138
QList< int > virtualDesktops
Definition WindowRegistry.h:136
QString effectiveActivity(const QString &currentActivity) const
Effective activity, the activity axis of effectiveDesktop: a window on several activities resolves to...
Definition WindowRegistry.h:161
QString activity
Definition WindowRegistry.h:137
int effectiveDesktop(int screenCurrentDesktop) const
Effective desktop for per-window mode resolution: the window's own desktop when known (virtualDesktop...
Definition WindowRegistry.h:149
int virtualDesktop
Definition WindowRegistry.h:135