From 4ea9d431c22b1c19979982997b04cfdc6ec920d2 Mon Sep 17 00:00:00 2001 From: Pierre Le Marre Date: Thu, 16 Nov 2023 17:12:03 +0100 Subject: [PATCH] rules: Add support for :all qualifier Some layout options require to be applied to every group to maintain consistency (e.g. a group switcher). Currently this must be done manually for all layout indexes. This is error prone and prevents the increase of the maximum group count. This commit introduces the `:all` qualifier for KcCGST values. When a rule with this qualifier is matched, it will expands the qualified value (and its optional merge mode) for every layout, e.g. `+group(toggle):all` (respectively `|group(toggle)`) would expand to `+group(toggle):1+group(toggle):2` (respectively `|group(toggle):1|group(toggle):2`) if there are 2 layouts, etc. If there is no merge mode, it defaults to *override* `+`, e.g. `x:all` expands to `x:1+x:2+x:3` for 3 layouts. Note that only the qualified *value* is expanded, e.g. `x+y:all` expands to `x+y:1+y:2` for 2 layouts. `:all` can be used in combination with special layout indexes. Since this can lead to an unexpected behaviour, a warning will be raised. --- changes/api/+modern-rules.feature.md | 5 +- doc/rules-format.md | 137 +++++++++++++++++++++++---- src/scanner-utils.h | 24 +++-- src/xkbcomp/rules.c | 65 ++++++++++++- test/data/rules/all_qualifier | 59 ++++++++++++ test/data/rules/all_qualifier-limit | 18 ++++ test/data/rules/evdev-modern | 2 +- test/rules-file.c | 98 ++++++++++++++++++- 8 files changed, 370 insertions(+), 38 deletions(-) create mode 100644 test/data/rules/all_qualifier create mode 100644 test/data/rules/all_qualifier-limit diff --git a/changes/api/+modern-rules.feature.md b/changes/api/+modern-rules.feature.md index d27af48b..fb1c00a8 100644 --- a/changes/api/+modern-rules.feature.md +++ b/changes/api/+modern-rules.feature.md @@ -7,8 +7,9 @@ Rules: Added support for special layouts indexes: `layout[2]` .. `layout[4]`. - *any*: matches layout at any position. This is an index range. -Also added the special index `%i` which correspond to the index of the matched -layout. +Also added: +- the special index `%i` which correspond to the index of the matched layout. +- the `:all` qualifier: it applies the qualified item to all layouts. See the [documentation](https://xkbcommon.org/doc/current/rule-file-format.html) for further information. diff --git a/doc/rules-format.md b/doc/rules-format.md index 99c4dc80..43615e4d 100644 --- a/doc/rules-format.md +++ b/doc/rules-format.md @@ -12,9 +12,9 @@ components. @tableofcontents{html:2} -`xkbcomp` uses the `xkb_component_names` struct internally, which maps -directly to [include statements] of the appropriate [sections] \(called -[KcCGST] for short): +`libxkbcommon`’s keymap compiler `xkbcomp` uses the `xkb_component_names` +struct internally, which maps directly to [include statements] of the +appropriate [sections] \(called [KcCGST] for short): - [key codes], - [compatibility], @@ -150,7 +150,8 @@ Kccgst ::= "keycodes" | "symbols" | "types" | "compat" | "geometry" Rule ::= { MlvoValue } "=" { KccgstValue } "\n" MlvoValue ::= "*" | GroupName | -KccgstValue ::= +KccgstValue ::= [ { Qualifier } ] +Qualifier ::= ":" ({ NumericIndex } | "all") ```