[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] ioemu: fix SDL mouse events processing



ioemu: fix SDL mouse events processing
- GetRelativeMouseState always returns the last position, so when the
  polling loop gets several mouse events in one go, we would send
  useless 'no move' events.
- So as to make sure we don't miss any mouse click / double click, we
  should not use GetRelativeMouseState() to get the button state, but
  keep records of the button state ourselves.

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>

diff -r 86e64b684fb2 tools/ioemu/sdl.c
--- a/tools/ioemu/sdl.c Wed Mar 05 11:10:29 2008 +0000
+++ b/tools/ioemu/sdl.c Wed Mar 05 11:41:24 2008 +0000
@@ -360,6 +360,7 @@
 {
     SDL_Event ev1, *ev = &ev1;
     int mod_state;
+    int state;
                      
     if (last_vm_running != vm_running) {
         last_vm_running = vm_running;
@@ -368,6 +369,7 @@
 
     vga_hw_update();
 
+    state = SDL_GetMouseState(NULL, NULL);
     while (SDL_PollEvent(ev)) {
         switch (ev->type) {
         case SDL_VIDEOEXPOSE:
@@ -475,41 +477,38 @@
         case SDL_MOUSEMOTION:
             if (gui_grab || kbd_mouse_is_absolute() ||
                 absolute_enabled) {
-                int dx, dy, state;
-                state = SDL_GetRelativeMouseState(&dx, &dy);
-                sdl_send_mouse_event(dx, dy, 0, state);
+                int dx, dy;
+                SDL_GetRelativeMouseState(&dx, &dy);
+                if (dx || dy)
+                    sdl_send_mouse_event(dx, dy, 0, state);
             }
             break;
         case SDL_MOUSEBUTTONUP:
             if (gui_grab || kbd_mouse_is_absolute()) {
-                int dx, dy, state;
-                state = SDL_GetRelativeMouseState(&dx, &dy);
-                sdl_send_mouse_event(dx, dy, 0, state);
+                state &= ~SDL_BUTTON(ev->button.button);
+                sdl_send_mouse_event(0, 0, 0, state);
             }
             break;
         case SDL_MOUSEBUTTONDOWN:
             {
                 SDL_MouseButtonEvent *bev = &ev->button;
                 if (!gui_grab && !kbd_mouse_is_absolute()) {
-                    if (ev->type == SDL_MOUSEBUTTONDOWN &&
-                        (bev->state & SDL_BUTTON_LMASK)) {
+                    if (bev->button == SDL_BUTTON_LEFT) {
                         /* start grabbing all events */
                         sdl_grab_start();
                     }
                 } else {
-                    int dx, dy, dz, state;
+                    int dz;
                     dz = 0;
-                    state = SDL_GetRelativeMouseState(&dx, &dy);
+                    state |= SDL_BUTTON(bev->button);
 #ifdef SDL_BUTTON_WHEELUP
                     if (bev->button == SDL_BUTTON_WHEELUP) {
                         dz = -1;
                     } else if (bev->button == SDL_BUTTON_WHEELDOWN) {
                         dz = 1;
-                    } else {
-                        state = bev->button | state;
                     }
 #endif               
-                    sdl_send_mouse_event(dx, dy, dz, state);
+                    sdl_send_mouse_event(0, 0, dz, state);
                 }
             }
             break;

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.