summaryrefslogtreecommitdiffstats
path: root/input/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'input/input.c')
-rw-r--r--input/input.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/input/input.c b/input/input.c
index f97487c1f7..d9c95238d1 100644
--- a/input/input.c
+++ b/input/input.c
@@ -36,6 +36,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"
@@ -228,6 +229,7 @@ static const struct key_name key_names[] = {
{ KEY_PAGE_UP, "PGUP" },
{ KEY_PAGE_DOWN, "PGDWN" },
{ KEY_ESC, "ESC" },
+ { KEY_PRINT, "PRINT" },
{ KEY_RIGHT, "RIGHT" },
{ KEY_LEFT, "LEFT" },
{ KEY_DOWN, "DOWN" },
@@ -644,6 +646,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++) {
@@ -658,8 +671,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);
@@ -1188,7 +1202,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) {
@@ -1506,10 +1520,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++) {