This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit a968054212ba848e75a66a0e7e3d62fd9c945341
Author: Boris Faure <[email protected]>
AuthorDate: Sat Nov 14 22:48:59 2026 +0000

    win: track key presses and send releases to keyin
    
    The kitty keyboard protocol reports key releases only for keys whose
    press was reported, so the keys currently held must be tracked. Add the
    pressed-key table to Keys_Handler, filled from the window key-down
    callback and drained on key-up; the press sets the Keyin_Action
    (PRESS or REPEAT) passed to the encoder, and a flag records whether
    the press reached a pty.
    
    The table is emptied on window focus-out: a key released while another
    window has the focus is never seen, and no synthetic releases are
    invented for it. It is also emptied when a terminal loses the focus
    within the window, as when a key binding switches tabs while a modifier
    is held: the release would otherwise reach a terminal that never saw
    the press.
    
    With the event-types flag (2) not yet advertised, the encoder drops
    every release, so this produces no new output; the tracking itself is
    covered by the keyin_pressed unit test.
---
 src/bin/keyin.c        | 14 ++++++++++
 src/bin/keyin.h        | 20 +++++++++++++++
 src/bin/keyin_encode.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/tytest.c       |  1 +
 src/bin/tytest_keyin.c | 52 +++++++++++++++++++++++++++++++++++++
 src/bin/unit_tests.h   |  1 +
 src/bin/win.c          | 43 +++++++++++++++++++++++++++++--
 7 files changed, 199 insertions(+), 2 deletions(-)

diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index f7b50b74..66d99a1c 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -78,6 +78,20 @@ keyin_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
    keyin_encode_event(ty, &kev);
 }
 
+void
+keyin_handle_key_up_to_pty(Termpty *ty, const Evas_Event_Key_Up *ev)
+{
+   Keyin_Event kev = {
+      .key = ev->key,
+      .keyname = ev->keyname,
+      .string = ev->string,
+      .mods = _keyin_mods_get(ev->modifiers, ev->locks),
+      .action = ""
+   };
+
+   keyin_encode_event(ty, &kev);
+}
+
 static Key_Binding *
 key_binding_lookup(const char *keyname,
                    Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift,
diff --git a/src/bin/keyin.h b/src/bin/keyin.h
index a3c7c0a9..0aec1a47 100644
--- a/src/bin/keyin.h
+++ b/src/bin/keyin.h
@@ -5,17 +5,37 @@
 
 typedef struct tag_Keys_Handler Keys_Handler;
 
+/* the keys currently held, for the event types of the kitty protocol */
+#define KEYIN_PRESSED_MAX 16
+
+typedef struct tag_Keyin_Pressed_Key
+{
+   unsigned int keycode;
+   const char *key;              /* stringshare, for the modifier side check */
+   unsigned char reported : 1;   /* the press reached keyin_encode_event() */
+} Keyin_Pressed_Key;
+
 struct tag_Keys_Handler
 {
    Ecore_IMF_Context *imf;
    unsigned int last_keyup;
    Eina_List *seq;
+   Keyin_Pressed_Key pressed[KEYIN_PRESSED_MAX];
+   unsigned int pressed_count;
    unsigned char composing : 1;
 };
 
 void
 keyin_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
                         Keyin_Action action);
