libxkbcommon/test
Peter Hutterer ca033a29d2 rules: add include statements to rules files
The majority use-case for extending XKB on a machine is to override one or a
few keys with custom keycodes, not to define whole layouts.

Previously, we relied on the rules file to be a single file, making it hard to
extend. libxkbcommon parses $XDG_CONFIG_HOME/xkb/ but that only works as long
as there is a rule that matches the user-specified RMLVO. This works for MLV
but not for options which don't have a wildcard defined. Users have to copy
the whole rules file and then work from there - not something easy to extend
and maintain.

This patch adds a new ! include directive to rules files that allows including
another file. The file path must be without quotes and may not start with the
literal "include". Two directives are supported, %H to $HOME and %S for the
system-installed rules directory (usually /usr/share/X11/xkb/rules).

A user would typically use a custom rules file like this:

! option                =       symbols
  custom:foo            =       +custom(foo)
  custom:bar            =       +custom(baz)

! include %S/evdev

Where the above defines the two options and then includes the system-installed
evdev rule. Since most current implementations default to loading the "evdev"
ruleset, it's best to name this $XDG_CONFIG_HOME/xkb/rules/evdev, but any
valid name is allowed.

The include functionally replaces the line with the content of the included
file which means the behavior of rules files is maintained. Specifically,
custom options must be defined before including another file because the first
match usually wins. In other words, the following ruleset will not assign
my_model as one would expect:

! include %S/evdev

! model                 =  symbols
  my_model              =  +custom(foo)

The default evdev ruleset has wildcards for model and those match before the
my_model is hit.

The actual resolved components need only be in one of the XKB lookup
directories, e.g. for the example above:

$ cat $XDG_CONFIG_HOME/xkb/symbols/custom
partial alphanumeric_keys
xkb_symbols "foo" {
    key <TLDE> {        [      VoidSymbol ]       };
};

partial alphanumeric_keys
xkb_symbols "baz" {
    key <AB01> {        [      k, K ]       };
};

This can then be loaded with the XKB option "custom:foo,custom:bar".

The use of "custom" is just as an example, there are no naming requirements
beyond avoiding already-used ones. Also note the bar/baz above - the option
names don't have to match the component names.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
..
data rules: add include statements to rules files 2019-12-24 09:50:03 +02:00
.gitignore test: add a tool to test-compile all LVO combinations from xkeyboard-config 2018-08-21 11:30:45 +10:00
atom.c atom: combine atom_intern() and atom_lookup() 2019-11-09 21:28:43 +02:00
buffercomp.c keymap: add xkb_keymap_new_from_buffer() 2013-04-01 18:04:06 +01:00
common.c test: remove a superfluous string-is-null check 2019-11-07 11:10:00 +02:00
compose.c compose: correctly parse modifier syntax 2015-03-24 16:49:47 +02:00
context.c test: add test for the various default include paths 2019-10-31 19:29:30 +02:00
evdev-scancodes.h test: make most tests portable by copying linux/input.h locally 2014-09-06 11:29:15 +03:00
filecomp.c keycodes: fix keymap compilation with no aliases and malloc(0)==NULL 2014-09-10 13:44:33 +03:00
interactive-evdev.c x11/keymap,test/interactive-evdev: fix a couple of clang-analyzer warnings 2017-07-31 15:55:48 +03:00
interactive-wayland.c interactive-wayland: Port to stable xdg-shell (#100) 2019-07-02 15:48:32 +03:00
interactive-x11.c test/interactive-x11: handle NULL from xcb_wait_for_event 2017-04-28 09:33:25 +03:00
keymap.c keymap: add xkb_keymap_key_by_name(), xkb_keymap_key_get_name(), tests 2016-01-20 23:17:10 +02:00
keyseq.c test/data: sync with xkeyboard-config 2.22 2017-12-03 13:07:21 +02:00
keysym.c keysym-utf: reject out-of-range Unicode codepoints in xkb_keysym_to_utf{8,32} 2018-06-23 22:53:42 +03:00
log.c test: Use test_get_context() in log.c 2013-03-19 10:34:28 +00:00
print-compiled-keymap.c test: drop the rmlvo ability from print-compiled-keymap 2018-08-21 11:31:07 +10:00
rmlvo-to-kccgst.c test: let rmlvo-to-kccgst take long options like rmlvo-to-keymap 2019-11-18 15:32:35 +02:00
rmlvo-to-keymap.c test/rmlvo-to-keymap: drop basename usage 2019-07-25 12:00:27 +03:00
rules-file-includes.c rules: add include statements to rules files 2019-12-24 09:50:03 +02:00
rules-file.c build: remove unneeded preprocessor include flags 2017-07-31 15:55:48 +03:00
rulescomp.c Move benchmarks from tests to their own files in bench/ 2014-10-02 22:03:28 +03:00
state.c state: add GTK consumed modifiers mode 2016-10-31 12:52:28 +02:00
stringcomp.c xkbcomp: escape the section names before storing them in the keymap 2013-07-18 14:50:21 +03:00
symbols-leak-test.bash travis: improve configuration and add macOS 2019-07-25 14:34:17 +03:00
test.h state: allow different modes for calculating consumed modifiers 2016-10-31 12:52:26 +02:00
utf8.c keysym-utf: reject out-of-range Unicode codepoints in xkb_keysym_to_utf{8,32} 2018-06-23 22:53:42 +03:00
x11.c test/x11: properly clean up also when skipping test 2017-12-12 15:58:32 +02:00
x11comp.c test/x11comp: fix compiler warnings 2017-07-31 15:55:48 +03:00
xkeyboard-config-test.py.in test: xkeyboard-config: bring back the progress bar 2019-11-01 10:45:43 +02:00