qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/15] sdl: Usability improvements
@ 2011-07-30  9:39 Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode Jan Kiszka
                   ` (16 more replies)
  0 siblings, 17 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel; +Cc: Stefano Stabellini

As SDL is my preferred way of working ad-hoc with guests, I had a closer
look at oddities and shortcomings that this GUI exposed, at least here
on Linux hosts. The result is a series of patches I've now finally
polished and completed. Highlights:
 - fix termination in -no-shutdown mode
 - fix various issues when switching to/from full screen mode
 - polish mouse grabbing in full screen mode, under text console and
   when in absolute mouse mode
 - dynamically grab keyboard input in absolute mouse mode, enabling
   e.g. ALT+TAB in the guest
 - add zoom hot keys to make window scaling more attractive
 - refactor some ugly functions

Please review/merge.

CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Jan Kiszka (15):
  sdl: Fix termination in -no-shutdown mode
  sdl: Do not make full screen mode resizable
  sdl: Avoid redundant scaling deactivation
  sdl: Properly mark modifier+u as hotkey
  sdl: Fix full screen toggling from scaled mode
  sdl: Restore scaling mode on return from full screen
  sdl: Drop bogus gui_fullscreen_initial_grab
  sdl: Initialize gui_fullscreen earlier during setup
  sdl: Consistently avoid grabbing input for text consoles
  sdl: Never release input while in full screen mode
  sdl: Fix cursor handling when switching consoles in absolute mouse
    mode
  sdl: Dynamically grab input in absolute mouse mode
  sdl: Add zoom hot keys
  sdl: Factor out event handlers from sdl_refresh
  sdl: Refactor sdl_send_mouse_event

 qemu-doc.texi |    8 +
 ui/sdl.c      |  547 ++++++++++++++++++++++++++++++++++++---------------------
 2 files changed, 355 insertions(+), 200 deletions(-)

-- 
1.7.3.4

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30 12:57   ` Anthony Liguori
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 02/15] sdl: Do not make full screen mode resizable Jan Kiszka
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

Just like the monitor does, we need to clear no_shutdown before calling
qemu_system_shutdown_request on quit requests. Otherwise, QEMU just
stops the VM.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 6dbc5cb..9efcda5 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -672,8 +672,10 @@ static void sdl_refresh(DisplayState *ds)
                 sdl_process_key(&ev->key);
             break;
         case SDL_QUIT:
-            if (!no_quit)
+            if (!no_quit) {
+                no_shutdown = 0;
                 qemu_system_shutdown_request();
+            }
             break;
         case SDL_MOUSEMOTION:
             if (gui_grab || kbd_mouse_is_absolute() ||
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 02/15] sdl: Do not make full screen mode resizable
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 03/15] sdl: Avoid redundant scaling deactivation Jan Kiszka
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel; +Cc: Stefano Stabellini

From: Jan Kiszka <jan.kiszka@siemens.com>

This prevents continuous resizing events and improper screen setups when
going full screen.

CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 9efcda5..9a92b47 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -97,9 +97,12 @@ static void do_sdl_resize(int new_width, int new_height, int bpp)
 
     //    printf("resizing to %d %d\n", w, h);
 
-    flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_RESIZABLE;
-    if (gui_fullscreen)
+    flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
+    if (gui_fullscreen) {
         flags |= SDL_FULLSCREEN;
+    } else {
+        flags |= SDL_RESIZABLE;
+    }
     if (gui_noframe)
         flags |= SDL_NOFRAME;
 
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 03/15] sdl: Avoid redundant scaling deactivation
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 02/15] sdl: Do not make full screen mode resizable Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 04/15] sdl: Properly mark modifier+u as hotkey Jan Kiszka
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

Prevents screen flickering.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 9a92b47..1563ee1 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -583,10 +583,12 @@ static void sdl_refresh(DisplayState *ds)
                         gui_keysym = 1;
                         break;
                     case 0x16: /* 'u' key on US keyboard */
-                        scaling_active = 0;
-                        sdl_resize(ds);
-                        vga_hw_invalidate();
-                        vga_hw_update();
+                        if (scaling_active) {
+                            scaling_active = 0;
+                            sdl_resize(ds);
+                            vga_hw_invalidate();
+                            vga_hw_update();
+                        }
                         break;
                     case 0x02 ... 0x0a: /* '1' to '9' keys */
                         /* Reset the modifiers sent to the current console */
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 04/15] sdl: Properly mark modifier+u as hotkey
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (2 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 03/15] sdl: Avoid redundant scaling deactivation Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 05/15] sdl: Fix full screen toggling from scaled mode Jan Kiszka
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 1563ee1..e6c9597 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -589,6 +589,7 @@ static void sdl_refresh(DisplayState *ds)
                             vga_hw_invalidate();
                             vga_hw_update();
                         }
+                        gui_keysym = 1;
                         break;
                     case 0x02 ... 0x0a: /* '1' to '9' keys */
                         /* Reset the modifiers sent to the current console */
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 05/15] sdl: Fix full screen toggling from scaled mode
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (3 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 04/15] sdl: Properly mark modifier+u as hotkey Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 06/15] sdl: Restore scaling mode on return from full screen Jan Kiszka
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel; +Cc: Stefano Stabellini

From: Jan Kiszka <jan.kiszka@siemens.com>

When switching to full screen mode from a scaled window, we need to
resize to DisplayState's dimension, not the scaled "real" screen size.
Moreover, scaling mode may have manipulated the bpp. So we need to
restore it from the DisplayState as well.

CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index e6c9597..4acfe81 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -529,7 +529,8 @@ static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state
 static void toggle_full_screen(DisplayState *ds)
 {
     gui_fullscreen = !gui_fullscreen;
-    do_sdl_resize(real_screen->w, real_screen->h, real_screen->format->BitsPerPixel);
+    do_sdl_resize(ds_get_width(ds), ds_get_height(ds),
+                  ds_get_bits_per_pixel(ds));
     if (gui_fullscreen) {
         scaling_active = 0;
         gui_saved_grab = gui_grab;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 06/15] sdl: Restore scaling mode on return from full screen
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (4 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 05/15] sdl: Fix full screen toggling from scaled mode Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 07/15] sdl: Drop bogus gui_fullscreen_initial_grab Jan Kiszka
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel; +Cc: Stefano Stabellini

