sdl2.c (7754c97179a40c563935b7610aa3146291abefcc) sdl2.c (0337e4123e62721bd0bcb4d5645fee2a31e8906d)
1/*
2 * QEMU SDL display driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 189 unchanged lines hidden (view full) ---

198{
199 if (scon->opts->has_show_cursor && scon->opts->show_cursor) {
200 return;
201 }
202
203 SDL_ShowCursor(SDL_DISABLE);
204 SDL_SetCursor(sdl_cursor_hidden);
205
1/*
2 * QEMU SDL display driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 189 unchanged lines hidden (view full) ---

198{
199 if (scon->opts->has_show_cursor && scon->opts->show_cursor) {
200 return;
201 }
202
203 SDL_ShowCursor(SDL_DISABLE);
204 SDL_SetCursor(sdl_cursor_hidden);
205
206 if (!qemu_input_is_absolute()) {
206 if (!qemu_input_is_absolute(scon->dcl.con)) {
207 SDL_SetRelativeMouseMode(SDL_TRUE);
208 }
209}
210
211static void sdl_show_cursor(struct sdl2_console *scon)
212{
213 if (scon->opts->has_show_cursor && scon->opts->show_cursor) {
214 return;
215 }
216
207 SDL_SetRelativeMouseMode(SDL_TRUE);
208 }
209}
210
211static void sdl_show_cursor(struct sdl2_console *scon)
212{
213 if (scon->opts->has_show_cursor && scon->opts->show_cursor) {
214 return;
215 }
216
217 if (!qemu_input_is_absolute()) {
217 if (!qemu_input_is_absolute(scon->dcl.con)) {
218 SDL_SetRelativeMouseMode(SDL_FALSE);
219 }
220
221 if (guest_cursor &&
218 SDL_SetRelativeMouseMode(SDL_FALSE);
219 }
220
221 if (guest_cursor &&
222 (gui_grab || qemu_input_is_absolute() || absolute_enabled)) {
222 (gui_grab || qemu_input_is_absolute(scon->dcl.con) || absolute_enabled)) {
223 SDL_SetCursor(guest_sprite);
224 } else {
225 SDL_SetCursor(sdl_cursor_normal);
226 }
227
228 SDL_ShowCursor(SDL_ENABLE);
229}
230

--- 9 unchanged lines hidden (view full) ---

240 * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
241 * application (SDL bug).
242 */
243 if (!(SDL_GetWindowFlags(scon->real_window) & SDL_WINDOW_INPUT_FOCUS)) {
244 return;
245 }
246 if (guest_cursor) {
247 SDL_SetCursor(guest_sprite);
223 SDL_SetCursor(guest_sprite);
224 } else {
225 SDL_SetCursor(sdl_cursor_normal);
226 }
227
228 SDL_ShowCursor(SDL_ENABLE);
229}
230

--- 9 unchanged lines hidden (view full) ---

240 * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
241 * application (SDL bug).
242 */
243 if (!(SDL_GetWindowFlags(scon->real_window) & SDL_WINDOW_INPUT_FOCUS)) {
244 return;
245 }
246 if (guest_cursor) {
247 SDL_SetCursor(guest_sprite);
248 if (!qemu_input_is_absolute() && !absolute_enabled) {
248 if (!qemu_input_is_absolute(scon->dcl.con) && !absolute_enabled) {
249 SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y);
250 }
251 } else {
252 sdl_hide_cursor(scon);
253 }
254 SDL_SetWindowGrab(scon->real_window, SDL_TRUE);
255 gui_grab = 1;
256 win32_kbd_set_grab(true);

--- 18 unchanged lines hidden (view full) ---

275 if (mouse_x > 0 && mouse_x < scr_w - 1 &&
276 mouse_y > 0 && mouse_y < scr_h - 1) {
277 sdl_grab_start(scon);
278 }
279}
280
281static void sdl_mouse_mode_change(Notifier *notify, void *data)
282{
249 SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y);
250 }
251 } else {
252 sdl_hide_cursor(scon);
253 }
254 SDL_SetWindowGrab(scon->real_window, SDL_TRUE);
255 gui_grab = 1;
256 win32_kbd_set_grab(true);

--- 18 unchanged lines hidden (view full) ---