+void
+keyin_handle_key_up_to_pty(Termpty *ty, const Evas_Event_Key_Up *ev);
+Keyin_Action
+keyin_key_down_track(Keys_Handler *khdl, const Evas_Event_Key_Down *ev);
+void keyin_key_reported_set(Keys_Handler *khdl, unsigned int keycode);
+Eina_Bool
+keyin_key_up_track(Keys_Handler *khdl, const Evas_Event_Key_Up *ev);
+void keyin_pressed_reset(Keys_Handler *khdl);
 Eina_Bool
 termpty_can_handle_key(const Termpty *ty,
                        const Keys_Handler *khdl,
diff --git a/src/bin/keyin_encode.c b/src/bin/keyin_encode.c
index 27533ef3..84410abe 100644
--- a/src/bin/keyin_encode.c
+++ b/src/bin/keyin_encode.c
@@ -1,10 +1,12 @@
 #include "private.h"
 
 #include <Elementary.h>
+#include <Ecore_IMF.h>
 #include "termpty.h"
 #include "termptyops.h"
 #include "keyin_encode.h"
 #include "keyin_kitty.h"
+#include "keyin.h"
 
 typedef struct tag_Tty_Key Tty_Key;
 typedef struct tag_Key_Values Key_Values;
@@ -355,3 +357,71 @@ keyin_encode_event(Termpty *ty, const Keyin_Event *kev)
 
    _encode_legacy(ty, kev);
 }
