summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Antti Korpimäki2021-12-13 13:08:58 +0100
committerGravatar Antti Korpimäki2021-12-13 13:08:58 +0100
commit0b9c1bce1f71fa870e624055a86e6fb73690dfde (patch)
tree54d2a8c18c872b808143e7bc20c7208fb4dcd1d8
parentdc5d4e0919b2f1fd18aee16468a23a6631c26251 (diff)
downloadxkbcat-0b9c1bce1f71fa870e624055a86e6fb73690dfde.tar.gz
xkbcat-0b9c1bce1f71fa870e624055a86e6fb73690dfde.zip
Use group 0 if current group contains no keysym
Fixes #5, perhaps fully this time. It seems non-zero keysym groups work such that if no keysym is defined in it, the default 0 group's keysym is assumed. In other words, common keys that would otherwise just be duplicated in the group's definition, such as Return, Backspace, Delete, Shift, Space, or the numpad keys, just have no symbol mapped to them at all in the group (XkbKeycodeToKeysym returns NoSymbol). In such cases, it seems the receiving program is expected to just fall back to group 0 and read the keysym from there instead. This is about XKeycodeToKeysym, but XkbKeycodeToKeysym which we're using (note the different prefix) seems to function the same: https://stackoverflow.com/questions/54483276/xkeysymtokeycode-and-keyboard-layout This seems to be correct with the keyboard layouts I've tested. - - - Other Xlib users have replaced XKeycodeToKeysym with XGetKeyboardMapping instead. These patches to that effect imply XKeycodeToKeysym is deprecated: - https://lists.freedesktop.org/archives/piglit/2012-January/001795.html - https://github.com/ArcticaProject/nx-libs/commit/c79f2d289004d419d8bb76cf8bf731980d40da5d XkbKeycodeToKeysym is not deprecated though, and seems a much better fit here than doing heap allocations in a loop, so I'll go with it.
-rw-r--r--xkbcat.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/xkbcat.c b/xkbcat.c
index c56cce0..5e28cc2 100644
--- a/xkbcat.c
+++ b/xkbcat.c
@@ -125,7 +125,20 @@ int main(int argc, char * argv[]) {
// regardless of what modifiers are held down.
KeySym s = XkbKeycodeToKeysym(
disp, ev->detail, group, 0 /*shift level*/);
- if (NoSymbol == s) continue;
+
+ // Non-zero keysym groups are "overlays" on the base (`0`)
+ // group. If the current group has no keysym for this
+ // keycode, defer to the base group instead. (This usually
+ // happens with common shared keys like Return, Backspace,
+ // or numeric keypad keys.)
+ if (NoSymbol == s) {
+ if (group == 0) continue;
+ else {
+ s = XkbKeycodeToKeysym(disp, ev->detail,
+ 0 /* base group */, 0 /*shift level*/);
+ if (NoSymbol == s) continue;
+ }
+ }
char *str = XKeysymToString(s);
if (NULL == str) continue;