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
20{
21 QString appId;
22 QString desktopFile;
23 QString title;
24 QString windowRole{};
25 int pid = 0;
27 QString activity{};
29
30 // ── Extended window properties. The kwin-effect snapshots these at metadata-push
31 // time so the daemon's window-rule resolvers (shouldFloatByRule /
32 // shouldRestoreFloatedPosition) can match the same KWin-property / geometry
33 // fields the effect path resolves live. std::optional so an absent value (the
34 // compositor could not report it — e.g. no underlying KWin::Window) leaves the
35 // corresponding WindowQuery field disengaged, keeping a predicate over it inert,
36 // mirroring window_query.cpp's engage-only-when-known contract. ──
37 std::optional<bool> isMinimized;
38 std::optional<bool> isFullscreen;
39 std::optional<bool> isSticky;
40 std::optional<bool> isMaximized;
41 std::optional<bool> isFocused;
46 std::optional<bool> isTransient;
47 std::optional<bool> isNotification;
48 std::optional<bool> keepAbove;
49 std::optional<bool> keepBelow;
50 std::optional<bool> skipTaskbar;
51 std::optional<bool> skipPager;
52 std::optional<bool> skipSwitcher;
53 std::optional<bool> isModal;
54 std::optional<bool> hasDecoration;
55 std::optional<bool> isResizable;
56 std::optional<int> width;
57 std::optional<int> height;
58 std::optional<int> positionX;
59 std::optional<int> positionY;
60 std::optional<QString> captionNormal;
61
62 bool operator==(const WindowMetadata& other) const
63 {
64 return appId == other.appId && desktopFile == other.desktopFile && title == other.title
65 && windowRole == other.windowRole && pid == other.pid && virtualDesktop == other.virtualDesktop
66 && activity == other.activity && windowType == other.windowType && isMinimized == other.isMinimized
67 && isFullscreen == other.isFullscreen && isSticky == other.isSticky && isMaximized == other.isMaximized
68 && isFocused == other.isFocused && isTransient == other.isTransient
69 && isNotification == other.isNotification && keepAbove == other.keepAbove && keepBelow == other.keepBelow
70 && skipTaskbar == other.skipTaskbar && skipPager == other.skipPager && skipSwitcher == other.skipSwitcher
71 && isModal == other.isModal && hasDecoration == other.hasDecoration && isResizable == other.isResizable
72 && width == other.width && height == other.height && positionX == other.positionX
73 && positionY == other.positionY && captionNormal == other.captionNormal;
74 }
75 bool operator!=(const WindowMetadata& other) const
76 {
77 return !(*this == other);
78 }
79};
80
81class PHOSPHORENGINE_EXPORT WindowRegistry : public QObject, public IWindowRegistry
82{
83 Q_OBJECT
84
85public:
86 explicit WindowRegistry(QObject* parent = nullptr);
87 ~WindowRegistry() override;
88
89 void upsert(const QString& instanceId, const WindowMetadata& metadata);
90 void remove(const QString& instanceId);
91
92 std::optional<WindowMetadata> metadata(const QString& instanceId) const;
93 Q_INVOKABLE QString appIdFor(const QString& instanceId) const override;
94 QStringList instancesWithAppId(const QString& appId) const;
95 bool contains(const QString& instanceId) const;
96 QStringList allInstances() const;
97 int size() const;
98 void clear();
99
100 Q_INVOKABLE QString canonicalizeWindowId(const QString& rawWindowId) override;
101 Q_INVOKABLE QString canonicalizeForLookup(const QString& rawWindowId) const override;
102 void releaseCanonical(const QString& anyWindowId);
103
113 int pruneStaleInstances(const QSet<QString>& aliveInstanceIds);
114
115Q_SIGNALS:
116 void windowAppeared(const QString& instanceId);
117 void metadataChanged(const QString& instanceId, const WindowMetadata& oldMetadata,
118 const WindowMetadata& newMetadata);
119 void windowDisappeared(const QString& instanceId);
120
121private:
122 QHash<QString, WindowMetadata> m_records;
123 QMultiHash<QString, QString> m_appIdIndex;
124 QHash<QString, QString> m_canonicalByInstance;
125
126 void indexInsert(const QString& instanceId, const QString& appId);
127 void indexRemove(const QString& instanceId, const QString& appId);
128};
129
130} // namespace PhosphorEngine
Definition IWindowRegistry.h:12
Definition WindowRegistry.h:82
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...
WindowRegistry(QObject *parent=nullptr)
void metadataChanged(const QString &instanceId, const WindowMetadata &oldMetadata, const WindowMetadata &newMetadata)
QString appIdFor(const QString &instanceId) const override
std::optional< WindowMetadata > metadata(const QString &instanceId) const
QStringList instancesWithAppId(const QString &appId) const
void remove(const QString &instanceId)
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)
void releaseCanonical(const QString &anyWindowId)
QStringList allInstances() const
QString canonicalizeWindowId(const QString &rawWindowId) override
Definition EngineTypes.h:13
WindowType
Window-type vocabulary shared by the compositor effect, the daemon's WindowRegistry,...
Definition WindowTypeEnum.h:22
@ Unknown
type could not be determined
Definition WindowRegistry.h:20
std::optional< bool > isFocused
focused at metadata-push time (point-in-time, NOT refreshed on focus change) — the open-path Float / ...
Definition WindowRegistry.h:41
bool operator!=(const WindowMetadata &other) const
Definition WindowRegistry.h:75
std::optional< bool > isTransient
dialog/utility/popup/menu/tooltip/splash family or has a transient parent
Definition WindowRegistry.h:46
std::optional< int > positionY
frame top edge Y in px
Definition WindowRegistry.h:59
QString activity
activity UUID; empty = all activities / unknown
Definition WindowRegistry.h:27
std::optional< bool > skipPager
Definition WindowRegistry.h:51
std::optional< bool > isSticky
on all virtual desktops
Definition WindowRegistry.h:39
std::optional< bool > keepBelow
Definition WindowRegistry.h:49
std::optional< bool > isFullscreen
Definition WindowRegistry.h:38
std::optional< bool > isMinimized
Definition WindowRegistry.h:37
std::optional< bool > keepAbove
Definition WindowRegistry.h:48
std::optional< int > width
frame width in px
Definition WindowRegistry.h:56
std::optional< bool > isResizable
Definition WindowRegistry.h:55
std::optional< int > height
frame height in px
Definition WindowRegistry.h:57
int virtualDesktop
1-based x11 desktop number; 0 = all desktops / unknown
Definition WindowRegistry.h:26
QString appId
Definition WindowRegistry.h:21
std::optional< bool > hasDecoration
server-side title-bar / border
Definition WindowRegistry.h:54
QString windowRole
X11 WM_WINDOW_ROLE; empty for Wayland-native windows.
Definition WindowRegistry.h:24
std::optional< bool > skipSwitcher
Definition WindowRegistry.h:52
std::optional< int > positionX
frame left edge X in px
Definition WindowRegistry.h:58
QString title
Definition WindowRegistry.h:23
bool operator==(const WindowMetadata &other) const
Definition WindowRegistry.h:62
std::optional< bool > isMaximized
MaximizeFull (both axes)
Definition WindowRegistry.h:40
std::optional< bool > isNotification
notification / critical-notification / on-screen-display
Definition WindowRegistry.h:47
int pid
process id; 0 = unknown
Definition WindowRegistry.h:25
std::optional< bool > isModal
Definition WindowRegistry.h:53
std::optional< QString > captionNormal
title without the WM-added app-name suffix
Definition WindowRegistry.h:60
std::optional< bool > skipTaskbar
Definition WindowRegistry.h:50
PhosphorProtocol::WindowType windowType
Definition WindowRegistry.h:28
QString desktopFile
Definition WindowRegistry.h:22