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
24namespace LayoutId {
25
26inline constexpr QLatin1String AutotilePrefix{"autotile:"};
27
28inline bool isAutotile(const QString& id)
29{
30 return id.startsWith(AutotilePrefix);
31}
32
38inline QString extractAlgorithmId(const QString& id)
39{
40 if (!isAutotile(id)) {
41 qWarning("PhosphorLayout::LayoutId::extractAlgorithmId called with non-autotile id: %s", qUtf8Printable(id));
42 return QString();
43 }
44 if (id.size() <= AutotilePrefix.size()) {
45 return {};
46 }
47 return id.mid(AutotilePrefix.size());
48}
49
50inline QString makeAutotileId(const QString& algorithmId)
51{
52 // Empty algorithmId is a legitimate caller intent: "autotile mode, let
53 // the engine pick the default algorithm". The KCM writes exactly this
54 // shape via LayoutAdaptor::setAssignmentEntry (mode=Autotile,
55 // tilingAlgorithm="") — see AssignmentEntry::activeLayoutId() and
56 // LayoutRegistry::setAssignmentEntryDirect's comment. Returning the
57 // bare prefix round-trips cleanly: isAutotile("autotile:") is true,
58 // extractAlgorithmId("autotile:") returns empty (LayoutId.h above
59 // handles id.size() <= prefix.size()), and the assignment cascade
60 // treats the entry as non-empty so modeForScreen correctly reports
61 // Autotile.
62 return AutotilePrefix + algorithmId;
63}
64
71inline QString normalizeAlgorithmId(const QString& id)
72{
73 if (id.isEmpty()) {
74 return id;
75 }
76 return isAutotile(id) ? id : makeAutotileId(id);
77}
78
79} // namespace LayoutId
80} // namespace PhosphorLayout
QString makeAutotileId(const QString &algorithmId)
Definition LayoutId.h:50
QString normalizeAlgorithmId(const QString &id)
Normalize an algorithm-id-or-prefixed-layout-id into the canonical autotile:<algo> form: pass-through...
Definition LayoutId.h:71
constexpr QLatin1String AutotilePrefix
Definition LayoutId.h:26
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 AlgorithmMetadata.h:10