]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keyboard: cancel repeat when handling key-bind
authorJohan Malm <jgm323@gmail.com>
Sun, 2 Jan 2022 15:28:35 +0000 (15:28 +0000)
committerJohan Malm <jgm323@gmail.com>
Sun, 2 Jan 2022 15:28:35 +0000 (15:28 +0000)
<keybind key="W-d">
  <action name="Execute">
    <command>dmenu_run</command>
  </action>
</keybind>

When using the keybind above (in rc.xml), on the first execution of W-d
all is okay, but the second time, a "d" pressed event is sent to dmenu
resulting in a continuous "ddddddd...") which has to be stopped pressing a
key.

This behaviour started in commit 7e57b7f because release events associated
with keybinds are no longer sent to clients (before that commit, the
release event for the ā€œdā€ would have been passed to dmenu, thus cancelling
the repeat).

Solves issue #176

Helped-by: @spectrum70
include/key-state.h
src/key-state.c
src/keyboard.c

index 1e7e5410c9edd0e7b14a5d8b57d5dc2b6ad19078..e5f72919e6c597a7fc530b62d61af229ed7cbaa9 100644 (file)
@@ -5,6 +5,8 @@
 void key_state_set_pressed(uint32_t keycode, bool ispressed);
 void key_state_store_pressed_keys_as_bound(void);
 bool key_state_corresponding_press_event_was_bound(uint32_t keycode);
-void key_state_bound_key_remove(uint32_t keycode);
+
+/* returns numbers of keys still pressed in a consumed key combination */
+int key_state_bound_key_remove(uint32_t keycode);
 
 #endif /* __LABWC_KEY_STATE_H */
index bc4844f6dcb6836fb9f83dde9ba5595b01832e8e..d2be54671cdb3279d930044983b339cc9c6a6678 100644 (file)
@@ -63,8 +63,9 @@ key_state_corresponding_press_event_was_bound(uint32_t keycode)
        return false;
 }
 
-void
+int
 key_state_bound_key_remove(uint32_t keycode)
 {
        remove_key(&bound, keycode);
+       return bound.nr_keys;
 }
index 1be0c002036d622c6c1f33b33002ee04e0d8b4ae..c10e3c9cf9a5493b7ed74d902f02239e6890b729 100644 (file)
@@ -59,12 +59,14 @@ static bool
 handle_keybinding(struct server *server, uint32_t modifiers, xkb_keysym_t sym)
 {
        struct keybind *keybind;
+       struct wlr_keyboard *kb = &server->seat.keyboard_group->keyboard;
        wl_list_for_each_reverse (keybind, &rc.keybinds, link) {
                if (modifiers ^ keybind->modifiers) {
                        continue;
                }
                for (size_t i = 0; i < keybind->keysyms_len; i++) {
                        if (xkb_keysym_to_lower(sym) == keybind->keysyms[i]) {
+                               wlr_keyboard_set_repeat_info(kb, 0, 0);
                                action(NULL, server, keybind->action,
                                       keybind->command, 0);
                                return true;
@@ -111,7 +113,11 @@ handle_compositor_keybindings(struct wl_listener *listener,
         */
        if (key_state_corresponding_press_event_was_bound(keycode)
                        && event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
-               key_state_bound_key_remove(keycode);
+               int nr_bound_keys = key_state_bound_key_remove(keycode);
+               if (!nr_bound_keys) {
+                       wlr_keyboard_set_repeat_info(device->keyboard,
+                               rc.repeat_rate, rc.repeat_delay);
+               }
                return true;
        }