r35961 - in trunk: Changelog input/input.c libvo/x11_common.c osdep/getch2.c osdep/keycodes.h
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 */
Author: reimar Date: Thu Mar 14 20:59:35 2013 New Revision: 35961
Log: Add support for binding any key in UTF-8 range.
+ // 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");
Just curious: Why doesn't a setlocale() call interfere here and are these the two only UTF-8 locales allowed (what if someone only has de_DE.UTF-8, for example)? Ingo
On 15 Mar 2013, at 02:08, Ingo Brückl <ib@wupperonline.de> wrote:
Author: reimar Date: Thu Mar 14 20:59:35 2013 New Revision: 35961
Log: Add support for binding any key in UTF-8 range.
+ // 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");
Just curious: Why doesn't a setlocale() call interfere here
As far as I can tell both locales behave in the way be expect/they do not significantly change behaviour compared to not setting the locale.
and are these the two only UTF-8 locales allowed (what if someone only has de_DE.UTF-8, for example)?
Well, there are several hundred country/region codes, trying them all is hardly reasonable. The C one is what we really want but is rare/new, the en_US one is the most commonly available alternative.
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/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.
+ * Support binding keys corresponding to non-Latin-1 characters.
Modified: trunk/libvo/x11_common.c ========================================================================= +++ trunk/libvo/x11_common.c Thu Mar 14 20:59:35 2013 (r35961) @@ -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");
+ mp_msg(MSGT_VO, MSGL_WARN, "Could not find a UTF-8 locale, non-Latin-1 keys will no be handled.\n"); Reimar, would you mind these changes? "Some keys" sounds somehow randomly (and I was asking myself which of my keys might not be handled; answer: none won't be handled, all keys are fine). According to the Xlib manual, KeySym is mapped, if possible, to an ISO Latin-1 character, and the patch only takes effect beyond this range. Ingo
On 08.02.2014, at 18:06, Ingo Brückl <ib@wupperonline.de> wrote:
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/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.
+ * Support binding keys corresponding to non-Latin-1 characters.
Modified: trunk/libvo/x11_common.c ========================================================================= +++ trunk/libvo/x11_common.c Thu Mar 14 20:59:35 2013 (r35961) @@ -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");
+ mp_msg(MSGT_VO, MSGL_WARN, "Could not find a UTF-8 locale, non-Latin-1 keys will no be handled.\n");
Reimar, would you mind these changes? "Some keys" sounds somehow randomly (and I was asking myself which of my keys might not be handled; answer: none won't be handled, all keys are fine).
According to the Xlib manual, KeySym is mapped, if possible, to an ISO Latin-1 character, and the patch only takes effect beyond this range.
I don't think so, the error was reported for the french special c character, so I believe that even certain Latin-1 characters are affected, so that changed message would be misleading.
Reimar Döffinger wrote on Sun, 9 Feb 2014 13:26:11 +0100:
On 08.02.2014, at 18:06, Ingo Brückl <ib@wupperonline.de> wrote:
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/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.
+ * Support binding keys corresponding to non-Latin-1 characters.
Modified: trunk/libvo/x11_common.c ========================================================================= +++ trunk/libvo/x11_common.c Thu Mar 14 20:59:35 2013 (r35961) @@ -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");
+ mp_msg(MSGT_VO, MSGL_WARN, "Could not find a UTF-8 locale, non-Latin-1 keys will no be handled.\n");
Reimar, would you mind these changes? "Some keys" sounds somehow randomly (and I was asking myself which of my keys might not be handled; answer: none won't be handled, all keys are fine).
According to the Xlib manual, KeySym is mapped, if possible, to an ISO Latin-1 character, and the patch only takes effect beyond this range.
I don't think so, the error was reported for the french special c character, so I believe that even certain Latin-1 characters are affected, so that changed message would be misleading.
Quite strange. Where was the error report? Without XRebindKeysym() (and I can't spot one in MPlayer sources), libX11's _XTranslateKeySym() transforms a Latin 1 U+0020..U+00FF symbol into c = symbol & 0xFF and places c in buffer[0]. So I can't see why any Latin-1 character should be affected. Ingo
On 11 February 2014 11:07:22 CET, "Ingo Brückl" <ib@wupperonline.de> wrote:
Reimar Döffinger wrote on Sun, 9 Feb 2014 13:26:11 +0100:
On 08.02.2014, at 18:06, Ingo Brückl <ib@wupperonline.de> wrote:
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/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.
+ * Support binding keys corresponding to non-Latin-1 characters.
Modified: trunk/libvo/x11_common.c
=========================================================================
+++ trunk/libvo/x11_common.c Thu Mar 14 20:59:35 2013 (r35961) @@ -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");
+ mp_msg(MSGT_VO, MSGL_WARN, "Could not find a UTF-8 locale, non-Latin-1 keys will no be handled.\n");
Reimar, would you mind these changes? "Some keys" sounds somehow randomly (and I was asking myself which of my keys might not be handled; answer: none won't be handled, all keys are fine).
According to the Xlib manual, KeySym is mapped, if possible, to an ISO Latin-1 character, and the patch only takes effect beyond this range.
I don't think so, the error was reported for the french special c character, so I believe that even certain Latin-1 characters are affected, so that changed message would be misleading.
Quite strange. Where was the error report?
I thought it was on the bug tracker, but can't find it.
Without XRebindKeysym() (and I can't spot one in MPlayer sources), libX11's _XTranslateKeySym() transforms a Latin 1 U+0020..U+00FF symbol into c = symbol & 0xFF and places c in buffer[0].
So I can't see why any Latin-1 character should be affected.
You're probably right, I think the issue there was that specifying the key binding wasn't working, which I believe was fixed by an earlier commit, so I think overall the Changelog is right. What concerns the error message: some non-Latin 1 characters will work either way, like the cursor keys etc. But I guess your message is still more user-friendly.
Reimar Döffinger wrote on Tue, 11 Feb 2014 16:09:50 +0100:
What concerns the error message: some non-Latin 1 characters will work either way, like the cursor keys etc.
What about: "Could not find a UTF-8 locale, non-Latin-1 character keys will no be handled."? Ingo
On 11 February 2014 22:27:23 CET, "Ingo Brückl" <ib@wupperonline.de> wrote:
Reimar Döffinger wrote on Tue, 11 Feb 2014 16:09:50 +0100:
What concerns the error message: some non-Latin 1 characters will work either way, like the cursor keys etc.
What about: "Could not find a UTF-8 locale, non-Latin-1 character keys will no be handled."?
That is exactly the same message as you suggested earlier, including the spelling error? As I said, I don't mind since it's probably a more useful message, but as i also explained it is not really correct. Even more so since I think there is some trick to make the x functions always use UTF-8, though maybe i am just imagining that... It's just a question of pick two out of three, do you want the error message to be short, correct or useful? Microsoft opted for only the first and used numbers, so we'll at least do better than that no matter what...
Reimar Döffinger wrote on Wed, 12 Feb 2014 10:03:20 +0100:
On 11 February 2014 22:27:23 CET, "Ingo Brückl" <ib@wupperonline.de> wrote:
Reimar Döffinger wrote on Tue, 11 Feb 2014 16:09:50 +0100:
What concerns the error message: some non-Latin 1 characters will work either way, like the cursor keys etc.
What about: "Could not find a UTF-8 locale, non-Latin-1 character keys will no be handled."?
That is exactly the same message as you suggested earlier, including the spelling error?
You are correct about the spelling error, but I added "character" between "non-Latin-1" and "keys" to focus on keys that usually print characters. If anyone has an idea for a more precise one-liner... (If not, I'll apply.)
do you want the error message to be short, correct or useful?
An optimum of all of that. ;-) Ingo
I wrote on Wed, 12 Feb 2014 21:21:42 +0100:
Reimar Döffinger wrote on Wed, 12 Feb 2014 10:03:20 +0100:
On 11 February 2014 22:27:23 CET, "Ingo Brückl" <ib@wupperonline.de> wrote:
Reimar Döffinger wrote on Tue, 11 Feb 2014 16:09:50 +0100:
What concerns the error message: some non-Latin 1 characters will work either way, like the cursor keys etc.
Is "Could not find a UTF-8 locale, no binding for keys outside the Latin-1 range." better than "Could not find a UTF-8 locale, non-Latin-1 character keys will not be handled."? At least, it's easier to read and corresponds to MSGTR_NoBindFound. Ingo
participants (3)
-
Ingo Brückl -
reimar -
Reimar Döffinger