8#include <QLoggingCategory>
24#include "phosphorrules_export.h"
89 if (screenId.isEmpty()) {
92 const bool hasDesktop = virtualDesktop > 0;
93 const bool hasActivity = !activity.isEmpty();
94 if (hasDesktop && hasActivity) {
114inline QString
contextRuleName(
const QString& screenId,
int virtualDesktop,
const QString& activity)
116 return screenId + (virtualDesktop > 0 ? QStringLiteral(
" · Desktop ") + QString::number(virtualDesktop) : QString())
117 + (activity.isEmpty() ? QString() : QStringLiteral(
" · Activity"));
128 static const QUuid ns(QStringLiteral(
"{c4e3d2b1-8a5f-6071-9cad-1e2f3a4b5c6d}"));
143inline QString
contextIdentityKey(QLatin1StringView family,
const QString& screenId,
int virtualDesktop,
144 const QString& activity)
166 return QUuid::createUuidV5(
184inline QUuid
disableRuleIdFor(
const QString& screenId,
int virtualDesktop,
const QString& activity,
185 const QString& modeToken)
197 const QByteArray tag = QByteArray(
"disable-") + modeToken.toUtf8();
198 return QUuid::createUuidV5(
201 virtualDesktop, activity));
214 QList<MatchExpression> children;
215 if (!screenId.isEmpty()) {
218 if (virtualDesktop > 0) {
221 if (!activity.isEmpty()) {
224 if (children.isEmpty()) {
227 if (children.size() == 1) {
228 return children.first();
271 const QString& tilingAlgorithm,
const QString& scrollingTemplate)
273 QList<RuleAction> actions;
278 actions.append(modeAction);
280 if (!snappingLayout.isEmpty()) {
284 actions.append(layoutAction);
286 if (!tilingAlgorithm.isEmpty()) {
290 actions.append(tilingAction);
292 if (!scrollingTemplate.isEmpty()) {
296 actions.append(templateAction);
317 const QString& activity,
const QString& modeToken,
const QString& snappingLayout,
318 const QString& tilingAlgorithm,
int priority,
const QString& scrollingTemplate)
348inline Rule makeDisableRule(
const QString& name,
const QString& screenId,
int virtualDesktop,
const QString& activity,
349 const QString& modeToken,
int priority)
425 const QList<MatchExpression> leaves = match.
isLeaf() ? QList<MatchExpression>{match} : match.
children();
426 bool sawScreen =
false;
427 bool sawDesktop =
false;
428 bool sawActivity =
false;
432 qCWarning(lcRule) <<
"ContextRuleBridge::contextDimsOf: duplicate ScreenId leaf — refusing to coerce.";
439 screenId = leaf.predicate().value.toString();
443 <<
"ContextRuleBridge::contextDimsOf: duplicate VirtualDesktop leaf — refusing to coerce.";
458 const int desktopValue = leaf.predicate().value.toInt(&ok);
459 if (!ok || desktopValue <= 0) {
461 <<
"ContextRuleBridge::contextDimsOf: malformed VirtualDesktop value — refusing to coerce."
462 << leaf.predicate().value;
468 virtualDesktop = desktopValue;
471 qCWarning(lcRule) <<
"ContextRuleBridge::contextDimsOf: duplicate Activity leaf — refusing to coerce.";
478 activity = leaf.predicate().value.toString();
497 if (!sawScreen && !sawDesktop && !sawActivity) {
524 static const QSet<Field> kNonDimensionContextFields = [] {
534 fields.insert(descriptor.field);
565 int virtualDesktop = 0;
572 if (!
contextDimsOf(match, screenId, virtualDesktop, activity)) {
637 const QString& activity)
659 return s == screenId && d == virtualDesktop && a == activity;
690 if (disableAction !=
nullptr) {
695 disableAction = &action;
697 if (disableAction ==
nullptr) {
701 if (mode.isEmpty()) {
745 if (!ok || old <= 0) {
748 const int moved = desktop(old);
755 QList<MatchExpression> children;
756 children.reserve(match.
children().size());
757 bool changed =
false;
760 changed = changed || children.constLast() != child;
765 switch (match.
kind()) {
782 bool namedGone =
false;
784 bool changed = match != rule.
match;
785 rule.
match = std::move(match);
791 if (!target.isDouble() || target.toInt() <= 0) {
794 const int moved = desktop(target.toInt());
797 }
else if (moved != target.toInt()) {
802 if (namedGone && rule.
enabled) {
813inline bool isContextSetting(
const Rule& rule,
const QString& screenId,
int virtualDesktop,
const QString& activity)
823 return ActionRegistry::instance().domainFor(action) == ActionDomain::Context;
859 QList<Rule> remapped;
860 remapped.reserve(rules.size());
862 moved.reserve(rules.size());
863 QSet<QUuid> movedIds;
865 bool changed =
false;
866 for (
const Rule& rule : rules) {
868 heldIds.insert(rule.id);
869 remapped.append(rule);
882 changed = changed || ruleMoved;
883 remapped.append(ruleMoved ? copy : rule);
884 moved.append(ruleMoved);
887 const int newDesktop = desktop > 0 && remap.
desktop ? remap.
desktop(desktop) : desktop;
889 if ((desktop > 0 && newDesktop <= 0) || activityGone) {
893 if (newDesktop == desktop) {
894 remapped.append(rule);
899 bool namedGone =
false;
902 const bool mintedDisable = mode && rule.id ==
disableRuleIdFor(screenId, desktop, activity, *mode);
905 }
else if (mintedDisable) {
913 if (rule.name == oldLabel) {
915 }
else if (mintedDisable && rule.name.endsWith(QStringLiteral(
" · ") + oldLabel)) {
916 copy.
name = rule.name.chopped(oldLabel.size()) +
contextRuleName(screenId, newDesktop, activity);
918 movedIds.insert(copy.
id);
919 remapped.append(copy);
926 if (!movedIds.isEmpty()) {
928 deduped.reserve(remapped.size());
929 for (qsizetype i = 0; i < remapped.size(); ++i) {
930 const QUuid&
id = remapped.at(i).id;
933 const bool keep = moved.at(i) ? !heldIds.contains(
id) : (heldIds.contains(
id) || !movedIds.contains(
id));
935 deduped.append(remapped.at(i));
Shared length-prefixed segment encoder used by every bridge that derives a stable identity key from a...
A composable predicate tree evaluated against a WindowQuery.
Definition MatchExpression.h:50
@ None
NOT-any — no child may match.
Definition MatchExpression.h:57
@ All
AND — every child must match.
Definition MatchExpression.h:55
@ Any
OR — at least one child must match.
Definition MatchExpression.h:56
static MatchExpression makeLeaf(const Predicate &predicate)
Constructs a leaf predicate expression.
static MatchExpression makeNone(const QList< MatchExpression > &children)
bool isContextOnly() const
True if this expression references only context fields (ScreenId / VirtualDesktop / Activity / Mode /...
Kind kind() const
Definition MatchExpression.h:88
const QList< MatchExpression > & children() const
Composite accessor — empty for a leaf.
Definition MatchExpression.h:104
const Predicate & predicate() const
Leaf accessor — only meaningful when isLeaf().
Definition MatchExpression.h:98
static MatchExpression makeAny(const QList< MatchExpression > &children)
bool isCatchAll() const
True if this is the empty catch-all All{} — matches every query.
Definition MatchExpression.h:110
static MatchExpression makeAll(const QList< MatchExpression > &children)
Constructs a composite expression.
bool referencesAnyField(const QSet< Field > &fields) const
True if any leaf predicate anywhere in the tree (including inside none{} negations) tests one of fiel...
bool isLeaf() const
Definition MatchExpression.h:92
constexpr QLatin1StringView LayoutId
Definition ActionParams.h:99
constexpr QLatin1StringView TargetDesktop
Definition ActionParams.h:118
constexpr QLatin1StringView Mode
Definition ActionParams.h:82
constexpr QLatin1StringView Algorithm
Definition ActionParams.h:101
constexpr QLatin1StringView SetSnappingLayout
Definition ActionTypes.h:24
constexpr QLatin1StringView SetScrollingTemplate
Scrolling-mode template for the matched context: a NATIVE ScrollingTemplate id (its own picker kind,...
Definition ActionTypes.h:33
constexpr QLatin1StringView DisableEngine
Definition ActionTypes.h:34
constexpr QLatin1StringView SetTilingAlgorithm
Definition ActionTypes.h:25
constexpr QLatin1StringView SetEngineMode
Definition ActionTypes.h:23
constexpr QLatin1StringView RouteToDesktop
Route a matched window to a specific virtual desktop on open.
Definition ActionTypes.h:124
Definition ContextRuleBridge.h:120
QString encodeSegment(const QString &segment)
Length-prefix a segment so concatenated identity keys are unambiguous: a screenId / activity may itse...
Definition IdentityKey.h:33
bool remapRuleDesktops(Rule &rule, const std::function< int(int)> &desktop)
A rule that is not one context's own setting follows its desktops: its VirtualDesktop Equals leaves a...
Definition ContextRuleBridge.h:780
bool isContextSetting(const Rule &rule, const QString &screenId, int virtualDesktop, const QString &activity)
Whether rule, whose match is the exact context shape decoded into the tuple, is that context's own se...
Definition ContextRuleBridge.h:813
QString contextIdentityKey(QLatin1StringView family, const QString &screenId, int virtualDesktop, const QString &activity)
Stable per-rule key for the v5-UUID derivation.
Definition ContextRuleBridge.h:143
const QUuid & namespaceUuid()
Fixed v5-UUID namespace for context-rule identities.
Definition ContextRuleBridge.h:126
MatchExpression remapDesktopLeaves(const MatchExpression &match, const std::function< int(int)> &desktop, bool &namedGone)
match with every VirtualDesktop Equals leaf, at any depth, moved through desktop.
Definition ContextRuleBridge.h:736
Definition ContextRuleBridge.h:48
bool matchIsExactContext(const MatchExpression &match, const QString &screenId, int virtualDesktop, const QString &activity)
True if match is the exact-shape context for screenId / virtualDesktop / activity — i....
Definition ContextRuleBridge.h:636
bool matchIsExactContextActivity(const MatchExpression &match)
BROAD per-activity family classifier — true if match is a context-only rule pinning an activity (with...
Definition ContextRuleBridge.h:604
bool isContextEqualsLeaf(const MatchExpression &expr, Field field)
True if expr is an exact Field == value equality leaf for field.
Definition ContextRuleBridge.h:377
bool pinsNonDimensionContextField(const MatchExpression &match)
True if match pins a context field that is NOT one of the three cascade dimensions — any context fiel...
Definition ContextRuleBridge.h:522
std::optional< QList< Rule > > remapContextRules(const QList< Rule > &rules, const ContextRemap &remap)
rules with the desktops and activities they name moved by remap.
Definition ContextRuleBridge.h:854
std::optional< QString > disableRuleMode(const Rule &rule)
If rule is a per-mode disable rule, return its mode wire token verbatim; otherwise nullopt.
Definition ContextRuleBridge.h:683
ContextAxis contextAxisOf(const QString &screenId, int virtualDesktop, const QString &activity)
Classify a (screen, desktop, activity) tuple into its cascade axis.
Definition ContextRuleBridge.h:87
bool matchIsExactContextBase(const MatchExpression &match)
True if match is a context-only "screen-only" pin — screen present, no desktop, no activity.
Definition ContextRuleBridge.h:580
QString contextRuleName(const QString &screenId, int virtualDesktop, const QString &activity)
Human-readable label for a context rule's tuple.
Definition ContextRuleBridge.h:114
constexpr int kContextBandBase
Default precedence band base for context rules (zone assignments and per-mode disables).
Definition ContextRuleBridge.h:56
ContextAxis
The cascade axis a context tuple resolves to.
Definition ContextRuleBridge.h:69
@ Desktop
screen + desktop.
Definition ContextRuleBridge.h:75
@ Combined
screen + desktop + activity (the exact-pin shape).
Definition ContextRuleBridge.h:77
@ CatchAll
empty screenId (the catch-all), OR a context match that pins a non-dimension field beyond screen/desk...
Definition ContextRuleBridge.h:70
@ Monitor
screen only.
Definition ContextRuleBridge.h:74
@ Activity
screen + activity.
Definition ContextRuleBridge.h:76
QUuid disableRuleIdFor(const QString &screenId, int virtualDesktop, const QString &activity, const QString &modeToken)
The deterministic v5 rule id makeDisableRule would assign for a given (screen, desktop,...
Definition ContextRuleBridge.h:184
QList< RuleAction > makeAssignmentActions(const QString &modeToken, const QString &snappingLayout, const QString &tilingAlgorithm, const QString &scrollingTemplate)
Build the lossless action list for a migrated zone Assignment.
Definition ContextRuleBridge.h:270
Rule makeAssignmentRule(const QString &name, const QString &screenId, int virtualDesktop, const QString &activity, const QString &modeToken, const QString &snappingLayout, const QString &tilingAlgorithm, int priority, const QString &scrollingTemplate)
Build a complete migrated zone-Assignment Rule.
Definition ContextRuleBridge.h:316
constexpr Field kContextDimensionFields[]
The three cascade dimensions makeContextMatch can emit — the only context fields contextDimsOf decode...
Definition ContextRuleBridge.h:505
Rule makeDisableRule(const QString &name, const QString &screenId, int virtualDesktop, const QString &activity, const QString &modeToken, int priority)
Build a DisableEngine context rule for a per-mode disable entry.
Definition ContextRuleBridge.h:348
bool matchIsExactContextCombined(const MatchExpression &match)
STRICT Combined classifier — screen + desktop + activity all pinned.
Definition ContextRuleBridge.h:626
QUuid assignmentRuleIdFor(const QString &screenId, int virtualDesktop, const QString &activity)
The deterministic v5 rule id makeAssignmentRule would assign for a given (screen, desktop,...
Definition ContextRuleBridge.h:164
bool matchIsExactContextActivityStrict(const MatchExpression &match)
STRICT per-activity classifier — screen+activity ONLY, no desktop pin.
Definition ContextRuleBridge.h:617
bool matchIsExactContextDesktop(const MatchExpression &match)
True if match is a context-only "screen + desktop" pin (no activity).
Definition ContextRuleBridge.h:588
bool contextDimsOf(const MatchExpression &match, QString &screenId, int &virtualDesktop, QString &activity)
Decompose a context rule's match into its pinned dimensions.
Definition ContextRuleBridge.h:411
MatchExpression makeContextMatch(const QString &screenId, int virtualDesktop, const QString &activity)
Build the context-only MatchExpression for a (screen, desktop, activity) tuple.
Definition ContextRuleBridge.h:212
ContextAxis contextAxisFor(const MatchExpression &match)
Classify match's pinned-dimension shape as a ContextAxis.
Definition ContextRuleBridge.h:550
QString encodeSegment(const QString &segment)
Length-prefix a segment so concatenated identity keys are unambiguous.
Definition IdentityKey.h:33
Definition ActionParams.h:25
Field
Match fields.
Definition MatchTypes.h:23
@ VirtualDesktop
context — always present
Definition MatchTypes.h:36
@ ScreenId
context — always present
Definition MatchTypes.h:35
@ Activity
context — always present
Definition MatchTypes.h:37
@ Context
resolvable during a windowless context query (screen / desktop / activity / mode / screen orientation...
Definition MatchTypes.h:201
@ Equals
case-insensitive for strings, numeric for ints, bool for flags
Definition MatchTypes.h:442
constexpr FieldDescriptor kFieldTable[]
The master field table — indexed by static_cast<int>(field).
Definition MatchTypes.h:217
How the desktops and activities a rule set names have moved.
Definition ContextRuleBridge.h:724
std::function< int(int)> desktop
Definition ContextRuleBridge.h:725
std::function< bool(const Rule &)> applies
Definition ContextRuleBridge.h:727
std::function< bool(const QString &)> activityAlive
Definition ContextRuleBridge.h:726
Compile-time descriptor for one Field.
Definition MatchTypes.h:209
Operator op
Definition MatchExpression.h:64
QVariant value
Definition MatchExpression.h:65
Field field
Definition MatchExpression.h:63
One action carried by a Rule.
Definition RuleAction.h:65
QJsonObject params
Action-specific payload.
Definition RuleAction.h:72
QString type
registered action type id (e.g.
Definition RuleAction.h:66
One rule — { id, name, enabled, priority, match, actions, managed }.
Definition Rule.h:106
QUuid id
Definition Rule.h:107
QList< RuleAction > actions
Definition Rule.h:112
QString name
Definition Rule.h:108
MatchExpression match
default-constructs to the catch-all All{}
Definition Rule.h:111
int priority
Definition Rule.h:110
bool enabled
Definition Rule.h:109