[MPlayer-cvslog] r36262 - trunk/libvo/x11_common.c

reimar subversion at mplayerhq.hu
Thu May 9 16:06:17 CEST 2013


Author: reimar
Date: Thu May  9 16:06:17 2013
New Revision: 36262

Log:
Handle X events even while waiting for a map event.

Modified:
   trunk/libvo/x11_common.c

Modified: trunk/libvo/x11_common.c
==============================================================================
--- trunk/libvo/x11_common.c	Thu May  9 16:06:16 2013	(r36261)
+++ trunk/libvo/x11_common.c	Thu May  9 16:06:17 2013	(r36262)
@@ -826,44 +826,28 @@ err:
     return 0;
 }
 
-int vo_x11_check_events(Display * mydisplay)
+static int handle_x11_event(Display *mydisplay, XEvent *event)
 {
-    int ret = 0;
-    XEvent Event;
     uint8_t buf[16] = {0};
     KeySym keySym;
     static XComposeStatus stat;
     static int ctrl_state;
-
-    if (vo_mouse_autohide && mouse_waiting_hide &&
-                                 (GetTimerMS() - mouse_timer >= 1000)) {
-        vo_hidecursor(mydisplay, vo_window);
-        mouse_waiting_hide = 0;
-    }
-
-    if (WinID > 0)
-        ret |= check_resize();
-    while (XPending(mydisplay))
-    {
-        XNextEvent(mydisplay, &Event);
 #ifdef CONFIG_GUI
         if (use_gui)
         {
-            gui(GUI_HANDLE_X_EVENT, &Event);
-            if (vo_window != Event.xany.window)
-                continue;
+            gui(GUI_HANDLE_X_EVENT, event);
+            if (vo_window != event->xany.window)
+                return 0;
         }
 #endif
-        switch (Event.type)
+        switch (event->type)
         {
             case Expose:
-                ret |= VO_EVENT_EXPOSE;
-                break;
+                return VO_EVENT_EXPOSE;
             case ConfigureNotify:
                 if (vo_window == None)
                     break;
-                ret |= check_resize();
-                break;
+                return check_resize();
             case KeyPress:
             case KeyRelease:
                 {
@@ -873,7 +857,7 @@ int vo_x11_check_events(Display * mydisp
                     if ( use_gui ) { break; }
 #endif
 
-                    XLookupString(&Event.xkey, buf, sizeof(buf), &keySym,
+                    XLookupString(&event->xkey, buf, sizeof(buf), &keySym,
                                   &stat);
                     key =
                         ((keySym & 0xff00) !=
@@ -881,18 +865,18 @@ int vo_x11_check_events(Display * mydisp
                     utf8 = buf[0] > 0xc0 ? to_utf8(buf) : 0;
                     if (utf8) key = 0;
                     if (key == wsLeftCtrl || key == wsRightCtrl) {
-                        ctrl_state = Event.type == KeyPress;
+                        ctrl_state = event->type == KeyPress;
                         mplayer_put_key(KEY_CTRL |
                             (ctrl_state ? MP_KEY_DOWN : 0));
-                    } else if (Event.type == KeyRelease) {
+                    } else if (event->type == KeyRelease) {
                         break;
                     }
                     // Attempt to fix if somehow our state got out of
                     // sync with reality.
                     // This usually happens when a shortcut involving CTRL
                     // was used to switch to a different window/workspace.
-                    if (ctrl_state != !!(Event.xkey.state & 4)) {
-                        ctrl_state = !!(Event.xkey.state & 4);
+                    if (ctrl_state != !!(event->xkey.state & 4)) {
+                        ctrl_state = !!(event->xkey.state & 4);
                         mplayer_put_key(KEY_CTRL |
                             (ctrl_state ? MP_KEY_DOWN : 0));
                     }
@@ -900,11 +884,11 @@ int vo_x11_check_events(Display * mydisp
                         if (utf8) mplayer_put_key(utf8);
                         else vo_x11_putkey(key);
                     }
-                    ret |= VO_EVENT_KEYPRESS;
+                    return VO_EVENT_KEYPRESS;
                 }
                 break;
             case MotionNotify:
-                vo_mouse_movement(Event.xmotion.x, Event.xmotion.y);
+                vo_mouse_movement(event->xmotion.x, event->xmotion.y);
 
                 if (vo_mouse_autohide)
                 {
@@ -922,11 +906,11 @@ int vo_x11_check_events(Display * mydisp
                 }
 #ifdef CONFIG_GUI
                 // Ignore mouse button 1-3 under GUI.
-                if (use_gui && (Event.xbutton.button >= 1)
-                    && (Event.xbutton.button <= 3))
+                if (use_gui && (event->xbutton.button >= 1)
+                    && (event->xbutton.button <= 3))
                     break;
 #endif
-                mplayer_put_key((MOUSE_BTN0 + Event.xbutton.button -
+                mplayer_put_key((MOUSE_BTN0 + event->xbutton.button -
                                  1) | MP_KEY_DOWN);
                 break;
             case ButtonRelease:
@@ -938,16 +922,16 @@ int vo_x11_check_events(Display * mydisp
                 }
 #ifdef CONFIG_GUI
                 // Ignore mouse button 1-3 under GUI.
-                if (use_gui && (Event.xbutton.button >= 1)
-                    && (Event.xbutton.button <= 3))
+                if (use_gui && (event->xbutton.button >= 1)
+                    && (event->xbutton.button <= 3))
                     break;
 #endif
-                mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1);
+                mplayer_put_key(MOUSE_BTN0 + event->xbutton.button - 1);
                 break;
             case PropertyNotify:
                 {
                     char *name =
-                        XGetAtomName(mydisplay, Event.xproperty.atom);
+                        XGetAtomName(mydisplay, event->xproperty.atom);
 
                     if (!name)
                         break;
@@ -967,11 +951,31 @@ int vo_x11_check_events(Display * mydisp
                 mplayer_put_key(KEY_CLOSE_WIN);
                 break;
 	    case ClientMessage:
-                if (Event.xclient.message_type == XAWM_PROTOCOLS &&
-                    Event.xclient.data.l[0] == XAWM_DELETE_WINDOW)
+                if (event->xclient.message_type == XAWM_PROTOCOLS &&
+                    event->xclient.data.l[0] == XAWM_DELETE_WINDOW)
                     mplayer_put_key(KEY_CLOSE_WIN);
                 break;
         }
+        return 0;
+}
+
+int vo_x11_check_events(Display * mydisplay)
+{
+    int ret = 0;
+    XEvent Event;
+
+    if (vo_mouse_autohide && mouse_waiting_hide &&
+                                 (GetTimerMS() - mouse_timer >= 1000)) {
+        vo_hidecursor(mydisplay, vo_window);
+        mouse_waiting_hide = 0;
+    }
+
+    if (WinID > 0)
+        ret |= check_resize();
+    while (XPending(mydisplay))
+    {
+        XNextEvent(mydisplay, &Event);
+        ret |= handle_x11_event(mydisplay, &Event);
     }
     return ret;
 }
@@ -1176,6 +1180,7 @@ void vo_x11_create_vo_window(XVisualInfo
     // wait for map
     do {
       XNextEvent(mDisplay, &xev);
+      handle_x11_event(mDisplay, &xev);
     } while (xev.type != MapNotify || xev.xmap.event != vo_window);
     vo_x11_clearwindow(mDisplay, vo_window);
     vo_x11_selectinput_witherr(mDisplay, vo_window,


More information about the MPlayer-cvslog mailing list