Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
LayoutId.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 <QLatin1String>
7#include <QString>
8#include <QtGlobal>
9
10namespace PhosphorLayout {
11
30namespace LayoutId {
31
32inline constexpr QLatin1String AutotilePrefix{"autotile:"};
37inline constexpr QLatin1String ScrollingId{"scrolling:"};
38
39inline bool isAutotile(const QString& id)
40{
41 return id.startsWith(AutotilePrefix);
42}
43
44inline bool isScrolling(const QString& id)
45{
46 // Exact compare, not startsWith: unlike AutotilePrefix, this sentinel
47 // carries no payload — "scrolling:foo" is NOT a valid id, and prefix
48 // matching would classify it as Scrolling while silently dropping the
49 // "foo" in every consumer.
50 return id == ScrollingId;
51}
52
64inline QString extractAlgorithmId(const QString& id)
65{
66 if (!isAutotile(id)) {
67 qWarning("PhosphorLayout::LayoutId::extractAlgorithmId called with non-autotile id: %s", qUtf8Printable(id));
68 return QString();
69 }
70 if (id.size() <= AutotilePrefix.size()) {
71 return {};
72 }
73 return id.mid(AutotilePrefix.size());
74}
75
76inline QString makeAutotileId(const QString& algorithmId)
77{
78 // Empty algorithmId is a legitimate caller intent: "autotile mode, let
79 // the engine pick the default algorithm". The KCM writes exactly this
80 // shape via LayoutAdaptor::setAssignmentEntry (mode=Autotile,
81 // tilingAlgorithm="") — see AssignmentEntry::activeLayoutId() and
82 // LayoutRegistry::setAssignmentEntryDirect's comment. Returning the
83 // bare prefix round-trips cleanly: isAutotile("autotile:") is true,
84 // extractAlgorithmId("autotile:") returns empty (LayoutId.h above
85 // handles id.size() <= prefix.size()), and the assignment cascade
86 // treats the entry as non-empty so modeForScreen correctly reports
87 // Autotile.
88 return AutotilePrefix + algorithmId;
89}
90
91// ── The scrolling FAMILY: rules-visible template stamp ──────────────────────
92//
93// Two id namespaces share the "scrolling:" spelling and must not be mixed:
94//
95// - ASSIGNMENT ids are always the bare sentinel. isScrolling stays an exact
96// compare, the cascade round-trips a payload-free id, and nothing on the
97// D-Bus assignment surface ever carries a prefixed form.
98// - The rules-visible WindowQuery::activeLayout value on a Scrolling context
99// is the PREFIXED "scrolling:<templateUuid>" when the context resolves a
100// template layout, and the bare sentinel when it does not — parity with
101// autotile's "autotile:<algorithmId>" stamp, so a rule can target one
102// specific template the way it targets one algorithm. Only the query
103// stamp in LayoutRegistry's context resolvers produces this form.
104//
105// A rule authored `ActiveLayout Equals "scrolling:"` therefore means
106// "scrolling with no template"; "any scrolling screen" is `Mode Equals
107// scrolling`.
108
112inline bool isScrollingFamily(const QString& id)
113{
114 return id.startsWith(ScrollingId);
115}
116
120inline QString makeScrollingId(const QString& templateLayoutId)
121{
122 return ScrollingId + templateLayoutId;
123}
124
129inline QString extractTemplateId(const QString& id)
130{
131 if (!isScrollingFamily(id)) {
132 qWarning("PhosphorLayout::LayoutId::extractTemplateId called with non-scrolling id: %s", qUtf8Printable(id));
133 return QString();
134 }
135 if (id.size() <= ScrollingId.size()) {
136 return {};
137 }
138 return id.mid(ScrollingId.size());
139}
140
141} // namespace LayoutId
142} // namespace PhosphorLayout
constexpr QLatin1String ScrollingId
Scrolling has no layout entity, so its whole id is the bare sentinel — it exists so a mode-only Scrol...
Definition LayoutId.h:37
QString extractTemplateId(const QString &id)
Extract the template layout UUID from a scrolling-family id.
Definition LayoutId.h:129
bool isScrollingFamily(const QString &id)
Prefix test over the whole scrolling family: the bare sentinel AND the prefixed template stamp.
Definition LayoutId.h:112
QString makeAutotileId(const QString &algorithmId)
Definition LayoutId.h:76
bool isScrolling(const QString &id)
Definition LayoutId.h:44
constexpr QLatin1String AutotilePrefix
Definition LayoutId.h:32
QString makeScrollingId(const QString &templateLayoutId)
Build the rules-visible template stamp.
Definition LayoutId.h:120
bool isAutotile(const QString &id)
Definition LayoutId.h:39
QString extractAlgorithmId(const QString &id)
Extract the algorithm id portion from an autotile preview id.
Definition LayoutId.h:64
Definition AlgorithmMetadata.h:10