From: Jan Kiszka <jan.kiszka@siemens.com>

Save the scaling mode and its geometry when going full screen, restore
it when returning to windowed mode.

CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |   48 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 4acfe81..e18c59a 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -39,6 +39,9 @@ static SDL_Surface *real_screen;
 static SDL_Surface *guest_screen = NULL;
 static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
 static int last_vm_running;
+static bool gui_saved_scaling;
+static int gui_saved_width;
+static int gui_saved_height;
 static int gui_saved_grab;
 static int gui_fullscreen;
 static int gui_noframe;
@@ -526,16 +529,42 @@ static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state
     kbd_mouse_event(dx, dy, dz, buttons);
 }
 
+static void sdl_scale(DisplayState *ds, int width, int height)
+{
+    int bpp = real_screen->format->BitsPerPixel;
+
+    if (bpp != 16 && bpp != 32) {
+        bpp = 32;
+    }
+    do_sdl_resize(width, height, bpp);
+    scaling_active = 1;
+    if (!is_buffer_shared(ds->surface)) {
+        ds->surface = qemu_resize_displaysurface(ds, ds_get_width(ds),
+                                                 ds_get_height(ds));
+        dpy_resize(ds);
+    }
+}
+
 static void toggle_full_screen(DisplayState *ds)
 {
     gui_fullscreen = !gui_fullscreen;
-    do_sdl_resize(ds_get_width(ds), ds_get_height(ds),
-                  ds_get_bits_per_pixel(ds));
     if (gui_fullscreen) {
+        gui_saved_width = real_screen->w;
+        gui_saved_height = real_screen->h;
+        gui_saved_scaling = scaling_active;
+
+        do_sdl_resize(ds_get_width(ds), ds_get_height(ds),
+                      ds_get_bits_per_pixel(ds));
         scaling_active = 0;
+
         gui_saved_grab = gui_grab;
         sdl_grab_start();
     } else {
+        if (gui_saved_scaling) {
+            sdl_scale(ds, gui_saved_width, gui_saved_height);
+        } else {
+            do_sdl_resize(ds_get_width(ds), ds_get_height(ds), 0);
+        }
         if (!gui_saved_grab)
             sdl_grab_end();
     }
@@ -737,22 +766,11 @@ static void sdl_refresh(DisplayState *ds)
                 }
             }
             break;
-	case SDL_VIDEORESIZE:
-        {
-	    SDL_ResizeEvent *rev = &ev->resize;
-            int bpp = real_screen->format->BitsPerPixel;
-            if (bpp != 16 && bpp != 32)
-                bpp = 32;
-            do_sdl_resize(rev->w, rev->h, bpp);
-            scaling_active = 1;
-            if (!is_buffer_shared(ds->surface)) {
-                ds->surface = qemu_resize_displaysurface(ds, ds_get_width(ds), ds_get_height(ds));
-                dpy_resize(ds);
-            }
+        case SDL_VIDEORESIZE:
+            sdl_scale(ds, ev->resize.w, ev->resize.h);
             vga_hw_invalidate();
             vga_hw_update();
             break;
-        }
         default:
             break;
         }
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 07/15] sdl: Drop bogus gui_fullscreen_initial_grab
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (5 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 06/15] sdl: Restore scaling mode on return from full screen Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 08/15] sdl: Initialize gui_fullscreen earlier during setup Jan Kiszka
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

There must be no difference between initial -full-screen and switching
to this mode via the hot key.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index e18c59a..80bf776 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -47,7 +47,6 @@ static int gui_fullscreen;
 static int gui_noframe;
 static int gui_key_modifier_pressed;
 static int gui_keysym;
-static int gui_fullscreen_initial_grab;
 static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
 static uint8_t modifiers_state[256];
 static int width, height;
@@ -751,7 +750,7 @@ static void sdl_refresh(DisplayState *ds)
             break;
         case SDL_ACTIVEEVENT:
             if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
-                !ev->active.gain && !gui_fullscreen_initial_grab) {
+                !ev->active.gain && !gui_fullscreen) {
                 sdl_grab_end();
             }
             if (ev->active.state & SDL_APPACTIVE) {
@@ -923,7 +922,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     atexit(sdl_cleanup);
     if (full_screen) {
         gui_fullscreen = 1;
-        gui_fullscreen_initial_grab = 1;
         sdl_grab_start();
     }
 }
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 08/15] sdl: Initialize gui_fullscreen earlier during setup
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (6 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 07/15] sdl: Drop bogus gui_fullscreen_initial_grab Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 09/15] sdl: Consistently avoid grabbing input for text consoles Jan Kiszka
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

This ensures that we actually enter full screen on startup when e.g.
'-vga none -full-screen' was specified.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 80bf776..f19bae2 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -891,6 +891,11 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
         qemu_free(filename);
     }
 
+    if (full_screen) {
+        gui_fullscreen = 1;
+        sdl_grab_start();
+    }
+
     dcl = qemu_mallocz(sizeof(DisplayChangeListener));
     dcl->dpy_update = sdl_update;
     dcl->dpy_resize = sdl_resize;
@@ -920,8 +925,4 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     sdl_cursor_normal = SDL_GetCursor();
 
     atexit(sdl_cleanup);
-    if (full_screen) {
-        gui_fullscreen = 1;
-        sdl_grab_start();
-    }
 }
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 09/15] sdl: Consistently avoid grabbing input for text consoles
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (7 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 08/15] sdl: Initialize gui_fullscreen earlier during setup Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 10/15] sdl: Never release input while in full screen mode Jan Kiszka
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

