From f8cf0740e3028f262f2c2347a0106b058b1b0d21 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 12 Aug 2026 04:58:36 +1000 Subject: [PATCH] [client] keybind: validate and consume chord events --- client/src/app.c | 29 ++++++++++++++++++++++------- client/src/main.h | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/client/src/app.c b/client/src/app.c index f8509fdf..9ac55a7d 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -413,15 +413,17 @@ void app_handleKeyPressInternal(int sc) { if (sc == g_params.escapeKey && !g_state.escapeActive) { - g_state.escapeActive = true; - g_state.escapeTime = microtime(); - g_state.escapeAction = -1; + g_state.escapeActive = true; + g_state.escapeTime = microtime(); + g_state.escapeAction = -1; + g_state.escapeKeys[sc] = true; return; } if (g_state.escapeActive) { - g_state.escapeAction = sc; + g_state.escapeAction = sc; + g_state.escapeKeys[sc] = true; KeybindHandle handle; ll_forEachNL(g_state.bindings, item, handle) { @@ -435,6 +437,8 @@ void app_handleKeyPressInternal(int sc) } } + g_state.escapeKeys[sc] = false; + if (app_isOverlayMode()) { if (sc == KEY_ESC) @@ -459,7 +463,7 @@ void app_handleKeyPressInternal(int sc) void app_handleKeyReleaseInternal(int sc) { - if (g_state.escapeActive) + if (g_state.escapeActive && sc == g_params.escapeKey) { if (g_state.escapeAction == -1) { @@ -468,8 +472,13 @@ void app_handleKeyReleaseInternal(int sc) core_setGrab(!g_cursor.grab); } - if (sc == g_params.escapeKey) - g_state.escapeActive = false; + g_state.escapeActive = false; + } + + if (g_state.escapeKeys[sc]) + { + g_state.escapeKeys[sc] = false; + return; } if (app_isOverlayMode()) @@ -759,6 +768,12 @@ void app_showRecord(bool show) KeybindHandle app_registerKeybind(int sc, KeybindFn callback, void * opaque, const char * description) { + if (!callback) + { + DEBUG_ERROR("invalid keybind callback"); + return NULL; + } + if (sc <= KEY_RESERVED || sc >= KEY_MAX || !linux_to_display[sc]) { DEBUG_ERROR("invalid keybind keycode: %d", sc); diff --git a/client/src/main.h b/client/src/main.h index 900c2f5b..9eac12e8 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -124,6 +124,7 @@ struct AppState bool escapeActive; uint64_t escapeTime; int escapeAction; + bool escapeKeys[KEY_MAX]; bool escapeHelp; struct ll * bindings; bool haveSrcSize;