/*
* QEMU SDL display driver
- *
+ *
* Copyright (c) 2003 Fabrice Bellard
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "vl.h"
+#include "qemu-common.h"
+#include "console.h"
+#include "sysemu.h"
#include <SDL.h>
if (!vm_running)
status = " [Stopped]";
- else if (gui_grab)
- status = " - Press Ctrl-Alt to exit grab";
+ else if (gui_grab) {
+ if (!alt_grab)
+ status = " - Press Ctrl-Alt to exit grab";
+ else
+ status = " - Press Ctrl-Alt-Shift to exit grab";
+ }
if (qemu_name)
snprintf(buf, sizeof(buf), "QEMU (%s)%s", qemu_name, status);
} else
sdl_hide_cursor();
SDL_WM_GrabInput(SDL_GRAB_ON);
- /* dummy read to avoid moving the mouse */
- SDL_GetRelativeMouseState(NULL, NULL);
gui_grab = 1;
sdl_update_caption();
}
sdl_update_caption();
}
-static void sdl_send_mouse_event(int dz)
+static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state)
{
- int dx, dy, state, buttons;
- state = SDL_GetRelativeMouseState(&dx, &dy);
+ int buttons;
buttons = 0;
if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
buttons |= MOUSE_EVENT_LBUTTON;
absolute_enabled = 1;
}
- SDL_GetMouseState(&dx, &dy);
- dx = dx * 0x7FFF / width;
- dy = dy * 0x7FFF / height;
+ dx = x * 0x7FFF / (width - 1);
+ dy = y * 0x7FFF / (height - 1);
} else if (absolute_enabled) {
sdl_show_cursor();
absolute_enabled = 0;
} else if (guest_cursor) {
- SDL_GetMouseState(&dx, &dy);
- dx -= guest_x;
- dy -= guest_y;
- guest_x += dx;
- guest_y += dy;
+ x -= guest_x;
+ y -= guest_y;
+ guest_x += x;
+ guest_y += y;
+ dx = x;
+ dy = y;
}
kbd_mouse_event(dx, dy, dz, buttons);
{
SDL_Event ev1, *ev = &ev1;
int mod_state;
-
+ int buttonstate = SDL_GetMouseState(NULL, NULL);
+
if (last_vm_running != vm_running) {
last_vm_running = vm_running;
sdl_update_caption();
}
vga_hw_update();
+ SDL_EnableUNICODE(!is_graphic_console());
while (SDL_PollEvent(ev)) {
switch (ev->type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
if (ev->type == SDL_KEYDOWN) {
- mod_state = (SDL_GetModState() & gui_grab_code) ==
- gui_grab_code;
+ if (!alt_grab) {
+ mod_state = (SDL_GetModState() & gui_grab_code) ==
+ gui_grab_code;
+ } else {
+ mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
+ (gui_grab_code | KMOD_LSHIFT);
+ }
gui_key_modifier_pressed = mod_state;
if (gui_key_modifier_pressed) {
int keycode;
toggle_full_screen(ds);
gui_keysym = 1;
break;
- case 0x02 ... 0x0a: /* '1' to '9' keys */
+ case 0x02 ... 0x0a: /* '1' to '9' keys */
/* Reset the modifiers sent to the current console */
reset_keys();
console_select(keycode - 0x02);
}
}
} else if (ev->type == SDL_KEYUP) {
- mod_state = (ev->key.keysym.mod & gui_grab_code);
+ 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 (is_graphic_console() && !gui_keysym)
+ if (is_graphic_console() && !gui_keysym)
sdl_process_key(&ev->key);
break;
case SDL_QUIT:
case SDL_MOUSEMOTION:
if (gui_grab || kbd_mouse_is_absolute() ||
absolute_enabled) {
- sdl_send_mouse_event(0);
+ sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
+ ev->motion.x, ev->motion.y, ev->motion.state);
}
break;
case SDL_MOUSEBUTTONDOWN:
SDL_MouseButtonEvent *bev = &ev->button;
if (!gui_grab && !kbd_mouse_is_absolute()) {
if (ev->type == SDL_MOUSEBUTTONDOWN &&
- (bev->state & SDL_BUTTON_LMASK)) {
+ (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(dz);
+#endif
+ sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
}
}
break;
!ev->active.gain && !gui_fullscreen_initial_grab) {
sdl_grab_end();
}
+ if (ev->active.state & SDL_APPACTIVE) {
+ if (ev->active.gain) {
+ /* Back to default interval */
+ ds->gui_timer_interval = 0;
+ } else {
+ /* Sleeping interval */
+ ds->gui_timer_interval = 500;
+ }
+ }
break;
default:
break;
SDL_SetCursor(guest_sprite);
}
-static void sdl_cleanup(void)
+static void sdl_cleanup(void)
{
if (guest_sprite)
SDL_FreeCursor(guest_sprite);
sdl_resize(ds, 640, 400);
sdl_update_caption();
SDL_EnableKeyRepeat(250, 50);
- SDL_EnableUNICODE(1);
gui_grab = 0;
sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);