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

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



Hi all,
this patch fixes some SDL mouse event related issues; it was originally
posted on qemu-devel by Samuel:

http://lists.gnu.org/archive/html/qemu-devel/2008-03/msg00049.html

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

---

diff --git a/sdl.c b/sdl.c
index 72e7d82..9afd884 100644
--- a/sdl.c
+++ b/sdl.c
@@ -492,8 +492,6 @@ static void sdl_grab_start(void)
 {
     sdl_hide_cursor();
     SDL_WM_GrabInput(SDL_GRAB_ON);
-    /* dummy read to avoid moving the mouse */
-    SDL_GetRelativeMouseState(NULL, NULL);
     gui_grab = 1;
     sdl_update_caption();
 }
@@ -685,39 +683,37 @@ static void sdl_refresh(DisplayState *ds)
                 absolute_enabled) {
                 int dx, dy, state;
                 state = SDL_GetRelativeMouseState(&dx, &dy);
-                sdl_send_mouse_event(dx, dy, 0, state);
+                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);
-            }
-            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)) {
+                        (bev->button == SDL_BUTTON_LEFT)) {
                         /* start grabbing all events */
                         sdl_grab_start();
                     }
                 } else {
-                    int dx, dy, dz, state;
+                    int dz, state;
                     dz = 0;
-                    state = SDL_GetRelativeMouseState(&dx, &dy);
+                    state = SDL_GetMouseState(NULL, NULL);
+                    if (ev->type == SDL_MOUSEBUTTONDOWN) {
+                        state |= SDL_BUTTON(bev->button);
+                    } else {
+                        state &= ~SDL_BUTTON(bev->button);
+                    }
 #ifdef SDL_BUTTON_WHEELUP
-                    if (bev->button == SDL_BUTTON_WHEELUP) {
+                    if (bev->button == SDL_BUTTON_WHEELUP && ev->type == 
SDL_MOUSEBUTTONDOWN) {
                         dz = -1;
-                    } else if (bev->button == SDL_BUTTON_WHEELDOWN) {
+                    } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type 
== SDL_MOUSEBUTTONDOWN) {
                         dz = 1;
-                    } else {
-                        state = bev->button | state;
                     }
-#endif               
-                    sdl_send_mouse_event(dx, dy, dz, state);
+#endif
+                    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®.