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
12namespace PhosphorProtocol {
13
22enum class WindowType : int {
23 Unknown = 0,
24 Normal = 1,
25 Dialog = 2,
26 Utility = 3,
27 Toolbar = 4,
28 Splash = 5,
29 Menu = 6,
30 Tooltip = 7,
31 Notification = 8,
32 Dock = 9,
33 Desktop = 10,
34 OnScreenDisplay = 11,
35 Popup = 12,
36};
37
40inline constexpr int windowTypeMinValue = static_cast<int>(WindowType::Unknown);
41inline constexpr int windowTypeMaxValue = static_cast<int>(WindowType::Popup);
42
44inline bool isValidWindowType(int value)
45{
46 return value >= windowTypeMinValue && value <= windowTypeMaxValue;
47}
48
52{
53 return isValidWindowType(value) ? static_cast<WindowType>(value) : WindowType::Unknown;
54}
55
57inline QString windowTypeToString(WindowType type)
58{
59 switch (type) {
61 return QStringLiteral("unknown");
63 return QStringLiteral("normal");
65 return QStringLiteral("dialog");
67 return QStringLiteral("utility");
69 return QStringLiteral("toolbar");
71 return QStringLiteral("splash");
73 return QStringLiteral("menu");
75 return QStringLiteral("tooltip");
77 return QStringLiteral("notification");
79 return QStringLiteral("dock");
81 return QStringLiteral("desktop");
83 return QStringLiteral("onscreendisplay");
85 return QStringLiteral("popup");
86 }
87 return QStringLiteral("unknown");
88}
89
92inline std::optional<WindowType> windowTypeFromString(QStringView s)
93{
94 static constexpr std::pair<QLatin1StringView, WindowType> kTable[] = {
95 {QLatin1StringView("unknown"), WindowType::Unknown},
96 {QLatin1StringView("normal"), WindowType::Normal},
97 {QLatin1StringView("dialog"), WindowType::Dialog},
98 {QLatin1StringView("utility"), WindowType::Utility},
99 {QLatin1StringView("toolbar"), WindowType::Toolbar},
100 {QLatin1StringView("splash"), WindowType::Splash},
101 {QLatin1StringView("menu"), WindowType::Menu},
102 {QLatin1StringView("tooltip"), WindowType::Tooltip},
103 {QLatin1StringView("notification"), WindowType::Notification},
104 {QLatin1StringView("dock"), WindowType::Dock},
105 {QLatin1StringView("desktop"), WindowType::Desktop},
106 {QLatin1StringView("onscreendisplay"), WindowType::OnScreenDisplay},
107 {QLatin1StringView("popup"), WindowType::Popup},
108 };
109 for (const auto& [token, type] : kTable) {
110 if (s.compare(token, Qt::CaseInsensitive) == 0) {
111 return type;
112 }
113 }
114 return std::nullopt;
115}
116
117} // namespace PhosphorProtocol
D-Bus marshalling for the autotile value types (see AutotileTypes.h).
Definition AutotileMarshalling.h:16
WindowType windowTypeFromInt(int value)
Cast an int that crossed D-Bus to a WindowType; out-of-range values (version skew,...
Definition WindowTypeEnum.h:51
WindowType
Window-type vocabulary shared by the compositor effect, the daemon's WindowRegistry,...
Definition WindowTypeEnum.h:22
@ Popup
generic override-redirect popup
@ Unknown
type could not be determined
@ Normal
ordinary application toplevel
@ Menu
menu / popup menu / dropdown menu
bool isValidWindowType(int value)
True if value is a valid WindowType underlying value.
Definition WindowTypeEnum.h:44
QString windowTypeToString(WindowType type)
Canonical lowercase wire string for a WindowType.
Definition WindowTypeEnum.h:57
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:92
constexpr int windowTypeMaxValue
Definition WindowTypeEnum.h:41
constexpr int windowTypeMinValue
Inclusive bounds of the valid WindowType underlying values — used to range-check an int that crossed ...
Definition WindowTypeEnum.h:40