changeset 36166:a6263abe514f

Handle X events even while waiting for a map event.
author reimar
date Thu, 09 May 2013 14:06:17 +0000
parents 9514b53f6f04
children 29fb09ef97b9
files libvo/x11_common.c
diffstat 1 files changed, 44 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/x11_common.c	Thu May 09 14:06:16 2013 +0000
+++ b/libvo/x11_common.c	Thu May 09 14:06:17 2013 +0000
@@ -826,44 +826,28 @@
     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 @@
                     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 @@
                     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 @@
                         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 @@
                 }
 #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 @@
                 }
 #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 @@
                 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 @@
     // 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,