Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Correctly handle bindings for the same mod key with and without --rel…
Browse files Browse the repository at this point in the history
…ease

Before this commit, get_binding() exited on the first match without
marking the rest --release bindings with B_UPON_KEYRELEASE_IGNORE_MODS.

Similarly, once it found a --release binding during a KeyPress event it
would stop searching for a matching key press binding.

Example config, placing the --release line first will trigger the second
problem:

# i3 config file (v4)
bindsym Super_L exec notify-send "press"
# or
# bindcode 133 exec notify-send "press"
bindsym --release Super_L exec notify-send "release"
# or
# bindcode --release 133 exec notify-send "release"

Fixes #2733
  • Loading branch information
orestisfl committed Mar 20, 2018
1 parent 130b3ce commit ff579ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ void regrab_all_buttons(xcb_connection_t *conn) {
*/
static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_release, uint16_t input_code, input_type_t input_type) {
Binding *bind;
Binding *result = NULL;

if (!is_release) {
/* On a press event, we first reset all B_UPON_KEYRELEASE_IGNORE_MODS
Expand Down Expand Up @@ -271,23 +272,26 @@ static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_releas
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;
if (result) {
break;
}
continue;
}

/* Check if the binding is for a press or a release event */
if ((bind->release == B_UPON_KEYPRESS && is_release) ||
(bind->release >= B_UPON_KEYRELEASE && !is_release)) {
if ((bind->release == B_UPON_KEYPRESS && is_release)) {
continue;
}

break;
if (is_release) {
return bind;
} else if (!result) {
/* Continue looping to mark needed B_UPON_KEYRELEASE_IGNORE_MODS. */
result = bind;
}
}

return (bind == TAILQ_END(bindings) ? NULL : bind);
return result;
}

/*
Expand Down
24 changes: 24 additions & 0 deletions testcases/t/258-keypress-release.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ bindsym Mod1+b nop Mod1+b
bindsym --release Mod1+Shift+b nop Mod1+Shift+b release
bindsym --release Shift+x nop Shift+x
# see issue #2733
# 133 == Mod4
bindcode 133 nop 133
bindcode --release 133 nop 133 release
EOT
use i3test::XTEST;
use ExtUtils::PkgConfig;
Expand Down Expand Up @@ -110,6 +115,25 @@ is(listen_for_binding(
),
'Shift+x',
'triggered the "Shift+x" keybinding by releasing Shift first');

is(listen_for_binding(
sub {
xtest_key_press(133);
xtest_sync_with_i3;
},
),
'133',
'triggered the 133 keycode press binding');

is(listen_for_binding(
sub {
xtest_key_release(133);
xtest_sync_with_i3;
},
),
'133 release',
'triggered the 133 keycode release binding');

}

done_testing;

0 comments on commit ff579ef

Please sign in to comment.