There were some preexisting bits that released the input when switching
to text console. This patch spreads this logic consistently and also
avoids grabbing the input while a text console is active.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index f19bae2..27465b2 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -564,8 +564,9 @@ static void toggle_full_screen(DisplayState *ds)
         } else {
             do_sdl_resize(ds_get_width(ds), ds_get_height(ds), 0);
         }
-        if (!gui_saved_grab)
+        if (!gui_saved_grab || !is_graphic_console()) {
             sdl_grab_end();
+        }
     }
     vga_hw_invalidate();
     vga_hw_update();
@@ -689,8 +690,10 @@ static void sdl_refresh(DisplayState *ds)
                                    'SDL_WM_GrabInput(SDL_GRAB_ON)'
                                    from blocking all the application
                                    (SDL bug). */
-                                if (SDL_GetAppState() & SDL_APPACTIVE)
+                                if (is_graphic_console() &&
+                                    SDL_GetAppState() & SDL_APPACTIVE) {
                                     sdl_grab_start();
+                                }
                             } else {
                                 sdl_grab_end();
                             }
@@ -721,7 +724,7 @@ static void sdl_refresh(DisplayState *ds)
             break;
         case SDL_MOUSEBUTTONDOWN:
         case SDL_MOUSEBUTTONUP:
-            {
+            if (is_graphic_console()) {
                 SDL_MouseButtonEvent *bev = &ev->button;
                 if (!gui_grab && !kbd_mouse_is_absolute()) {
                     if (ev->type == SDL_MOUSEBUTTONDOWN &&
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 10/15] sdl: Never release input while in full screen mode
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (8 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 09/15] sdl: Consistently avoid grabbing input for text consoles Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 11/15] sdl: Fix cursor handling when switching consoles in absolute mouse mode Jan Kiszka
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

It's confusing to suddenly find two mice in full screen mode when
switching consoles or accidentally hitting the grab hot keys.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 27465b2..662ffef 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -626,9 +626,10 @@ static void sdl_refresh(DisplayState *ds)
                         reset_keys();
                         console_select(keycode - 0x02);
                         if (!is_graphic_console()) {
-                            /* display grab if going to a text console */
-                            if (gui_grab)
+                            /* release grab if going to a text console */
+                            if (gui_grab && !gui_fullscreen) {
                                 sdl_grab_end();
+                            }
                         }
                         gui_keysym = 1;
                         break;
@@ -694,7 +695,7 @@ static void sdl_refresh(DisplayState *ds)
                                     SDL_GetAppState() & SDL_APPACTIVE) {
                                     sdl_grab_start();
                                 }
-                            } else {
+                            } else if (!gui_fullscreen) {
                                 sdl_grab_end();
                             }
                             /* SDL does not send back all the
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 11/15] sdl: Fix cursor handling when switching consoles in absolute mouse mode
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (9 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 10/15] sdl: Never release input while in full screen mode Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 12/15] sdl: Dynamically grab input " Jan Kiszka
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

Restore the cursor when switching from graphic to text console while the
mouse is in absolute mode. Disable it again when returning.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 662ffef..5ad38d5 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -452,7 +452,7 @@ static void sdl_show_cursor(void)
     if (!cursor_hide)
         return;
 
-    if (!kbd_mouse_is_absolute()) {
+    if (!kbd_mouse_is_absolute() || !is_graphic_console()) {
         SDL_ShowCursor(1);
         if (guest_cursor &&
                 (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
@@ -625,13 +625,20 @@ static void sdl_refresh(DisplayState *ds)
                         /* Reset the modifiers sent to the current console */
                         reset_keys();
                         console_select(keycode - 0x02);
+                        gui_keysym = 1;
+                        if (gui_fullscreen) {
+                            break;
+                        }
                         if (!is_graphic_console()) {
                             /* release grab if going to a text console */
-                            if (gui_grab && !gui_fullscreen) {
+                            if (gui_grab) {
                                 sdl_grab_end();
+                            } else if (absolute_enabled) {
+                                sdl_show_cursor();
                             }
+                        } else if (absolute_enabled) {
+                            sdl_hide_cursor();
                         }
-                        gui_keysym = 1;
                         break;
                     default:
                         break;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 12/15] sdl: Dynamically grab input in absolute mouse mode
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (10 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 11/15] sdl: Fix cursor handling when switching consoles in absolute mouse mode Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 13/15] sdl: Add zoom hot keys Jan Kiszka
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

Not grabbing the input means that special keys like ALT+TAB are still
handled by the host. Improve the usability by grabbing input once the
mouse is inside the guest screen, provided the SDL window has the input
focus. Release it again when the mouse is moved to any border. Also grab
the input when we gain the input focus and the mouse is within the
screen limits.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |   43 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 5ad38d5..e8ac3bb 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -490,15 +490,12 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
 {
     if (kbd_mouse_is_absolute()) {
         if (!absolute_enabled) {
-            sdl_hide_cursor();
-            if (gui_grab) {
-                sdl_grab_end();
-            }
+            sdl_grab_start();
             absolute_enabled = 1;
         }
     } else if (absolute_enabled) {
-	sdl_show_cursor();
-	absolute_enabled = 0;
+        sdl_grab_end();
+        absolute_enabled = 0;
     }
 }
 
@@ -572,6 +569,19 @@ 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 sdl_refresh(DisplayState *ds)
 {
     SDL_Event ev1, *ev = &ev1;
@@ -638,6 +648,7 @@ static void sdl_refresh(DisplayState *ds)
                             }
                         } else if (absolute_enabled) {
                             sdl_hide_cursor();
+                            absolute_mouse_grab();
                         }
                         break;
                     default:
@@ -724,6 +735,22 @@ static void sdl_refresh(DisplayState *ds)
             }
             break;
         case SDL_MOUSEMOTION:
