Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions: Break latch on modifier/group changes #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ xkb_action_breaks_latch(const union xkb_action *action)
case ACTION_TYPE_CTRL_LOCK:
case ACTION_TYPE_SWITCH_VT:
case ACTION_TYPE_TERMINATE:
case ACTION_TYPE_MOD_SET:
case ACTION_TYPE_MOD_LATCH:
case ACTION_TYPE_MOD_LOCK:
case ACTION_TYPE_GROUP_SET:
case ACTION_TYPE_GROUP_LATCH:
case ACTION_TYPE_GROUP_LOCK:
return true;
default:
return false;
Expand Down
13 changes: 13 additions & 0 deletions test/data/compat/testlatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
partial default xkb_compatibility "testlatch" {
interpret Shift_L {
action= LatchMods(modifiers=Shift);
};

interpret Lock+Exactly(Shift) {
action= LockMods(modifiers=Lock,affect=lock);
};

interpret Lock+Exactly(Shift+Lock) {
action= LockMods(modifiers=Lock,affect=unlock);
};
};
2 changes: 2 additions & 0 deletions test/data/rules/evdev
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
* $sun_custom $sun_var = pc+sun_vndr/%l%(v)

! model layout = symbols
testlatch * = testlatch(%l)
* ar = pc+ara
* ben = pc+in(ben)
* bs = pc+ba
Expand Down Expand Up @@ -893,6 +894,7 @@
* jp = complete+japan
olpc * = olpc
olpcm * = olpc
testlatch * = complete+testlatch
* * = complete

! model layout[1] = compat
Expand Down
58 changes: 58 additions & 0 deletions test/data/symbols/testlatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Latch behaviour testing

partial default alphanumeric_keys
xkb_symbols "us" {
name[Group1] = "English";

include "testlatch(base)"


key <AD01> { [ q, Q ]};
key <AD02> { [ w, W ]};
key <AD03> { [ e, E ]};
key <AD04> { [ r, R ]};
key <AD05> { [ t, T ]};
key <AD06> { [ y, Y ]};
key <AD07> { [ u, U ]};
key <AD08> { [ i, I ]};
key <AD09> { [ o, O ]};
key <AD10> { [ p, P ]};

key <AC01> { [ a, A ]};
key <AC02> { [ s, S ]};
key <AC03> { [ d, D ]};
key <AC04> { [ f, F ]};
key <AC05> { [ g, G ]};
key <AC06> { [ h, H ]};
key <AC07> { [ j, J ]};
key <AC08> { [ k, K ]};
key <AC09> { [ l, L ]};

key <AB01> { [ z, Z ]};
key <AB02> { [ x, X ]};
key <AB03> { [ c, C ]};
key <AB04> { [ v, V ]};
key <AB05> { [ b, B ]};
key <AB06> { [ n, N ]};
key <AB07> { [ m, M ]};
};

partial alphanumeric_keys
xkb_symbols "base" {
key <ESC> { [ Escape ] };

// We want Shift to latch normally, but also to produce caps when pressed
// twice in a row.
key <LFSH> { [ Shift_L, Caps_Lock ] };

key <AE01> { [ 1, exclam ]};
key <AE02> { [ 2, quotedbl ]};
key <AE03> { [ 3, currency ]};
key <AE04> { [ 4, at ]};
key <AE05> { [ 5, percent ]};
key <AE06> { [ 6, question ]};
key <AE07> { [ 7, minus ]};
key <AE08> { [ 8, plus ]};
key <AE09> { [ 9, apostrophe ]};
key <AE10> { [ 0, equal ]};
};
50 changes: 50 additions & 0 deletions test/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,54 @@ test_ctrl_string_transformation(struct xkb_keymap *keymap)
xkb_state_unref(state);
}

static void
test_latch_mod_cancel(struct xkb_context *context)
{
struct xkb_keymap *keymap;

keymap = test_compile_rules(context, "evdev", "testlatch", "us",
NULL, NULL);
assert(keymap);

assert(test_key_seq(keymap,
KEY_A, BOTH, XKB_KEY_a, NEXT, /* plain a */
KEY_1, BOTH, XKB_KEY_1, NEXT, /* plain 1 */

KEY_LEFTSHIFT, BOTH, XKB_KEY_Shift_L, NEXT,
KEY_A, BOTH, XKB_KEY_A, NEXT, /* shift latched */
KEY_A, BOTH, XKB_KEY_a, NEXT, /* ... and unlatched */

KEY_LEFTSHIFT, BOTH, XKB_KEY_Shift_L, NEXT,
KEY_1, BOTH, XKB_KEY_exclam, NEXT, /* and again */
KEY_1, BOTH, XKB_KEY_1, NEXT,

KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L, NEXT,
KEY_1, BOTH, XKB_KEY_exclam, NEXT, /* should unlatch */
KEY_LEFTSHIFT, UP, XKB_KEY_Caps_Lock, NEXT,
KEY_1, BOTH, XKB_KEY_1, NEXT,

KEY_LEFTSHIFT, BOTH, XKB_KEY_Shift_L, NEXT,
KEY_LEFTSHIFT, BOTH, XKB_KEY_Caps_Lock, NEXT, /* caps lock! */
/* Without the change we fail here, as Lock is locked but Shift still latched */
KEY_A, BOTH, XKB_KEY_A, NEXT,
KEY_1, BOTH, XKB_KEY_1, NEXT,
KEY_LEFTSHIFT, BOTH, XKB_KEY_Shift_L, NEXT,
KEY_1, BOTH, XKB_KEY_exclam, NEXT, /* shift latched */
KEY_1, BOTH, XKB_KEY_1, NEXT, /* ... and unlatched */
KEY_LEFTSHIFT, BOTH, XKB_KEY_Shift_L, NEXT,
KEY_A, BOTH, XKB_KEY_a, NEXT, /* shift latched, cancel */
KEY_A, BOTH, XKB_KEY_A, NEXT,

KEY_LEFTSHIFT, BOTH, XKB_KEY_Shift_L, NEXT,
KEY_LEFTSHIFT, BOTH, XKB_KEY_Caps_Lock, NEXT, /* caps unlock */

KEY_A, BOTH, XKB_KEY_a, NEXT,
KEY_A, BOTH, XKB_KEY_a, NEXT,
KEY_1, BOTH, XKB_KEY_1, FINISH));

xkb_keymap_unref(keymap);
}

int
main(void)
{
Expand Down Expand Up @@ -738,6 +786,8 @@ main(void)

test_caps_keysym_transformation(keymap);

test_latch_mod_cancel(context);

xkb_keymap_unref(keymap);
xkb_context_unref(context);
}