Skip to content

Commit

Permalink
mods: Add more built-in names
Browse files Browse the repository at this point in the history
Changed the value of the following constant to match the actual
name of their corresponding modifier:
- `XKB_MOD_NAME_ALT`
- `XKB_MOD_NAME_LOGO`
- `XKB_MOD_NAME_NUM`

Added support for the following modifiers:
- `Meta`
- `Super` (alternative constant)
- `Hyper`
- `LevelThree`
- `LevelFive`
- `ScrollLock`
  • Loading branch information
wismill committed Sep 27, 2024
1 parent 601425e commit aed910b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
9 changes: 9 additions & 0 deletions changes/api/+modified-modifiers-names.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The following constants for modifiers names were modified to match the actual
names and not their corresponding real modifier mapping:
- `XKB_MOD_NAME_ALT`: `Alt` (was: `Mod1`)
- `XKB_MOD_NAME_LOGO`: `Super` (was: `Mod4`)
- `XKB_MOD_NAME_NUM`: `NumLock` (was: `Mod2`)

This is a breaking change per se, but together with the changes in the functions
`xkb_state_mod_*_active` it should has no visible impact. In fact it will make
these functions resilient to unusual modifiers mappings.
12 changes: 12 additions & 0 deletions changes/api/+new-modifiers-names.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Added the following modifiers names definitions in `xkbcommon-names.h`:
- `XKB_MOD_NAME_MOD1`
- `XKB_MOD_NAME_MOD2`
- `XKB_MOD_NAME_MOD3`
- `XKB_MOD_NAME_MOD4`
- `XKB_MOD_NAME_MOD5`
- `XKB_MOD_NAME_META`
- `XKB_MOD_NAME_SUPER`
- `XKB_MOD_NAME_HYPER`
- `XKB_MOD_NAME_LEVEL3`
- `XKB_MOD_NAME_LEVEL5`
- `XKB_MOD_NAME_SCROLL`
16 changes: 12 additions & 4 deletions include/xkbcommon/xkbcommon-names.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@
#define XKB_MOD_NAME_MOD4 "Mod4"
#define XKB_MOD_NAME_MOD5 "Mod5"

/* Usual virtual modifiers mappings to real modifiers */
#define XKB_MOD_NAME_ALT "Mod1"
#define XKB_MOD_NAME_NUM "Mod2"
#define XKB_MOD_NAME_LOGO "Mod4"
/* Common virtual modifiers, encoded in xkeyboard-config in the compat and
* symbols files. They have been stable since the beginning of the project and
* are unlikely to ever change. */
#define XKB_MOD_NAME_ALT "Alt"
#define XKB_MOD_NAME_META "Meta"
#define XKB_MOD_NAME_SUPER "Super"
#define XKB_MOD_NAME_HYPER "Hyper"
#define XKB_MOD_NAME_LOGO XKB_MOD_NAME_SUPER
#define XKB_MOD_NAME_NUM "NumLock"
#define XKB_MOD_NAME_LEVEL3 "LevelThree"
#define XKB_MOD_NAME_LEVEL5 "LevelFive"
#define XKB_MOD_NAME_SCROLL "ScrollLock"

/* LEDs names are encoded in xkeyboard-config, in the keycodes and compat files.
* They have been stable since the beginning of the project and are unlikely to
Expand Down
29 changes: 29 additions & 0 deletions test/modifiers.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ test_real_mod(struct xkb_keymap *keymap, const char* name,
mapping == (1u << idx);
}

static bool
test_virtual_mod(struct xkb_keymap *keymap, const char* name,
xkb_mod_index_t idx, xkb_mod_mask_t mapping)
{
return xkb_keymap_mod_get_index(keymap, name) == idx &&
(keymap->mods.mods[idx].type == MOD_VIRT) &&
mapping == keymap->mods.mods[idx].mapping;
}

/* Check that the provided modifier names work */
static void
test_modifiers_names(struct xkb_context *context)
Expand All @@ -80,6 +89,26 @@ test_modifiers_names(struct xkb_context *context)
assert(test_real_mod(keymap, XKB_MOD_NAME_MOD4, Mod4Index, Mod4Mask));
assert(test_real_mod(keymap, XKB_MOD_NAME_MOD5, Mod5Index, Mod5Mask));

/* Virtual modifiers
* The indexes depends on the keymap files */
assert(test_virtual_mod(keymap, XKB_MOD_NAME_ALT, Mod5Index + 2, Mod1Mask));
assert(test_virtual_mod(keymap, XKB_MOD_NAME_META, Mod5Index + 11, Mod1Mask));
assert(test_virtual_mod(keymap, XKB_MOD_NAME_NUM, Mod5Index + 1, Mod2Mask));
assert(test_virtual_mod(keymap, XKB_MOD_NAME_SUPER, Mod5Index + 12, Mod4Mask));
assert(test_virtual_mod(keymap, XKB_MOD_NAME_LOGO, Mod5Index + 12, Mod4Mask));
assert(test_virtual_mod(keymap, XKB_MOD_NAME_HYPER, Mod5Index + 13, Mod4Mask));
assert(test_virtual_mod(keymap, XKB_MOD_NAME_LEVEL3, Mod5Index + 3, Mod5Mask));
assert(test_virtual_mod(keymap, XKB_MOD_NAME_SCROLL, Mod5Index + 8, 0));
/* TODO: current xkeyboard-config maps LevelFive to Nod3 by default */
assert(test_virtual_mod(keymap, XKB_MOD_NAME_LEVEL5, Mod5Index + 9, 0));
/* Legacy stuff, removed from xkeyboard-config */
assert(keymap->mods.num_mods == 21);
assert(test_virtual_mod(keymap, "LAlt", Mod5Index + 4, 0));
assert(test_virtual_mod(keymap, "RAlt", Mod5Index + 5, 0));
assert(test_virtual_mod(keymap, "LControl", Mod5Index + 7, 0));
assert(test_virtual_mod(keymap, "RControl", Mod5Index + 6, 0));
assert(test_virtual_mod(keymap, "AltGr", Mod5Index + 10, Mod5Mask));

xkb_keymap_unref(keymap);
}

Expand Down
4 changes: 2 additions & 2 deletions test/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ test_update_mask_mods(struct xkb_keymap *keymap)
assert(caps != XKB_MOD_INVALID);
shift = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_SHIFT);
assert(shift != XKB_MOD_INVALID);
num = xkb_keymap_mod_get_index(keymap, "NumLock");
num = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM);
assert(num != XKB_MOD_INVALID);
alt = xkb_keymap_mod_get_index(keymap, "Alt");
alt = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_ALT);
assert(alt != XKB_MOD_INVALID);
mod1 = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_MOD1);
assert(mod1 != XKB_MOD_INVALID);
Expand Down

0 comments on commit aed910b

Please sign in to comment.