+            if (is_graphic_console() &&
+                (kbd_mouse_is_absolute() || absolute_enabled)) {
+                int max_x = real_screen->w - 1;
+                int max_y = real_screen->h - 1;
+
+                if (gui_grab &&
+                    (ev->motion.x == 0 || ev->motion.y == 0 ||
+                     ev->motion.x == max_x || ev->motion.y == max_y)) {
+                    sdl_grab_end();
+                }
+                if (!gui_grab && SDL_GetAppState() & SDL_APPINPUTFOCUS &&
+                    (ev->motion.x > 0 && ev->motion.x < max_x &&
+                     ev->motion.y > 0 && ev->motion.y < max_y)) {
+                    sdl_grab_start();
+                }
+            }
             if (gui_grab || kbd_mouse_is_absolute() ||
                 absolute_enabled) {
                 sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
@@ -764,6 +791,10 @@ static void sdl_refresh(DisplayState *ds)
                 !ev->active.gain && !gui_fullscreen) {
                 sdl_grab_end();
             }
+            if (!gui_grab && ev->active.gain && is_graphic_console() &&
+                (kbd_mouse_is_absolute() || absolute_enabled)) {
+                absolute_mouse_grab();
+            }
             if (ev->active.state & SDL_APPACTIVE) {
                 if (ev->active.gain) {
                     /* Back to default interval */
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 13/15] sdl: Add zoom hot keys
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (11 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 12/15] sdl: Dynamically grab input " Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 14/15] sdl: Factor out event handlers from sdl_refresh Jan Kiszka
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel; +Cc: Stefano Stabellini

From: Jan Kiszka <jan.kiszka@siemens.com>

Allow to enlarge or shrink the screen via CTRL-ALT-+/-. In contrast to
scaling the window, these controls always preserve the aspect ratio of
the current console.

CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 qemu-doc.texi |    8 ++++++++
 ui/sdl.c      |   13 +++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/qemu-doc.texi b/qemu-doc.texi
index 47e1991..31199f6 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -288,6 +288,14 @@ then the modifier is Ctrl-Alt-Shift (instead of Ctrl-Alt) and if you use
 @kindex Ctrl-Alt-f
 Toggle full screen
 
+@item Ctrl-Alt-+
+@kindex Ctrl-Alt-+
+Enlarge the screen
+
+@item Ctrl-Alt--
+@kindex Ctrl-Alt--
+Shrink the screen
+
 @item Ctrl-Alt-u
 @kindex Ctrl-Alt-u
 Restore the screen's un-scaled dimensions
diff --git a/ui/sdl.c b/ui/sdl.c
index e8ac3bb..fc63c8e 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -651,6 +651,19 @@ static void sdl_refresh(DisplayState *ds)
                             absolute_mouse_grab();
                         }
                         break;
+                    case 0x1b: /* '+' */
+                    case 0x35: /* '-' */
+                        if (!gui_fullscreen) {
+                            int width = MAX(real_screen->w +
+                                            (keycode == 0x1b ? 50 : -50), 160);
+                            int height = (ds_get_height(ds) * width) /
+                                         ds_get_width(ds);
+
+                            sdl_scale(ds, width, height);
+                            vga_hw_invalidate();
+                            vga_hw_update();
+                            gui_keysym = 1;
+                        }
                     default:
                         break;
                     }
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 14/15] sdl: Factor out event handlers from sdl_refresh
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (12 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 13/15] sdl: Add zoom hot keys Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 15/15] sdl: Refactor sdl_send_mouse_event Jan Kiszka
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

No functional changes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |  476 +++++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 271 insertions(+), 205 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index fc63c8e..e5b8a5f 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -582,11 +582,274 @@ static void absolute_mouse_grab(void)
     }
 }
 
