sdl: various fixes
cover sdl: various fixes
See individual patches for details.
Jan Kiszka (5):
sdl: Do not grab mouse on mode switch while in background
sdl: Fix block prevention of SDL_WM_GrabInput Revert "Handle SDL grabs failing (Mark McLoughlin)"
sdl: Grab input on end of non-absolute mouse click
sdl: Limit sdl_grab_end in handle_activation to Windows hosts
ui/sdl.c | 60 ++++++++++++++++++++++++++++++++---------------------------- 1 files changed, 32 insertions(+), 28 deletions(-)
Signature · 1 line
1.7.3.4
PATCH 4/5 sdl: Grab input on end of non-absolute mouse click
By grabbing the input already on button down, we leave the button in that state for the host GUI. Thus it takes another click after releasing the input again to synchronize the mouse button state.
Avoid this by grabbing on button up.
--- ui/sdl.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
ui/sdl.c +1 -2
@@ -802,8 +802,7 @@ static void handle_mousebutton(DisplayState *ds, SDL_Event *ev) bev = &ev->button;if (!gui_grab && !kbd_mouse_is_absolute ()) { -if (ev->type ==SDL_MOUSEBUTTONDOWN && - (bev->button ==SDL_BUTTON_LEFT )) { +if (ev->type ==SDL_MOUSEBUTTONUP && bev->button ==SDL_BUTTON_LEFT ) {/* start grabbing all events */ sdl_grab_start (); }
Signature · 1 line
1.7.3.4
PATCH 2/5 sdl: Fix block prevention of SDL_WM_GrabInput
In reply to Jan KiszkaConsistently 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.
--- ui/sdl.c | 26 ++++++++++++++------------ 1 files changed, 14 insertions(+), 12 deletions(-)
ui/sdl.c +14 -12
@@ -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 ();
Signature · 1 line
1.7.3.4
PATCH 3/5 Revert "Handle SDL grabs failing (Mark McLoughlin)"
In reply to Jan KiszkaThis reverts commit 6bb816031f8bc0aafc3476e6dfa4293ee3a5f106.
SDL_WM_GrabInput does not reliably bail out if grabbing is impossible. So if we get here, we already lost and will block. But this can no longer happen due to the check in sdl_grab_start. So this patch became obsolete.
Conflicts:
sdl.c
--- ui/sdl.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-)
ui/sdl.c +3 -6
@@ -475,12 +475,9 @@ static void sdl_grab_start(void)SDL_WarpMouse (guest_x, guest_y); }else sdl_hide_cursor (); - -if (SDL_WM_GrabInput (SDL_GRAB_ON ) ==SDL_GRAB_ON ) { - gui_grab =1 ; -sdl_update_caption (); - }else -sdl_show_cursor (); +SDL_WM_GrabInput (SDL_GRAB_ON ); + gui_grab =1 ; +sdl_update_caption (); }static void sdl_grab_end (void )
Signature · 1 line
1.7.3.4
PATCH 1/5 sdl: Do not grab mouse on mode switch while in background
In reply to Jan KiszkaWhen the mouse mode changes to absolute while the SDL windows is not in focus, refrain from grabbing the input. It would steal from some other window.
--- ui/sdl.c | 30 ++++++++++++++++-------------- 1 files changed, 16 insertions(+), 14 deletions(-)
ui/sdl.c +16 -14
@@ -483,12 +483,27 @@ static void sdl_grab_end(void)sdl_update_caption (); } +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 (); + } + } +} +static void sdl_mouse_mode_change (Notifier *notify,void *data) {if (kbd_mouse_is_absolute ()) {if (!absolute_enabled) { -sdl_grab_start (); absolute_enabled =1 ; +if (is_graphic_console ()) { +absolute_mouse_grab (); + } } }else if (absolute_enabled) {if (!gui_fullscreen) {
@@ -571,19 +586,6 @@ static void toggle_full_screen(DisplayState *ds)vga_hw_update (); } -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 (); - } - } -} -static void handle_keydown (DisplayState *ds,SDL_Event *ev) {int mod_state;
Signature · 1 line
1.7.3.4
PATCH 5/5 sdl: Limit sdl_grab_end in handle_activation to Windows hosts
In reply to Jan KiszkaThere are scenarios on Linux with some SDL versions where handle_activation is continuous invoked with state = SDL_APPINPUTFOCUS and gain = 0 while we grabbed the input. This causes a ping-pong when we grab the input after an absolute mouse entered the window.
As this sdl_grab_end was once introduced to work around a Windows-only issue (0294ffb9c8), limit it to that platform.
--- ui/sdl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
ui/sdl.c +4 -0
@@ -828,10 +828,14 @@ static void handle_mousebutton(DisplayState *ds, SDL_Event *ev)static void handle_activation (DisplayState *ds,SDL_Event *ev) { +#ifdef _WIN32 +/* Disable grab if the window no longer has the focus +* (Windows-only workaround) */ if (gui_grab && ev->active.state ==SDL_APPINPUTFOCUS && !ev->active.gain && !gui_fullscreen) {sdl_grab_end (); } +#endif if (!gui_grab && ev->active.gain &&is_graphic_console () && (kbd_mouse_is_absolute () || absolute_enabled)) {absolute_mouse_grab ();
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 5/5] sdl: Limit sdl_grab_end in handle_activation to Windows hosts
Quoted 23 lines · Jan Kiszka
There are scenarios on Linux with some SDL versions where
handle_activationis continuous invoked with state =SDL_APPINPUTFOCUSand gain = 0 while we grabbed the input. This causes a ping-pong when we grab the input after an absolute mouse entered the window.As this
sdl_grab_endwas once introduced to work around a Windows-only issue (0294ffb9c8), limit it to that platform.CC Erik Rull<[email protected]>Signed-off-by Jan Kiszka<[email protected]>--- ui/sdl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)ui/sdl.c +1
-0@@ -828,10 +828,14 @@ static void handle_mousebutton(DisplayState *ds, SDL_Event *ev)static void handle_activation (DisplayState *ds,SDL_Event *ev) { +#ifdef _WIN32
ui/sdl.c static void handle_mousebutton(DisplayState *ds, SDL_Event *ev) · line 841
Quoted 10 lines
ui/sdl.c +3
-0+/* Disable grab if the window no longer has the focus +* (Windows-only workaround) */ if (gui_grab&& ev->active.state ==SDL_APPINPUTFOCUS && !ev->active.gain&& !gui_fullscreen) {sdl_grab_end (); } +#endif if (!gui_grab&& ev->active.gain&&is_graphic_console ()&& (kbd_mouse_is_absolute () || absolute_enabled)) {absolute_mouse_grab ();
Hi Jan,
thanks for your help.
When will the patches be applied to the qemu-git?
Best regards,
Erik
Anthony Liguori
AppliedQuoted 11 lines · Jan Kiszka
See individual patches for details.
CC Erik Rull<[email protected]>Jan Kiszka (5):
sdl: Do not grab mouse on mode switch while in background
sdl: Fix block prevention ofSDL_WM_GrabInputRevert "Handle SDL grabs failing (Mark McLoughlin)"
sdl: Grab input on end of non-absolute mouse click
sdl: Limitsdl_grab_endinhandle_activationto Windows hosts
Quoted 2 lines
ui/sdl.c | 60 ++++++++++++++++++++++++++++++++---------------------------- 1 files changed, 32 insertions(+), 28 deletions(-)
Applied. Thanks.
Regards,
Anthony Liguori