Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ScreenContextTracker.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
6#include <phosphorengine_export.h>
8
9#include <functional>
10
11#include <QHash>
12#include <QString>
13
14namespace PhosphorEngine {
15
24{
27 bool changed = false;
30 bool armSwitch = false;
31};
32
45class PHOSPHORENGINE_EXPORT ScreenContextTracker
46{
47public:
49
68 PlacementStateKey currentKeyForScreen(const QString& screenId) const;
69
70 // ── Getters ──────────────────────────────────────────────────────────────
71 int currentDesktop() const noexcept
72 {
73 return m_currentDesktop;
74 }
75 const QString& currentActivity() const noexcept
76 {
77 return m_currentActivity;
78 }
79 bool desktopContextEverSet() const noexcept
80 {
81 return m_desktopContextEverSet;
82 }
83 bool activityContextEverSet() const noexcept
84 {
85 return m_activityContextEverSet;
86 }
100 int screenDesktop(const QString& screenId) const
101 {
102 return m_screenCurrentDesktop.value(screenId, m_currentDesktop);
103 }
104
105 // ── Context mutators ─────────────────────────────────────────────────────
107 ContextChange setCurrentDesktopForScreen(const QString& screenId, int desktop);
119 void clearCurrentDesktopForScreen(const QString& screenId)
120 {
121 m_screenCurrentDesktop.remove(screenId);
122 }
123 ContextChange setCurrentActivity(const QString& activity);
124
125 // ── Sticky-pin override (m_screenDesktopOverride) ────────────────────────
126 bool hasStickyPin(const QString& screenId) const
127 {
128 return m_screenDesktopOverride.contains(screenId);
129 }
137 void setStickyPin(const QString& screenId, int desktop)
138 {
139 if (desktop < 1) {
140 return;
141 }
142 m_screenDesktopOverride.insert(screenId, desktop);
143 }
148 int stickyPinnedDesktop(const QString& screenId) const
149 {
150 return m_screenDesktopOverride.value(screenId, 0);
151 }
154 int takeStickyPin(const QString& screenId)
155 {
156 return m_screenDesktopOverride.take(screenId);
157 }
158
159 // ── Bulk per-screen cleanup ──────────────────────────────────────────────
171 void removeScreen(const QString& screenId)
172 {
173 m_screenDesktopOverride.remove(screenId);
174 m_screenCurrentDesktop.remove(screenId);
175 }
211 void releaseScreenOwnership(const QString& screenId)
212 {
213 m_screenDesktopOverride.remove(screenId);
214 }
217 void removeScreensIf(const std::function<bool(const QString&)>& pred);
220 void pruneDesktop(int removedDesktop);
221
222private:
228 int m_currentDesktop = 1;
229 QString m_currentActivity;
230 bool m_desktopContextEverSet = false;
231 bool m_activityContextEverSet = false;
232
238 QHash<QString, int> m_screenDesktopOverride;
239
245 QHash<QString, int> m_screenCurrentDesktop;
246};
247
248} // namespace PhosphorEngine
Tracks the "current context" of each screen for a placement engine: the global current virtual deskto...
Definition ScreenContextTracker.h:46
int stickyPinnedDesktop(const QString &screenId) const
The sticky-pin desktop for a screen, or 0 when it is not pinned.
Definition ScreenContextTracker.h:148
void pruneDesktop(int removedDesktop)
Drop entries from both per-screen maps whose DESKTOP value equals removedDesktop (a virtual desktop w...
bool activityContextEverSet() const noexcept
Definition ScreenContextTracker.h:83
ContextChange setCurrentActivity(const QString &activity)
void removeScreensIf(const std::function< bool(const QString &)> &pred)
Drop entries from both per-screen maps whose SCREEN key matches pred (e.g.
void clearCurrentDesktopForScreen(const QString &screenId)
Drop a screen's per-output desktop entry, falling it back to the global.
Definition ScreenContextTracker.h:119
void releaseScreenOwnership(const QString &screenId)
Drop only the ENGINE-OWNED half for a screen leaving this engine's mode set, keeping the per-output d...
Definition ScreenContextTracker.h:211
bool desktopContextEverSet() const noexcept
Definition ScreenContextTracker.h:79
void setStickyPin(const QString &screenId, int desktop)
Pin a screen to a desktop, outranking both the per-output and the global value in currentKeyForScreen...
Definition ScreenContextTracker.h:137
const QString & currentActivity() const noexcept
Definition ScreenContextTracker.h:75
void removeScreen(const QString &screenId)
Drop both per-screen maps' entries for a screen leaving the engine's set.
Definition ScreenContextTracker.h:171
bool hasStickyPin(const QString &screenId) const
Definition ScreenContextTracker.h:126
int takeStickyPin(const QString &screenId)
Remove and return the sticky-pin desktop for a screen (default-constructed int == 0 when absent,...
Definition ScreenContextTracker.h:154
int currentDesktop() const noexcept
Definition ScreenContextTracker.h:71
int screenDesktop(const QString &screenId) const
The screen's PER-OUTPUT desktop: its own entry if set, else the global current desktop.
Definition ScreenContextTracker.h:100
ContextChange setCurrentDesktopForScreen(const QString &screenId, int desktop)
ContextChange setCurrentDesktop(int desktop)
PlacementStateKey currentKeyForScreen(const QString &screenId) const
Construct the owning key for a screen in the current context.
Definition EngineTypes.h:14
Outcome of a context mutation on ScreenContextTracker.
Definition ScreenContextTracker.h:24
bool changed
The tracked current value actually changed (a real switch, not a same-value re-push that only establi...
Definition ScreenContextTracker.h:27
bool armSwitch
Value the engine should OR into its own context-switch flag: true only when a context had already bee...
Definition ScreenContextTracker.h:30
Identity of a per-screen placement state: a window's placement is scoped to the (screen,...
Definition EngineTypes.h:22