-static void sdl_refresh(DisplayState *ds)
+static void handle_keydown(DisplayState *ds, SDL_Event *ev)
 {
-    SDL_Event ev1, *ev = &ev1;
     int mod_state;
+    int keycode;
+
+    if (alt_grab) {
+        mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
+                    (gui_grab_code | KMOD_LSHIFT);
+    } else if (ctrl_grab) {
+        mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
+    } else {
+        mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code;
+    }
+    gui_key_modifier_pressed = mod_state;
+
+    if (gui_key_modifier_pressed) {
+        keycode = sdl_keyevent_to_keycode(&ev->key);
+        switch (keycode) {
+        case 0x21: /* 'f' key on US keyboard */
+            toggle_full_screen(ds);
+            gui_keysym = 1;
+            break;
+        case 0x16: /* 'u' key on US keyboard */
+            if (scaling_active) {
+                scaling_active = 0;
+                sdl_resize(ds);
+                vga_hw_invalidate();
+                vga_hw_update();
+            }
+            gui_keysym = 1;
+            break;
+        case 0x02 ... 0x0a: /* '1' to '9' keys */
+            /* Reset the modifiers sent to the current console */
+            reset_keys();
+            console_select(keycode - 0x02);
+            gui_keysym = 1;
+            if (gui_fullscreen) {
+                break;
+            }
+            if (!is_graphic_console()) {
+                /* release grab if going to a text console */
+                if (gui_grab) {
+                    sdl_grab_end();
+                } else if (absolute_enabled) {
+                    sdl_show_cursor();
+                }
+            } else if (absolute_enabled) {
+                sdl_hide_cursor();
+                absolute_mouse_grab();
+            }
+            break;
+        case 0x1b: /* '+' */
+        case 0x35: /* '-' */
+            if (!gui_fullscreen) {
+                int width = MAX(real_screen->w + (keycode == 0x1b ? 50 : -50),
+                                160);
+                int height = (ds_get_height(ds) * width) / ds_get_width(ds);
+
+                sdl_scale(ds, width, height);
+                vga_hw_invalidate();
+                vga_hw_update();
+                gui_keysym = 1;
+            }
+        default:
+            break;
+        }
+    } else if (!is_graphic_console()) {
+        int keysym = 0;
+
+        if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
+            switch (ev->key.keysym.sym) {
+            case SDLK_UP:
+                keysym = QEMU_KEY_CTRL_UP;
+                break;
+            case SDLK_DOWN:
+                keysym = QEMU_KEY_CTRL_DOWN;
+                break;
+            case SDLK_LEFT:
+                keysym = QEMU_KEY_CTRL_LEFT;
+                break;
+            case SDLK_RIGHT:
+                keysym = QEMU_KEY_CTRL_RIGHT;
+                break;
+            case SDLK_HOME:
+                keysym = QEMU_KEY_CTRL_HOME;
+                break;
+            case SDLK_END:
+                keysym = QEMU_KEY_CTRL_END;
+                break;
+            case SDLK_PAGEUP:
+                keysym = QEMU_KEY_CTRL_PAGEUP;
+                break;
+            case SDLK_PAGEDOWN:
+                keysym = QEMU_KEY_CTRL_PAGEDOWN;
+                break;
+            default:
+                break;
+            }
+        } else {
+            switch (ev->key.keysym.sym) {
+            case SDLK_UP:
+                keysym = QEMU_KEY_UP;
+                break;
+            case SDLK_DOWN:
+                keysym = QEMU_KEY_DOWN;
+                break;
+            case SDLK_LEFT:
+                keysym = QEMU_KEY_LEFT;
+                break;
+            case SDLK_RIGHT:
+                keysym = QEMU_KEY_RIGHT;
+                break;
+            case SDLK_HOME:
+                keysym = QEMU_KEY_HOME;
+                break;
+            case SDLK_END:
+                keysym = QEMU_KEY_END;
+                break;
+            case SDLK_PAGEUP:
+                keysym = QEMU_KEY_PAGEUP;
+                break;
+            case SDLK_PAGEDOWN:
+                keysym = QEMU_KEY_PAGEDOWN;
+                break;
+            case SDLK_BACKSPACE:
+                keysym = QEMU_KEY_BACKSPACE;
+                break;
+            case SDLK_DELETE:
+                keysym = QEMU_KEY_DELETE;
+                break;
+            default:
+                break;
+            }
+        }
+        if (keysym) {
+            kbd_put_keysym(keysym);
+        } else if (ev->key.keysym.unicode != 0) {
+            kbd_put_keysym(ev->key.keysym.unicode);
+        }
+    }
+    if (is_graphic_console() && !gui_keysym) {
+        sdl_process_key(&ev->key);
+    }
+}
+
+static void handle_keyup(DisplayState *ds, SDL_Event *ev)
+{
+    int mod_state;
+
+    if (!alt_grab) {
+        mod_state = (ev->key.keysym.mod & gui_grab_code);
+    } else {
+        mod_state = (ev->key.keysym.mod & (gui_grab_code | KMOD_LSHIFT));
+    }
+    if (!mod_state && gui_key_modifier_pressed) {
+        gui_key_modifier_pressed = 0;
+        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) {
+                    sdl_grab_start();
+                }
+            } else if (!gui_fullscreen) {
+                sdl_grab_end();
+            }
+            /* SDL does not send back all the modifiers key, so we must
+             * correct it. */
+            reset_keys();
+            return;
+        }
+        gui_keysym = 0;
+    }
+    if (is_graphic_console() && !gui_keysym) {
+        sdl_process_key(&ev->key);
+    }
+}
+
+static void handle_mousemotion(DisplayState *ds, SDL_Event *ev)
+{
+    int max_x, max_y;
+
+    if (is_graphic_console() &&
+        (kbd_mouse_is_absolute() || absolute_enabled)) {
+        max_x = real_screen->w - 1;
+        max_y = real_screen->h - 1;
+        if (gui_grab && (ev->motion.x == 0 || ev->motion.y == 0 ||
+            ev->motion.x == max_x || ev->motion.y == max_y)) {
+            sdl_grab_end();
+        }
+        if (!gui_grab && SDL_GetAppState() & SDL_APPINPUTFOCUS &&
+            (ev->motion.x > 0 && ev->motion.x < max_x &&
+            ev->motion.y > 0 && ev->motion.y < max_y)) {
+            sdl_grab_start();
+        }
+    }
+    if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+        sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
+                             ev->motion.x, ev->motion.y, ev->motion.state);
+    }
+}
+
+static void handle_mousebutton(DisplayState *ds, SDL_Event *ev)
+{
     int buttonstate = SDL_GetMouseState(NULL, NULL);
+    SDL_MouseButtonEvent *bev;
+    int dz;
+
+    if (!is_graphic_console()) {
+        return;
+    }
+
+    bev = &ev->button;
+    if (!gui_grab && !kbd_mouse_is_absolute()) {
+        if (ev->type == SDL_MOUSEBUTTONDOWN &&
+            (bev->button == SDL_BUTTON_LEFT)) {
+            /* start grabbing all events */
+            sdl_grab_start();
+        }
+    } else {
+        dz = 0;
+        if (ev->type == SDL_MOUSEBUTTONDOWN) {
+            buttonstate |= SDL_BUTTON(bev->button);
+        } else {
+            buttonstate &= ~SDL_BUTTON(bev->button);
+        }
+#ifdef SDL_BUTTON_WHEELUP
+        if (bev->button == SDL_BUTTON_WHEELUP &&
+            ev->type == SDL_MOUSEBUTTONDOWN) {
+            dz = -1;
+        } else if (bev->button == SDL_BUTTON_WHEELDOWN &&
+                   ev->type == SDL_MOUSEBUTTONDOWN) {
+            dz = 1;
+        }
+#endif
+        sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
+    }
+}
+
+static void handle_activation(DisplayState *ds, SDL_Event *ev)
+{
+    if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
+        !ev->active.gain && !gui_fullscreen) {
+        sdl_grab_end();
+    }
+    if (!gui_grab && ev->active.gain && is_graphic_console() &&
+        (kbd_mouse_is_absolute() || absolute_enabled)) {
+        absolute_mouse_grab();
+    }
+    if (ev->active.state & SDL_APPACTIVE) {
+        if (ev->active.gain) {
+            /* Back to default interval */
+            dcl->gui_timer_interval = 0;
+            dcl->idle = 0;
+        } else {
+            /* Sleeping interval */
+            dcl->gui_timer_interval = 500;
+            dcl->idle = 1;
+        }
+    }
+}
+
+static void sdl_refresh(DisplayState *ds)
+{
+    SDL_Event ev1, *ev = &ev1;
 
     if (last_vm_running != vm_running) {
         last_vm_running = vm_running;
@@ -602,144 +865,10 @@ static void sdl_refresh(DisplayState *ds)
             sdl_update(ds, 0, 0, real_screen->w, real_screen->h);
             break;
         case SDL_KEYDOWN:
+            handle_keydown(ds, ev);
+            break;
         case SDL_KEYUP:
-            if (ev->type == SDL_KEYDOWN) {
-                if (alt_grab) {
-                    mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
-                                (gui_grab_code | KMOD_LSHIFT);
-                } else if (ctrl_grab) {
-                    mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
-                } else {
-                    mod_state = (SDL_GetModState() & gui_grab_code) ==
-                                gui_grab_code;
-                }
-                gui_key_modifier_pressed = mod_state;
-                if (gui_key_modifier_pressed) {
-                    int keycode;
-                    keycode = sdl_keyevent_to_keycode(&ev->key);
-                    switch(keycode) {
-                    case 0x21: /* 'f' key on US keyboard */
-                        toggle_full_screen(ds);
-                        gui_keysym = 1;
-                        break;
-                    case 0x16: /* 'u' key on US keyboard */
-                        if (scaling_active) {
-                            scaling_active = 0;
-                            sdl_resize(ds);
-                            vga_hw_invalidate();
-                            vga_hw_update();
-                        }
-                        gui_keysym = 1;
-                        break;
-                    case 0x02 ... 0x0a: /* '1' to '9' keys */
-                        /* Reset the modifiers sent to the current console */
-                        reset_keys();
-                        console_select(keycode - 0x02);
-                        gui_keysym = 1;
-                        if (gui_fullscreen) {
-                            break;
-                        }
-                        if (!is_graphic_console()) {
-                            /* release grab if going to a text console */
-                            if (gui_grab) {
-                                sdl_grab_end();
-                            } else if (absolute_enabled) {
-                                sdl_show_cursor();
-                            }
-                        } else if (absolute_enabled) {
-                            sdl_hide_cursor();
-                            absolute_mouse_grab();
-                        }
-                        break;
-                    case 0x1b: /* '+' */
-                    case 0x35: /* '-' */
-                        if (!gui_fullscreen) {
-                            int width = MAX(real_screen->w +
-                                            (keycode == 0x1b ? 50 : -50), 160);
-                            int height = (ds_get_height(ds) * width) /
-                                         ds_get_width(ds);
-
-                            sdl_scale(ds, width, height);
-                            vga_hw_invalidate();
-                            vga_hw_update();
-                            gui_keysym = 1;
-                        }
-                    default:
-                        break;
-                    }
-                } else if (!is_graphic_console()) {
-                    int keysym;
-                    keysym = 0;
-                    if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
-                        switch(ev->key.keysym.sym) {
-                        case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break;
-                        case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break;
-                        case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break;
-                        case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break;
-                        case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break;
-                        case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
-                        case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
-                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
-                        default: break;
-                        }
-                    } else {
-                        switch(ev->key.keysym.sym) {
-                        case SDLK_UP: keysym = QEMU_KEY_UP; break;
-                        case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break;
-                        case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break;
-                        case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break;
-                        case SDLK_HOME: keysym = QEMU_KEY_HOME; break;
-                        case SDLK_END: keysym = QEMU_KEY_END; break;
-                        case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break;
-                        case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break;
-                        case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break;
-                        case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break;
-                        default: break;
-                        }
-                    }
-                    if (keysym) {
-                        kbd_put_keysym(keysym);
-                    } else if (ev->key.keysym.unicode != 0) {
-                        kbd_put_keysym(ev->key.keysym.unicode);
-                    }
-                }
-            } else if (ev->type == SDL_KEYUP) {
-                if (!alt_grab) {
-                    mod_state = (ev->key.keysym.mod & gui_grab_code);
-                } else {
-                    mod_state = (ev->key.keysym.mod &
-                                 (gui_grab_code | KMOD_LSHIFT));
-                }
-                if (!mod_state) {
-                    if (gui_key_modifier_pressed) {
-                        gui_key_modifier_pressed = 0;
-                        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) {
-                                    sdl_grab_start();
-                                }
-                            } else if (!gui_fullscreen) {
-                                sdl_grab_end();
-                            }
-                            /* SDL does not send back all the
-                               modifiers key, so we must correct it */
-                            reset_keys();
-                            break;
-                        }
-                        gui_keysym = 0;
-                    }
-                }
-            }
-            if (is_graphic_console() && !gui_keysym)
-                sdl_process_key(&ev->key);
+            handle_keyup(ds, ev);
             break;
         case SDL_QUIT:
             if (!no_quit) {
@@ -748,77 +877,14 @@ static void sdl_refresh(DisplayState *ds)
             }
             break;
         case SDL_MOUSEMOTION:
