6#include <QLatin1StringView>
109inline constexpr QLatin1StringView
Snapping{
"snapping"};
110inline constexpr QLatin1StringView
Tiling{
"tiling"};
111inline constexpr QLatin1StringView
Scrolling{
"scrolling"};
137 {QLatin1StringView(
"1:1"), 1.0}, {QLatin1StringView(
"5:4"), 5.0 / 4.0},
138 {QLatin1StringView(
"4:3"), 4.0 / 3.0}, {QLatin1StringView(
"3:2"), 3.0 / 2.0},
139 {QLatin1StringView(
"16:10"), 16.0 / 10.0}, {QLatin1StringView(
"16:9"), 16.0 / 9.0},
140 {QLatin1StringView(
"21:9"), 21.0 / 9.0}, {QLatin1StringView(
"32:10"), 32.0 / 10.0},
141 {QLatin1StringView(
"32:9"), 32.0 / 9.0}, {QLatin1StringView(
"4:5"), 4.0 / 5.0},
142 {QLatin1StringView(
"3:4"), 3.0 / 4.0}, {QLatin1StringView(
"2:3"), 2.0 / 3.0},
143 {QLatin1StringView(
"10:16"), 10.0 / 16.0}, {QLatin1StringView(
"9:16"), 9.0 / 16.0},
144 {QLatin1StringView(
"9:21"), 9.0 / 21.0}, {QLatin1StringView(
"10:32"), 10.0 / 32.0},
145 {QLatin1StringView(
"9:32"), 9.0 / 32.0},
155 if (width <= 0 || height <= 0) {
158 const double logRatio = std::log(
double(width) /
double(height));
160 double bestDistance = 0.0;
162 const double distance = std::abs(logRatio - std::log(candidate.ratio));
163 if (!best || distance < bestDistance) {
165 bestDistance = distance;
168 return QString(best->
token);
178 if (width <= 0 || height <= 0) {
181 return height > width ? QStringLiteral(
"portrait") : QStringLiteral(
"landscape");
349 "kFieldTable must have one entry per Field");
359 static const QSet<Field> fields = [] {
386 const int idx =
static_cast<int>(field);
390 return QStringLiteral(
"appId");
398 if (s.compare(d.wire, Qt::CaseInsensitive) == 0) {
409 const int idx =
static_cast<int>(field);
416 const int idx =
static_cast<int>(field);
423 const int idx =
static_cast<int>(field);
433 const int idx =
static_cast<int>(field);
461 return QStringLiteral(
"equals");
463 return QStringLiteral(
"contains");
465 return QStringLiteral(
"startsWith");
467 return QStringLiteral(
"endsWith");
469 return QStringLiteral(
"regex");
471 return QStringLiteral(
"appIdMatches");
473 return QStringLiteral(
"greaterThan");
475 return QStringLiteral(
"lessThan");
477 return QStringLiteral(
"equals");
483 static constexpr std::pair<QLatin1StringView, Operator> kTable[] = {
493 for (
const auto& [token, op] : kTable) {
494 if (s.compare(token, Qt::CaseInsensitive) == 0) {
The closed wire vocabulary of Field::Mode — the placement mode a window is in, or that a context reso...
Definition MatchTypes.h:108
constexpr QLatin1StringView Snapping
Definition MatchTypes.h:109
constexpr QLatin1StringView Tiling
autotile OR scrolling-engine tiling
Definition MatchTypes.h:110
constexpr QLatin1StringView Scrolling
Definition MatchTypes.h:111
Definition ActionParams.h:25
constexpr AspectRatioToken kAspectRatioTokens[]
The complete Field::ScreenAspectRatio vocabulary, landscape first and then the portrait forms a rotat...
Definition MatchTypes.h:136
constexpr int FieldCount
The number of distinct Field enumerators.
Definition MatchTypes.h:83
consteval bool verifyFieldTableOrder()
Definition MatchTypes.h:371
bool fieldIsBool(Field field)
True if field carries a boolean value (window-state flags).
Definition MatchTypes.h:421
bool fieldIsContext(Field field)
True if field describes the context a window appears in (screen / virtual desktop / activity / placem...
Definition MatchTypes.h:431
QString operatorToString(Operator op)
Canonical lowercase wire string for an Operator.
Definition MatchTypes.h:457
constexpr QLatin1StringView kModeTokens[]
The complete Field::Mode vocabulary, for callers that validate or enumerate it (a settings picker,...
Definition MatchTypes.h:118
QString aspectRatioTokenFor(int width, int height)
The Field::ScreenAspectRatio token for a width x height screen: the vocabulary entry whose ratio is n...
Definition MatchTypes.h:153
const QSet< Field > & windowSourcedFields()
Every Window-sourced field, derived from the table so a new field can never silently miss it.
Definition MatchTypes.h:357
bool fieldIsString(Field field)
True if field carries a string value (the four string operators and Regex apply to these; numeric/boo...
Definition MatchTypes.h:407
Field
Match fields.
Definition MatchTypes.h:23
@ IsFocused
Definition MatchTypes.h:39
@ WindowType
Definition MatchTypes.h:31
@ IsSticky
Definition MatchTypes.h:32
@ PositionX
Definition MatchTypes.h:52
@ TiledWindowCount
context — tiled windows on this screen + desktop
Definition MatchTypes.h:63
@ PositionY
Definition MatchTypes.h:53
@ AppId
Definition MatchTypes.h:25
@ Width
Definition MatchTypes.h:42
@ VirtualDesktop
context — always present
Definition MatchTypes.h:36
@ IsMovable
window can be moved
Definition MatchTypes.h:65
@ SkipTaskbar
Definition MatchTypes.h:46
@ IsNotification
Definition MatchTypes.h:41
@ KeepAbove
Definition MatchTypes.h:44
@ IsFullscreen
Definition MatchTypes.h:33
@ ScreenWidth
context — the resolving screen's width in device pixels
Definition MatchTypes.h:75
@ HasDecoration
Definition MatchTypes.h:50
@ IsTiled
managed by a tiling-family engine — autotile or scrolling (distinct from IsSnapped)
Definition MatchTypes.h:59
@ WindowClass
Definition MatchTypes.h:26
@ IsMinimized
Definition MatchTypes.h:34
@ IsFloating
floated out of tiling (any placement engine)
Definition MatchTypes.h:56
@ Mode
context — current placement mode (snapping / tiling / scrolling)
Definition MatchTypes.h:61
@ CaptionNormal
Definition MatchTypes.h:54
@ ScreenHeight
context — the resolving screen's height in device pixels
Definition MatchTypes.h:76
@ IsMaximized
Definition MatchTypes.h:38
@ ScreenId
context — always present
Definition MatchTypes.h:35
@ ActiveLayout
context — the layout id currently resolved for the screen (snap UUID, "autotile:<algo>",...
Definition MatchTypes.h:70
@ KeepBelow
Definition MatchTypes.h:45
@ WindowRole
Definition MatchTypes.h:28
@ ScreenOrientation
context — "portrait" / "landscape" of the resolving screen
Definition MatchTypes.h:68
@ ScreenAspectRatio
context — the resolving screen's nearest common aspect ratio ("16:9", "32:9", …)
Definition MatchTypes.h:77
@ Pid
Definition MatchTypes.h:29
@ Zone
the snap zone's UUID the window occupies
Definition MatchTypes.h:58
@ Title
Definition MatchTypes.h:30
@ IsResizable
Definition MatchTypes.h:51
@ IsSnapped
occupies a snap zone
Definition MatchTypes.h:57
@ IsModal
Definition MatchTypes.h:49
@ SkipPager
Definition MatchTypes.h:47
@ DesktopFile
Definition MatchTypes.h:27
@ IsMaximizable
window can be maximized
Definition MatchTypes.h:66
@ SkipSwitcher
Definition MatchTypes.h:48
@ ColorScheme
context — "light" / "dark" system colour scheme, session-wide
Definition MatchTypes.h:73
@ Activity
context — always present
Definition MatchTypes.h:37
@ Height
Definition MatchTypes.h:43
@ IsTransient
Definition MatchTypes.h:40
FieldSource
Whether a field is a window property or a context attribute.
Definition MatchTypes.h:199
@ Context
resolvable during a windowless context query (screen / desktop / activity / mode / screen orientation...
Definition MatchTypes.h:201
@ Window
absent during windowless context queries
Definition MatchTypes.h:200
Operator
Match operators.
Definition MatchTypes.h:441
@ Equals
case-insensitive for strings, numeric for ints, bool for flags
Definition MatchTypes.h:442
@ EndsWith
suffix, case-insensitive (strings)
Definition MatchTypes.h:445
@ Regex
QRegularExpression, precompiled & cached per predicate.
Definition MatchTypes.h:446
@ StartsWith
prefix, case-insensitive (strings)
Definition MatchTypes.h:444
@ AppIdMatches
segment-aware reverse-DNS match (AppId only)
Definition MatchTypes.h:447
@ Contains
substring, case-insensitive (strings)
Definition MatchTypes.h:443
@ LessThan
numeric compare (every FieldType::Int field)
Definition MatchTypes.h:449
@ GreaterThan
numeric compare (every FieldType::Int field)
Definition MatchTypes.h:448
std::optional< Operator > operatorFromString(QStringView s)
Strict parse: an unknown token returns nullopt.
Definition MatchTypes.h:481
bool fieldIsNumeric(Field field)
True if field carries a numeric value.
Definition MatchTypes.h:414
constexpr FieldDescriptor kFieldTable[]
The master field table — indexed by static_cast<int>(field).
Definition MatchTypes.h:217
QString fieldToString(Field field)
Canonical lowercase wire string for a Field.
Definition MatchTypes.h:384
FieldType
Value-kind of a field's payload in a WindowQuery.
Definition MatchTypes.h:191
@ Int
int-valued (operators: Equals/GreaterThan/LessThan)
Definition MatchTypes.h:194
@ String
QString-valued (operators: Equals/Contains/StartsWith/EndsWith/Regex).
Definition MatchTypes.h:192
@ Bool
bool-valued (operator: Equals)
Definition MatchTypes.h:193
@ Enum
enum-as-int (WindowType) — Equals only
Definition MatchTypes.h:195
constexpr int OperatorCount
The number of distinct Operator enumerators.
Definition MatchTypes.h:454
std::optional< Field > fieldFromString(QStringView s)
Strict parse: an unknown token returns nullopt so the loader can drop the malformed predicate rather ...
Definition MatchTypes.h:395
QString orientationTokenFor(int width, int height)
The Field::ScreenOrientation token for a width x height screen: "portrait" when it is taller than wid...
Definition MatchTypes.h:176
One entry of the Field::ScreenAspectRatio vocabulary: the token a rule compares against and the width...
Definition MatchTypes.h:127
QLatin1StringView token
Definition MatchTypes.h:128
double ratio
Definition MatchTypes.h:129
Compile-time descriptor for one Field.
Definition MatchTypes.h:209
QLatin1StringView wire
Definition MatchTypes.h:211
FieldSource source
Definition MatchTypes.h:213
FieldType type
Definition MatchTypes.h:212
Field field
Definition MatchTypes.h:210