no-sdl-grab patch
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.
Signature · 2 lines
Infinite complexity begets infinite beauty. Infinite precision begets infinite perfection.
sdl.c +14 -6
@@ -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 ;
vl.c +6 -1
@@ -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: {
vl.h +1 -0
@@ -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 )
Quoted 3 lines · Jim C. Brown
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.
Signature · 2 lines
Infinite complexity begets infinite beauty. Infinite precision begets infinite perfection.
monitor.c +8 -0
@@ -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, }, };