-            if (is_graphic_console() &&
-                (kbd_mouse_is_absolute() || absolute_enabled)) {
-                int max_x = real_screen->w - 1;
-                int max_y = real_screen->h - 1;
-
-                if (gui_grab &&
-                    (ev->motion.x == 0 || ev->motion.y == 0 ||
-                     ev->motion.x == max_x || ev->motion.y == max_y)) {
-                    sdl_grab_end();
-                }
-                if (!gui_grab && SDL_GetAppState() & SDL_APPINPUTFOCUS &&
-                    (ev->motion.x > 0 && ev->motion.x < max_x &&
-                     ev->motion.y > 0 && ev->motion.y < max_y)) {
-                    sdl_grab_start();
-                }
-            }
-            if (gui_grab || kbd_mouse_is_absolute() ||
-                absolute_enabled) {
-                sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
-                       ev->motion.x, ev->motion.y, ev->motion.state);
-            }
+            handle_mousemotion(ds, ev);
             break;
         case SDL_MOUSEBUTTONDOWN:
         case SDL_MOUSEBUTTONUP:
-            if (is_graphic_console()) {
-                SDL_MouseButtonEvent *bev = &ev->button;
-                if (!gui_grab && !kbd_mouse_is_absolute()) {
-                    if (ev->type == SDL_MOUSEBUTTONDOWN &&
-                        (bev->button == SDL_BUTTON_LEFT)) {
-                        /* start grabbing all events */
-                        sdl_grab_start();
-                    }
-                } else {
-                    int dz;
-                    dz = 0;
-                    if (ev->type == SDL_MOUSEBUTTONDOWN) {
-                        buttonstate |= SDL_BUTTON(bev->button);
-                    } else {
-                        buttonstate &= ~SDL_BUTTON(bev->button);
-                    }
-#ifdef SDL_BUTTON_WHEELUP
-                    if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
-                        dz = -1;
-                    } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
-                        dz = 1;
-                    }
-#endif
-                    sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
-                }
-            }
+            handle_mousebutton(ds, ev);
             break;
         case SDL_ACTIVEEVENT:
