[MPlayer-cvslog] r28172 - in trunk/libvo: video_out.c video_out.h w32_common.c x11_common.c

reimar subversion at mplayerhq.hu
Sat Dec 20 12:52:12 CET 2008


Author: reimar
Date: Sat Dec 20 12:52:11 2008
New Revision: 28172

Log:
Add and use a special lookup function to do table-based translation to MPlayer keycodes.


Modified:
   trunk/libvo/video_out.c
   trunk/libvo/video_out.h
   trunk/libvo/w32_common.c
   trunk/libvo/x11_common.c

Modified: trunk/libvo/video_out.c
==============================================================================
--- trunk/libvo/video_out.c	(original)
+++ trunk/libvo/video_out.c	Sat Dec 20 12:52:11 2008
@@ -328,6 +328,17 @@ int config_video_out(const vo_functions_
   return vo->config(width, height, d_width, d_height, flags, title, format);
 }
 
+/**
+ * \brief lookup an integer in a table, table must have 0 as the last key
+ * \param key key to search for
+ * \result translation corresponding to key or "to" value of last mapping
+ *         if not found.
+ */
+int lookup_keymap_table(const struct keymap *map, int key) {
+  while (map->from && map->from != key) map++;
+  return map->to;
+}
+
 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA)
 /* Borrowed from vo_fbdev.c
 Monitor ranges related functions*/

Modified: trunk/libvo/video_out.h
==============================================================================
--- trunk/libvo/video_out.h	(original)
+++ trunk/libvo/video_out.h	Sat Dec 20 12:52:11 2008
@@ -251,4 +251,10 @@ extern char *monitor_hfreq_str;
 extern char *monitor_vfreq_str;
 extern char *monitor_dotclock_str;
 
+struct keymap {
+  int from;
+  int to;
+};
+int lookup_keymap_table(const struct keymap *map, int key);
+
 #endif /* MPLAYER_VIDEO_OUT_H */

