From c4ff6751981cefbd600136cf044a1ca0ed3456b6 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Sat, 7 Sep 2024 07:51:51 -0400 Subject: [PATCH] input: add MP_KEY_STATE_SET_ONLY Trivial. --- input/input.c | 10 ++++++---- input/keycodes.h | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/input/input.c b/input/input.c index 686b672dce..68bb2b0859 100644 --- a/input/input.c +++ b/input/input.c @@ -598,7 +598,8 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale, int scale_units) { int state = code & (MP_KEY_STATE_DOWN | MP_KEY_STATE_UP); - code = code & ~(unsigned)state; + bool no_emit = code & MP_KEY_STATE_SET_ONLY; + code = code & ~(unsigned)(state | MP_KEY_STATE_SET_ONLY); if (mp_msg_test(ictx->log, MSGL_TRACE)) { char *key = mp_input_get_key_name(code); @@ -648,9 +649,10 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale, return; // Don't emit a command on key-down if the key is designed to emit commands - // on key-up (like mouse buttons). Also, if the command specifically should - // be sent both on key down and key up, still emit the command. - if (cmd->emit_on_up && !cmd->def->on_updown) { + // on key-up (like mouse buttons), or setting key state only without emitting commands. + // Also, if the command specifically should be sent both on key down and key up, + // still emit the command. + if ((cmd->emit_on_up && !cmd->def->on_updown) || no_emit) { talloc_free(cmd); return; } diff --git a/input/keycodes.h b/input/keycodes.h index 93633e69de..e2384d6719 100644 --- a/input/keycodes.h +++ b/input/keycodes.h @@ -251,6 +251,9 @@ // or don't use MP_KEY_STATE_DOWN in the first place. #define MP_KEY_STATE_UP (1u<<29) +// Only set the key state without triggering key bindings. +#define MP_KEY_STATE_SET_ONLY (1u<<30) + #define MP_KEY_MODIFIER_MASK (MP_KEY_MODIFIER_SHIFT | MP_KEY_MODIFIER_CTRL | \ MP_KEY_MODIFIER_ALT | MP_KEY_MODIFIER_META | \ MP_KEY_STATE_DOWN | MP_KEY_STATE_UP)