1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 01:22:30 +00:00

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.
This commit is contained in:
wm4 2019-11-21 22:22:45 +01:00
parent a098e98198
commit 0a6c09b96f
4 changed files with 19 additions and 4 deletions

View File

@ -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
-------------------

View File

@ -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) {

View File

@ -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;
}

View File

@ -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.