Mercurial > mplayer.hg
changeset 35867:6ac59489c815
Add support for binding any key in UTF-8 range.
X11 part is a bit hackish since we need to use
setlocale to get desired behaviour for XLookupString.
author | reimar |
---|---|
date | Thu, 14 Mar 2013 19:59:35 +0000 |
parents | 24349a6cdad7 |
children | 3edaed3c1d60 |
files | Changelog input/input.c libvo/x11_common.c osdep/getch2.c osdep/keycodes.h |
diffstat | 5 files changed, 40 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Changelog Wed Mar 13 10:13:13 2013 +0000 +++ b/Changelog Thu Mar 14 19:59:35 2013 +0000 @@ -13,6 +13,7 @@ better than -vo gl (it is in many ways worse). * Fixes for DVB, teletext and closed-caption based subtitles. * Support teletext and CC subtitles in WTV. + * Support binding keys corresponding to non-ASCII characters. 1.1: "We gave up on 1.0"
--- a/input/input.c Wed Mar 13 10:13:13 2013 +0000 +++ b/input/input.c Thu Mar 14 19:59:35 2013 +0000 @@ -38,6 +38,7 @@ #include "osdep/getch2.h" #include "osdep/keycodes.h" #include "osdep/timer.h" +#include "libavutil/common.h" #include "libavutil/avstring.h" #include "mp_msg.h" #include "help_mp.h" @@ -1474,6 +1475,7 @@ int mp_input_get_key_from_name(const char *name) { + uint32_t utf8 = 0; int i,ret = 0,len = strlen(name); if(len == 1) { // Direct key code ret = (unsigned char)name[0]; @@ -1486,6 +1488,10 @@ return key_names[i].key; } + GET_UTF8(utf8, (uint8_t)*name++, return -1;) + if (*name == 0 && utf8 < KEY_BASE) + return utf8; + return -1; }
--- a/libvo/x11_common.c Wed Mar 13 10:13:13 2013 +0000 +++ b/libvo/x11_common.c Thu Mar 14 19:59:35 2013 +0000 @@ -21,6 +21,7 @@ #include <math.h> #include <inttypes.h> #include <limits.h> +#include <locale.h> #include "config.h" #include "mp_msg.h" @@ -427,6 +428,9 @@ return 1; // already called } + // Required so that XLookupString returns UTF-8 + if (!setlocale(LC_CTYPE, "C.UTF-8") && !setlocale(LC_CTYPE, "en_US.utf8")) + mp_msg(MSGT_VO, MSGL_WARN, "Could not find a UTF-8 locale, some keys will no be handled.\n"); XSetErrorHandler(x11_errorhandler); dispName = XDisplayName(mDisplayName); @@ -810,11 +814,22 @@ return rc; } +static int to_utf8(const uint8_t *in) +{ + uint32_t v = 0; + GET_UTF8(v, *in++, goto err;) + if (*in || v >= KEY_BASE) + goto err; + return v; +err: + return 0; +} + int vo_x11_check_events(Display * mydisplay) { int ret = 0; XEvent Event; - char buf[100]; + uint8_t buf[16] = {0}; KeySym keySym; static XComposeStatus stat; static int ctrl_state; @@ -852,7 +867,7 @@ case KeyPress: case KeyRelease: { - int key; + int key, utf8; #ifdef CONFIG_GUI if ( use_gui ) { break; } @@ -863,6 +878,8 @@ key = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); + utf8 = to_utf8(buf); + if (utf8) key = 0; if (key == wsLeftCtrl || key == wsRightCtrl) { ctrl_state = Event.type == KeyPress; mplayer_put_key(KEY_CTRL | @@ -880,7 +897,8 @@ (ctrl_state ? MP_KEY_DOWN : 0)); } if (!vo_x11_putkey_ext(keySym)) { - vo_x11_putkey(key); + if (utf8) mplayer_put_key(utf8); + else vo_x11_putkey(key); } ret |= VO_EVENT_KEYPRESS; }
--- a/osdep/getch2.c Wed Mar 13 10:13:13 2013 +0000 +++ b/osdep/getch2.c Thu Mar 14 19:59:35 2013 +0000 @@ -60,6 +60,7 @@ #include "mp_fifo.h" #include "keycodes.h" #include "getch2.h" +#include "libavutil/common.h" #ifdef HAVE_TERMIOS static struct termios tio_orig; @@ -201,6 +202,14 @@ len = 2; } code = KEY_ENTER; + } else if (code >= 0xc0) { + uint32_t utf8 = 0; + i = 0; + GET_UTF8(utf8, (i < getch2_len ? getch2_buf[i++] : 0), goto not_utf8;) + if (utf8 < KEY_BASE) { + code = utf8; + len = i; + } } } else if (getch2_len > 1) { @@ -262,6 +271,7 @@ } } } + not_utf8: found: getch2_len -= len; for (i = 0; i < getch2_len; i++)
--- a/osdep/keycodes.h Wed Mar 13 10:13:13 2013 +0000 +++ b/osdep/keycodes.h Thu Mar 14 19:59:35 2013 +0000 @@ -23,7 +23,7 @@ #ifndef MPLAYER_KEYCODES_H #define MPLAYER_KEYCODES_H -#define KEY_BASE 0x100 +#define KEY_BASE 0x1000000 enum { KEY_TAB = 9, @@ -76,7 +76,7 @@ KEY_VOLUME_DOWN, KEY_MUTE, /* Special internal/virtual keys */ - KEY_CLOSE_WIN = 0x1000, + KEY_CLOSE_WIN = KEY_BASE + 0x1000, }; /* Control keys short name */