diff options
author | wm4 <wm4@mplayer2.org> | 2012-01-18 04:19:24 +0100 |
---|---|---|
committer | wm4 <wm4@mplayer2.org> | 2012-01-18 04:19:24 +0100 |
commit | 064f8c2fb656462db9662c67bdbc6716958a4de4 (patch) | |
tree | 28e2bc410b80f246629053661eeb77cfd7cfeeb2 /input | |
parent | f341b21a90d27977562645fb80f0cbbc2a17af7b (diff) | |
parent | 54ed2eeed394e4908e2848146543f27bc787fc63 (diff) | |
download | mpv-064f8c2fb656462db9662c67bdbc6716958a4de4.tar.bz2 mpv-064f8c2fb656462db9662c67bdbc6716958a4de4.tar.xz |
Merge branch 'utf8_input' into my_master
Diffstat (limited to 'input')
-rw-r--r-- | input/input.c | 33 | ||||
-rw-r--r-- | input/keycodes.h | 39 |
2 files changed, 46 insertions, 26 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++) { diff --git a/input/keycodes.h b/input/keycodes.h index 45e7ec7d4b..84b41a3e89 100644 --- a/input/keycodes.h +++ b/input/keycodes.h @@ -21,19 +21,16 @@ #ifndef MPLAYER_KEYCODES_H #define MPLAYER_KEYCODES_H +#define MP_KEY_BASE (1<<21) + // For appleir.c which includes another header with KEY_ENTER etc defines #ifndef AR_DEFINES_ONLY #define KEY_ENTER 13 #define KEY_TAB 9 -#define KEY_BASE 0x100 - -/* Function keys */ -#define KEY_F (KEY_BASE+64) - /* Control keys */ -#define KEY_CTRL (KEY_BASE) +#define KEY_CTRL (MP_KEY_BASE) #define KEY_BACKSPACE (KEY_CTRL+0) #define KEY_DELETE (KEY_CTRL+1) #define KEY_INSERT (KEY_CTRL+2) @@ -42,6 +39,7 @@ #define KEY_PAGE_UP (KEY_CTRL+5) #define KEY_PAGE_DOWN (KEY_CTRL+6) #define KEY_ESC (KEY_CTRL+7) +#define KEY_PRINT (KEY_CTRL+8) /* Control keys short name */ #define KEY_BS KEY_BACKSPACE @@ -52,14 +50,14 @@ #define KEY_PGDWN KEY_PAGE_DOWN /* Cursor movement */ -#define KEY_CRSR (KEY_BASE+16) +#define KEY_CRSR (MP_KEY_BASE+0x10) #define KEY_RIGHT (KEY_CRSR+0) #define KEY_LEFT (KEY_CRSR+1) #define KEY_DOWN (KEY_CRSR+2) #define KEY_UP (KEY_CRSR+3) /* Multimedia keyboard/remote keys */ -#define KEY_MM_BASE (0x100+384) +#define KEY_MM_BASE (MP_KEY_BASE+0x20) #define KEY_POWER (KEY_MM_BASE+0) #define KEY_MENU (KEY_MM_BASE+1) #define KEY_PLAY (KEY_MM_BASE+2) @@ -74,8 +72,11 @@ #define KEY_VOLUME_DOWN (KEY_MM_BASE+11) #define KEY_MUTE (KEY_MM_BASE+12) +/* Function keys */ +#define KEY_F (MP_KEY_BASE+0x40) + /* Keypad keys */ -#define KEY_KEYPAD (KEY_BASE+32) +#define KEY_KEYPAD (MP_KEY_BASE+0x60) #define KEY_KP0 (KEY_KEYPAD+0) #define KEY_KP1 (KEY_KEYPAD+1) #define KEY_KP2 (KEY_KEYPAD+2) @@ -93,7 +94,7 @@ // Joystick input module -#define JOY_BASE (0x100+128) +#define JOY_BASE (MP_KEY_BASE+0x70) #define JOY_AXIS0_PLUS (JOY_BASE+0) #define JOY_AXIS0_MINUS (JOY_BASE+1) #define JOY_AXIS1_PLUS (JOY_BASE+2) @@ -115,7 +116,7 @@ #define JOY_AXIS9_PLUS (JOY_BASE+18) #define JOY_AXIS9_MINUS (JOY_BASE+19) -#define JOY_BTN_BASE ((0x100+148)|MP_NO_REPEAT_KEY) +#define JOY_BTN_BASE ((MP_KEY_BASE+0x90)|MP_NO_REPEAT_KEY) #define JOY_BTN0 (JOY_BTN_BASE+0) #define JOY_BTN1 (JOY_BTN_BASE+1) #define JOY_BTN2 (JOY_BTN_BASE+2) @@ -129,7 +130,7 @@ // Mouse events from VOs -#define MOUSE_BASE ((0x100+256)|MP_NO_REPEAT_KEY) +#define MOUSE_BASE ((MP_KEY_BASE+0xA0)|MP_NO_REPEAT_KEY) #define MOUSE_BTN0 (MOUSE_BASE+0) #define MOUSE_BTN1 (MOUSE_BASE+1) #define MOUSE_BTN2 (MOUSE_BASE+2) @@ -152,7 +153,7 @@ #define MOUSE_BTN19 (MOUSE_BASE+19) #define MOUSE_BTN_END (MOUSE_BASE+20) -#define MOUSE_BASE_DBL (0x300|MP_NO_REPEAT_KEY) +#define MOUSE_BASE_DBL ((MP_KEY_BASE+0xC0)|MP_NO_REPEAT_KEY) #define MOUSE_BTN0_DBL (MOUSE_BASE_DBL+0) #define MOUSE_BTN1_DBL (MOUSE_BASE_DBL+1) #define MOUSE_BTN2_DBL (MOUSE_BASE_DBL+2) @@ -179,7 +180,7 @@ #endif // AR_DEFINES_ONLY // Apple Remote input module -#define AR_BASE 0x500 +#define AR_BASE (MP_KEY_BASE+0xE0) #define AR_PLAY (AR_BASE + 0) #define AR_PLAY_HOLD (AR_BASE + 1) #define AR_NEXT (AR_BASE + 2) @@ -195,14 +196,14 @@ /* Special keys */ -#define KEY_INTERN (0x1000) +#define KEY_INTERN (MP_KEY_BASE+0x1000) #define KEY_CLOSE_WIN (KEY_INTERN+0) /* Modifiers added to individual keys */ -#define KEY_MODIFIER_SHIFT 0x2000 -#define KEY_MODIFIER_CTRL 0x4000 -#define KEY_MODIFIER_ALT 0x8000 -#define KEY_MODIFIER_META 0x10000 +#define KEY_MODIFIER_SHIFT (1<<22) +#define KEY_MODIFIER_CTRL (1<<23) +#define KEY_MODIFIER_ALT (1<<24) +#define KEY_MODIFIER_META (1<<25) #endif // AR_DEFINES_ONLY |