]> jfr.im git - irc/weechat/weechat.git/commitdiff
core: don't send key_pressed signal again for the same key press
authorTrygve Aaberge <redacted>
Mon, 3 Jul 2023 19:59:23 +0000 (21:59 +0200)
committerSébastien Helleu <redacted>
Mon, 3 Jul 2023 20:57:10 +0000 (22:57 +0200)
If you press an incomplete key sequence, previously WeeChat would send
the key_pressed signal again for the same keys on the next key.

E.g. if you press escape and then 1, previously you would get the
key_pressed signal with signal_data `\x01[` when you pressed escape, and
then key_pressed with `\x01[` again when you pressed 1 (plus key_pressed
with `1` for the 1 key). So two signals for the escape key, even though
it was only pressed once.

With this patch, you only get one signal for each key press. So one with
`\x01[` when you press escape and then one with `1` when you press 1.

src/gui/curses/gui-curses-key.c
src/gui/gui-key.c
src/gui/gui-key.h

index eeedbb27be64ac5daaffae890d77813b305e6468..8eea1bb7fe40d352e98a506eae5dcc48d98a5c31 100644 (file)
@@ -396,12 +396,13 @@ gui_key_flush (int paste)
              * or if the mouse code is valid UTF-8 (do not send partial mouse
              * code which is not UTF-8 valid)
              */
-            if (!paste
+            if (!paste && i > gui_key_last_key_pressed_sent
                 && (!gui_mouse_event_pending
                     || utf8_is_valid (key_str, -1, NULL)))
             {
                 (void) hook_signal_send ("key_pressed",
                                          WEECHAT_HOOK_SIGNAL_STRING, key_str);
+                gui_key_last_key_pressed_sent = i;
             }
 
             if (gui_current_window->buffer->text_search != GUI_TEXT_SEARCH_DISABLED)
index ee43631aba6e7559f7755a11f5713cbe6c2f6481..7212e10bc1a394160bad6b864d9b3dc4b75cfdf4 100644 (file)
@@ -94,6 +94,7 @@ int gui_key_grab_delay = 0;         /* delay for grab (default is 500)      */
 int *gui_key_buffer = NULL;         /* input buffer (for paste detection)   */
 int gui_key_buffer_alloc = 0;       /* input buffer allocated size          */
 int gui_key_buffer_size = 0;        /* input buffer size in bytes           */
+int gui_key_last_key_pressed_sent = -1;
 
 int gui_key_paste_pending = 0;      /* 1 is big paste was detected and      */
                                     /* WeeChat is asking user what to do    */
@@ -2695,6 +2696,7 @@ gui_key_buffer_reset ()
         gui_key_buffer_optimize ();
     }
     gui_key_paste_lines = 0;
+    gui_key_last_key_pressed_sent = -1;
 }
 
 /*
index b0aeb2ad8c6f958b4ea76bab6241841ccb7518e1..cbc600c2fadd4e0345b29fae821c3e1e89d33c56 100644 (file)
@@ -82,6 +82,7 @@ extern int gui_key_grab;
 extern int gui_key_grab_count;
 extern int *gui_key_buffer;
 extern int gui_key_buffer_size;
+extern int gui_key_last_key_pressed_sent;
 extern int gui_key_paste_pending;
 extern int gui_key_paste_bracketed;
 extern time_t gui_key_last_activity_time;