Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
FloatingCache.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
8#include <QSet>
9#include <QString>
10
11namespace PhosphorCompositor {
12
25{
26public:
27 bool isFloating(const QString& windowId) const
28 {
29 if (m_floatingWindows.contains(windowId)) {
30 return true;
31 }
32 QString appId = ::PhosphorIdentity::WindowId::extractAppId(windowId);
33 return (appId != windowId && m_floatingWindows.contains(appId));
34 }
35
36 void setFloating(const QString& windowId, bool floating)
37 {
38 if (floating) {
39 m_floatingWindows.insert(windowId);
40 } else {
41 m_floatingWindows.remove(windowId);
42 QString appId = ::PhosphorIdentity::WindowId::extractAppId(windowId);
43 if (appId != windowId) {
44 // Only remove bare appId key if no other full-ID entry shares it.
45 // Without this guard, clearing "firefox|1" would also clear the bare
46 // "firefox" key, making isFloating("firefox|2") return false via the
47 // appId fallback even though "firefox|2" is still floating.
48 bool otherFullIdExists = false;
49 for (const QString& entry : m_floatingWindows) {
50 if (entry != appId && ::PhosphorIdentity::WindowId::extractAppId(entry) == appId) {
51 otherFullIdExists = true;
52 break;
53 }
54 }
55 if (!otherFullIdExists) {
56 m_floatingWindows.remove(appId);
57 }
58 }
59 }
60 }
61
62 void clear()
63 {
64 m_floatingWindows.clear();
65 }
66
67 int size() const
68 {
69 return m_floatingWindows.size();
70 }
71
74 void insert(const QString& windowId)
75 {
76 setFloating(windowId, true);
77 }
78
80 void remove(const QString& windowId)
81 {
82 setFloating(windowId, false);
83 }
84
85private:
86 QSet<QString> m_floatingWindows;
87};
88
89} // namespace PhosphorCompositor
Compositor-agnostic floating window state cache.
Definition FloatingCache.h:25
void remove(const QString &windowId)
Convenience alias for setFloating(windowId, false).
Definition FloatingCache.h:80
void setFloating(const QString &windowId, bool floating)
Definition FloatingCache.h:36
void clear()
Definition FloatingCache.h:62
int size() const
Definition FloatingCache.h:67
void insert(const QString &windowId)
Convenience alias for setFloating(windowId, true).
Definition FloatingCache.h:74
bool isFloating(const QString &windowId) const
Definition FloatingCache.h:27
Definition AutotileState.h:16
QString extractAppId(const QString &windowId)
Extract app identity from window ID (portion before the '|' separator) Format: "appId|internalUuid" →...
Definition WindowId.h:56