* [Qemu-devel] [PATCH 1/5] sdl: Do not grab mouse on mode switch while in background
2012-01-31 12:45 [Qemu-devel] [PATCH 0/5] sdl: various fixes Jan Kiszka
@ 2012-01-31 12:45 ` Jan Kiszka
2012-01-31 12:45 ` [Qemu-devel] [PATCH 2/5] sdl: Fix block prevention of SDL_WM_GrabInput Jan Kiszka
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Jan Kiszka @ 2012-01-31 12:45 UTC (permalink / raw)
To: Anthony Liguori, qemu-devel
When 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.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
ui/sdl.c | 30 ++++++++++++++++--------------
1 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/ui/sdl.c b/ui/sdl.c
index 8cafc44..384276d 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -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;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 2/5] sdl: Fix block prevention of SDL_WM_GrabInput
2012-01-31 12:45 [Qemu-devel] [PATCH 0/5] sdl: various fixes Jan Kiszka
2012-01-31 12:45 ` [Qemu-devel] [PATCH 1/5] sdl: Do not grab mouse on mode switch while in background Jan Kiszka
@ 2012-01-31 12:45 ` Jan Kiszka
2012-01-31 12:45 ` [Qemu-devel] [PATCH 3/5] Revert "Handle SDL grabs failing (Mark McLoughlin)" Jan Kiszka
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Jan Kiszka @ 2012-01-31 12:45 UTC (permalink / raw)
To: Anthony Liguori, qemu-devel
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>
---
ui/sdl.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/ui/sdl.c b/ui/sdl.c
index 384276d..d845efb 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -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();
--
1.7.3.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 3/5] Revert "Handle SDL grabs failing (Mark McLoughlin)"
2012-01-31 12:45 [Qemu-devel] [PATCH 0/5] sdl: various fixes Jan Kiszka
2012-01-31 12:45 ` [Qemu-devel] [PATCH 1/5] sdl: Do not grab mouse on mode switch while in background Jan Kiszka
2012-01-31 12:45 ` [Qemu-devel] [PATCH 2/5] sdl: Fix block prevention of SDL_WM_GrabInput Jan Kiszka
@ 2012-01-31 12:45 ` Jan Kiszka
2012-01-31 12:45 ` [Qemu-devel] [PATCH 4/5] sdl: Grab input on end of non-absolute mouse click Jan Kiszka
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Jan Kiszka @ 2012-01-31 12:45 UTC (permalink / raw)
To: Anthony Liguori, qemu-devel
This 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
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
ui/sdl.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/ui/sdl.c b/ui/sdl.c
index d845efb..0d3a889 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -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)
--
1.7.3.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 4/5] sdl: Grab input on end of non-absolute mouse click
2012-01-31 12:45 [Qemu-devel] [PATCH 0/5] sdl: various fixes Jan Kiszka
` (2 preceding siblings ...)
2012-01-31 12:45 ` [Qemu-devel] [PATCH 3/5] Revert "Handle SDL grabs failing (Mark McLoughlin)" Jan Kiszka
@ 2012-01-31 12:45 ` Jan Kiszka
2012-01-31 12:45 ` [Qemu-devel] [PATCH 5/5] sdl: Limit sdl_grab_end in handle_activation to Windows hosts Jan Kiszka
2012-02-01 22:12 ` [Qemu-devel] [PATCH 0/5] sdl: various fixes Anthony Liguori
5 siblings, 0 replies; 8+ messages in thread
From: Jan Kiszka @ 2012-01-31 12:45 UTC (permalink / raw)
To: Anthony Liguori, qemu-devel
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.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
ui/sdl.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/ui/sdl.c b/ui/sdl.c
index 0d3a889..73e5839 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -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();
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 5/5] sdl: Limit sdl_grab_end in handle_activation to Windows hosts
2012-01-31 12:45 [Qemu-devel] [PATCH 0/5] sdl: various fixes Jan Kiszka
` (3 preceding siblings ...)
2012-01-31 12:45 ` [Qemu-devel] [PATCH 4/5] sdl: Grab input on end of non-absolute mouse click Jan Kiszka
@ 2012-01-31 12:45 ` Jan Kiszka
2012-01-31 19:55 ` Erik Rull
2012-02-01 22:12 ` [Qemu-devel] [PATCH 0/5] sdl: various fixes Anthony Liguori
5 siblings, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2012-01-31 12:45 UTC (permalink / raw)
To: Anthony Liguori, qemu-devel; +Cc: Erik Rull
There 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.
CC: Erik Rull <erik.rull@rdsoftware.de>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
ui/sdl.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/ui/sdl.c b/ui/sdl.c
index 73e5839..6f8091c 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -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();
--
1.7.3.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 5/5] sdl: Limit sdl_grab_end in handle_activation to Windows hosts
2012-01-31 12:45 ` [Qemu-devel] [PATCH 5/5] sdl: Limit sdl_grab_end in handle_activation to Windows hosts Jan Kiszka
@ 2012-01-31 19:55 ` Erik Rull
0 siblings, 0 replies; 8+ messages in thread
From: Erik Rull @ 2012-01-31 19:55 UTC (permalink / raw)
To: Jan Kiszka; +Cc: qemu-devel
Jan Kiszka wrote:
> There 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.
>
> CC: Erik Rull<erik.rull@rdsoftware.de>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
> ---
> ui/sdl.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/ui/sdl.c b/ui/sdl.c
> index 73e5839..6f8091c 100644
> --- a/ui/sdl.c
> +++ b/ui/sdl.c
> @@ -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();
Hi Jan,
thanks for your help.
When will the patches be applied to the qemu-git?
Best regards,
Erik
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 0/5] sdl: various fixes
2012-01-31 12:45 [Qemu-devel] [PATCH 0/5] sdl: various fixes Jan Kiszka
` (4 preceding siblings ...)
2012-01-31 12:45 ` [Qemu-devel] [PATCH 5/5] sdl: Limit sdl_grab_end in handle_activation to Windows hosts Jan Kiszka
@ 2012-02-01 22:12 ` Anthony Liguori
5 siblings, 0 replies; 8+ messages in thread
From: Anthony Liguori @ 2012-02-01 22:12 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Erik Rull, qemu-devel
On 01/31/2012 06:45 AM, Jan Kiszka wrote:
> See individual patches for details.
>
> CC: Erik Rull<erik.rull@rdsoftware.de>
>
> 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(-)
Applied. Thanks.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 8+ messages in thread