From 2244c843a8cc4055dabb314f8547e34b1269b8b3 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 12 Sep 2016 12:57:13 +0200 Subject: [PATCH] =?utf8?q?Bugfix:=20don=E2=80=99t=20trigger=20unrelated=20?= =?utf8?q?key=20bindings=20for=20--release=20bindings?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit fixes #2442 --- src/bindings.c | 9 ++++++++- testcases/t/258-keypress-release.t | 30 +++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index db88aee3..463a4f62 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -271,8 +271,15 @@ static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_releas * user pressed. We therefore mark it as B_UPON_KEYRELEASE_IGNORE_MODS * for later, so that the user can release the modifiers before the * actual key or button and the release event will still be matched. */ - if (bind->release == B_UPON_KEYRELEASE && !is_release) + if (bind->release == B_UPON_KEYRELEASE && !is_release) { bind->release = B_UPON_KEYRELEASE_IGNORE_MODS; + DLOG("marked bind %p as B_UPON_KEYRELEASE_IGNORE_MODS\n", bind); + /* The correct binding has been found, so abort the search, but + * also don’t return this binding, since it should not be executed + * yet (only when the keys are released). */ + bind = TAILQ_END(bindings); + break; + } /* Check if the binding is for a press or a release event */ if ((bind->release == B_UPON_KEYPRESS && is_release) || diff --git a/testcases/t/258-keypress-release.t b/testcases/t/258-keypress-release.t index 4c2775b6..b0d77858 100644 --- a/testcases/t/258-keypress-release.t +++ b/testcases/t/258-keypress-release.t @@ -33,6 +33,10 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 bindsym Print nop Print bindsym --release Control+Print nop Control+Print + +# see issue #2442 +bindsym Mod1+b nop Mod1+b +bindsym --release Mod1+Shift+b nop Mod1+Shift+b release EOT my $pid = launch_with_config($config); @@ -59,8 +63,32 @@ is(listen_for_binding( 'Control+Print', 'triggered the "Control+Print" keybinding'); +is(listen_for_binding( + sub { + xtest_key_press(64); # Alt_L + xtest_key_press(56); # b + xtest_key_release(56); # b + xtest_key_release(64); # Alt_L + }, + ), + 'Mod1+b', + 'triggered the "Mod1+b" keybinding'); + +is(listen_for_binding( + sub { + xtest_key_press(64); # Alt_L + xtest_key_press(50); # Shift_L + xtest_key_press(56); # b + xtest_key_release(56); # b + xtest_key_release(50); # Shift_L + xtest_key_release(64); # Alt_L + }, + ), + 'Mod1+Shift+b release', + 'triggered the "Mod1+Shift+b" release keybinding'); + sync_with_i3; -is(scalar @i3test::XTEST::binding_events, 2, 'Received exactly 2 binding events'); +is(scalar @i3test::XTEST::binding_events, 4, 'Received exactly 4 binding events'); exit_gracefully($pid); -- 2.39.5