+
+/* {{{ Pressed key tracking */
+
+/* the spec reports a release only for a key whose press was reported */
+
+static Keyin_Pressed_Key *
+_pressed_key_get(Keys_Handler *khdl, unsigned int keycode)
+{
+   unsigned int i;
+
+   for (i = 0; i < khdl->pressed_count; i++)
+     if (khdl->pressed[i].keycode == keycode)
+       return &khdl->pressed[i];
+   return NULL;
+}
+
+Keyin_Action
+keyin_key_down_track(Keys_Handler *khdl, const Evas_Event_Key_Down *ev)
+{
+   Keyin_Pressed_Key *pk;
+
+   pk = _pressed_key_get(khdl, ev->keycode);
+   if (pk)
+     return KEYIN_ACTION_REPEAT;
+   /* a key past the table gets no release: 16 held keys is plenty */
+   if (khdl->pressed_count >= KEYIN_PRESSED_MAX)
+     return KEYIN_ACTION_PRESS;
+   pk = &khdl->pressed[khdl->pressed_count++];
+   pk->keycode = ev->keycode;
+   pk->key = eina_stringshare_add(ev->key);
+   pk->reported = 0;
+   return KEYIN_ACTION_PRESS;
+}
+
+void
+keyin_key_reported_set(Keys_Handler *khdl, unsigned int keycode)
+{
+   Keyin_Pressed_Key *pk = _pressed_key_get(khdl, keycode);
+
+   if (pk)
+     pk->reported = 1;
+}
+
+Eina_Bool
+keyin_key_up_track(Keys_Handler *khdl, const Evas_Event_Key_Up *ev)
+{
+   Keyin_Pressed_Key *pk = _pressed_key_get(khdl, ev->keycode);
+   Eina_Bool reported = EINA_FALSE;
+
+   if (!pk)
+     return EINA_FALSE;
+   reported = pk->reported;
+   eina_stringshare_del(pk->key);
+   *pk = khdl->pressed[--khdl->pressed_count];
+   return reported;
+}
+
+void
+keyin_pressed_reset(Keys_Handler *khdl)
+{
+   unsigned int i;
+
+   for (i = 0; i < khdl->pressed_count; i++)
+     eina_stringshare_del(khdl->pressed[i].key);
+   khdl->pressed_count = 0;
+}
+
+/* }}} */
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index f5ee9bda..148e6eeb 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -109,6 +109,7 @@ static struct {
        { "keyin_keysyms", tytest_keyin_keysyms},
        { "keyin_kitty_disambiguate", tytest_keyin_kitty_disambiguate},
        { "keyin_kitty_alternates", tytest_keyin_kitty_alternates},
+       { "keyin_pressed", tytest_keyin_pressed},
        { "config_erase_is_del_upgrade", tytest_config_erase_is_del_upgrade},
        { "config_selection_read_upgrade", tytest_config_selection_read_upgrade},
        { "config_cursor_blink_timeout_upgrade", tytest_config_cursor_blink_timeout_upgrade},
diff --git a/src/bin/tytest_keyin.c b/src/bin/tytest_keyin.c
index 20cd8624..024084cb 100644
--- a/src/bin/tytest_keyin.c
+++ b/src/bin/tytest_keyin.c
@@ -12,6 +12,7 @@
 #include "termpty.h"
 #include "termptyops.h"
 #include "keyin_encode.h"
+#include "keyin.h"
 #include "unit_tests.h"
 
 /* keyin_encode_key() writes through termpty_write(), which appends to
@@ -644,4 +645,55 @@ tytest_keyin_keysyms(void)
    return bad;
 }
 
+int
+tytest_keyin_pressed(void)
+{
+   Keys_Handler khdl;
+   Evas_Event_Key_Down down;
+   Evas_Event_Key_Up up;
+   unsigned int i;
+
+   /* keyin_key_down_track() only reads keycode, key and keyname, so a
+    * stack-allocated event is enough */
+   memset(&khdl, 0, sizeof(khdl));
+   memset(&down, 0, sizeof(down));
+   down.key = "q";
+   down.keyname = "q";
+   down.keycode = 24;
+   memset(&up, 0, sizeof(up));
+   up.keycode = 24;
+
+   _init();
+
+   assert(keyin_key_down_track(&khdl, &down) == KEYIN_ACTION_PRESS);
+   assert(keyin_key_down_track(&khdl, &down) == KEYIN_ACTION_REPEAT);
+   /* the press was not reported, so no release */
+   assert(keyin_key_up_track(&khdl, &up) == EINA_FALSE);
+   assert(keyin_key_down_track(&khdl, &down) == KEYIN_ACTION_PRESS);
+   keyin_key_reported_set(&khdl, 24);
+   assert(keyin_key_up_track(&khdl, &up) == EINA_TRUE);
+   assert(keyin_key_up_track(&khdl, &up) == EINA_FALSE);
+
+   /* a 17th key is not tracked: no release for it */
+   for (i = 0; i < KEYIN_PRESSED_MAX; i++)
+     {
+        down.keycode = 100 + i;
+        assert(keyin_key_down_track(&khdl, &down) == KEYIN_ACTION_PRESS);
+     }
+   down.keycode = 200;
+   assert(keyin_key_down_track(&khdl, &down) == KEYIN_ACTION_PRESS);
+   up.keycode = 200;
+   assert(keyin_key_up_track(&khdl, &up) == EINA_FALSE);
+
+   /* a key held across a focus out is a fresh press afterwards */
+   down.keycode = 100;
+   assert(keyin_key_down_track(&khdl, &down) == KEYIN_ACTION_REPEAT);
+   keyin_pressed_reset(&khdl);
+   assert(keyin_key_down_track(&khdl, &down) == KEYIN_ACTION_PRESS);
+   keyin_pressed_reset(&khdl);
+
+   _shutdown();
+   return 0;
+}
+
 #endif
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 5af95193..00e38847 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -109,6 +109,7 @@ int tytest_keyin_keypad(void);
 int tytest_keyin_keysyms(void);
 int tytest_keyin_kitty_disambiguate(void);
 int tytest_keyin_kitty_alternates(void);
+int tytest_keyin_pressed(void);
 int tytest_config_erase_is_del_upgrade(void);
 int tytest_config_selection_read_upgrade(void);
 int tytest_config_cursor_blink_timeout_upgrade(void);
diff --git a/src/bin/win.c b/src/bin/win.c
index 3f08e2d0..dec1ebe5 100644
--- a/src/bin/win.c
+++ b/src/bin/win.c
@@ -817,6 +817,8 @@ _solo_unfocus(Term_Container *tc, Term_Container *relative)
 
    tc->is_focused = EINA_FALSE;
    termio_focus_out(term->termio);
+   /* a release must not reach a terminal its press did not */
+   keyin_pressed_reset(&term->wn->khdl);
 
    if (tc->parent != relative)
      tc->parent->unfocus(tc->parent, tc);
