diff -ru qemu-snapshot-2005-02-10_23/hw/cirrus_vga.c qemu-snapshot-2005-02-10_23.patched/hw/cirrus_vga.c --- qemu-snapshot-2005-02-10_23/hw/cirrus_vga.c 2005-01-26 20:50:16.000000000 +0100 +++ qemu-snapshot-2005-02-10_23.patched/hw/cirrus_vga.c 2005-02-27 17:05:18.000000000 +0100 @@ -1172,6 +1172,18 @@ case 0xf0: // Graphics Cursor X s->sr[0x10] = reg_value; s->hw_cursor_x = (reg_value << 3) | (reg_index >> 5); +#ifdef DEBUG_CIRRUS + if (s->hw_cursor_x < 10 || s->hw_cursor_x > s->last_scr_width - 20) + printf("1; hw_cursor_x= %d; last_cursor_x= %d\n", s->hw_cursor_x, s->last_hw_cursor_x); +#endif + if ( (s->hw_cursor_x <= 1 && s->hw_cursor_x >= 0 && s->last_hw_cursor_x - (int) s->hw_cursor_x > 4)) + { + s->ds->cursor_release(s->ds, 0, s->hw_cursor_y); + } + else if (s->hw_cursor_x >= s->last_scr_width - 12 && s->hw_cursor_x <= s->last_scr_width + 1 && (int) s->hw_cursor_x - s->last_hw_cursor_x > 4) + { + s->ds->cursor_release(s->ds, s->last_scr_width + 1, s->hw_cursor_y); + } break; case 0x11: case 0x31: @@ -1183,6 +1195,18 @@ case 0xf1: // Graphics Cursor Y s->sr[0x11] = reg_value; s->hw_cursor_y = (reg_value << 3) | (reg_index >> 5); +#ifdef DEBUG_CIRRUS + if (s->hw_cursor_y < 10 || s->hw_cursor_y > s->last_scr_height - 20) + printf("4; hw_cursor_y= %d; last_cursor_y= %d\n", s->hw_cursor_y, s->last_hw_cursor_y); +#endif + if (s->hw_cursor_y <= 1 && s->hw_cursor_y >= 0 && s->last_hw_cursor_y - (int) s->hw_cursor_y > 4) + { + s->ds->cursor_release(s->ds, s->hw_cursor_x, 0); + } + else if (s->hw_cursor_y >= s->last_scr_height - 12 && s->hw_cursor_y <= s->last_scr_height + 1 && (int) s->hw_cursor_y - s->last_hw_cursor_y > 4) + { + s->ds->cursor_release(s->ds, s->hw_cursor_x, s->last_scr_height + 1); + } break; case 0x07: // Extended Sequencer Mode case 0x08: // EEPROM Control @@ -2085,6 +2109,7 @@ invalidate_cursor1(s); s->last_hw_cursor_size = size; + s->ds->hw_cursor_size = size; s->last_hw_cursor_x = s->hw_cursor_x; s->last_hw_cursor_y = s->hw_cursor_y; /* compute the real cursor min and max y */ diff -ru qemu-snapshot-2005-02-10_23/sdl.c qemu-snapshot-2005-02-10_23.patched/sdl.c --- qemu-snapshot-2005-02-10_23/sdl.c 2005-01-17 23:32:23.000000000 +0100 +++ qemu-snapshot-2005-02-10_23.patched/sdl.c 2005-03-02 20:59:15.000000000 +0100 @@ -39,6 +39,7 @@ static int gui_fullscreen_initial_grab; static int gui_grab_code = KMOD_LALT | KMOD_LCTRL; static uint8_t modifiers_state[256]; +static int ignoreMouseEvent = 0; static void sdl_update(DisplayState *ds, int x, int y, int w, int h) { @@ -283,6 +284,12 @@ { int dx, dy, state, buttons; state = SDL_GetRelativeMouseState(&dx, &dy); + if (ignoreMouseEvent) + { + ignoreMouseEvent = 0; + return; + } + buttons = 0; if (state & SDL_BUTTON(SDL_BUTTON_LEFT)) buttons |= MOUSE_EVENT_LBUTTON; @@ -308,6 +315,18 @@ vga_update_display(); } +void sdl_cursor_release(struct DisplayState *s, int x, int y) +{ + //printf("releasing cursor at %d/%d; grab=%d; fullscreen=%d; vga_console=%d; modstate=%d; mousestate=%d\n", + // x, y, gui_grab, gui_fullscreen, is_active_console(vga_console), SDL_GetModState(), SDL_GetMouseState(NULL, NULL)); + if (mouse_autograb && gui_grab && !gui_fullscreen && is_active_console(vga_console) && + SDL_GetModState() | KMOD_NUM == KMOD_NUM && !SDL_GetMouseState(NULL, NULL)) + { + sdl_grab_end(); + SDL_WarpMouse(x, y); + } +} + static void sdl_refresh(DisplayState *ds) { SDL_Event ev1, *ev = &ev1; @@ -446,10 +465,17 @@ } break; case SDL_ACTIVEEVENT: - if (gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0 && + if (!mouse_autograb && gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0 && !gui_fullscreen_initial_grab) { sdl_grab_end(); } + else if (mouse_autograb && ev->active.state == SDL_APPMOUSEFOCUS && ev->active.gain == 1 && + !gui_grab && !gui_fullscreen && is_active_console(vga_console) && + ds->hw_cursor_size) + { + ignoreMouseEvent = 1; + sdl_grab_start(); + } break; default: break; @@ -491,6 +517,7 @@ ds->dpy_update = sdl_update; ds->dpy_resize = sdl_resize; ds->dpy_refresh = sdl_refresh; + ds->cursor_release = sdl_cursor_release; sdl_resize(ds, 640, 400); sdl_update_caption(); diff -ru qemu-snapshot-2005-02-10_23/vl.c qemu-snapshot-2005-02-10_23.patched/vl.c --- qemu-snapshot-2005-02-10_23/vl.c 2005-02-10 23:00:06.000000000 +0100 +++ qemu-snapshot-2005-02-10_23.patched/vl.c 2005-03-02 20:48:27.000000000 +0100 @@ -137,6 +137,7 @@ TextConsole *vga_console; CharDriverState *serial_hds[MAX_SERIAL_PORTS]; CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; +int mouse_autograb = 0; /***********************************************************/ /* x86 ISA bus support */ @@ -2852,6 +2853,7 @@ QEMU_OPTION_full_screen, QEMU_OPTION_pidfile, QEMU_OPTION_no_kqemu, + QEMU_OPTION_mouse_autograb, }; typedef struct QEMUOption { @@ -2918,6 +2920,7 @@ { "loadvm", HAS_ARG, QEMU_OPTION_loadvm }, { "full-screen", 0, QEMU_OPTION_full_screen }, { "pidfile", HAS_ARG, QEMU_OPTION_pidfile }, + { "autograb", 0, QEMU_OPTION_mouse_autograb }, /* temporary options */ { "pci", 0, QEMU_OPTION_pci }, @@ -3370,6 +3373,9 @@ kqemu_allowed = 0; break; #endif + case QEMU_OPTION_mouse_autograb: + mouse_autograb = 1; + break; } } } diff -ru qemu-snapshot-2005-02-10_23/vl.h qemu-snapshot-2005-02-10_23.patched/vl.h --- qemu-snapshot-2005-02-10_23/vl.h 2005-02-10 23:00:06.000000000 +0100 +++ qemu-snapshot-2005-02-10_23.patched/vl.h 2005-03-02 20:59:18.000000000 +0100 @@ -125,6 +125,7 @@ extern int graphic_depth; extern const char *keyboard_layout; extern int kqemu_allowed; +extern int mouse_autograb; /* XXX: make it dynamic */ #if defined (TARGET_PPC) @@ -542,9 +543,11 @@ int depth; int width; int height; + int hw_cursor_size; void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h); void (*dpy_resize)(struct DisplayState *s, int w, int h); void (*dpy_refresh)(struct DisplayState *s); + void (*cursor_release)(struct DisplayState *s, int x, int y); }; static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)