Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
Rule.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 <QJsonObject>
7#include <QList>
8#include <QString>
9#include <QUuid>
10
11#include <optional>
12
13#include "MatchExpression.h"
14#include "RuleAction.h"
15#include "phosphorrules_export.h"
16
17namespace PhosphorRules {
18
34struct PHOSPHORRULES_EXPORT ValidationIssue
35{
38 enum class Code : int {
44 ContextActionWithWindowMatch = 0,
57 TerminalActionWithEffectActions = 1,
66 DuplicateSlotActions = 2,
78 IncompleteActionPayload = 3,
79 };
80
83 int actionIndex = -1;
85 QString actionType;
88 QString message;
89
90 bool operator==(const ValidationIssue& other) const
91 {
92 return code == other.code && actionIndex == other.actionIndex && actionType == other.actionType
93 && message == other.message;
94 }
95};
96
105struct PHOSPHORRULES_EXPORT Rule
106{
107 QUuid id;
108 QString name;
109 bool enabled = true;
110 int priority = 0;
112 QList<RuleAction> actions;
119 bool managed = false;
120
123 bool isValid() const;
124
128 bool hasTerminalAction() const;
129
153 QList<ValidationIssue> validationIssues() const;
154
155 bool operator==(const Rule& other) const;
156 bool operator!=(const Rule& other) const
157 {
158 return !(*this == other);
159 }
160
161 QJsonObject toJson() const;
162
166 static std::optional<Rule> fromJson(const QJsonObject& obj);
167};
168
169} // namespace PhosphorRules
A composable predicate tree evaluated against a WindowQuery.
Definition MatchExpression.h:50
Definition ActionParams.h:25
One rule — { id, name, enabled, priority, match, actions, managed }.
Definition Rule.h:106
QList< ValidationIssue > validationIssues() const
Semantic compatibility issues between match and each action.
bool operator==(const Rule &other) const
QUuid id
Definition Rule.h:107
bool hasTerminalAction() const
True if any of this rule's actions is terminal (one of the Exclude family — Exclude / ExcludePlacemen...
QJsonObject toJson() const
QList< RuleAction > actions
Definition Rule.h:112
bool managed
True for built-in rules the application owns rather than the user (currently the baseline appearance ...
Definition Rule.h:119
QString name
Definition Rule.h:108
bool isValid() const
True if the rule has a non-null id, a valid match expression, and every action validates against the ...
static std::optional< Rule > fromJson(const QJsonObject &obj)
Strict loader — drops the rule (returns nullopt) on a missing/invalid id, a malformed match expressio...
MatchExpression match
default-constructs to the catch-all All{}
Definition Rule.h:111
int priority
Definition Rule.h:110
bool operator!=(const Rule &other) const
Definition Rule.h:156
bool enabled
Definition Rule.h:109
One semantic compatibility issue between a rule's match and an action.
Definition Rule.h:35
Code code
Definition Rule.h:81
Code
Wire-stable code so callers can localise the message themselves without string-matching the diagnosti...
Definition Rule.h:38
@ ContextActionWithWindowMatch
A context-domain action (e.g.
Definition Rule.h:44
QString actionType
Action type id for diagnostics (avoids the caller re-indexing actions).
Definition Rule.h:85
bool operator==(const ValidationIssue &other) const
Definition Rule.h:90
QString message
English diagnostic suitable for logging.
Definition Rule.h:88
int actionIndex
Index into the rule's actions list — points at the offending action.
Definition Rule.h:83