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"
9
10#include <functional>
11
12#include <QHash>
13#include <QString>
14
15namespace PhosphorEngine {
16
17class DesktopRemap;
18
27{
30 bool changed = false;
33 bool armSwitch = false;
34};
35
48class PHOSPHORENGINE_EXPORT ScreenContextTracker
49{
50public:
52
71 PlacementStateKey currentKeyForScreen(const QString& screenId) const;
72
73 // ── Getters ──────────────────────────────────────────────────────────────
74 int currentDesktop() const noexcept
75 {
76 return m_currentDesktop;
77 }
78 const QString& currentActivity() const noexcept
79 {
80 return m_currentActivity;
81 }
82 bool desktopContextEverSet() const noexcept
83 {
84 return m_desktopContextEverSet;
85 }
86 bool activityContextEverSet() const noexcept
87 {
88 return m_activityContextEverSet;
89 }
90
103 int screenDesktop(const QString& screenId) const
104 {
105 if (const auto perOut = m_screenCurrentDesktop.constFind(screenId);
106 perOut != m_screenCurrentDesktop.constEnd()) {
107 return perOut.value();
108 }
109 // The per-output push is keyed by the PHYSICAL output the effect
110 // reports; a subdivided output's `/vs:N` children are asked about by
111 // their own id and never pushed. Resolve a virtual id against its
112 // parent before falling back to the global desktop, as the desktop
113 // manager does, or every key minted for a virtual screen sits on the
114 // startup desktop while the zone commits (which read the manager)
115 // land on the live one.
117 if (const auto parent =
118 m_screenCurrentDesktop.constFind(PhosphorIdentity::VirtualScreenId::extractPhysicalId(screenId));
119 parent != m_screenCurrentDesktop.constEnd()) {
120 return parent.value();
121 }
122 }
123 return m_currentDesktop;
124 }
125
126 // ── Context mutators ─────────────────────────────────────────────────────
128 ContextChange setCurrentDesktopForScreen(const QString& screenId, int desktop);
140 void clearCurrentDesktopForScreen(const QString& screenId)
141 {
142 m_screenCurrentDesktop.remove(screenId);
143 }
144 ContextChange setCurrentActivity(const QString& activity);
145
146 // ── Sticky-pin override (m_screenDesktopOverride) ────────────────────────
147 bool hasStickyPin(const QString& screenId) const
148 {
149 return m_screenDesktopOverride.contains(screenId);
150 }
151
158 void setStickyPin(const QString& screenId, int desktop)
159 {
160 if (desktop < 1) {
161 return;
162 }
163 m_screenDesktopOverride.insert(screenId, desktop);
164 }
165
169 int stickyPinnedDesktop(const QString& screenId) const
170 {
171 return m_screenDesktopOverride.value(screenId, 0);
172 }
173
175 int takeStickyPin(const QString& screenId)
176 {
177 return m_screenDesktopOverride.take(screenId);
178 }
179
180 // ── Bulk per-screen cleanup ──────────────────────────────────────────────
192 void removeScreen(const QString& screenId)
193 {
194 m_screenDesktopOverride.remove(screenId);
195 m_screenCurrentDesktop.remove(screenId);
196 }
197
232 void releaseScreenOwnership(const QString& screenId)
233 {
234 m_screenDesktopOverride.remove(screenId);
235 }
236
238 void removeScreensIf(const std::function<bool(const QString&)>& pred);
241 void pruneDesktop(int removedDesktop);
242
252 void renumberDesktopsAfterRemoval(int removedDesktop);
253
260 void remapDesktops(const DesktopRemap& remap);
263 int highestDesktop() const;
264
265private:
271 int m_currentDesktop = 1;
272 QString m_currentActivity;
273 bool m_desktopContextEverSet = false;
274 bool m_activityContextEverSet = false;
275
281 QHash<QString, int> m_screenDesktopOverride;
282
288 QHash<QString, int> m_screenCurrentDesktop;
289};
290
291} // 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
int stickyPinnedDesktop(const QString &screenId) const
The sticky-pin desktop for a screen, or 0 when it is not pinned.
Definition ScreenContextTracker.h:169
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:86
ContextChange setCurrentActivity(const QString &activity)
int highestDesktop() const
The highest desktop number any of the stored values names (the global desktop included),...
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:140
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:232
bool desktopContextEverSet() const noexcept
Definition ScreenContextTracker.h:82
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:158
const QString & currentActivity() const noexcept
Definition ScreenContextTracker.h:78
void removeScreen(const QString &screenId)
Drop both per-screen maps' entries for a screen leaving the engine's set.
Definition ScreenContextTracker.h:192
bool hasStickyPin(const QString &screenId) const
Definition ScreenContextTracker.h:147
int takeStickyPin(const QString &screenId)
Remove and return the sticky-pin desktop for a screen (default-constructed int == 0 when absent,...
Definition ScreenContextTracker.h:175
void renumberDesktopsAfterRemoval(int removedDesktop)
Shift every stored desktop number ABOVE removedDesktop down by one, the global desktop included,...
void remapDesktops(const DesktopRemap &remap)
Move every stored desktop number through remap, for any change of KWin's desktop list (F763,...
int currentDesktop() const noexcept
Definition ScreenContextTracker.h:74
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:103
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 DesktopRemap.h:12
QString extractPhysicalId(const QString &screenId)
Extract the physical screen ID from a virtual screen ID.
Definition VirtualScreenId.h:39
bool isVirtual(const QString &screenId)
Check if a screen ID is a virtual screen ID (contains "/vs:").
Definition VirtualScreenId.h:31
Outcome of a context mutation on ScreenContextTracker.
Definition ScreenContextTracker.h:27
bool changed
The tracked current value actually changed (a real switch, not a same-value re-push that only establi...
Definition ScreenContextTracker.h:30
bool armSwitch
Value the engine should OR into its own context-switch flag: true only when a context had already bee...
Definition ScreenContextTracker.h:33
Identity of a per-screen placement state: a window's placement is scoped to the (screen,...
Definition EngineTypes.h:25