From 0a6c09b96f17fa0247d3fe53ff396f61e5868d0c Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 21 Nov 2019 22:22:45 +0100 Subject: input: introduce a pseudo key name that grabs all text input The intended target for this is the mpv.repl script, which manually added every single ASCII key as a separate key binding. This provides a simpler mechanism, that will catch any kind of text input. Due to its special nature, explicitly do not give a guarantee for compatibility; thus the warning in input.rst. --- DOCS/man/input.rst | 5 +++++ input/input.c | 7 ++++++- input/keycodes.c | 4 ++-- input/keycodes.h | 7 ++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index eb1e7791bc..81126efd43 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -152,6 +152,11 @@ Comments on some symbolic names: Pseudo-key that matches any unmapped key. (You should probably avoid this if possible, because it might change behavior or get removed in the future.) +``ANY_UNICODE`` + Pseudo-key that matches any key that produces text. (You should probably + avoid this if possible, because it might change behavior or get removed in + the future.) + Flat command syntax ------------------- diff --git a/input/input.c b/input/input.c index 87956cf2b9..89ef1ace90 100644 --- a/input/input.c +++ b/input/input.c @@ -456,7 +456,12 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section, if (ictx->opts->test) return handle_test(ictx, code); - struct cmd_bind *cmd = find_any_bind_for_key(ictx, force_section, code); + struct cmd_bind *cmd = NULL; + + if (MP_KEY_IS_UNICODE(code)) + cmd = find_any_bind_for_key(ictx, force_section, MP_KEY_ANY_UNICODE); + if (!cmd) + cmd = find_any_bind_for_key(ictx, force_section, code); if (!cmd) cmd = find_any_bind_for_key(ictx, force_section, MP_KEY_UNMAPPED); if (!cmd) { diff --git a/input/keycodes.c b/input/keycodes.c index a03f07e59a..3d7fd09d11 100644 --- a/input/keycodes.c +++ b/input/keycodes.c @@ -208,6 +208,7 @@ static const struct key_name key_names[] = { { MP_KEY_MOUSE_ENTER, "MOUSE_ENTER" }, { MP_KEY_UNMAPPED, "UNMAPPED" }, + { MP_KEY_ANY_UNICODE, "ANY_UNICODE" }, { 0, NULL } }; @@ -271,8 +272,7 @@ static void mp_input_append_key_name(bstr *buf, int key) } } - // printable, and valid unicode range - if (key >= 32 && key <= 0x10FFFF) { + if (MP_KEY_IS_UNICODE(key)) { mp_append_utf8_bstr(NULL, buf, key); return; } diff --git a/input/keycodes.h b/input/keycodes.h index 12b45e528a..7385440851 100644 --- a/input/keycodes.h +++ b/input/keycodes.h @@ -22,6 +22,10 @@ // Special keys come after this. #define MP_KEY_BASE (1<<21) +// printable, and valid unicode range (we don't care too much about whether +// certain sub-ranges are reserved and disallowed, like surrogate pairs) +#define MP_KEY_IS_UNICODE(key) ((key) >= 32 && (key) <= 0x10FFFF) + #define MP_KEY_ENTER 13 #define MP_KEY_TAB 9 @@ -210,7 +214,8 @@ (MP_KEY_IS_MOUSE_CLICK(code) || MP_KEY_IS_MOUSE_MOVE(code)) // No input source should generate this. -#define MP_KEY_UNMAPPED (MP_KEY_INTERN+4) +#define MP_KEY_UNMAPPED (MP_KEY_INTERN+4) +#define MP_KEY_ANY_UNICODE (MP_KEY_INTERN+5) // Emit a command even on key-up (normally key-up is ignored). This means by // default they binding will be triggered on key-up instead of key-down. -- cgit v1.2.3