Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
ContextRuleBridge.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 <QLoggingCategory>
9#include <QSet>
10#include <QString>
11#include <QUuid>
12
13#include <algorithm>
14#include <functional>
15#include <iterator>
16#include <optional>
17
18#include "IdentityKey.h"
19#include "MatchExpression.h"
20#include "MatchTypes.h"
21#include "RuleAction.h"
22#include "Rule.h"
23#include "RuleLogging.h"
24#include "phosphorrules_export.h"
25
45
46namespace PhosphorRules {
47
49
56inline constexpr int kContextBandBase = 300;
57
79
87inline ContextAxis contextAxisOf(const QString& screenId, int virtualDesktop, const QString& activity)
88{
89 if (screenId.isEmpty()) {
91 }
92 const bool hasDesktop = virtualDesktop > 0;
93 const bool hasActivity = !activity.isEmpty();
94 if (hasDesktop && hasActivity) {
96 }
97 if (hasActivity) {
99 }
100 if (hasDesktop) {
102 }
104}
105
114inline QString contextRuleName(const QString& screenId, int virtualDesktop, const QString& activity)
115{
116 return screenId + (virtualDesktop > 0 ? QStringLiteral(" · Desktop ") + QString::number(virtualDesktop) : QString())
117 + (activity.isEmpty() ? QString() : QStringLiteral(" · Activity"));
118}
119
120namespace detail {
121
126inline const QUuid& namespaceUuid()
127{
128 static const QUuid ns(QStringLiteral("{c4e3d2b1-8a5f-6071-9cad-1e2f3a4b5c6d}"));
129 return ns;
130}
131
138
143inline QString contextIdentityKey(QLatin1StringView family, const QString& screenId, int virtualDesktop,
144 const QString& activity)
145{
146 return encodeSegment(QString(family)) + encodeSegment(screenId) + encodeSegment(QString::number(virtualDesktop))
147 + encodeSegment(activity);
148}
149
150} // namespace detail
151
164inline QUuid assignmentRuleIdFor(const QString& screenId, int virtualDesktop, const QString& activity)
165{
166 return QUuid::createUuidV5(
168 detail::contextIdentityKey(QLatin1StringView("assignment"), screenId, virtualDesktop, activity));
169}
170
184inline QUuid disableRuleIdFor(const QString& screenId, int virtualDesktop, const QString& activity,
185 const QString& modeToken)
186{
187 // contextIdentityKey() takes a QLatin1StringView, but the source bytes
188 // are produced via `toUtf8()` so non-Latin1 tokens (a future
189 // non-ASCII mode wire string) injectively distinguish their UUIDs —
190 // `toLatin1()` replaces every non-Latin1 codepoint with '?', collapsing
191 // distinct tokens onto identical UUIDs. For the current ASCII-only
192 // vocabulary ("snapping" / "autotile" / "scrolling") UTF-8 and
193 // Latin1 produce identical bytes, so existing rule UUIDs are preserved
194 // verbatim; only future non-ASCII tokens diverge. The view's source
195 // bytes must live for the full call — naming the QByteArray local
196 // keeps it from expiring before createUuidV5 reads through the view.
197 const QByteArray tag = QByteArray("disable-") + modeToken.toUtf8();
198 return QUuid::createUuidV5(
200 detail::contextIdentityKey(QLatin1StringView(tag.constData(), static_cast<qsizetype>(tag.size())), screenId,
201 virtualDesktop, activity));
202}
203
212inline MatchExpression makeContextMatch(const QString& screenId, int virtualDesktop, const QString& activity)
213{
214 QList<MatchExpression> children;
215 if (!screenId.isEmpty()) {
217 }
218 if (virtualDesktop > 0) {
219 children.append(MatchExpression::makeLeaf(Field::VirtualDesktop, Operator::Equals, virtualDesktop));
220 }
221 if (!activity.isEmpty()) {
223 }
224 if (children.isEmpty()) {
225 return MatchExpression(); // empty All{} — the catch-all
226 }
227 if (children.size() == 1) {
228 return children.first();
229 }
230 return MatchExpression::makeAll(children);
231}
232
270inline QList<RuleAction> makeAssignmentActions(const QString& modeToken, const QString& snappingLayout,
271 const QString& tilingAlgorithm, const QString& scrollingTemplate)
272{
273 QList<RuleAction> actions;
274
275 RuleAction modeAction;
276 modeAction.type = QString(ActionType::SetEngineMode);
277 modeAction.params.insert(ActionParam::Mode, modeToken);
278 actions.append(modeAction);
279
280 if (!snappingLayout.isEmpty()) {
281 RuleAction layoutAction;
282 layoutAction.type = QString(ActionType::SetSnappingLayout);
283 layoutAction.params.insert(ActionParam::LayoutId, snappingLayout);
284 actions.append(layoutAction);
285 }
286 if (!tilingAlgorithm.isEmpty()) {
287 RuleAction tilingAction;
288 tilingAction.type = QString(ActionType::SetTilingAlgorithm);
289 tilingAction.params.insert(ActionParam::Algorithm, tilingAlgorithm);
290 actions.append(tilingAction);
291 }
292 if (!scrollingTemplate.isEmpty()) {
293 RuleAction templateAction;
294 templateAction.type = QString(ActionType::SetScrollingTemplate);
295 templateAction.params.insert(ActionParam::LayoutId, scrollingTemplate);
296 actions.append(templateAction);
297 }
298 return actions;
299}
300
316inline Rule makeAssignmentRule(const QString& name, const QString& screenId, int virtualDesktop,
317 const QString& activity, const QString& modeToken, const QString& snappingLayout,
318 const QString& tilingAlgorithm, int priority, const QString& scrollingTemplate)
319{
320 Rule rule;
321 // Deterministic id derived from the source context identity — identical
322 // assignments yield identical rules, keeping the migration idempotent.
323 rule.id = assignmentRuleIdFor(screenId, virtualDesktop, activity);
324 rule.name = name;
325 rule.enabled = true;
326 rule.priority = priority;
327 rule.match = makeContextMatch(screenId, virtualDesktop, activity);
328 rule.actions = makeAssignmentActions(modeToken, snappingLayout, tilingAlgorithm, scrollingTemplate);
329 return rule;
330}
331
348inline Rule makeDisableRule(const QString& name, const QString& screenId, int virtualDesktop, const QString& activity,
349 const QString& modeToken, int priority)
350{
351 Rule rule;
352 // Deterministic id — a disable rule's identity is its context tuple plus
353 // which engine it disables (per-mode disables for the same context are
354 // distinct rules and must not collide).
355 rule.id = disableRuleIdFor(screenId, virtualDesktop, activity, modeToken);
356 rule.name = name;
357 rule.enabled = true;
358 rule.priority = priority;
359 rule.match = makeContextMatch(screenId, virtualDesktop, activity);
360
361 RuleAction action;
362 action.type = QString(ActionType::DisableEngine);
363 action.params.insert(ActionParam::Mode, modeToken);
364 rule.actions.append(action);
365 return rule;
366}
367
368// ── Readback: context rule → (screen, desktop, activity) ───────────────────
369//
370// The inverse of @ref makeContextMatch — decompose a context rule's match
371// expression back into the (screenId, virtualDesktop, activity) tuple it
372// pins. Used by consumers that need to enumerate stored context rules
373// (the per-mode disable lists in Settings, the assignment introspection
374// helpers in LayoutRegistry).
375
377inline bool isContextEqualsLeaf(const MatchExpression& expr, Field field)
378{
379 return expr.isLeaf() && expr.predicate().field == field && expr.predicate().op == Operator::Equals;
380}
381
411inline bool contextDimsOf(const MatchExpression& match, QString& screenId, int& virtualDesktop, QString& activity)
412{
413 screenId.clear();
414 virtualDesktop = 0;
415 activity.clear();
416 if (match.isCatchAll()) {
417 return true;
418 }
419 // Only a leaf or a flat All{} is a context rule this bridge produced. A
420 // composite of any other kind (Any / None) — or an All{} carrying a
421 // nested composite child — is outside the contract; leave the defaults.
422 if (!match.isLeaf() && match.kind() != MatchExpression::Kind::All) {
423 return false;
424 }
425 const QList<MatchExpression> leaves = match.isLeaf() ? QList<MatchExpression>{match} : match.children();
426 bool sawScreen = false;
427 bool sawDesktop = false;
428 bool sawActivity = false;
429 for (const MatchExpression& leaf : leaves) {
431 if (sawScreen) {
432 qCWarning(lcRule) << "ContextRuleBridge::contextDimsOf: duplicate ScreenId leaf — refusing to coerce.";
433 screenId.clear();
434 virtualDesktop = 0;
435 activity.clear();
436 return false;
437 }
438 sawScreen = true;
439 screenId = leaf.predicate().value.toString();
440 } else if (isContextEqualsLeaf(leaf, Field::VirtualDesktop)) {
441 if (sawDesktop) {
442 qCWarning(lcRule)
443 << "ContextRuleBridge::contextDimsOf: duplicate VirtualDesktop leaf — refusing to coerce.";
444 screenId.clear();
445 virtualDesktop = 0;
446 activity.clear();
447 return false;
448 }
449 sawDesktop = true;
450 // Refuse a malformed VirtualDesktop value — `QVariant::toInt()`
451 // silently returns 0 for "abc" or a non-positive int, which the
452 // bridge contract reads as "no desktop pinned" and would
453 // misclassify the rule as a monitor-axis match. `makeContextMatch`
454 // only stores a strictly-positive int here, so any other source
455 // is a hand-edit or migration error — bail to the same
456 // refuse-to-coerce shape the duplicate-leaf guards use.
457 bool ok = false;
458 const int desktopValue = leaf.predicate().value.toInt(&ok);
459 if (!ok || desktopValue <= 0) {
460 qCWarning(lcRule)
461 << "ContextRuleBridge::contextDimsOf: malformed VirtualDesktop value — refusing to coerce."
462 << leaf.predicate().value;
463 screenId.clear();
464 virtualDesktop = 0;
465 activity.clear();
466 return false;
467 }
468 virtualDesktop = desktopValue;
469 } else if (isContextEqualsLeaf(leaf, Field::Activity)) {
470 if (sawActivity) {
471 qCWarning(lcRule) << "ContextRuleBridge::contextDimsOf: duplicate Activity leaf — refusing to coerce.";
472 screenId.clear();
473 virtualDesktop = 0;
474 activity.clear();
475 return false;
476 }
477 sawActivity = true;
478 activity = leaf.predicate().value.toString();
479 }
480 // Any leaf that is not a ScreenId / VirtualDesktop / Activity equality
481 // leaf is ignored here — a flat mixed rule still yields its context
482 // projection, per the contract above. This includes every other
483 // context leaf (Mode, TiledWindowCount, the screen-shape fields,
484 // ActiveLayout, ColorScheme): each IS a context field, but none is one
485 // of the three decomposed dimensions, so they are deliberately
486 // projected out of contextDimsOf. Callers that must not lose them gate on
487 // pinsNonDimensionContextField first — contextAxisFor already does.
488 }
489 // If no context-equality leaf was matched, the input was either a
490 // context-axis-empty mixed rule (e.g. `ScreenId NotEquals "DP-1"`) or
491 // a structurally-malformed All{}. Either way, no decomposition succeeded
492 // — return false so downstream classifiers don't read this as a
493 // successful catch-all decode. The catch-all case is handled at the
494 // top of the function (`isCatchAll() → return true`); reaching here
495 // with all three flags false means the leaves were all non-equality
496 // or non-context.
497 if (!sawScreen && !sawDesktop && !sawActivity) {
498 return false;
499 }
500 return true;
501}
502
506
523{
524 static const QSet<Field> kNonDimensionContextFields = [] {
525 QSet<Field> fields;
526 for (const FieldDescriptor& descriptor : kFieldTable) {
527 if (descriptor.source != FieldSource::Context) {
528 continue;
529 }
530 if (std::find(std::begin(kContextDimensionFields), std::end(kContextDimensionFields), descriptor.field)
531 != std::end(kContextDimensionFields)) {
532 continue;
533 }
534 fields.insert(descriptor.field);
535 }
536 return fields;
537 }();
538 return match.referencesAnyField(kNonDimensionContextFields);
539}
540
551{
552 if (!match.isContextOnly()) {
554 }
555 // A match that ALSO pins a non-dimension context field (any context field
556 // outside kContextDimensionFields) is not the
557 // (screen, desktop, activity) shape makeContextMatch emits, so it is not an
558 // exact-context assignment; treat it as CatchAll-axis so the batch
559 // projections skip it. It still resolves normally through the evaluator,
560 // which sees those fields via the WindowQuery.
561 if (pinsNonDimensionContextField(match)) {
563 }
564 QString screenId;
565 int virtualDesktop = 0;
566 QString activity;
567 // The decode result is honoured, matching matchIsExactContext below. A
568 // failed decode already fails safe (the outputs stay at ("", 0, "") and
569 // contextAxisOf maps an empty screenId to CatchAll), so this is currently
570 // equivalent — but relying on that couples this classifier to another
571 // function's zero-initialisation, which the next refactor need not keep.
572 if (!contextDimsOf(match, screenId, virtualDesktop, activity)) {
574 }
575 return contextAxisOf(screenId, virtualDesktop, activity);
576}
577
581{
582 return contextAxisFor(match) == ContextAxis::Monitor;
583}
584
589{
590 return contextAxisFor(match) == ContextAxis::Desktop;
591}
592
605{
606 const ContextAxis axis = contextAxisFor(match);
607 return axis == ContextAxis::Activity || axis == ContextAxis::Combined;
608}
609
618{
619 return contextAxisFor(match) == ContextAxis::Activity;
620}
621
627{
628 return contextAxisFor(match) == ContextAxis::Combined;
629}
630
636inline bool matchIsExactContext(const MatchExpression& match, const QString& screenId, int virtualDesktop,
637 const QString& activity)
638{
639 if (!match.isContextOnly()) {
640 return false;
641 }
642 // A pinned non-dimension context leaf (any context field outside
643 // kContextDimensionFields) means the match is more specific than the
644 // bare (screen, desktop, activity) shape, so it is NOT exact — see
645 // contextAxisFor for why dropping it here would lose the leaf on rebuild.
646 if (pinsNonDimensionContextField(match)) {
647 return false;
648 }
649 QString s;
650 int d = 0;
651 QString a;
652 // Honour the decode verdict. On failure contextDimsOf resets the outputs to
653 // ("", 0, ""), which is exactly the global catch-all tuple — so discarding
654 // the bool would report a malformed match as the exact catch-all context and
655 // let a caller rebuild it as one, dropping whatever it really pinned.
656 if (!contextDimsOf(match, s, d, a)) {
657 return false;
658 }
659 return s == screenId && d == virtualDesktop && a == activity;
660}
661
683inline std::optional<QString> disableRuleMode(const Rule& rule)
684{
685 const RuleAction* disableAction = nullptr;
686 for (const RuleAction& action : rule.actions) {
687 if (action.type != QString(ActionType::DisableEngine)) {
688 continue;
689 }
690 if (disableAction != nullptr) {
691 // A second DisableEngine action — the rule is ambiguous and was
692 // not produced by makeDisableRule. Not a per-mode disable rule.
693 return std::nullopt;
694 }
695 disableAction = &action;
696 }
697 if (disableAction == nullptr) {
698 return std::nullopt;
699 }
700 const QString mode = disableAction->params.value(ActionParam::Mode).toString();
701 if (mode.isEmpty()) {
702 // An empty token is a malformed payload, not a recognised mode.
703 return std::nullopt;
704 }
705 // The wire vocabulary is the open set the DisableEngine descriptor's
706 // validator recognises — Settings does the wire → Mode mapping via
707 // `PhosphorZones::modeFromWireString`, which is the authoritative
708 // recognised-tokens list. This helper stays string-typed so the
709 // PhosphorRules lib does not need to depend on PhosphorZones.
710 return mode;
711}
712
713// ── Renumbering: a desktop or an activity edit ─────────────────────────────
714
724{
725 std::function<int(int)> desktop{};
726 std::function<bool(const QString&)> activityAlive{};
727 std::function<bool(const Rule&)> applies{};
728};
729
730namespace detail {
731
736inline MatchExpression remapDesktopLeaves(const MatchExpression& match, const std::function<int(int)>& desktop,
737 bool& namedGone)
738{
739 if (match.isLeaf()) {
741 return match;
742 }
743 bool ok = false;
744 const int old = match.predicate().value.toInt(&ok);
745 if (!ok || old <= 0) {
746 return match;
747 }
748 const int moved = desktop(old);
749 if (moved <= 0) {
750 namedGone = true;
751 return match;
752 }
753 return moved == old ? match : MatchExpression::makeLeaf(Field::VirtualDesktop, Operator::Equals, moved);
754 }
755 QList<MatchExpression> children;
756 children.reserve(match.children().size());
757 bool changed = false;
758 for (const MatchExpression& child : match.children()) {
759 children.append(remapDesktopLeaves(child, desktop, namedGone));
760 changed = changed || children.constLast() != child;
761 }
762 if (!changed) {
763 return match;
764 }
765 switch (match.kind()) {
767 return MatchExpression::makeAny(children);
769 return MatchExpression::makeNone(children);
770 default:
771 return MatchExpression::makeAll(children);
772 }
773}
774
780inline bool remapRuleDesktops(Rule& rule, const std::function<int(int)>& desktop)
781{
782 bool namedGone = false;
783 MatchExpression match = remapDesktopLeaves(rule.match, desktop, namedGone);
784 bool changed = match != rule.match;
785 rule.match = std::move(match);
786 for (RuleAction& action : rule.actions) {
787 if (action.type != QString(ActionType::RouteToDesktop)) {
788 continue;
789 }
790 const QJsonValue target = action.params.value(ActionParam::TargetDesktop);
791 if (!target.isDouble() || target.toInt() <= 0) {
792 continue;
793 }
794 const int moved = desktop(target.toInt());
795 if (moved <= 0) {
796 namedGone = true;
797 } else if (moved != target.toInt()) {
798 action.params.insert(ActionParam::TargetDesktop, moved);
799 changed = true;
800 }
801 }
802 if (namedGone && rule.enabled) {
803 rule.enabled = false;
804 changed = true;
805 }
806 return changed;
807}
808
813inline bool isContextSetting(const Rule& rule, const QString& screenId, int virtualDesktop, const QString& activity)
814{
815 if (rule.id == assignmentRuleIdFor(screenId, virtualDesktop, activity)) {
816 return true;
817 }
818 if (const auto mode = disableRuleMode(rule);
819 mode && rule.id == disableRuleIdFor(screenId, virtualDesktop, activity, *mode)) {
820 return true;
821 }
822 return std::all_of(rule.actions.cbegin(), rule.actions.cend(), [](const RuleAction& action) {
823 return ActionRegistry::instance().domainFor(action) == ActionDomain::Context;
824 });
825}
826
827} // namespace detail
828
854inline std::optional<QList<Rule>> remapContextRules(const QList<Rule>& rules, const ContextRemap& remap)
855{
856 if (!remap.desktop && !remap.activityAlive) {
857 return std::nullopt;
858 }
859 QList<Rule> remapped;
860 remapped.reserve(rules.size());
861 QList<bool> moved;
862 moved.reserve(rules.size());
863 QSet<QUuid> movedIds;
864 QSet<QUuid> heldIds;
865 bool changed = false;
866 for (const Rule& rule : rules) {
867 if (remap.applies && !remap.applies(rule)) {
868 heldIds.insert(rule.id);
869 remapped.append(rule);
870 moved.append(false);
871 continue;
872 }
873 QString screenId;
874 int desktop = 0;
875 QString activity;
876 const bool contextRule = rule.match.isContextOnly() && !pinsNonDimensionContextField(rule.match)
877 && contextDimsOf(rule.match, screenId, desktop, activity)
878 && detail::isContextSetting(rule, screenId, desktop, activity);
879 if (!contextRule) {
880 Rule copy = rule;
881 const bool ruleMoved = remap.desktop && detail::remapRuleDesktops(copy, remap.desktop);
882 changed = changed || ruleMoved;
883 remapped.append(ruleMoved ? copy : rule);
884 moved.append(ruleMoved);
885 continue;
886 }
887 const int newDesktop = desktop > 0 && remap.desktop ? remap.desktop(desktop) : desktop;
888 const bool activityGone = !activity.isEmpty() && remap.activityAlive && !remap.activityAlive(activity);
889 if ((desktop > 0 && newDesktop <= 0) || activityGone) {
890 changed = true;
891 continue;
892 }
893 if (newDesktop == desktop) {
894 remapped.append(rule);
895 moved.append(false);
896 continue;
897 }
898 Rule copy = rule;
899 bool namedGone = false;
900 copy.match = detail::remapDesktopLeaves(rule.match, remap.desktop, namedGone);
901 const auto mode = disableRuleMode(rule);
902 const bool mintedDisable = mode && rule.id == disableRuleIdFor(screenId, desktop, activity, *mode);
903 if (rule.id == assignmentRuleIdFor(screenId, desktop, activity)) {
904 copy.id = assignmentRuleIdFor(screenId, newDesktop, activity);
905 } else if (mintedDisable) {
906 copy.id = disableRuleIdFor(screenId, newDesktop, activity, *mode);
907 }
908 // The generated name is the context label, or for a minted disable
909 // rule a mode prefix ending in " · " before it ("Autotile off · DP-1 ·
910 // Desktop 3"). The prefix is kept and the label re-minted; any other
911 // name is the user's own and stays.
912 const QString oldLabel = contextRuleName(screenId, desktop, activity);
913 if (rule.name == oldLabel) {
914 copy.name = contextRuleName(screenId, newDesktop, activity);
915 } else if (mintedDisable && rule.name.endsWith(QStringLiteral(" · ") + oldLabel)) {
916 copy.name = rule.name.chopped(oldLabel.size()) + contextRuleName(screenId, newDesktop, activity);
917 }
918 movedIds.insert(copy.id);
919 remapped.append(copy);
920 moved.append(true);
921 changed = true;
922 }
923 if (!changed) {
924 return std::nullopt;
925 }
926 if (!movedIds.isEmpty()) {
927 QList<Rule> deduped;
928 deduped.reserve(remapped.size());
929 for (qsizetype i = 0; i < remapped.size(); ++i) {
930 const QUuid& id = remapped.at(i).id;
931 // A held rule is newer truth than a moved one, so the moved one
932 // gives way to it. Otherwise the moved one outranks the stale rule.
933 const bool keep = moved.at(i) ? !heldIds.contains(id) : (heldIds.contains(id) || !movedIds.contains(id));
934 if (keep) {
935 deduped.append(remapped.at(i));
936 }
937 }
938 return deduped;
939 }
940 return remapped;
941}
942
943} // namespace ContextRuleBridge
944
945} // namespace PhosphorRules
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