[MPlayer-cvslog] r35961 - in trunk: Changelog input/input.c libvo/x11_common.c osdep/getch2.c osdep/keycodes.h
reimar
subversion at mplayerhq.hu
Thu Mar 14 20:59:35 CET 2013
Author: reimar
Date: Thu Mar 14 20:59:35 2013
New Revision: 35961
Log:
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.
Modified:
trunk/Changelog
trunk/input/input.c
trunk/libvo/x11_common.c
trunk/osdep/getch2.c
trunk/osdep/keycodes.h
Modified: trunk/Changelog
==============================================================================
--- trunk/Changelog Wed Mar 13 11:13:13 2013 (r35960)
+++ trunk/Changelog Thu Mar 14 20:59:35 2013 (r35961)
@@ -13,6 +13,7 @@ MPlayer
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"
Modified: trunk/input/input.c
==============================================================================
--- trunk/input/input.c Wed Mar 13 11:13:13 2013 (r35960)
+++ trunk/input/input.c Thu Mar 14 20:59:35 2013 (r35961)
@@ -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 @@ mp_input_get_key_name(int key) {
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 @@ mp_input_get_key_from_name(const char *n
return key_names[i].key;
}
+ GET_UTF8(utf8, (uint8_t)*name++, return -1;)
+ if (*name == 0 && utf8 < KEY_BASE)
+ return utf8;
+
return -1;
}
Modified: trunk/libvo/x11_common.c
==============================================================================
--- trunk/libvo/x11_common.c Wed Mar 13 11:13:13 2013 (r35960)
+++ trunk/libvo/x11_common.c Thu Mar 14 20:59:35 2013 (r35961)
@@ -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 @@ int vo_init(void)
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 @@ static int check_resize(void)
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 @@ int vo_x11_check_events(Display * mydisp
case KeyPress:
case KeyRelease:
{
- int key;
+ int key, utf8;
#ifdef CONFIG_GUI
if ( use_gui ) { break; }
@@ -863,6 +878,8 @@ int vo_x11_check_events(Display * mydisp
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 @@ int vo_x11_check_events(Display * mydisp
(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;
}
Modified: trunk/osdep/getch2.c
==============================================================================
--- trunk/osdep/getch2.c Wed Mar 13 11:13:13 2013 (r35960)
+++ trunk/osdep/getch2.c Thu Mar 14 20:59:35 2013 (r35961)
@@ -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 @@ void getch2(void)
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 @@ void getch2(void)
}
}
}
+ not_utf8:
found:
getch2_len -= len;
for (i = 0; i < getch2_len; i++)
Modified: trunk/osdep/keycodes.h
==============================================================================
--- trunk/osdep/keycodes.h Wed Mar 13 11:13:13 2013 (r35960)
+++ trunk/osdep/keycodes.h Thu Mar 14 20:59:35 2013 (r35961)
@@ -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 @@ enum {
KEY_VOLUME_DOWN,
KEY_MUTE,
/* Special internal/virtual keys */
- KEY_CLOSE_WIN = 0x1000,
+ KEY_CLOSE_WIN = KEY_BASE + 0x1000,
};
/* Control keys short name */
More information about the MPlayer-cvslog
mailing list