275 if (mouse_x > 0 && mouse_x < scr_w - 1 &&
276 mouse_y > 0 && mouse_y < scr_h - 1) {
277 sdl_grab_start(scon);
278 }
279}
280
281static void sdl_mouse_mode_change(Notifier *notify, void *data)
282{
283 if (qemu_input_is_absolute()) {
283 if (qemu_input_is_absolute(sdl2_console[0].dcl.con)) {
284 if (!absolute_enabled) {
285 absolute_enabled = 1;
286 SDL_SetRelativeMouseMode(SDL_FALSE);
287 absolute_mouse_grab(&sdl2_console[0]);
288 }
289 } else if (absolute_enabled) {
290 if (!gui_fullscreen) {
291 sdl_grab_end(&sdl2_console[0]);

--- 14 unchanged lines hidden (view full) ---

306 };
307 static uint32_t prev_state;
308
309 if (prev_state != state) {
310 qemu_input_update_buttons(scon->dcl.con, bmap, prev_state, state);
311 prev_state = state;
312 }
313
284 if (!absolute_enabled) {
285 absolute_enabled = 1;
286 SDL_SetRelativeMouseMode(SDL_FALSE);
287 absolute_mouse_grab(&sdl2_console[0]);
288 }
289 } else if (absolute_enabled) {
290 if (!gui_fullscreen) {
291 sdl_grab_end(&sdl2_console[0]);

--- 14 unchanged lines hidden (view full) ---

306 };
307 static uint32_t prev_state;
308
309 if (prev_state != state) {
310 qemu_input_update_buttons(scon->dcl.con, bmap, prev_state, state);
311 prev_state = state;
312 }
313
314 if (qemu_input_is_absolute()) {
314 if (qemu_input_is_absolute(scon->dcl.con)) {
315 qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X,
316 x, 0, surface_width(scon->surface));
317 qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y,
318 y, 0, surface_height(scon->surface));
319 } else {
320 if (guest_cursor) {
321 x -= guest_x;
322 y -= guest_y;

--- 169 unchanged lines hidden (view full) ---

492{
493 int max_x, max_y;
494 struct sdl2_console *scon = get_scon_from_window(ev->motion.windowID);
495
496 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) {
497 return;
498 }
499
315 qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X,
316 x, 0, surface_width(scon->surface));
317 qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y,
318 y, 0, surface_height(scon->surface));
319 } else {
320 if (guest_cursor) {
321 x -= guest_x;
322 y -= guest_y;

--- 169 unchanged lines hidden (view full) ---

492{
493 int max_x, max_y;
494 struct sdl2_console *scon = get_scon_from_window(ev->motion.windowID);
495
496 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) {
497 return;
498 }
499
500 if (qemu_input_is_absolute() || absolute_enabled) {
500 if (qemu_input_is_absolute(scon->dcl.con) || absolute_enabled) {
501 int scr_w, scr_h;
502 SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
503 max_x = scr_w - 1;
504 max_y = scr_h - 1;
505 if (gui_grab && !gui_fullscreen
506 && (ev->motion.x == 0 || ev->motion.y == 0 ||
507 ev->motion.x == max_x || ev->motion.y == max_y)) {
508 sdl_grab_end(scon);
509 }
510 if (!gui_grab &&
511 (ev->motion.x > 0 && ev->motion.x < max_x &&
512 ev->motion.y > 0 && ev->motion.y < max_y)) {
513 sdl_grab_start(scon);
514 }
515 }
501 int scr_w, scr_h;
502 SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
503 max_x = scr_w - 1;
504 max_y = scr_h - 1;
505 if (gui_grab && !gui_fullscreen
506 && (ev->motion.x == 0 || ev->motion.y == 0 ||
507 ev->motion.x == max_x || ev->motion.y == max_y)) {
508 sdl_grab_end(scon);
509 }
510 if (!gui_grab &&
511 (ev->motion.x > 0 && ev->motion.x < max_x &&
512 ev->motion.y > 0 && ev->motion.y < max_y)) {
513 sdl_grab_start(scon);
514 }
515 }
516 if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
516 if (gui_grab || qemu_input_is_absolute(scon->dcl.con) || absolute_enabled) {
517 sdl_send_mouse_event(scon, ev->motion.xrel, ev->motion.yrel,
518 ev->motion.x, ev->motion.y, ev->motion.state);
519 }
520}
521
522static void handle_mousebutton(SDL_Event *ev)
523{
524 int buttonstate = SDL_GetMouseState(NULL, NULL);
525 SDL_MouseButtonEvent *bev;
526 struct sdl2_console *scon = get_scon_from_window(ev->button.windowID);
527
528 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) {
529 return;
530 }
531
532 bev = &ev->button;
517 sdl_send_mouse_event(scon, ev->motion.xrel, ev->motion.yrel,
518 ev->motion.x, ev->motion.y, ev->motion.state);
519 }
520}
521
522static void handle_mousebutton(SDL_Event *ev)
523{
524 int buttonstate = SDL_GetMouseState(NULL, NULL);
525 SDL_MouseButtonEvent *bev;
526 struct sdl2_console *scon = get_scon_from_window(ev->button.windowID);
527
528 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) {
529 return;
530 }
531
532 bev = &ev->button;
533 if (!gui_grab && !qemu_input_is_absolute()) {
533 if (!gui_grab && !qemu_input_is_absolute(scon->dcl.con)) {
534 if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
535 /* start grabbing all events */
536 sdl_grab_start(scon);
537 }
538 } else {
539 if (ev->type == SDL_MOUSEBUTTONDOWN) {
540 buttonstate |= SDL_BUTTON(bev->button);
541 } else {

--- 56 unchanged lines hidden (view full) ---

598 break;
599 case SDL_WINDOWEVENT_FOCUS_GAINED:
600 win32_kbd_set_grab(gui_grab);
601 if (qemu_console_is_graphic(scon->dcl.con)) {
602 win32_kbd_set_window(sdl2_win32_get_hwnd(scon));
603 }
604 /* fall through */
605 case SDL_WINDOWEVENT_ENTER:
534 if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
535 /* start grabbing all events */
536 sdl_grab_start(scon);
537 }
538 } else {
539 if (ev->type == SDL_MOUSEBUTTONDOWN) {
540 buttonstate |= SDL_BUTTON(bev->button);
541 } else {

--- 56 unchanged lines hidden (view full) ---

598 break;
599 case SDL_WINDOWEVENT_FOCUS_GAINED:
600 win32_kbd_set_grab(gui_grab);
601 if (qemu_console_is_graphic(scon->dcl.con)) {
602 win32_kbd_set_window(sdl2_win32_get_hwnd(scon));
603 }
604 /* fall through */
605 case SDL_WINDOWEVENT_ENTER:
606 if (!gui_grab && (qemu_input_is_absolute() || absolute_enabled)) {
606 if (!gui_grab && (qemu_input_is_absolute(scon->dcl.con) || absolute_enabled)) {
607 absolute_mouse_grab(scon);
608 }
609 /* If a new console window opened using a hotkey receives the
610 * focus, SDL sends another KEYDOWN event to the new window,
611 * closing the console window immediately after.
612 *
613 * Work around this by ignoring further hotkey events until a
614 * key is released.

--- 113 unchanged lines hidden (view full) ---

728 if (!qemu_console_is_graphic(scon->dcl.con)) {
729 return;
730 }
731
732 if (on) {
733 if (!guest_cursor) {
734 sdl_show_cursor(scon);
735 }
607 absolute_mouse_grab(scon);
608 }
609 /* If a new console window opened using a hotkey receives the
610 * focus, SDL sends another KEYDOWN event to the new window,
611 * closing the console window immediately after.
612 *
613 * Work around this by ignoring further hotkey events until a
614 * key is released.

--- 113 unchanged lines hidden (view full) ---

728 if (!qemu_console_is_graphic(scon->dcl.con)) {
729 return;
730 }
731
732 if (on) {
733 if (!guest_cursor) {
734 sdl_show_cursor(scon);
735 }
736 if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
736 if (gui_grab || qemu_input_is_absolute(scon->dcl.con) || absolute_enabled) {
737 SDL_SetCursor(guest_sprite);
737 SDL_SetCursor(guest_sprite);
738 if (!qemu_input_is_absolute() && !absolute_enabled) {
738 if (!qemu_input_is_absolute(scon->dcl.con) && !absolute_enabled) {
739 SDL_WarpMouseInWindow(scon->real_window, x, y);
740 }
741 }
742 } else if (gui_grab) {
743 sdl_hide_cursor(scon);
744 }
745 guest_cursor = on;
746 guest_x = x, guest_y = y;

--- 21 unchanged lines hidden (view full) ---

768 }
769 guest_sprite = SDL_CreateColorCursor(guest_sprite_surface,
770 c->hot_x, c->hot_y);
771 if (!guest_sprite) {
772 fprintf(stderr, "Failed to make color cursor from %p\n", c);
773 return;
774 }
775 if (guest_cursor &&
739 SDL_WarpMouseInWindow(scon->real_window, x, y);
740 }
741 }
742 } else if (gui_grab) {
743 sdl_hide_cursor(scon);
744 }
745 guest_cursor = on;
746 guest_x = x, guest_y = y;

--- 21 unchanged lines hidden (view full) ---

768 }
769 guest_sprite = SDL_CreateColorCursor(guest_sprite_surface,
770 c->hot_x, c->hot_y);
771 if (!guest_sprite) {
772 fprintf(stderr, "Failed to make color cursor from %p\n", c);
773 return;
774 }
775 if (guest_cursor &&
776 (gui_grab || qemu_input_is_absolute() || absolute_enabled)) {
776 (gui_grab || qemu_input_is_absolute(dcl->con) || absolute_enabled)) {
777 SDL_SetCursor(guest_sprite);
778 }
779}
780
781static void sdl_cleanup(void)
782{
783 if (guest_sprite) {
784 SDL_FreeCursor(guest_sprite);

--- 189 unchanged lines hidden ---
777 SDL_SetCursor(guest_sprite);
778 }
779}
780
781static void sdl_cleanup(void)
782{
783 if (guest_sprite) {
784 SDL_FreeCursor(guest_sprite);

--- 189 unchanged lines hidden ---