Skip to contentSkip to conversation

sdl hide pointer when not in focus

PATCH In review Stefano Stabellini 2 participants 2 messages Nov 4, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sdl hide pointer when not in focus

Hide the mouse pointer when the sdl window is not in focus.

sdl.c +11 -1
diff -r e42ba25a7313 sdl.c
@@ -50,6 +50,7 @@
 static int guest_cursor = 0;
 static int guest_x, guest_y;
 static SDL_Cursor *guest_sprite = 0;
+static int mouse_active = SDL_ENABLE;
 
 static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
 {
@@ -514,7 +515,8 @@
                         dz = 1;
                     }
 #endif
-                    sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
+                    if (mouse_active == SDL_ENABLE)
+                        sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
                 }
             }
             break;
@@ -522,6 +524,14 @@
             if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
                 !ev->active.gain && !gui_fullscreen_initial_grab) {
                 sdl_grab_end();
+            }
+            /* Send mouse pointer to oblivion on focus change */
+            if ((ev->active.state == SDL_APPINPUTFOCUS) ||
+                (ev->active.state == SDL_APPMOUSEFOCUS))
+            {
+                mouse_active = ev->active.gain;
+                if (mouse_active != SDL_ENABLE)
+                    kbd_mouse_event(0x7FFF, 0x7FFF, 0, 0);
             }
             if (ev->active.state & SDL_APPACTIVE) {
                 if (ev->active.gain) {
#1 lore raw
Quoted 2 lines · Stefano Stabellini

Hide the mouse pointer when the sdl window is not in focus.

I don't fully grok how this makes things better. This seems like a nasty little hack too. When you leave the window, the mouse disappears into one side of the screen, and when you come back, you have to move to where ever you were previously.

I understand how this could be useful with -no-grab, but this would defeat the sort of behavior that I commonly rely on when using grab (ungrab with a mouse in a convenient place, then come back and click on a button).

What's the user experience you are aiming for here?

Regards,

Anthony Liguori