-            if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
-                !ev->active.gain && !gui_fullscreen) {
-                sdl_grab_end();
-            }
-            if (!gui_grab && ev->active.gain && is_graphic_console() &&
-                (kbd_mouse_is_absolute() || absolute_enabled)) {
-                absolute_mouse_grab();
-            }
-            if (ev->active.state & SDL_APPACTIVE) {
-                if (ev->active.gain) {
-                    /* Back to default interval */
-                    dcl->gui_timer_interval = 0;
-                    dcl->idle = 0;
-                } else {
-                    /* Sleeping interval */
-                    dcl->gui_timer_interval = 500;
-                    dcl->idle = 1;
-                }
-            }
+            handle_activation(ds, ev);
             break;
         case SDL_VIDEORESIZE:
             sdl_scale(ds, ev->resize.w, ev->resize.h);
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [Qemu-devel] [PATCH 15/15] sdl: Refactor sdl_send_mouse_event
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (13 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 14/15] sdl: Factor out event handlers from sdl_refresh Jan Kiszka
@ 2011-07-30  9:39 ` Jan Kiszka
  2011-08-01  0:28 ` [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Anthony Liguori
  2011-08-05 16:47 ` Anthony Liguori
  16 siblings, 0 replies; 19+ messages in thread
From: Jan Kiszka @ 2011-07-30  9:39 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

From: Jan Kiszka <jan.kiszka@siemens.com>

Replace width/height globals with the identical values from real_screen,
refactor the function according to our coding style.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 ui/sdl.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index e5b8a5f..30cde86 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -49,7 +49,6 @@ static int gui_key_modifier_pressed;
 static int gui_keysym;
 static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
 static uint8_t modifiers_state[256];
-static int width, height;
 static SDL_Cursor *sdl_cursor_normal;
 static SDL_Cursor *sdl_cursor_hidden;
 static int absolute_enabled = 0;
@@ -93,7 +92,7 @@ static void sdl_setdata(DisplayState *ds)
                                             ds->surface->pf.bmask, ds->surface->pf.amask);
 }
 
-static void do_sdl_resize(int new_width, int new_height, int bpp)
+static void do_sdl_resize(int width, int height, int bpp)
 {
     int flags;
 
@@ -108,8 +107,6 @@ static void do_sdl_resize(int new_width, int new_height, int bpp)
     if (gui_noframe)
         flags |= SDL_NOFRAME;
 
-    width = new_width;
-    height = new_height;
     real_screen = SDL_SetVideoMode(width, height, bpp, flags);
     if (!real_screen) {
 	fprintf(stderr, "Could not open SDL display (%dx%dx%d): %s\n", width, 
@@ -501,18 +498,21 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
 
 static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state)
 {
-    int buttons;
-    buttons = 0;
-    if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
+    int buttons = 0;
+
+    if (state & SDL_BUTTON(SDL_BUTTON_LEFT)) {
         buttons |= MOUSE_EVENT_LBUTTON;
-    if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))
+    }
+    if (state & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
         buttons |= MOUSE_EVENT_RBUTTON;
-    if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE))
+    }
+    if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) {
         buttons |= MOUSE_EVENT_MBUTTON;
+    }
 
     if (kbd_mouse_is_absolute()) {
-       dx = x * 0x7FFF / (width - 1);
-       dy = y * 0x7FFF / (height - 1);
+        dx = x * 0x7FFF / (real_screen->w - 1);
+        dy = y * 0x7FFF / (real_screen->h - 1);
     } else if (guest_cursor) {
         x -= guest_x;
         y -= guest_y;
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode Jan Kiszka
@ 2011-07-30 12:57   ` Anthony Liguori
  0 siblings, 0 replies; 19+ messages in thread
From: Anthony Liguori @ 2011-07-30 12:57 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel

On 07/30/2011 04:39 AM, Jan Kiszka wrote:
> From: Jan Kiszka<jan.kiszka@siemens.com>
>
> Just like the monitor does, we need to clear no_shutdown before calling
> qemu_system_shutdown_request on quit requests. Otherwise, QEMU just
> stops the VM.
>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   ui/sdl.c |    4 +++-
>   1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/ui/sdl.c b/ui/sdl.c
> index 6dbc5cb..9efcda5 100644
> --- a/ui/sdl.c
> +++ b/ui/sdl.c
> @@ -672,8 +672,10 @@ static void sdl_refresh(DisplayState *ds)
>                   sdl_process_key(&ev->key);
>               break;
>           case SDL_QUIT:
> -            if (!no_quit)
> +            if (!no_quit) {
> +                no_shutdown = 0;
>                   qemu_system_shutdown_request();
> +            }
>               break;
>           case SDL_MOUSEMOTION:
>               if (gui_grab || kbd_mouse_is_absolute() ||

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [PATCH 00/15] sdl: Usability improvements
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (14 preceding siblings ...)
  2011-07-30  9:39 ` [Qemu-devel] [PATCH 15/15] sdl: Refactor sdl_send_mouse_event Jan Kiszka
@ 2011-08-01  0:28 ` Anthony Liguori
  2011-08-05 16:47 ` Anthony Liguori
  16 siblings, 0 replies; 19+ messages in thread
From: Anthony Liguori @ 2011-08-01  0:28 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel, Stefano Stabellini

On 07/30/2011 04:39 AM, Jan Kiszka wrote:
> As SDL is my preferred way of working ad-hoc with guests, I had a closer
> look at oddities and shortcomings that this GUI exposed, at least here
> on Linux hosts. The result is a series of patches I've now finally
> polished and completed. Highlights:
>   - fix termination in -no-shutdown mode
>   - fix various issues when switching to/from full screen mode
>   - polish mouse grabbing in full screen mode, under text console and
>     when in absolute mouse mode
>   - dynamically grab keyboard input in absolute mouse mode, enabling
>     e.g. ALT+TAB in the guest
>   - add zoom hot keys to make window scaling more attractive
>   - refactor some ugly functions
>
> Please review/merge.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

For the whole series.  I'll merge tomorrow after some testing.

At some point, I need to rebase my gtk backend...

Regards,

Anthony Liguori

>
> CC: Stefano Stabellini<stefano.stabellini@eu.citrix.com>
>
> Jan Kiszka (15):
>    sdl: Fix termination in -no-shutdown mode
>    sdl: Do not make full screen mode resizable
>    sdl: Avoid redundant scaling deactivation
>    sdl: Properly mark modifier+u as hotkey
>    sdl: Fix full screen toggling from scaled mode
>    sdl: Restore scaling mode on return from full screen
>    sdl: Drop bogus gui_fullscreen_initial_grab
>    sdl: Initialize gui_fullscreen earlier during setup
>    sdl: Consistently avoid grabbing input for text consoles
>    sdl: Never release input while in full screen mode
>    sdl: Fix cursor handling when switching consoles in absolute mouse
>      mode
>    sdl: Dynamically grab input in absolute mouse mode
>    sdl: Add zoom hot keys
>    sdl: Factor out event handlers from sdl_refresh
>    sdl: Refactor sdl_send_mouse_event
>
>   qemu-doc.texi |    8 +
>   ui/sdl.c      |  547 ++++++++++++++++++++++++++++++++++++---------------------
>   2 files changed, 355 insertions(+), 200 deletions(-)
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Qemu-devel] [PATCH 00/15] sdl: Usability improvements
  2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
                   ` (15 preceding siblings ...)
  2011-08-01  0:28 ` [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Anthony Liguori
@ 2011-08-05 16:47 ` Anthony Liguori
  16 siblings, 0 replies; 19+ messages in thread
From: Anthony Liguori @ 2011-08-05 16:47 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel, Stefano Stabellini

On 07/30/2011 04:39 AM, Jan Kiszka wrote:
> As SDL is my preferred way of working ad-hoc with guests, I had a closer
> look at oddities and shortcomings that this GUI exposed, at least here
> on Linux hosts. The result is a series of patches I've now finally
> polished and completed. Highlights:
>   - fix termination in -no-shutdown mode
>   - fix various issues when switching to/from full screen mode
>   - polish mouse grabbing in full screen mode, under text console and
>     when in absolute mouse mode
>   - dynamically grab keyboard input in absolute mouse mode, enabling
>     e.g. ALT+TAB in the guest
>   - add zoom hot keys to make window scaling more attractive
>   - refactor some ugly functions
>
> Please review/merge.
>
> CC: Stefano Stabellini<stefano.stabellini@eu.citrix.com>

Applied all.  Thanks.

Regards,

Anthony Liguori

>
> Jan Kiszka (15):
>    sdl: Fix termination in -no-shutdown mode
>    sdl: Do not make full screen mode resizable
>    sdl: Avoid redundant scaling deactivation
>    sdl: Properly mark modifier+u as hotkey
>    sdl: Fix full screen toggling from scaled mode
>    sdl: Restore scaling mode on return from full screen
>    sdl: Drop bogus gui_fullscreen_initial_grab
>    sdl: Initialize gui_fullscreen earlier during setup
>    sdl: Consistently avoid grabbing input for text consoles
>    sdl: Never release input while in full screen mode
>    sdl: Fix cursor handling when switching consoles in absolute mouse
>      mode
>    sdl: Dynamically grab input in absolute mouse mode
>    sdl: Add zoom hot keys
>    sdl: Factor out event handlers from sdl_refresh
>    sdl: Refactor sdl_send_mouse_event
>
>   qemu-doc.texi |    8 +
>   ui/sdl.c      |  547 ++++++++++++++++++++++++++++++++++++---------------------
>   2 files changed, 355 insertions(+), 200 deletions(-)
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-08-05 16:47 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-30  9:39 [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 01/15] sdl: Fix termination in -no-shutdown mode Jan Kiszka
2011-07-30 12:57   ` Anthony Liguori
2011-07-30  9:39 ` [Qemu-devel] [PATCH 02/15] sdl: Do not make full screen mode resizable Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 03/15] sdl: Avoid redundant scaling deactivation Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 04/15] sdl: Properly mark modifier+u as hotkey Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 05/15] sdl: Fix full screen toggling from scaled mode Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 06/15] sdl: Restore scaling mode on return from full screen Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 07/15] sdl: Drop bogus gui_fullscreen_initial_grab Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 08/15] sdl: Initialize gui_fullscreen earlier during setup Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 09/15] sdl: Consistently avoid grabbing input for text consoles Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 10/15] sdl: Never release input while in full screen mode Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 11/15] sdl: Fix cursor handling when switching consoles in absolute mouse mode Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 12/15] sdl: Dynamically grab input " Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 13/15] sdl: Add zoom hot keys Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 14/15] sdl: Factor out event handlers from sdl_refresh Jan Kiszka
2011-07-30  9:39 ` [Qemu-devel] [PATCH 15/15] sdl: Refactor sdl_send_mouse_event Jan Kiszka
2011-08-01  0:28 ` [Qemu-devel] [PATCH 00/15] sdl: Usability improvements Anthony Liguori
2011-08-05 16:47 ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).