Modified: trunk/libvo/w32_common.c
==============================================================================
--- trunk/libvo/w32_common.c	(original)
+++ trunk/libvo/w32_common.c	Sat Dec 20 12:52:11 2008
@@ -40,9 +40,24 @@ static HMONITOR (WINAPI* myMonitorFromWi
 static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO);
 static BOOL (WINAPI* myEnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
 
+static const struct keymap vk_map[] = {
+    // special keys
+    {VK_ESCAPE, KEY_ESC}, {VK_BACK, KEY_BS}, {VK_TAB, KEY_TAB}, {VK_CONTROL, KEY_CTRL},
+
+    // cursor keys
+    {VK_LEFT, KEY_LEFT}, {VK_UP, KEY_UP}, {VK_RIGHT, KEY_RIGHT}, {VK_DOWN, KEY_DOWN},
+
+    // navigation block
+    {VK_INSERT, KEY_INSERT}, {VK_DELETE, KEY_DELETE}, {VK_HOME, KEY_HOME}, {VK_END, KEY_END},
+    {VK_PRIOR, KEY_PAGE_UP}, {VK_NEXT, KEY_PAGE_DOWN},
+
+    {0, 0}
+};
+
 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
     RECT r;
     POINT p;
+    int mpkey;
     switch (message) {
         case WM_ERASEBKGND: // no need to erase background seperately
             return 1;
@@ -88,22 +103,9 @@ static LRESULT CALLBACK WndProc(HWND hWn
             }
             break;
         case WM_KEYDOWN:
-            switch (wParam) {
-                case VK_LEFT:    mplayer_put_key(KEY_LEFT);      break;
-                case VK_UP:      mplayer_put_key(KEY_UP);        break;
-                case VK_RIGHT:   mplayer_put_key(KEY_RIGHT);     break;
-                case VK_DOWN:    mplayer_put_key(KEY_DOWN);      break;
-                case VK_TAB:     mplayer_put_key(KEY_TAB);       break;
-                case VK_CONTROL: mplayer_put_key(KEY_CTRL);      break;
-                case VK_BACK:    mplayer_put_key(KEY_BS);        break;
-                case VK_DELETE:  mplayer_put_key(KEY_DELETE);    break;
-                case VK_INSERT:  mplayer_put_key(KEY_INSERT);    break;
-                case VK_HOME:    mplayer_put_key(KEY_HOME);      break;
-                case VK_END:     mplayer_put_key(KEY_END);       break;
-                case VK_PRIOR:   mplayer_put_key(KEY_PAGE_UP);   break;
-                case VK_NEXT:    mplayer_put_key(KEY_PAGE_DOWN); break;
-                case VK_ESCAPE:  mplayer_put_key(KEY_ESC);       break;
-            }
+            mpkey = lookup_keymap_table(vk_map, wParam);
+            if (mpkey)
+                mplayer_put_key(mpkey);
             break;
         case WM_CHAR:
             mplayer_put_key(wParam);

Modified: trunk/libvo/x11_common.c
==============================================================================
--- trunk/libvo/x11_common.c	(original)
+++ trunk/libvo/x11_common.c	Sat Dec 20 12:52:11 2008
@@ -543,47 +543,23 @@ void vo_uninit(void)
 #include "wskeys.h"
 
 #ifdef XF86XK_AudioPause
+static const struct keymap keysym_map[] = {
+    {XF86XK_MenuKB, KEY_MENU},
+    {XF86XK_AudioPlay, KEY_PLAY}, {XF86XK_AudioPause, KEY_PAUSE}, {XF86XK_AudioStop, KEY_STOP},
+    {XF86XK_AudioPrev, KEY_PREV}, {XF86XK_AudioNext, KEY_NEXT},
+    {XF86XK_AudioMute, KEY_MUTE}, {XF86XK_AudioLowerVolume, KEY_VOLUME_DOWN}, {XF86XK_AudioRaiseVolume, KEY_VOLUME_UP},
+    {0, 0}
+};
+
 static void vo_x11_putkey_ext(int keysym)
 {
-    switch (keysym)
-    {
-        case XF86XK_MenuKB:
-            mplayer_put_key(KEY_MENU);
-            break;
-        case XF86XK_AudioPlay:
-            mplayer_put_key(KEY_PLAY);
-            break;
-        case XF86XK_AudioPause:
-            mplayer_put_key(KEY_PAUSE);
-            break;
-        case XF86XK_AudioStop:
-            mplayer_put_key(KEY_STOP);
-            break;
-        case XF86XK_AudioPrev:
-            mplayer_put_key(KEY_PREV);
-            break;
-        case XF86XK_AudioNext:
-            mplayer_put_key(KEY_NEXT);
-            break;
-        case XF86XK_AudioMute:
-            mplayer_put_key(KEY_MUTE);
-            break;
-        case XF86XK_AudioLowerVolume:
-            mplayer_put_key(KEY_VOLUME_DOWN);
-            break;
-        case XF86XK_AudioRaiseVolume:
-            mplayer_put_key(KEY_VOLUME_UP);
-            break;
-        default:
-            break;
-    }
+    int mpkey = lookup_keymap_table(keysym_map, keysym);
+    if (mpkey)
+        mplayer_put_key(mpkey);
 }
 #endif
 
-struct {
-    int x11key;
-    int mpkey;
-} static const keymap[] = {
+static const struct keymap keymap[] = {
     // special keys
     {wsEscape, KEY_ESC}, {wsBackSpace, KEY_BS}, {wsTab, KEY_TAB}, {wsEnter, KEY_ENTER},
 
@@ -629,9 +605,8 @@ void vo_x11_putkey(int key)
         (key >  0   && key <  256 && strchr(passthrough_keys, key)))
         mpkey = key;
 
-    for (i = 0; !mpkey && keymap[i].x11key; i++)
-        if (keymap[i].x11key == key)
-            mpkey = keymap[i].mpkey;
+    if (!mpkey)
+        lookup_keymap_table(keymap, key);
 
     if (mpkey)
         mplayer_put_key(mpkey);



More information about the MPlayer-cvslog mailing list