summaryrefslogtreecommitdiff
path: root/ui/sdl.c
diff options
context:
space:
mode:
authorEvgeny Voevodin <e.voevodin@samsung.com>2012-06-08 13:45:29 +0400
committerEvgeny Voevodin <e.voevodin@samsung.com>2012-06-15 11:21:10 +0400
commit02935a553fb88f79fb0c79f094fb5ca0b42c96f3 (patch)
tree7a317e392c43f920faa1044cdb3df4c75b2c3639 /ui/sdl.c
parent5b1adc390502140a03bc1e872b0b103d09e048f6 (diff)
downloadqemu-02935a553fb88f79fb0c79f094fb5ca0b42c96f3.tar.gz
qemu-02935a553fb88f79fb0c79f094fb5ca0b42c96f3.tar.bz2
qemu-02935a553fb88f79fb0c79f094fb5ca0b42c96f3.zip
Upgrade to upstream v1.1.0.
Signed-off-by: Evgeny Voevodin <e.voevodin@samsung.com>
Diffstat (limited to 'ui/sdl.c')
-rw-r--r--ui/sdl.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/ui/sdl.c b/ui/sdl.c
index 8cafc44e71..f6f711c1bb 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -167,10 +167,6 @@ static PixelFormat sdl_to_qemu_pixelformat(SDL_PixelFormat *sdl_pf)
static DisplaySurface* sdl_create_displaysurface(int width, int height)
{
DisplaySurface *surface = (DisplaySurface*) g_malloc0(sizeof(DisplaySurface));
- if (surface == NULL) {
- fprintf(stderr, "sdl_create_displaysurface: malloc failed\n");
- exit(1);
- }
surface->width = width;
surface->height = height;
@@ -461,18 +457,23 @@ static void sdl_show_cursor(void)
static void sdl_grab_start(void)
{
+ /*
+ * If the application is not active, do not try to enter grab state. This
+ * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
+ * application (SDL bug).
+ */
+ if (!(SDL_GetAppState() & SDL_APPINPUTFOCUS)) {
+ return;
+ }
if (guest_cursor) {
SDL_SetCursor(guest_sprite);
if (!kbd_mouse_is_absolute() && !absolute_enabled)
SDL_WarpMouse(guest_x, guest_y);
} else
sdl_hide_cursor();
-
- if (SDL_WM_GrabInput(SDL_GRAB_ON) == SDL_GRAB_ON) {
- gui_grab = 1;
- sdl_update_caption();
- } else
- sdl_show_cursor();
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ gui_grab = 1;
+ sdl_update_caption();
}
static void sdl_grab_end(void)
@@ -483,12 +484,25 @@ static void sdl_grab_end(void)
sdl_update_caption();
}
+static void absolute_mouse_grab(void)
+{
+ int mouse_x, mouse_y;
+
+ 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_mouse_mode_change(Notifier *notify, void *data)
{
if (kbd_mouse_is_absolute()) {
if (!absolute_enabled) {
- sdl_grab_start();
absolute_enabled = 1;
+ if (is_graphic_console()) {
+ absolute_mouse_grab();
+ }
}
} else if (absolute_enabled) {
if (!gui_fullscreen) {
@@ -571,19 +585,6 @@ 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 handle_keydown(DisplayState *ds, SDL_Event *ev)
{
int mod_state;
@@ -743,11 +744,7 @@ static void handle_keyup(DisplayState *ds, SDL_Event *ev)
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) {
+ if (is_graphic_console()) {
sdl_grab_start();
}
} else if (!gui_fullscreen) {
@@ -777,7 +774,7 @@ static void handle_mousemotion(DisplayState *ds, SDL_Event *ev)
ev->motion.x == max_x || ev->motion.y == max_y)) {
sdl_grab_end();
}
- if (!gui_grab && SDL_GetAppState() & SDL_APPINPUTFOCUS &&
+ if (!gui_grab &&
(ev->motion.x > 0 && ev->motion.x < max_x &&
ev->motion.y > 0 && ev->motion.y < max_y)) {
sdl_grab_start();
@@ -801,8 +798,7 @@ static void handle_mousebutton(DisplayState *ds, SDL_Event *ev)
bev = &ev->button;
if (!gui_grab && !kbd_mouse_is_absolute()) {
- if (ev->type == SDL_MOUSEBUTTONDOWN &&
- (bev->button == SDL_BUTTON_LEFT)) {
+ if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
/* start grabbing all events */
sdl_grab_start();
}
@@ -828,10 +824,14 @@ static void handle_mousebutton(DisplayState *ds, SDL_Event *ev)
static void handle_activation(DisplayState *ds, SDL_Event *ev)
{
+#ifdef _WIN32
+ /* Disable grab if the window no longer has the focus
+ * (Windows-only workaround) */
if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
!ev->active.gain && !gui_fullscreen) {
sdl_grab_end();
}
+#endif
if (!gui_grab && ev->active.gain && is_graphic_console() &&
(kbd_mouse_is_absolute() || absolute_enabled)) {
absolute_mouse_grab();