Skip to content

loadkeys: Add --tkeymap to dump the keymap as text#132

Merged
legionus merged 1 commit intolegionus:masterfrom
wismill:loadkeys/dump
May 31, 2025
Merged

loadkeys: Add --tkeymap to dump the keymap as text#132
legionus merged 1 commit intolegionus:masterfrom
wismill:loadkeys/dump

Conversation

@wismill
Copy link
Copy Markdown
Contributor

@wismill wismill commented May 31, 2025

Before this commit, the loadkeys tool enabled to dump a keymap in various formats (binary, C) but not in its own text format. However, there are some use cases that require text format:

  • reformatting;
  • golden test;
  • round-trip test;
  • convert XKB keymaps and thus replace ckbcomp1 (requires the upcoming XKB support).

Added the --tkeymap (short: -t) options to the loadkeys tool, enabling dumping the keymap in text format after parsing it.

The output format (shape) can be optionally specified, e.g. --tkeymap=4 for a full table.

The option name mirrors the --bkeymap option that outputs a binary table, so that option names are consistent: --{b,t}keymap.

Footnotes

  1. https://manpages.debian.org/buster/console-setup/ckbcomp.1.en.html

Before this commit, the loadkeys tool enabled to dump a keymap in
various formats (binary, C) but not in its own text format. However,
there are some use cases that require text format:

- reformatting;
- golden test;
- round-trip test;
- convert XKB keymaps and thus replace ckbcomp[^1] (requires the
  upcoming XKB support).

Added the `--tkeymap` (short: `-t`) options to the loadkeys tool,
enabling dumping the keymap in *text* format after parsing it.

The output format (shape) can be optionally specified, e.g. `--tkeymap=4`
for a full table.

The option name mirrors the `--bkeymap` option that outputs a *binary*
table, so that option names are consistent: `--{b,t}keymap`.

[^1]: https://manpages.debian.org/buster/console-setup/ckbcomp.1.en.html

Signed-off-by: Pierre Le Marre <dev@wismill.eu>
@wismill
Copy link
Copy Markdown
Contributor Author

wismill commented May 31, 2025

While the shape can be chosen, it will always print the strings and Compose entries. I am not sure what is the best approach here.

Also, it seems that shapes 2 and 16 do not roundtrip, e.g. dumpkeys -S2 | loadkeys -u -t2 - does not produce the same output as dumpkeys -S2, although they seem implemented with the same functions.

@legionus
Copy link
Copy Markdown
Owner

While the shape can be chosen, it will always print the strings and Compose entries. I am not sure what is the best approach here.

Also, it seems that shapes 2 and 16 do not roundtrip, e.g. dumpkeys -S2 | loadkeys -u -t2 - does not produce the same output as dumpkeys -S2, although they seem implemented with the same functions.

Hm. Indeed. Really interesting effect.

$ ./dumpkeys -S2 > out.dumpkeys.txt
$ ./loadkeys -u -t2 - < out.dumpkeys.txt > out.loadkeys.txt
--- out.dumpkeys.txt      2025-05-31 17:01:32.693525586 +0200
+++ out.loadkeys.txt      2025-05-31 17:06:29.921167687 +0200
@@ -397,2 +397 @@
-keycode  58 = AltGr_Lock
-       shift   keycode  58 = Caps_Lock
+keycode  58 = AltGr_Lock       Caps_Lock
@@ -508 +506,0 @@
-       shift   control keycode  87 = VoidSymbol
@@ -510 +507,0 @@
-       shift   alt     keycode  87 = VoidSymbol
@@ -512 +508,0 @@
-       shift   altgr   alt     keycode  87 = VoidSymbol
@@ -516 +511,0 @@
-       shift   control keycode  88 = VoidSymbol
@@ -518 +512,0 @@
-       shift   alt     keycode  88 = VoidSymbol
@@ -520 +513,0 @@
-       shift   altgr   alt     keycode  88 = VoidSymbol
@@ -527 +519,0 @@
-       shift   control keycode  99 = VoidSymbol
@@ -533,2 +525 @@
-keycode 104 = Prior
-       shift   keycode 104 = Scroll_Backward
+keycode 104 = Prior            Scroll_Backward
@@ -542,2 +533 @@
-keycode 109 = Next
-       shift   keycode 109 = Scroll_Forward
+keycode 109 = Next             Scroll_Forward

There seems to be a problem with the processing of VoidSymbol i.e. K(KT_SPEC, 0).

However that's a different issue and not relevant to adding an option. The patch code seems correct to me.

@legionus legionus merged commit b1bf002 into legionus:master May 31, 2025
14 of 16 checks passed
@wismill wismill deleted the loadkeys/dump branch May 31, 2025 17:08
@wismill
Copy link
Copy Markdown
Contributor Author

wismill commented Jun 1, 2025

@legionus there seem to be an issue with CI.

@legionus
Copy link
Copy Markdown
Owner

legionus commented Jun 1, 2025

@legionus there seem to be an issue with CI.

@wismill Yeah. That's why I'm already merge it.

The problem in CI with one test and only on ppc64le. On this test valgrind sometimes fails with a very strange error. I am still looking for ways to solve this.

https://gist.github.com/legionus/a6f5eeca4f86d9142d5377158ae420eb

@legionus
Copy link
Copy Markdown
Owner

legionus commented Jun 1, 2025

I have added a commit to master that disables this buggy test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants