From e6b41172da01225747f4551d95d4eac64befb4fa Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 30 Jun 2023 08:57:19 +0200 Subject: Regrab buttons on mode change (#5554) Unfortunately, grabbing / ungrabbing doesn't seem to work correctly in xvfb so we can't really test this. I also fixed the deduplication code in bindings_get_buttons_to_grab(). --- release-notes/bugfixes/3-bindsym-button-mode | 1 + src/bindings.c | 14 +++-- testcases/t/320-mouse-bindings.t | 89 ++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 release-notes/bugfixes/3-bindsym-button-mode create mode 100644 testcases/t/320-mouse-bindings.t diff --git a/release-notes/bugfixes/3-bindsym-button-mode b/release-notes/bugfixes/3-bindsym-button-mode new file mode 100644 index 00000000..8d929d3b --- /dev/null +++ b/release-notes/bugfixes/3-bindsym-button-mode @@ -0,0 +1 @@ +fix mouse bindings in modes diff --git a/src/bindings.c b/src/bindings.c index 2c8d5970..e5804919 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -631,6 +631,7 @@ void switch_mode(const char *new_mode) { current_binding_mode = mode->name; translate_keysyms(); grab_all_keys(conn); + regrab_all_buttons(conn); /* Reset all B_UPON_KEYRELEASE_IGNORE_MODS bindings to avoid possibly * activating one of them. */ @@ -1008,7 +1009,7 @@ bool load_keymap(void) { int *bindings_get_buttons_to_grab(void) { /* Let's make the reasonable assumption that there's no more than 25 * buttons. */ - int num_max = 25; + const int num_max = 25; int buffer[num_max]; int num = 0; @@ -1034,12 +1035,17 @@ int *bindings_get_buttons_to_grab(void) { } /* Avoid duplicates. */ + bool exists = false; for (int i = 0; i < num; i++) { - if (buffer[i] == button) - continue; + if (buffer[i] == button) { + exists = true; + break; + } } - buffer[num++] = button; + if (!exists) { + buffer[num++] = button; + } } buffer[num++] = 0; diff --git a/testcases/t/320-mouse-bindings.t b/testcases/t/320-mouse-bindings.t new file mode 100644 index 00000000..45e0f4ff --- /dev/null +++ b/testcases/t/320-mouse-bindings.t @@ -0,0 +1,89 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • https://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • https://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • https://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# +# Test button bindsyms +use i3test i3_config => <input_focus, $window->id, $msg); +} + +# Leftmost window is focused on button presses that have no binding +my $L = open_window; +my $A = open_window(wm_class => 'mark_A'); +my $B = open_window(wm_class => 'mark_B'); +is_focus($B, 'sanity check'); +is_focus(open_window, 'sanity check, other window'); + +button(1, $A, 'button 1 binding'); +button(1, $A, 'button 1 binding, again'); +button(2, $B, 'button 2 binding'); +button(1, $A, 'button 1 binding'); +button(3, $L, 'button 3, no binding'); + +# Test modes, see #4539 +# Unfortunately, grabbing / ungrabbing doesn't seem to work correctly in xvfb +# so we can't really test this. + +my $C = open_window(wm_class => 'mark_C'); +my $D = open_window(wm_class => 'mark_D'); + +button(4, $B, 'button 4 binding outside mode'); +button(5, $L, 'button 5 no binding outside mode'); + +cmd 'mode testmode'; +button(4, $C, 'button 4 binding inside mode'); +button(5, $D, 'button 5 binding inside mode'); + +cmd 'mode default'; +button(4, $B, 'button 4 binding outside mode'); +button(5, $L, 'button 5 no binding outside mode'); + +done_testing; -- cgit v1.2.3-54-g00ecf