summaryrefslogtreecommitdiffstats
path: root/input/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'input/input.c')
-rw-r--r--input/input.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/input/input.c b/input/input.c
index cde1b5e027..cc967bb4fa 100644
--- a/input/input.c
+++ b/input/input.c
@@ -38,6 +38,7 @@
#include "keycodes.h"
#include "osdep/timer.h"
#include "libavutil/avstring.h"
+#include "libavutil/common.h"
#include "mp_msg.h"
#include "m_config.h"
#include "m_option.h"
@@ -649,6 +650,17 @@ static const m_option_t mp_input_opts[] = {
static int default_cmd_func(int fd, char *buf, int l);
+// Encode the unicode codepoint as UTF-8, and append to the end of the
+// talloc'ed buffer.
+static char *append_utf8_buffer(char *buffer, uint32_t codepoint)
+{
+ char data[8];
+ uint8_t tmp;
+ char *output = data;
+ PUT_UTF8(codepoint, tmp, *output++ = tmp;);
+ return talloc_strndup_append_buffer(buffer, data, output - data);
+}
+
static char *get_key_name(int key, char *ret)
{
for (int i = 0; modifier_names[i].name; i++) {
@@ -663,8 +675,9 @@ static char *get_key_name(int key, char *ret)
return talloc_asprintf_append_buffer(ret, "%s", key_names[i].name);
}
- if (isascii(key))
- return talloc_asprintf_append_buffer(ret, "%c", key);
+ // printable, and valid unicode range
+ if (key >= 32 && key <= 0x10FFFF)
+ return append_utf8_buffer(ret, key);
// Print the hex key code
return talloc_asprintf_append_buffer(ret, "%#-8x", key);
@@ -1173,7 +1186,7 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code)
* shift modifier is still kept for special keys like arrow keys.
*/
int unmod = code & ~KEY_MODIFIER_MASK;
- if (unmod < 256 && unmod != KEY_ENTER && unmod != KEY_TAB)
+ if (unmod >= 32 && unmod < MP_KEY_BASE)
code &= ~KEY_MODIFIER_SHIFT;
if (code & MP_KEY_DOWN) {
@@ -1491,10 +1504,15 @@ int mp_input_get_key_from_name(const char *name)
found:
name = p + 1;
}
- int len = strlen(name);
- if (len == 1) // Direct key code
- return (unsigned char)name[0] + modifiers;
- else if (len > 2 && strncasecmp("0x", name, 2) == 0)
+
+ struct bstr bname = bstr(name);
+
+ struct bstr rest;
+ int code = bstr_decode_utf8(bname, &rest);
+ if (code >= 0 && rest.len == 0)
+ return code + modifiers;
+
+ if (bstr_startswith0(bname, "0x"))
return strtol(name, NULL, 16) + modifiers;
for (int i = 0; key_names[i].name != NULL; i++) {