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 7968d8ce04ef186f86e56c79c8196759849d4109
Author: Boris Faure <[email protected]>
AuthorDate: Sat Nov 14 22:52:29 2026 +0000
keyin: report kitty key event types
Implement flag 2 of the kitty keyboard protocol: the event type
(press, repeat, release) is reported in the escape code, and key
releases reach the pty at all. A release is only reported for keys
whose press was reported, as the protocol requires.
A modifier key sets or clears its own bit in the mods field: set on
press, cleared on release unless the other side of the keyboard is
still held, which the pressed-key table answers. Lock keys toggle
their bit as a best effort, as their new state can only be read from
the next event.
The kitty-kbd-unsupported.sh checksum moves with this commit: the
query now reports flags 1|2|4 as implemented instead of 1|4.
---
src/bin/keyin.c | 54 ++++++++++++++++++++++++++++++++++++++++++++-
src/bin/keyin.h | 3 ++-
src/bin/termpty.c | 12 +++++-----
src/bin/termptyops.h | 3 ++-
src/bin/tytest.c | 1 +
src/bin/tytest_keyin.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/bin/unit_tests.h | 1 +
src/bin/win.c | 9 ++++----
tests/tests.results | 2 +-
9 files changed, 130 insertions(+), 14 deletions(-)
diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index 66d99a1c..e4047151 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -63,6 +63,54 @@ _keyin_mods_get(const Evas_Modifier *modifiers, const Evas_Lock *locks)
return mods;
}
+/* The event's own modifier key, as the spec defines the mods field of a
+ * modifier key event: set on press, cleared on release unless the other
+ * side of the keyboard is still held. For the lock keys the new state
+ * can only be read from the next event, so the bit is toggled. */
+static unsigned int
+_keyin_mods_with_modifier_key(unsigned int mods, const Keys_Handler *khdl,
+ const char *key, Keyin_Action action)
+{
+ static const struct {
+ const char *left, *right;
+ unsigned int mod;
+ } modifiers[] = {
+ { "Shift_L", "Shift_R", KEYIN_MOD_SHIFT },
+ { "Control_L", "Control_R", KEYIN_MOD_CTRL },
+ { "Alt_L", "Alt_R", KEYIN_MOD_ALT },
+ { "Super_L", "Super_R", KEYIN_MOD_SUPER },
+ { "Meta_L", "Meta_R", KEYIN_MOD_META },
+ };
+ unsigned int i, j;
+
+ for (i = 0; i < sizeof(modifiers) / sizeof(modifiers[0]); i++)
+ {
+ const char *other_side = NULL;
+
+ if (!strcmp(key, modifiers[i].left))
+ other_side = modifiers[i].right;
+ else if (!strcmp(key, modifiers[i].right))
+ other_side = modifiers[i].left;
+ if (!other_side)
+ continue;
+ if (action != KEYIN_ACTION_RELEASE)
+ return mods | modifiers[i].mod;
+ /* the released key is already out of the pressed table, so a hit
+ * is the other side */
+ for (j = 0; j < khdl->pressed_count; j++)
+ if (khdl->pressed[j].key &&
+ !strcmp(khdl->pressed[j].key, other_side))
+ return mods;
+ return mods & ~modifiers[i].mod;
+ }
+
+ if (!strcmp(key, "Caps_Lock"))
+ return mods ^ KEYIN_MOD_CAPS_LOCK;
+ if (!strcmp(key, "Num_Lock"))
+ return mods ^ KEYIN_MOD_NUM_LOCK;
+ return mods;
+}
+
void
keyin_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
Keyin_Action action)
@@ -79,7 +127,8 @@ keyin_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
}
void
-keyin_handle_key_up_to_pty(Termpty *ty, const Evas_Event_Key_Up *ev)
+keyin_handle_key_up_to_pty(Termpty *ty, const Keys_Handler *khdl,
+ const Evas_Event_Key_Up *ev)
{
Keyin_Event kev = {
.key = ev->key,
@@ -89,6 +138,9 @@ keyin_handle_key_up_to_pty(Termpty *ty, const Evas_Event_Key_Up *ev)
.action = ""
};
+ if (key_is_modifier(ev->key))
+ kev.mods = _keyin_mods_with_modifier_key(kev.mods, khdl, ev->key,
+ kev.action);
keyin_encode_event(ty, &kev);
}
diff --git a/src/bin/keyin.h b/src/bin/keyin.h
index 0aec1a47..96dec6b4 100644
--- a/src/bin/keyin.h
+++ b/src/bin/keyin.h
@@ -29,7 +29,8 @@ 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_handle_key_up_to_pty(Termpty *ty, const Keys_Handler *khdl,
+ 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);
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 05e13c4b..815c083a 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -3433,15 +3433,15 @@ tytest_kitty_kbd_query(void)
_ty_feed(&ty, "\x1b[?0u");
_ty_reply_is(&ty, "\x1b[?0u");
- /* only implemented flags are stored and answered: 7 is 1|4, the
- * event-types flag 2 is not implemented yet */
- _ty_feed(&ty, "\x1b[>7u"); /* push */
+ /* only implemented flags are stored and answered: 15 is 1|2|4|8, the
+ * report-all flag 8 is not implemented yet */
+ _ty_feed(&ty, "\x1b[>15u"); /* push */
_ty_feed(&ty, "\x1b[?u");
- _ty_reply_is(&ty, "\x1b[?5u");
+ _ty_reply_is(&ty, "\x1b[?7u");
_ty_feed(&ty, "\x1b[<u"); /* pop */
- _ty_feed(&ty, "\x1b[=7;1u"); /* set */
+ _ty_feed(&ty, "\x1b[=15;1u"); /* set */
_ty_feed(&ty, "\x1b[?u");
- _ty_reply_is(&ty, "\x1b[?5u");
+ _ty_reply_is(&ty, "\x1b[?7u");
_ty_feed(&ty, "\x1b[=0;1u"); /* set */
assert(ty.write_buffer.len == 0);
diff --git a/src/bin/termptyops.h b/src/bin/termptyops.h
index 9e1852a3..79a34631 100644
--- a/src/bin/termptyops.h
+++ b/src/bin/termptyops.h
@@ -38,7 +38,8 @@ void termpty_soft_reset_state(Termpty *ty);
/* kitty keyboard protocol: the flags implemented so far */
#define TERMPTY_KITTY_KBD_SUPPORTED \
- (TERMPTY_KITTY_KBD_DISAMBIGUATE | TERMPTY_KITTY_KBD_REPORT_ALTERNATES)
+ (TERMPTY_KITTY_KBD_DISAMBIGUATE | TERMPTY_KITTY_KBD_REPORT_EVENTS | \
+ TERMPTY_KITTY_KBD_REPORT_ALTERNATES)
unsigned int termpty_kitty_kbd_flags_get(const Termpty *ty);
void termpty_kitty_kbd_set(Termpty *ty, unsigned int flags, int mode);
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 148e6eeb..6d48296b 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_kitty_events", tytest_keyin_kitty_events},
{ "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},
diff --git a/src/bin/tytest_keyin.c b/src/bin/tytest_keyin.c
index 024084cb..9d5bf8a3 100644
--- a/src/bin/tytest_keyin.c
+++ b/src/bin/tytest_keyin.c
@@ -600,6 +600,65 @@ tytest_keyin_kitty_alternates(void)
return bad;
}
+int
+tytest_keyin_kitty_events(void)
+{
+ static const Kitty_Case cases[] = {
+ /* flags key keyname string mods action expected */
+ { 3, "a", "a", "a", 0, R, "a" },
+ { 3, "a", "a", NULL, 0, U, "\033[97;1:3u" },
+ { 3, "a", "a", "\001", C, R, "\033[97;5:2u" },
+ { 3, "a", "a", NULL, C, U, "\033[97;5:3u" },
+ /* Return, Tab and BackSpace stay legacy without modifiers */
+ { 3, "Return", "Return", NULL, 0, U, "" },
+ { 3, "Return", "Return", "\r", 0, R, "\r" },
+ { 3, "Tab", "Tab", NULL, 0, U, "" },
+ { 3, "BackSpace", "BackSpace", NULL, 0, U, "" },
+ { 3, "Return", "Return", NULL, S, U, "\033[13;2:3u" },
+ { 3, "Escape", "Escape", NULL, 0, U, "\033[27;1:3u" },
+ { 3, "Left", "Left", NULL, 0, P, "\033[D" },
+ { 3, "Left", "Left", NULL, 0, R, "\033[1;1:2D" },
+ { 3, "Left", "Left", NULL, 0, U, "\033[1;1:3D" },
+ /* without flag 1, presses stay legacy, keeping DECCKM */
+ { 2, "a", "a", "\001", C, P, "\001" },
+ { 2, "a", "a", NULL, C, U, "\033[97;5:3u" },
+ { 2, "Escape", "Escape", NULL, 0, U, "\033[27;1:3u" },
+ { 7, "A", "a", NULL, S, U, "\033[97:65;2:3u" },
+ /* a release keeps the base key of its press */
+ { 7, "Cyrillic_es", "c", NULL, C, P, "\033[1089::99;5u" },
+ { 7, "Cyrillic_es", "c", NULL, C, U, "\033[1089::99;5:3u" },
+ };
+ Kitty_Case appcursor = { 2, "Left", "Left", NULL, 0, P, "\033OD" };
+ char *saved_locale;
+ size_t i;
+ int bad = 0;
+
+ /* towlower() needs a UTF-8 locale; the real terminal gets one from
+ * elm_init(), the harness does not */
+ saved_locale = strdup(setlocale(LC_CTYPE, NULL));
+ assert(saved_locale);
+ if (!setlocale(LC_CTYPE, "C.UTF-8"))
+ {
+ fprintf(stderr, "\n no C.UTF-8 locale, skipping");
+ free(saved_locale);
+ return 0;
+ }
+
+ _init();
+ for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ bad += _kitty_case_is(&cases[i]);
+ _ty->termstate.appcursor = EINA_TRUE;
+ bad += _kitty_case_is(&appcursor);
+ _ty->termstate.appcursor = EINA_FALSE;
+ _shutdown();
+ setlocale(LC_CTYPE, saved_locale);
+ free(saved_locale);
+
+ if (bad)
+ fprintf(stderr, "\n %d wrong encoding%s", bad, bad == 1 ? "" : "s");
+ return bad;
+}
+
#undef S
#undef A
#undef C
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 00e38847..2793b62f 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -110,6 +110,7 @@ int tytest_keyin_keysyms(void);
int tytest_keyin_kitty_disambiguate(void);
int tytest_keyin_kitty_alternates(void);
int tytest_keyin_pressed(void);
+int tytest_keyin_kitty_events(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 dec1ebe5..1e86d5ec 100644
--- a/src/bin/win.c
+++ b/src/bin/win.c
@@ -1809,12 +1809,13 @@ win_has_single_child(const Win *wn)
}
static void
-_win_key_up_to_term(Term *term, const Evas_Event_Key_Up *ev)
+_win_key_up_to_term(Term *term, Keys_Handler *khdl,
+ 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);
+ keyin_handle_key_up_to_pty(ty, khdl, ev);
}
static void
@@ -1839,7 +1840,7 @@ _cb_win_key_up(void *data,
Term *term;
GROUPED_INPUT_TERM_FOREACH(wn, l, term)
- _win_key_up_to_term(term, ev);
+ _win_key_up_to_term(term, &wn->khdl, ev);
}
else
{
@@ -1847,7 +1848,7 @@ _cb_win_key_up(void *data,
Term *term = tc->focused_term_get(tc);
if (term)
- _win_key_up_to_term(term, ev);
+ _win_key_up_to_term(term, &wn->khdl, ev);
}
}
diff --git a/tests/tests.results b/tests/tests.results
index 6101c9b7..dd731c7d 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -246,5 +246,5 @@ kitty-kbd-query.sh 2aeecb0992989a62a9b4cf5ce687852f
kitty-kbd-stack.sh 1940619ffdbe765b2495edbce9cf22cc
kitty-kbd-altscreen.sh df9913f9d85f856c75dd525a806da4f6
kitty-kbd-reset.sh bd10ee95b6b71d150fbe1a11c7b6ac94
-kitty-kbd-unsupported.sh bdc45fbe16a618e5576ee943cfcdfb09
+kitty-kbd-unsupported.sh 37ed332e16676c21a2ccfe719760dfca
kitty-kbd-malformed.sh bd10ee95b6b71d150fbe1a11c7b6ac94
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.