qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] no-sdl-grab patch
@ 2004-07-15 22:59 Jim C. Brown
  2004-07-15 23:23 ` Jim C. Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Jim C. Brown @ 2004-07-15 22:59 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 989 bytes --]

This patch adds a command line option, "-no-sdl-grab". If you use this option
then qemu won't grab the mouse but instead will have the guest mouse "follow"
the host mouse pointer. Ctrl-Shift still works, it toggles following in the
same way it toggles grabbing. Press Ctrl-Shift once will have the guest mouse
start following the host mouse, press it again and the guest mouse will stop.
(This can be used to keep the two pointers in sync with each other.)

I find this a convient feature because in no-sdl-grab mode I can switch from
one window to the next in the usual way, instead of having to manually release
the mouse in a qemu session before switching windows. (This is a matter of
personal preference but I find that needing to press Ctrl-Shift can really
interrupt my flow of thought.)

I'm looking into adding this into the monitor, so you can toggle this in a
running qemu session.

-- 
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.

[-- Attachment #2: qemu.diff --]
[-- Type: text/plain, Size: 3242 bytes --]

diff -ru fresh.qemu/sdl.c qemu/sdl.c
--- fresh.qemu/sdl.c	Thu Jul 15 13:18:14 2004
+++ qemu/sdl.c	Thu Jul 15 13:23:39 2004
@@ -40,6 +40,7 @@
 static int gui_fullscreen;
 static int gui_key_modifier_pressed;
 static int gui_keysym;
+static int saved_grab_with_sdl;
 
 static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
 {
@@ -347,8 +348,10 @@
 
 static void sdl_grab_start(void)
 {
-    SDL_ShowCursor(0);
-    SDL_WM_GrabInput(SDL_GRAB_ON);
+    if (grab_with_sdl) {
+        SDL_ShowCursor(0);
+        SDL_WM_GrabInput(SDL_GRAB_ON);
+    }
     /* dummy read to avoid moving the mouse */
     SDL_GetRelativeMouseState(NULL, NULL);
     gui_grab = 1;
@@ -357,8 +360,10 @@
 
 static void sdl_grab_end(void)
 {
-    SDL_WM_GrabInput(SDL_GRAB_OFF);
-    SDL_ShowCursor(1);
+    if (grab_with_sdl) {
+        SDL_WM_GrabInput(SDL_GRAB_OFF);
+        SDL_ShowCursor(1);
+    }
     gui_grab = 0;
     sdl_update_caption();
 }
@@ -391,10 +396,13 @@
     sdl_resize(ds, screen->w, screen->h);
     if (gui_fullscreen) {
         gui_saved_grab = gui_grab;
+	saved_grab_with_sdl = grab_with_sdl;
+	grab_with_sdl = 1;
         sdl_grab_start();
     } else {
-        if (!gui_saved_grab)
+        if (!gui_saved_grab || !saved_grab_with_sdl)
             sdl_grab_end();
+	grab_with_sdl = saved_grab_with_sdl;
     }
     vga_invalidate_display();
     vga_update_display();
@@ -525,7 +533,7 @@
             }
             break;
         case SDL_ACTIVEEVENT:
-            if (gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0) {
+            if (grab_with_sdl && gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0) {
                 sdl_grab_end();
             }
             break;
diff -ru fresh.qemu/vl.c qemu/vl.c
--- fresh.qemu/vl.c	Thu Jul 15 13:18:33 2004
+++ qemu/vl.c	Thu Jul 15 13:29:52 2004
@@ -138,6 +138,7 @@
 int graphic_width = 800;
 int graphic_height = 600;
 int graphic_depth = 15;
+int grab_with_sdl = 1;
 TextConsole *vga_console;
 
 /***********************************************************/
@@ -2438,6 +2439,7 @@
     QEMU_OPTION_cirrusvga,
     QEMU_OPTION_g,
     QEMU_OPTION_std_vga,
+    QEMU_OPTION_no_sdl_grab,
     QEMU_OPTION_monitor,
     QEMU_OPTION_serial,
 };
@@ -2491,9 +2493,9 @@
     { "localtime", 0, QEMU_OPTION_localtime },
     { "isa", 0, QEMU_OPTION_isa },
     { "std-vga", 0, QEMU_OPTION_std_vga },
+    { "no-sdl-grab", 0, QEMU_OPTION_no_sdl_grab },
     { "monitor", 1, QEMU_OPTION_monitor },
     { "serial", 1, QEMU_OPTION_serial },
-    
     /* temporary options */
     { "pci", 0, QEMU_OPTION_pci },
     { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
@@ -2791,6 +2793,9 @@
                 break;
             case QEMU_OPTION_std_vga:
                 cirrus_vga_enabled = 0;
+                break;
+            case QEMU_OPTION_no_sdl_grab:
+                grab_with_sdl = 0;
                 break;
             case QEMU_OPTION_g:
                 {
diff -ru fresh.qemu/vl.h qemu/vl.h
--- fresh.qemu/vl.h	Thu Jul 15 13:18:36 2004
+++ qemu/vl.h	Thu Jul 15 13:24:07 2004
@@ -241,6 +241,7 @@
 extern int graphic_width;
 extern int graphic_height;
 extern int graphic_depth;
+extern int grab_with_sdl;
 
 /* XXX: make it dynamic */
 #if defined (TARGET_PPC)

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

* Re: [Qemu-devel] no-sdl-grab patch
  2004-07-15 22:59 [Qemu-devel] no-sdl-grab patch Jim C. Brown
@ 2004-07-15 23:23 ` Jim C. Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Jim C. Brown @ 2004-07-15 23:23 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 422 bytes --]

On Thu, Jul 15, 2004 at 06:59:08PM -0400, Jim C. Brown wrote:
> I'm looking into adding this into the monitor, so you can toggle this in a
> running qemu session.
> 

Simplier than I thought. Attached is the patch to toggle it in the monitor.
Just type "sdl_grab_toggle" or "sdl" for short. Apply on top of my previous
patch.

-- 
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.

[-- Attachment #2: qemu.diff --]
[-- Type: text/plain, Size: 739 bytes --]

--- fresh.qemu/monitor.c	Thu Jul 15 13:17:52 2004
+++ qemu/monitor.c	Thu Jul 15 19:11:17 2004
@@ -681,6 +681,12 @@
     qemu_system_reset_request();
 }
 
+static void do_sdl_grab_toggle(void)
+{
+	grab_with_sdl = !grab_with_sdl;
+	term_printf("Grab with SDL is now set to: %s\n", grab_with_sdl ? "On" : "Off");
+}
+
 static term_cmd_t term_cmds[] = {
     { "help|?", "s?", do_help, 
       "[cmd]", "show the help" },
@@ -723,6 +729,8 @@
       "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
     { "system_reset", "", do_system_reset, 
       "", "reset the system" },
+    { "sdl|sdl_grab_toggle", "", do_sdl_grab_toggle,
+      "", "toggles SDL mouse grabbing vs mouse pointer following" },
     { NULL, NULL, }, 
 };
 

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

end of thread, other threads:[~2004-07-15 23:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-15 22:59 [Qemu-devel] no-sdl-grab patch Jim C. Brown
2004-07-15 23:23 ` Jim C. Brown

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).