sdl: Fix block prevention of SDL_WM_GrabInput

Consistently check for SDL_APPINPUTFOCUS before trying to grab the input
focus. Just checking for SDL_APPACTIVE doesn't work. Moving the check to
sdl_grab_start allows for some consolidation.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Jan Kiszka 2012-01-31 13:45:28 +01:00 committed by Anthony Liguori
parent 6659635619
commit 85f94f868f
1 changed files with 14 additions and 12 deletions

View File

@ -461,6 +461,14 @@ static void sdl_show_cursor(void)
static void sdl_grab_start(void)
{
/*
* If the application is not active, do not try to enter grab state. This
* prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
* application (SDL bug).
*/
if (!(SDL_GetAppState() & SDL_APPINPUTFOCUS)) {
return;
}
if (guest_cursor) {
SDL_SetCursor(guest_sprite);
if (!kbd_mouse_is_absolute() && !absolute_enabled)
@ -487,12 +495,10 @@ static void absolute_mouse_grab(void)
{
int mouse_x, mouse_y;
if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
SDL_GetMouseState(&mouse_x, &mouse_y);
if (mouse_x > 0 && mouse_x < real_screen->w - 1 &&
mouse_y > 0 && mouse_y < real_screen->h - 1) {
sdl_grab_start();
}
SDL_GetMouseState(&mouse_x, &mouse_y);
if (mouse_x > 0 && mouse_x < real_screen->w - 1 &&
mouse_y > 0 && mouse_y < real_screen->h - 1) {
sdl_grab_start();
}
}
@ -745,11 +751,7 @@ static void handle_keyup(DisplayState *ds, SDL_Event *ev)
if (gui_keysym == 0) {
/* exit/enter grab if pressing Ctrl-Alt */
if (!gui_grab) {
/* If the application is not active, do not try to enter grab
* state. It prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from
* blocking all the application (SDL bug). */
if (is_graphic_console() &&
SDL_GetAppState() & SDL_APPACTIVE) {
if (is_graphic_console()) {
sdl_grab_start();
}
} else if (!gui_fullscreen) {
@ -779,7 +781,7 @@ static void handle_mousemotion(DisplayState *ds, SDL_Event *ev)
ev->motion.x == max_x || ev->motion.y == max_y)) {
sdl_grab_end();
}
if (!gui_grab && SDL_GetAppState() & SDL_APPINPUTFOCUS &&
if (!gui_grab &&
(ev->motion.x > 0 && ev->motion.x < max_x &&
ev->motion.y > 0 && ev->motion.y < max_y)) {
sdl_grab_start();