Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Feb 12, 2024
1 parent 1b0464e commit b5e3084
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 58 deletions.
71 changes: 42 additions & 29 deletions test/data/keymaps/real-modifiers.xkb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ xkb_keycodes "test" {
};

xkb_types "complete" {
// Define a buch of virtual modifier to test mappings to Mod5-Mod10 real
// modifiers. WonderMod will be mapped to Mod5+Mod6.
virtual_modifiers MyMod5,MyMod6,MyMod6,MyMod7,MyMod8,MyMod9,MyMod10,WonderMod;

type "ONE_LEVEL" {
Expand All @@ -37,7 +39,7 @@ xkb_types "complete" {
level_name[1]= "Base";
level_name[2]= "Shift";
};
type "SO_MANY_LEVELS" {
type "SOOO_MANY_LEVELS" {
modifiers = Shift+MyMod5+MyMod6+MyMod6+MyMod7+MyMod8+MyMod9+MyMod10+WonderMod;
map[Shift] = 2;
map[MyMod5] = 3;
Expand Down Expand Up @@ -71,42 +73,43 @@ xkb_compatibility "complete" {
action = SetMods(modifiers=modMapMods,clearLocks);
};

interpret q {
// Define some letter keysyms as custom modifiers
interpret Q {
useModMapMods = level1;
virtualModifier = MyMod5;
action = SetMods(modifiers=MyMod5);
};
interpret w {
interpret W {
useModMapMods = level1;
virtualModifier = MyMod6;
action = SetMods(modifiers=MyMod6);
};
interpret e {
interpret E {
useModMapMods = level1;
virtualModifier = MyMod7;
action = SetMods(modifiers=MyMod7);
};
interpret r {
interpret R {
useModMapMods = level1;
virtualModifier = MyMod8;
action = SetMods(modifiers=MyMod8);
};
interpret t {
interpret T {
useModMapMods = level1;
virtualModifier = MyMod9;
action = SetMods(modifiers=MyMod9);
};
interpret y {
interpret Y {
useModMapMods = level1;
virtualModifier = MyMod10;
action = SetMods(modifiers=MyMod10);
};
interpret u {
interpret U {
useModMapMods = level1;
virtualModifier = WonderMod;
action = SetMods(modifiers=WonderMod);
};
interpret i {
interpret I {
useModMapMods = level1;
virtualModifier = WonderMod;
action = SetMods(modifiers=WonderMod);
Expand All @@ -115,36 +118,46 @@ xkb_compatibility "complete" {
xkb_symbols {
name[group1]="Test";

key <LFSH> { [Shift_L] };
modmap Shift { <LFSH> };
// Map the modifiers. The letter keysyms only serve to map
// the modifier actions (see interpret entries above).

key <AD01> { [q] };
modMap Mod5 { <AD01> };
key <LFSH> { [Shift_L] };
modifier_map Shift { <LFSH> };

key <AD02> { [w] };
modMap Mod6 { <AD02> };
// virtual modifier: MyMod5
key <AD01> { [Q] };
modifier_map Mod5 { <AD01> };

key <AD03> { [e] };
modMap Mod7 { <AD03> };
// virtual modifier: MyMod6
key <AD02> { [W] };
modifier_map Mod6 { <AD02> }; // real modifier not supported by X11

key <AD04> { [r] };
modMap Mod8 { <AD04> };
// virtual modifier: MyMod7
key <AD03> { [E] };
modifier_map Mod7 { <AD03> }; // real modifier not supported by X11

key <AD05> { [t] };
modMap Mod9 { <AD05> };
// virtual modifier: MyMod8
key <AD04> { [R] };
modifier_map Mod8 { <AD04> }; // real modifier not supported by X11

key <AD06> { [y] };
modMap Mod10 { <AD06> };
// virtual modifier: MyMod9
key <AD05> { [T] };
modifier_map Mod9 { <AD05> }; // real modifier not supported by X11

key <AD07> { [u] };
modMap Mod5 { <AD07> };
// virtual modifier: MyMod10
key <AD06> { [Y] };
modifier_map Mod10 { <AD06> }; // real modifier not supported by X11

key <AD08> { [i] };
modMap Mod6 { <AD08> };
// virtual modifier: WonderMod (Mod5+Mod6)
key <AD07> { [U] };
modifier_map Mod5 { <AD07> };
key <AD08> { [I] };
modifier_map Mod6 { <AD08> }; // real modifier not supported by X11

// Key to test that all the levels work
key <AD09> {
type[Group1]="SO_MANY_LEVELS",
symbols[Group1]=[a,b,c,d,e,f,g,h,i,j]
type[Group1]="SOOO_MANY_LEVELS",
symbols[Group1]=[1,2,3,4,5,6,7,8,9,A]
};

};
Expand Down
91 changes: 62 additions & 29 deletions test/modifiers.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define Mod8Mask (1 << 10)
#define Mod9Mask (1 << 11)
#define Mod10Mask (1 << 12)
#define HighestRealMask Mod10Mask
#define NoModifier 0

static void
Expand Down Expand Up @@ -172,42 +173,74 @@ test_real_mods(void)
assert(keycode != XKB_KEYCODE_INVALID);
key = XkbKey(keymap, keycode);
assert(key->modmap == Mod5Mask);
assert(key->vmodmap == Mod10Mask << 1);
/* Test that MyMod5 is the first defined virtual modifier */
assert(key->vmodmap == HighestRealMask << 1);

keycode = xkb_keymap_key_by_name(keymap, "AD02");
assert(keycode != XKB_KEYCODE_INVALID);
key = XkbKey(keymap, keycode);
assert(key->modmap == Mod6Mask);
assert(key->vmodmap == Mod10Mask << 2);
/* Test that MyMod5 is the second defined virtual modifier */
assert(key->vmodmap == HighestRealMask << 2);

/* Test that we get the expected keysym for each level of KEY_O (<AD09>).
* Most levels require support of the real modifiers Mod6-Mod10. */
assert(test_key_seq(keymap,
KEY_O, BOTH, XKB_KEY_a, NEXT,
KEY_Q, DOWN, XKB_KEY_q, NEXT,
KEY_O, BOTH, XKB_KEY_c, NEXT,
KEY_Q, UP, XKB_KEY_q, NEXT,
KEY_W, DOWN, XKB_KEY_w, NEXT,
KEY_O, BOTH, XKB_KEY_d, NEXT,
KEY_W, UP, XKB_KEY_w, NEXT,
KEY_E, DOWN, XKB_KEY_e, NEXT,
KEY_O, BOTH, XKB_KEY_f, NEXT,
KEY_E, UP, XKB_KEY_e, NEXT,
KEY_R, DOWN, XKB_KEY_r, NEXT,
KEY_O, BOTH, XKB_KEY_g, NEXT,
KEY_R, UP, XKB_KEY_r, NEXT,
KEY_T, DOWN, XKB_KEY_t, NEXT,
KEY_O, BOTH, XKB_KEY_h, NEXT,
KEY_T, UP, XKB_KEY_t, NEXT,
KEY_Y, DOWN, XKB_KEY_y, NEXT,
KEY_O, BOTH, XKB_KEY_i, NEXT,
KEY_Y, UP, XKB_KEY_y, NEXT,
KEY_U, DOWN, XKB_KEY_u, NEXT,
KEY_O, BOTH, XKB_KEY_j, NEXT,
KEY_U, UP, XKB_KEY_u, NEXT,
KEY_Q, DOWN, XKB_KEY_q, NEXT,
KEY_W, DOWN, XKB_KEY_w, NEXT,
KEY_O, BOTH, XKB_KEY_j, NEXT,
KEY_W, UP, XKB_KEY_w, NEXT,
KEY_Q, UP, XKB_KEY_q, FINISH));
/* Level 1 */
KEY_O, BOTH, XKB_KEY_1, NEXT,
/* Level 2 */
KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L, NEXT,
KEY_O, BOTH, XKB_KEY_2, NEXT,
KEY_LEFTSHIFT, UP, XKB_KEY_Shift_L, NEXT,
/* Level 3 (MyMod5 = Mod5) */
KEY_Q, DOWN, XKB_KEY_Q, NEXT,
KEY_O, BOTH, XKB_KEY_3, NEXT,
KEY_Q, UP, XKB_KEY_Q, NEXT,
/* Level 4 (MyMod6 = Mod6) */
KEY_W, DOWN, XKB_KEY_W, NEXT,
KEY_O, BOTH, XKB_KEY_4, NEXT,
/* Level 5 (MyMod6 + Shift = Mod6 + Shift) */
KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L, NEXT,
KEY_O, BOTH, XKB_KEY_5, NEXT,
KEY_LEFTSHIFT, UP, XKB_KEY_Shift_L, NEXT,
KEY_W, UP, XKB_KEY_W, NEXT,
/* Level 6 (MyMod7 = Mod7) */
KEY_E, DOWN, XKB_KEY_E, NEXT,
KEY_O, BOTH, XKB_KEY_6, NEXT,
KEY_E, UP, XKB_KEY_E, NEXT,
/* Level 7 (MyMod8 = Mod8) */
KEY_R, DOWN, XKB_KEY_R, NEXT,
KEY_O, BOTH, XKB_KEY_7, NEXT,
KEY_R, UP, XKB_KEY_R, NEXT,
/* Level 8 (MyMod9 = Mod9) */
KEY_T, DOWN, XKB_KEY_T, NEXT,
KEY_O, BOTH, XKB_KEY_8, NEXT,
KEY_T, UP, XKB_KEY_T, NEXT,
/* Level 9 (MyMod10 = Mod10) */
KEY_Y, DOWN, XKB_KEY_Y, NEXT,
KEY_O, BOTH, XKB_KEY_9, NEXT,
KEY_Y, UP, XKB_KEY_Y, NEXT,
/* Level 10 using KEY_U (WonderMod = Mod5 + Mod6) */
KEY_U, DOWN, XKB_KEY_U, NEXT,
KEY_O, BOTH, XKB_KEY_A, NEXT,
KEY_U, UP, XKB_KEY_U, NEXT,
/* Level 10 using KEY_I (WonderMod = Mod5 + Mod6) */
KEY_I, DOWN, XKB_KEY_I, NEXT,
KEY_O, BOTH, XKB_KEY_A, NEXT,
KEY_I, UP, XKB_KEY_I, NEXT,
/* Level 10 using KEY_Q + KEY_W
* MyMod5 + MyMod6 = Mod5 + Mod6 = WonderMod */
KEY_Q, DOWN, XKB_KEY_Q, NEXT,
KEY_W, DOWN, XKB_KEY_W, NEXT,
KEY_O, BOTH, XKB_KEY_A, NEXT,
KEY_W, UP, XKB_KEY_W, NEXT,
KEY_Q, UP, XKB_KEY_Q, NEXT,
/* Invalid level, fallback to base level */
KEY_W, DOWN, XKB_KEY_W, NEXT,
KEY_E, DOWN, XKB_KEY_E, NEXT,
KEY_O, BOTH, XKB_KEY_1, NEXT,
KEY_E, UP, XKB_KEY_E, NEXT,
KEY_W, UP, XKB_KEY_W, FINISH));

xkb_keymap_unref(keymap);
xkb_context_unref(context);
Expand Down

0 comments on commit b5e3084

Please sign in to comment.