From a63e880400c7c840858e499a18735c6e1f8248fe Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 14 Jan 2012 14:09:26 +0100 Subject: input: allow unicode keys and reassign internal key codes This moves all key codes above the highest valid unicode code point (which is 0x10FFFF). All key codes below MP_KEY_BASE now directly map to unicode. Configuration files (input.conf) can contain unicode characters in UTF-8 to map non-ASCII characters/keys. This shouldn't change anything user visible, except that "direct key codes" (as used in input.conf) will change their meaning. --- input/input.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'input/input.c') diff --git a/input/input.c b/input/input.c index e1c001077a..df9c884935 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" @@ -647,6 +648,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++) { @@ -661,8 +673,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); @@ -1171,7 +1184,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) { @@ -1489,10 +1502,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++) { -- cgit v1.2.3 From fdc7155ced89779a4ca59ea05c15c6ad419ee863 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 13 Jan 2012 10:09:40 +0100 Subject: x11: add print and menu keys --- input/input.c | 1 + 1 file changed, 1 insertion(+) (limited to 'input/input.c') diff --git a/input/input.c b/input/input.c index df9c884935..b5e66f6603 100644 --- a/input/input.c +++ b/input/input.c @@ -229,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" }, -- cgit v1.2.3