2 * QEMU SDL display driver
4 * Copyright (c) 2003 Fabrice Bellard
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
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
26 /* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
27 #undef WIN32_LEAN_AND_MEAN
30 #include <SDL_syswm.h>
32 #include "qemu-common.h"
33 #include "ui/console.h"
36 #include "sysemu/sysemu.h"
38 static int sdl2_num_outputs
;
39 static struct sdl2_console
*sdl2_console
;
41 static SDL_Surface
*guest_sprite_surface
;
42 static int gui_grab
; /* if true, all keyboard/mouse events are grabbed */
44 static bool gui_saved_scaling
;
45 static int gui_saved_width
;
46 static int gui_saved_height
;
47 static int gui_saved_grab
;
48 static int gui_fullscreen
;
49 static int gui_noframe
;
50 static int gui_key_modifier_pressed
;
51 static int gui_keysym
;
52 static int gui_grab_code
= KMOD_LALT
| KMOD_LCTRL
;
53 static SDL_Cursor
*sdl_cursor_normal
;
54 static SDL_Cursor
*sdl_cursor_hidden
;
55 static int absolute_enabled
;
56 static int guest_cursor
;
57 static int guest_x
, guest_y
;
58 static SDL_Cursor
*guest_sprite
;
59 static int scaling_active
;
60 static Notifier mouse_mode_notifier
;
62 static void sdl_update_caption(struct sdl2_console
*scon
);
64 static struct sdl2_console
*get_scon_from_window(uint32_t window_id
)
67 for (i
= 0; i
< sdl2_num_outputs
; i
++) {
68 if (sdl2_console
[i
].real_window
== SDL_GetWindowFromID(window_id
)) {
69 return &sdl2_console
[i
];
75 static void sdl_update(DisplayChangeListener
*dcl
,
76 int x
, int y
, int w
, int h
)
78 struct sdl2_console
*scon
= container_of(dcl
, struct sdl2_console
, dcl
);
80 DisplaySurface
*surf
= qemu_console_surface(dcl
->con
);
94 SDL_UpdateTexture(scon
->texture
, NULL
, surface_data(surf
),
95 surface_stride(surf
));
96 SDL_RenderCopy(scon
->real_renderer
, scon
->texture
, &rect
, &rect
);
97 SDL_RenderPresent(scon
->real_renderer
);
100 static void do_sdl_resize(struct sdl2_console
*scon
, int width
, int height
,
105 if (scon
->real_window
&& scon
->real_renderer
) {
106 if (width
&& height
) {
107 SDL_RenderSetLogicalSize(scon
->real_renderer
, width
, height
);
108 SDL_SetWindowSize(scon
->real_window
, width
, height
);
110 SDL_DestroyRenderer(scon
->real_renderer
);
111 SDL_DestroyWindow(scon
->real_window
);
112 scon
->real_renderer
= NULL
;
113 scon
->real_window
= NULL
;
116 if (!width
|| !height
) {
120 if (gui_fullscreen
) {
121 flags
|= SDL_WINDOW_FULLSCREEN
;
123 flags
|= SDL_WINDOW_RESIZABLE
;
126 flags
|= SDL_WINDOW_HIDDEN
;
129 scon
->real_window
= SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED
,
130 SDL_WINDOWPOS_UNDEFINED
,
131 width
, height
, flags
);
132 scon
->real_renderer
= SDL_CreateRenderer(scon
->real_window
, -1, 0);
133 sdl_update_caption(scon
);
137 static void sdl_switch(DisplayChangeListener
*dcl
,
138 DisplaySurface
*new_surface
)
140 struct sdl2_console
*scon
= container_of(dcl
, struct sdl2_console
, dcl
);
143 DisplaySurface
*old_surface
= scon
->surface
;
145 /* temporary hack: allows to call sdl_switch to handle scaling changes */
147 scon
->surface
= new_surface
;
150 if (!new_surface
&& idx
> 0) {
151 scon
->surface
= NULL
;
154 if (new_surface
== NULL
) {
155 do_sdl_resize(scon
, 0, 0, 0);
157 do_sdl_resize(scon
, surface_width(scon
->surface
),
158 surface_height(scon
->surface
), 0);
161 if (old_surface
&& scon
->texture
) {
162 SDL_DestroyTexture(scon
->texture
);
163 scon
->texture
= NULL
;
167 if (!scon
->texture
) {
168 if (surface_bits_per_pixel(scon
->surface
) == 16) {
169 format
= SDL_PIXELFORMAT_RGB565
;
170 } else if (surface_bits_per_pixel(scon
->surface
) == 32) {
171 format
= SDL_PIXELFORMAT_ARGB8888
;
174 scon
->texture
= SDL_CreateTexture(scon
->real_renderer
, format
,
175 SDL_TEXTUREACCESS_STREAMING
,
176 surface_width(new_surface
),
177 surface_height(new_surface
));
182 static void sdl_update_caption(struct sdl2_console
*scon
)
184 char win_title
[1024];
185 char icon_title
[1024];
186 const char *status
= "";
188 if (!runstate_is_running()) {
189 status
= " [Stopped]";
190 } else if (gui_grab
) {
192 status
= " - Press Ctrl-Alt-Shift to exit grab";
193 } else if (ctrl_grab
) {
194 status
= " - Press Right-Ctrl to exit grab";
196 status
= " - Press Ctrl-Alt to exit grab";
201 snprintf(win_title
, sizeof(win_title
), "QEMU (%s-%d)%s", qemu_name
,
203 snprintf(icon_title
, sizeof(icon_title
), "QEMU (%s)", qemu_name
);
205 snprintf(win_title
, sizeof(win_title
), "QEMU%s", status
);
206 snprintf(icon_title
, sizeof(icon_title
), "QEMU");
209 if (scon
->real_window
) {
210 SDL_SetWindowTitle(scon
->real_window
, win_title
);
214 static void sdl_hide_cursor(void)
220 if (qemu_input_is_absolute()) {
222 SDL_SetCursor(sdl_cursor_hidden
);
224 SDL_SetRelativeMouseMode(SDL_TRUE
);
228 static void sdl_show_cursor(void)
234 if (!qemu_input_is_absolute()) {
235 SDL_SetRelativeMouseMode(SDL_FALSE
);
238 (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
)) {
239 SDL_SetCursor(guest_sprite
);
241 SDL_SetCursor(sdl_cursor_normal
);
246 static void sdl_grab_start(struct sdl2_console
*scon
)
248 QemuConsole
*con
= scon
? scon
->dcl
.con
: NULL
;
250 if (!con
|| !qemu_console_is_graphic(con
)) {
254 * If the application is not active, do not try to enter grab state. This
255 * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
256 * application (SDL bug).
258 if (!(SDL_GetWindowFlags(scon
->real_window
) & SDL_WINDOW_INPUT_FOCUS
)) {
262 SDL_SetCursor(guest_sprite
);
263 if (!qemu_input_is_absolute() && !absolute_enabled
) {
264 SDL_WarpMouseInWindow(scon
->real_window
, guest_x
, guest_y
);
269 SDL_SetWindowGrab(scon
->real_window
, SDL_TRUE
);
271 sdl_update_caption(scon
);
274 static void sdl_grab_end(struct sdl2_console
*scon
)
276 SDL_SetWindowGrab(scon
->real_window
, SDL_FALSE
);
279 sdl_update_caption(scon
);
282 static void absolute_mouse_grab(struct sdl2_console
*scon
)
284 int mouse_x
, mouse_y
;
286 SDL_GetMouseState(&mouse_x
, &mouse_y
);
287 SDL_GetWindowSize(scon
->real_window
, &scr_w
, &scr_h
);
288 if (mouse_x
> 0 && mouse_x
< scr_w
- 1 &&
289 mouse_y
> 0 && mouse_y
< scr_h
- 1) {
290 sdl_grab_start(scon
);
294 static void sdl_mouse_mode_change(Notifier
*notify
, void *data
)
296 if (qemu_input_is_absolute()) {
297 if (!absolute_enabled
) {
298 absolute_enabled
= 1;
299 absolute_mouse_grab(&sdl2_console
[0]);
301 } else if (absolute_enabled
) {
302 if (!gui_fullscreen
) {
303 sdl_grab_end(&sdl2_console
[0]);
305 absolute_enabled
= 0;
309 static void sdl_send_mouse_event(struct sdl2_console
*scon
, int dx
, int dy
,
310 int x
, int y
, int state
)
312 static uint32_t bmap
[INPUT_BUTTON_MAX
] = {
313 [INPUT_BUTTON_LEFT
] = SDL_BUTTON(SDL_BUTTON_LEFT
),
314 [INPUT_BUTTON_MIDDLE
] = SDL_BUTTON(SDL_BUTTON_MIDDLE
),
315 [INPUT_BUTTON_RIGHT
] = SDL_BUTTON(SDL_BUTTON_RIGHT
),
317 static uint32_t prev_state
;
319 if (prev_state
!= state
) {
320 qemu_input_update_buttons(scon
->dcl
.con
, bmap
, prev_state
, state
);
324 if (qemu_input_is_absolute()) {
326 int max_w
= 0, max_h
= 0;
327 int off_x
= 0, off_y
= 0;
328 int cur_off_x
= 0, cur_off_y
= 0;
331 for (i
= 0; i
< sdl2_num_outputs
; i
++) {
332 struct sdl2_console
*thiscon
= &sdl2_console
[i
];
333 if (thiscon
->real_window
&& thiscon
->surface
) {
334 SDL_GetWindowSize(thiscon
->real_window
, &scr_w
, &scr_h
);
335 cur_off_x
= thiscon
->x
;
336 cur_off_y
= thiscon
->y
;
337 if (scr_w
+ cur_off_x
> max_w
) {
338 max_w
= scr_w
+ cur_off_x
;
340 if (scr_h
+ cur_off_y
> max_h
) {
341 max_h
= scr_h
+ cur_off_y
;
343 if (i
== scon
->idx
) {
349 qemu_input_queue_abs(scon
->dcl
.con
, INPUT_AXIS_X
, off_x
+ x
, max_w
);
350 qemu_input_queue_abs(scon
->dcl
.con
, INPUT_AXIS_Y
, off_y
+ y
, max_h
);
360 qemu_input_queue_rel(scon
->dcl
.con
, INPUT_AXIS_X
, dx
);
361 qemu_input_queue_rel(scon
->dcl
.con
, INPUT_AXIS_Y
, dy
);
363 qemu_input_event_sync();
366 static void sdl_scale(struct sdl2_console
*scon
, int width
, int height
)
369 do_sdl_resize(scon
, width
, height
, bpp
);
373 static void toggle_full_screen(struct sdl2_console
*scon
)
375 int width
= surface_width(scon
->surface
);
376 int height
= surface_height(scon
->surface
);
377 int bpp
= surface_bits_per_pixel(scon
->surface
);
379 gui_fullscreen
= !gui_fullscreen
;
380 if (gui_fullscreen
) {
381 SDL_GetWindowSize(scon
->real_window
,
382 &gui_saved_width
, &gui_saved_height
);
383 gui_saved_scaling
= scaling_active
;
385 do_sdl_resize(scon
, width
, height
, bpp
);
388 gui_saved_grab
= gui_grab
;
389 sdl_grab_start(scon
);
391 if (gui_saved_scaling
) {
392 sdl_scale(scon
, gui_saved_width
, gui_saved_height
);
394 do_sdl_resize(scon
, width
, height
, 0);
396 if (!gui_saved_grab
) {
400 graphic_hw_invalidate(scon
->dcl
.con
);
401 graphic_hw_update(scon
->dcl
.con
);
404 static void handle_keydown(SDL_Event
*ev
)
407 struct sdl2_console
*scon
= get_scon_from_window(ev
->key
.windowID
);
410 mod_state
= (SDL_GetModState() & (gui_grab_code
| KMOD_LSHIFT
)) ==
411 (gui_grab_code
| KMOD_LSHIFT
);
412 } else if (ctrl_grab
) {
413 mod_state
= (SDL_GetModState() & KMOD_RCTRL
) == KMOD_RCTRL
;
415 mod_state
= (SDL_GetModState() & gui_grab_code
) == gui_grab_code
;
417 gui_key_modifier_pressed
= mod_state
;
419 if (gui_key_modifier_pressed
) {
420 switch (ev
->key
.keysym
.scancode
) {
429 win
= ev
->key
.keysym
.scancode
- SDL_SCANCODE_1
;
430 if (win
< sdl2_num_outputs
) {
431 sdl2_console
[win
].hidden
= !sdl2_console
[win
].hidden
;
432 if (sdl2_console
[win
].real_window
) {
433 if (sdl2_console
[win
].hidden
) {
434 SDL_HideWindow(sdl2_console
[win
].real_window
);
436 SDL_ShowWindow(sdl2_console
[win
].real_window
);
443 toggle_full_screen(scon
);
447 if (scaling_active
) {
449 sdl_switch(&scon
->dcl
, NULL
);
450 graphic_hw_invalidate(scon
->dcl
.con
);
451 graphic_hw_update(scon
->dcl
.con
);
455 case SDL_SCANCODE_KP_PLUS
:
456 case SDL_SCANCODE_KP_MINUS
:
457 if (!gui_fullscreen
) {
460 SDL_GetWindowSize(scon
->real_window
, &scr_w
, &scr_h
);
462 width
= MAX(scr_w
+ (ev
->key
.keysym
.scancode
==
463 SDL_SCANCODE_KP_PLUS
? 50 : -50),
465 height
= (surface_height(scon
->surface
) * width
) /
466 surface_width(scon
->surface
);
468 sdl_scale(scon
, width
, height
);
469 graphic_hw_invalidate(NULL
);
470 graphic_hw_update(NULL
);
478 sdl2_process_key(scon
, &ev
->key
);
482 static void handle_keyup(SDL_Event
*ev
)
485 struct sdl2_console
*scon
= get_scon_from_window(ev
->key
.windowID
);
488 mod_state
= (ev
->key
.keysym
.mod
& gui_grab_code
);
490 mod_state
= (ev
->key
.keysym
.mod
& (gui_grab_code
| KMOD_LSHIFT
));
492 if (!mod_state
&& gui_key_modifier_pressed
) {
493 gui_key_modifier_pressed
= 0;
494 if (gui_keysym
== 0) {
495 /* exit/enter grab if pressing Ctrl-Alt */
497 sdl_grab_start(scon
);
498 } else if (!gui_fullscreen
) {
501 /* SDL does not send back all the modifiers key, so we must
503 sdl2_reset_keys(scon
);
509 sdl2_process_key(scon
, &ev
->key
);
513 static void handle_textinput(SDL_Event
*ev
)
515 struct sdl2_console
*scon
= get_scon_from_window(ev
->key
.windowID
);
516 QemuConsole
*con
= scon
? scon
->dcl
.con
: NULL
;
518 if (qemu_console_is_graphic(con
)) {
521 kbd_put_string_console(con
, ev
->text
.text
, strlen(ev
->text
.text
));
524 static void handle_mousemotion(SDL_Event
*ev
)
527 struct sdl2_console
*scon
= get_scon_from_window(ev
->key
.windowID
);
529 if (qemu_input_is_absolute() || absolute_enabled
) {
531 SDL_GetWindowSize(scon
->real_window
, &scr_w
, &scr_h
);
534 if (gui_grab
&& (ev
->motion
.x
== 0 || ev
->motion
.y
== 0 ||
535 ev
->motion
.x
== max_x
|| ev
->motion
.y
== max_y
)) {
539 (ev
->motion
.x
> 0 && ev
->motion
.x
< max_x
&&
540 ev
->motion
.y
> 0 && ev
->motion
.y
< max_y
)) {
541 sdl_grab_start(scon
);
544 if (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
) {
545 sdl_send_mouse_event(scon
, ev
->motion
.xrel
, ev
->motion
.yrel
,
546 ev
->motion
.x
, ev
->motion
.y
, ev
->motion
.state
);
550 static void handle_mousebutton(SDL_Event
*ev
)
552 int buttonstate
= SDL_GetMouseState(NULL
, NULL
);
553 SDL_MouseButtonEvent
*bev
;
554 struct sdl2_console
*scon
= get_scon_from_window(ev
->key
.windowID
);
557 if (!gui_grab
&& !qemu_input_is_absolute()) {
558 if (ev
->type
== SDL_MOUSEBUTTONUP
&& bev
->button
== SDL_BUTTON_LEFT
) {
559 /* start grabbing all events */
560 sdl_grab_start(scon
);
563 if (ev
->type
== SDL_MOUSEBUTTONDOWN
) {
564 buttonstate
|= SDL_BUTTON(bev
->button
);
566 buttonstate
&= ~SDL_BUTTON(bev
->button
);
568 sdl_send_mouse_event(scon
, 0, 0, bev
->x
, bev
->y
, buttonstate
);
572 static void handle_mousewheel(SDL_Event
*ev
)
574 struct sdl2_console
*scon
= get_scon_from_window(ev
->key
.windowID
);
575 SDL_MouseWheelEvent
*wev
= &ev
->wheel
;
579 btn
= INPUT_BUTTON_WHEEL_UP
;
580 } else if (wev
->y
< 0) {
581 btn
= INPUT_BUTTON_WHEEL_DOWN
;
586 qemu_input_queue_btn(scon
->dcl
.con
, btn
, true);
587 qemu_input_event_sync();
588 qemu_input_queue_btn(scon
->dcl
.con
, btn
, false);
589 qemu_input_event_sync();
592 static void handle_windowevent(DisplayChangeListener
*dcl
, SDL_Event
*ev
)
595 struct sdl2_console
*scon
= get_scon_from_window(ev
->key
.windowID
);
597 switch (ev
->window
.event
) {
598 case SDL_WINDOWEVENT_RESIZED
:
599 sdl_scale(scon
, ev
->window
.data1
, ev
->window
.data2
);
602 memset(&info
, 0, sizeof(info
));
603 info
.width
= ev
->window
.data1
;
604 info
.height
= ev
->window
.data2
;
605 dpy_set_ui_info(scon
->dcl
.con
, &info
);
607 graphic_hw_invalidate(scon
->dcl
.con
);
608 graphic_hw_update(scon
->dcl
.con
);
610 case SDL_WINDOWEVENT_EXPOSED
:
611 SDL_GetWindowSize(SDL_GetWindowFromID(ev
->window
.windowID
), &w
, &h
);
612 sdl_update(dcl
, 0, 0, w
, h
);
614 case SDL_WINDOWEVENT_FOCUS_GAINED
:
615 case SDL_WINDOWEVENT_ENTER
:
616 if (!gui_grab
&& (qemu_input_is_absolute() || absolute_enabled
)) {
617 absolute_mouse_grab(scon
);
620 case SDL_WINDOWEVENT_FOCUS_LOST
:
621 if (gui_grab
&& !gui_fullscreen
) {
625 case SDL_WINDOWEVENT_RESTORED
:
626 update_displaychangelistener(dcl
, GUI_REFRESH_INTERVAL_DEFAULT
);
628 case SDL_WINDOWEVENT_MINIMIZED
:
629 update_displaychangelistener(dcl
, 500);
631 case SDL_WINDOWEVENT_CLOSE
:
634 qemu_system_shutdown_request();
640 static void sdl_refresh(DisplayChangeListener
*dcl
)
642 struct sdl2_console
*scon
= container_of(dcl
, struct sdl2_console
, dcl
);
643 SDL_Event ev1
, *ev
= &ev1
;
645 if (scon
->last_vm_running
!= runstate_is_running()) {
646 scon
->last_vm_running
= runstate_is_running();
647 sdl_update_caption(scon
);
650 graphic_hw_update(dcl
->con
);
652 while (SDL_PollEvent(ev
)) {
661 handle_textinput(ev
);
666 qemu_system_shutdown_request();
669 case SDL_MOUSEMOTION
:
670 handle_mousemotion(ev
);
672 case SDL_MOUSEBUTTONDOWN
:
673 case SDL_MOUSEBUTTONUP
:
674 handle_mousebutton(ev
);
677 handle_mousewheel(ev
);
679 case SDL_WINDOWEVENT
:
680 handle_windowevent(dcl
, ev
);
688 static void sdl_mouse_warp(DisplayChangeListener
*dcl
,
689 int x
, int y
, int on
)
691 struct sdl2_console
*scon
= container_of(dcl
, struct sdl2_console
, dcl
);
696 if (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
) {
697 SDL_SetCursor(guest_sprite
);
698 if (!qemu_input_is_absolute() && !absolute_enabled
) {
699 SDL_WarpMouseInWindow(scon
->real_window
, x
, y
);
702 } else if (gui_grab
) {
706 guest_x
= x
, guest_y
= y
;
709 static void sdl_mouse_define(DisplayChangeListener
*dcl
,
714 SDL_FreeCursor(guest_sprite
);
717 if (guest_sprite_surface
) {
718 SDL_FreeSurface(guest_sprite_surface
);
721 guest_sprite_surface
=
722 SDL_CreateRGBSurfaceFrom(c
->data
, c
->width
, c
->height
, 32, c
->width
* 4,
723 0xff0000, 0x00ff00, 0xff, 0xff000000);
725 if (!guest_sprite_surface
) {
726 fprintf(stderr
, "Failed to make rgb surface from %p\n", c
);
729 guest_sprite
= SDL_CreateColorCursor(guest_sprite_surface
,
732 fprintf(stderr
, "Failed to make color cursor from %p\n", c
);
736 (gui_grab
|| qemu_input_is_absolute() || absolute_enabled
)) {
737 SDL_SetCursor(guest_sprite
);
741 static void sdl_cleanup(void)
744 SDL_FreeCursor(guest_sprite
);
746 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
749 static const DisplayChangeListenerOps dcl_ops
= {
751 .dpy_gfx_update
= sdl_update
,
752 .dpy_gfx_switch
= sdl_switch
,
753 .dpy_refresh
= sdl_refresh
,
754 .dpy_mouse_set
= sdl_mouse_warp
,
755 .dpy_cursor_define
= sdl_mouse_define
,
758 void sdl_display_init(DisplayState
*ds
, int full_screen
, int no_frame
)
770 /* on Linux, SDL may use fbcon|directfb|svgalib when run without
771 * accessible $DISPLAY to open X11 window. This is often the case
772 * when qemu is run using sudo. But in this case, and when actually
773 * run in X11 environment, SDL fights with X11 for the video card,
774 * making current display unavailable, often until reboot.
775 * So make x11 the default SDL video driver if this variable is unset.
776 * This is a bit hackish but saves us from bigger problem.
777 * Maybe it's a good idea to fix this in SDL instead.
779 setenv("SDL_VIDEODRIVER", "x11", 0);
782 flags
= SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
;
783 if (SDL_Init(flags
)) {
784 fprintf(stderr
, "Could not initialize SDL(%s) - exiting\n",
788 SDL_SetHint(SDL_HINT_GRAB_KEYBOARD
, "1");
791 QemuConsole
*con
= qemu_console_lookup_by_index(i
);
796 sdl2_num_outputs
= i
;
797 sdl2_console
= g_new0(struct sdl2_console
, sdl2_num_outputs
);
798 for (i
= 0; i
< sdl2_num_outputs
; i
++) {
799 QemuConsole
*con
= qemu_console_lookup_by_index(i
);
800 if (!qemu_console_is_graphic(con
)) {
801 sdl2_console
[i
].hidden
= true;
803 sdl2_console
[i
].dcl
.ops
= &dcl_ops
;
804 sdl2_console
[i
].dcl
.con
= con
;
805 register_displaychangelistener(&sdl2_console
[i
].dcl
);
806 sdl2_console
[i
].idx
= i
;
809 /* Load a 32x32x4 image. White pixels are transparent. */
810 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, "qemu-icon.bmp");
812 SDL_Surface
*image
= SDL_LoadBMP(filename
);
814 uint32_t colorkey
= SDL_MapRGB(image
->format
, 255, 255, 255);
815 SDL_SetColorKey(image
, SDL_TRUE
, colorkey
);
816 SDL_SetWindowIcon(sdl2_console
[0].real_window
, image
);
826 mouse_mode_notifier
.notify
= sdl_mouse_mode_change
;
827 qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier
);
831 sdl_cursor_hidden
= SDL_CreateCursor(&data
, &data
, 8, 1, 0, 0);
832 sdl_cursor_normal
= SDL_GetCursor();