summaryrefslogtreecommitdiffstats
path: root/input/input.c
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-14 14:09:26 +0100
committerwm4 <wm4@mplayer2.org>2012-01-18 04:11:48 +0100
commita63e880400c7c840858e499a18735c6e1f8248fe (patch)
treed01de78890c2b0432fd622a5b73f27e07a748312 /input/input.c
parent7700e6effca6358820cb969ddf896a2be4b77ede (diff)
downloadmpv-a63e880400c7c840858e499a18735c6e1f8248fe.tar.bz2
mpv-a63e880400c7c840858e499a18735c6e1f8248fe.tar.xz
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.
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 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++) {