@@ -1103,6 +1105,8 @@ _cb_win_focus_out(void *data,
 
    DBG("FOCUS OUT tc:%p tc->is_focused:%d",
        tc, tc->is_focused);
+   /* releases are not seen while unfocused: forget the keys held */
+   keyin_pressed_reset(&wn->khdl);
    tc->unfocus(tc, NULL);
    if (wn->group_input)
      {
@@ -1276,6 +1280,7 @@ win_free(Win *wn)
    config_del(wn->config);
    eina_stringshare_del(wn->preedit_str);
    keyin_compose_seq_reset(&wn->khdl);
+   keyin_pressed_reset(&wn->khdl);
    if (wn->khdl.imf)
      {
         ecore_imf_context_event_callback_del
@@ -1803,6 +1808,15 @@ win_has_single_child(const Win *wn)
    return (child->type == TERM_CONTAINER_TYPE_SOLO);
 }
 
+static void
+_win_key_up_to_term(Term *term, const Evas_Event_Key_Up *ev)
+{
+   Termpty *ty = termio_pty_get(term->termio);
+
+   if (ty && !ty->termstate.kbd_lock)
+     keyin_handle_key_up_to_pty(ty, ev);
+}
+
 static void
 _cb_win_key_up(void *data,
                Evas *_e EINA_UNUSED,
@@ -1811,10 +1825,30 @@ _cb_win_key_up(void *data,
 {
    Win *wn = data;
    Evas_Event_Key_Up *ev = event;
+   Eina_Bool reported;
 
    DBG("GROUP key up (%p) (ctrl:%d)",
        wn, evas_key_modifier_is_set(ev->modifiers, "Control"));
    keyin_handle_up(&wn->khdl, ev);
+   reported = keyin_key_up_track(&wn->khdl, ev);
+   if (!reported || wn->on_popover || wn->cmdbox_up)
+     return;
+   if (wn->group_input)
+     {
+        Eina_List *l;
+        Term *term;
+
+        GROUPED_INPUT_TERM_FOREACH(wn, l, term)
+          _win_key_up_to_term(term, ev);
+     }
+   else
+     {
+        Term_Container *tc = (Term_Container*) wn;
+        Term *term = tc->focused_term_get(tc);
+
+        if (term)
+          _win_key_up_to_term(term, ev);
+     }
 }
 
 const char *
@@ -1932,12 +1966,15 @@ _cb_win_key_down(void *data,
    Evas_Event_Key_Down *ev = event_info;
    Eina_Bool done = EINA_FALSE;
    int ctrl, alt, shift, win, meta, hyper;
+   Keyin_Action action;
 
    DBG("GROUP key down (%p) (ctrl:%d)",
        wn, evas_key_modifier_is_set(ev->modifiers, "Control"));
    _focus_validator();
    if ((wn->on_popover) || (wn->cmdbox_up)) return;
 
+   action = "" ev);
+
    ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
    alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
    shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
@@ -2155,7 +2192,8 @@ _cb_win_key_down(void *data,
              if (ty && termpty_can_handle_key(ty, &wn->khdl, ev))
                {
                   termpty_program_status_drop_unseen(ty);
-                  keyin_handle_key_to_pty(ty, ev, KEYIN_ACTION_PRESS);
+                  keyin_handle_key_to_pty(ty, ev, action);
+                  keyin_key_reported_set(&wn->khdl, ev->keycode);
                }
           }
      }
@@ -2166,7 +2204,8 @@ _cb_win_key_down(void *data,
         if (ty && termpty_can_handle_key(ty, &wn->khdl, ev))
           {
              termpty_program_status_drop_unseen(ty);
-             keyin_handle_key_to_pty(ty, ev, KEYIN_ACTION_PRESS);
+             keyin_handle_key_to_pty(ty, ev, action);
+             keyin_key_reported_set(&wn->khdl, ev->keycode);
           }
      }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to