Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
AssignmentEntry.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 <QHash>
9#include <QString>
10
11namespace PhosphorZones {
12
17{
18 QString screenId; // Stable EDID-based identifier (or connector name fallback)
19 int virtualDesktop = 0; // 0 = all desktops
20 QString activity; // Empty = all activities
21
22 bool operator==(const LayoutAssignmentKey& other) const
23 {
24 return screenId == other.screenId && virtualDesktop == other.virtualDesktop && activity == other.activity;
25 }
26
41 static LayoutAssignmentKey fromGroupName(const QString& groupName, const QString& prefix)
42 {
44 if (!groupName.startsWith(prefix))
45 return result;
46 QString remainder = groupName.mid(prefix.size());
47 if (remainder.isEmpty())
48 return result;
49
50 int actIdx = remainder.indexOf(QLatin1String(":Activity:"));
51 if (actIdx >= 0) {
52 const QString activity = remainder.mid(actIdx + 10);
53 if (!activity.isEmpty())
54 result.activity = activity;
55 remainder = remainder.left(actIdx);
56 }
57 int deskIdx = remainder.indexOf(QLatin1String(":Desktop:"));
58 if (deskIdx >= 0) {
59 bool ok = false;
60 int desktop = remainder.mid(deskIdx + 9).toInt(&ok);
61 if (ok && desktop > 0)
62 result.virtualDesktop = desktop;
63 remainder = remainder.left(deskIdx);
64 }
65 result.screenId = remainder;
66 return result;
67 }
68};
69
70inline size_t qHash(const LayoutAssignmentKey& key, size_t seed = 0)
71{
72 seed = ::qHash(key.screenId, seed);
73 seed = ::qHash(key.virtualDesktop, seed);
74 seed = ::qHash(key.activity, seed);
75 return seed;
76}
77
86{
87 enum Mode {
89 Autotile = 1
90 };
92 QString snappingLayout; // UUID string of manual layout
93 QString tilingAlgorithm; // e.g. "dwindle", "wide", "tall"
94
95 QString activeLayoutId() const
96 {
97 if (mode == Autotile) {
98 // Autotile mode always produces a non-empty id so the cascade
99 // visitors in LayoutRegistry accept it (they reject on
100 // activeLayoutId().isEmpty()). For a mode-only entry (empty
101 // tilingAlgorithm — what the KCM writes for "autotile, use
102 // default algorithm"), makeAutotileId returns the bare
103 // prefix @c "autotile:"; downstream callers use
104 // @ref PhosphorLayout::LayoutId::isAutotile to detect mode
105 // and @ref PhosphorLayout::LayoutId::extractAlgorithmId to
106 // get the algorithm (empty = engine default).
108 }
109 return snappingLayout;
110 }
111 bool isValid() const
112 {
113 return !snappingLayout.isEmpty() || !tilingAlgorithm.isEmpty();
114 }
115 bool operator==(const AssignmentEntry& other) const
116 {
117 return mode == other.mode && snappingLayout == other.snappingLayout && tilingAlgorithm == other.tilingAlgorithm;
118 }
119
125 static AssignmentEntry fromLayoutId(const QString& layoutId, const AssignmentEntry& existing)
126 {
127 AssignmentEntry entry = existing;
129 entry.mode = Autotile;
131 } else {
132 entry.mode = Snapping;
133 entry.snappingLayout = layoutId;
134 }
135 return entry;
136 }
138 static AssignmentEntry fromLayoutId(const QString& layoutId)
139 {
140 AssignmentEntry entry;
142 entry.mode = Autotile;
144 } else {
145 entry.mode = Snapping;
146 entry.snappingLayout = layoutId;
147 }
148 return entry;
149 }
150};
151
152} // namespace PhosphorZones
QString makeAutotileId(const QString &algorithmId)
Definition LayoutId.h:50
bool isAutotile(const QString &id)
Definition LayoutId.h:28
QString extractAlgorithmId(const QString &id)
Extract the algorithm id portion from an autotile preview id.
Definition LayoutId.h:38
Definition IWindowTrackingService.h:22
size_t qHash(const LayoutAssignmentKey &key, size_t seed=0)
Definition AssignmentEntry.h:70
Explicit per-context assignment entry storing both mode fields.
Definition AssignmentEntry.h:86
QString snappingLayout
Definition AssignmentEntry.h:92
static AssignmentEntry fromLayoutId(const QString &layoutId)
Create a fresh AssignmentEntry from a layoutId string.
Definition AssignmentEntry.h:138
static AssignmentEntry fromLayoutId(const QString &layoutId, const AssignmentEntry &existing)
Update an existing AssignmentEntry from a layoutId, preserving the "other" field.
Definition AssignmentEntry.h:125
QString activeLayoutId() const
Definition AssignmentEntry.h:95
Mode
Definition AssignmentEntry.h:87
@ Snapping
Definition AssignmentEntry.h:88
@ Autotile
Definition AssignmentEntry.h:89
bool operator==(const AssignmentEntry &other) const
Definition AssignmentEntry.h:115
bool isValid() const
Definition AssignmentEntry.h:111
QString tilingAlgorithm
Definition AssignmentEntry.h:93
Mode mode
Definition AssignmentEntry.h:91
Key for layout assignment (screen + desktop + activity)
Definition AssignmentEntry.h:17
static LayoutAssignmentKey fromGroupName(const QString &groupName, const QString &prefix)
Parse a "<prefix><screenId>[:Desktop:N][:Activity:uuid]" group name.
Definition AssignmentEntry.h:41
bool operator==(const LayoutAssignmentKey &other) const
Definition AssignmentEntry.h:22
QString screenId
Definition AssignmentEntry.h:18
int virtualDesktop
Definition AssignmentEntry.h:19
QString activity
Definition AssignmentEntry.h:20