Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
WindowTypeEnum.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 <QLatin1StringView>
7#include <QString>
8#include <QStringView>
9
10#include <optional>
11#include <utility> // std::pair (kTable)
12
13namespace PhosphorProtocol {
14
23enum class WindowType : int {
24 Unknown = 0,
25 Normal = 1,
26 Dialog = 2,
27 Utility = 3,
28 Toolbar = 4,
29 Splash = 5,
30 Menu = 6,
31 Tooltip = 7,
32 Notification = 8,
33 Dock = 9,
34 Desktop = 10,
35 OnScreenDisplay = 11,
36 Popup = 12,
48 AppletPopup = 13,
49};
50
55inline constexpr int windowTypeMinValue = static_cast<int>(WindowType::Unknown);
56inline constexpr int windowTypeMaxValue = static_cast<int>(WindowType::AppletPopup);
57
59inline constexpr bool isValidWindowType(int value)
60{
61 return value >= windowTypeMinValue && value <= windowTypeMaxValue;
62}
63
66inline constexpr WindowType windowTypeFromInt(int value)
67{
68 return isValidWindowType(value) ? static_cast<WindowType>(value) : WindowType::Unknown;
69}
70
71// Pin the bounds invariants beside the enum they describe: constexpr lets the
72// compiler enforce what the runtime test also checks.
73static_assert(windowTypeMinValue == 0);
76
78inline QString windowTypeToString(WindowType type)
79{
80 switch (type) {
82 return QStringLiteral("unknown");
84 return QStringLiteral("normal");
86 return QStringLiteral("dialog");
88 return QStringLiteral("utility");
90 return QStringLiteral("toolbar");
92 return QStringLiteral("splash");
94 return QStringLiteral("menu");
96 return QStringLiteral("tooltip");
98 return QStringLiteral("notification");
100 return QStringLiteral("dock");
102 return QStringLiteral("desktop");
104 return QStringLiteral("onscreendisplay");
106 return QStringLiteral("popup");
108 return QStringLiteral("appletpopup");
109 }
110 return QStringLiteral("unknown");
111}
112
115inline std::optional<WindowType> windowTypeFromString(QStringView s)
116{
117 static constexpr std::pair<QLatin1StringView, WindowType> kTable[] = {
118 {QLatin1StringView("unknown"), WindowType::Unknown},
119 {QLatin1StringView("normal"), WindowType::Normal},
120 {QLatin1StringView("dialog"), WindowType::Dialog},
121 {QLatin1StringView("utility"), WindowType::Utility},
122 {QLatin1StringView("toolbar"), WindowType::Toolbar},
123 {QLatin1StringView("splash"), WindowType::Splash},
124 {QLatin1StringView("menu"), WindowType::Menu},
125 {QLatin1StringView("tooltip"), WindowType::Tooltip},
126 {QLatin1StringView("notification"), WindowType::Notification},
127 {QLatin1StringView("dock"), WindowType::Dock},
128 {QLatin1StringView("desktop"), WindowType::Desktop},
129 {QLatin1StringView("onscreendisplay"), WindowType::OnScreenDisplay},
130 {QLatin1StringView("popup"), WindowType::Popup},
131 {QLatin1StringView("appletpopup"), WindowType::AppletPopup},
132 };
133 for (const auto& [token, type] : kTable) {
134 if (s.compare(token, Qt::CaseInsensitive) == 0) {
135 return type;
136 }
137 }
138 return std::nullopt;
139}
140
141} // namespace PhosphorProtocol
D-Bus marshalling for the shared tiling-family value types (see AutotileTypes.h; the file names preda...
Definition AutotileMarshalling.h:19
WindowType
Window-type vocabulary shared by the compositor effect, the daemon's WindowRegistry,...
Definition WindowTypeEnum.h:23
@ Popup
generic override-redirect popup
@ Unknown
type could not be determined
@ Normal
ordinary application toplevel
@ Menu
menu / popup menu / dropdown menu
@ AppletPopup
A Plasma applet's popup: Kickoff, the system-tray flyouts, any widget's expanded view.
constexpr WindowType windowTypeFromInt(int value)
Cast an int that crossed D-Bus to a WindowType; out-of-range values (version skew,...
Definition WindowTypeEnum.h:66
QString windowTypeToString(WindowType type)
Canonical lowercase wire string for a WindowType.
Definition WindowTypeEnum.h:78
constexpr bool isValidWindowType(int value)
True if value is a valid WindowType underlying value.
Definition WindowTypeEnum.h:59
std::optional< WindowType > windowTypeFromString(QStringView s)
Strict parse: an unknown token returns nullopt so callers can drop the input rather than silently coe...
Definition WindowTypeEnum.h:115
constexpr int windowTypeMaxValue
Definition WindowTypeEnum.h:56
constexpr int windowTypeMinValue
Inclusive bounds of the valid WindowType underlying values — used to range-check an int that crossed ...
Definition WindowTypeEnum.h:55