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
25 /* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
26 #undef WIN32_LEAN_AND_MEAN
29 #include <SDL_syswm.h>
31 #include "qemu-common.h"
32 #include "ui/console.h"
33 #include "sysemu/sysemu.h"
37 static DisplayChangeListener
*dcl
;
38 static SDL_Surface
*real_screen
;
39 static SDL_Surface
*guest_screen
= NULL
;
40 static int gui_grab
; /* if true, all keyboard/mouse events are grabbed */
41 static int last_vm_running
;
42 static bool gui_saved_scaling
;
43 static int gui_saved_width
;
44 static int gui_saved_height
;
45 static int gui_saved_grab
;
46 static int gui_fullscreen
;
47 static int gui_noframe
;
48 static int gui_key_modifier_pressed
;
49 static int gui_keysym
;
50 static int gui_grab_code
= KMOD_LALT
| KMOD_LCTRL
;
51 static uint8_t modifiers_state
[256];
52 static SDL_Cursor
*sdl_cursor_normal
;
53 static SDL_Cursor
*sdl_cursor_hidden
;
54 static int absolute_enabled
= 0;
55 static int guest_cursor
= 0;
56 static int guest_x
, guest_y
;
57 static SDL_Cursor
*guest_sprite
= NULL
;
58 static SDL_PixelFormat host_format
;
59 static int scaling_active
= 0;
60 static Notifier mouse_mode_notifier
;
62 static void sdl_update(DisplayState
*ds
, int x
, int y
, int w
, int h
)
64 // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
72 if (!scaling_active
) {
73 SDL_BlitSurface(guest_screen
, &rec
, real_screen
, &rec
);
75 if (sdl_zoom_blit(guest_screen
, real_screen
, SMOOTHING_ON
, &rec
) < 0) {
76 fprintf(stderr
, "Zoom blit failed\n");
81 SDL_UpdateRect(real_screen
, rec
.x
, rec
.y
, rec
.w
, rec
.h
);
84 static void sdl_setdata(DisplayState
*ds
)
86 if (guest_screen
!= NULL
) SDL_FreeSurface(guest_screen
);
88 guest_screen
= SDL_CreateRGBSurfaceFrom(ds_get_data(ds
), ds_get_width(ds
), ds_get_height(ds
),
89 ds_get_bits_per_pixel(ds
), ds_get_linesize(ds
),
90 ds
->surface
->pf
.rmask
, ds
->surface
->pf
.gmask
,
91 ds
->surface
->pf
.bmask
, ds
->surface
->pf
.amask
);
94 static void do_sdl_resize(int width
, int height
, int bpp
)
98 // printf("resizing to %d %d\n", w, h);
100 flags
= SDL_HWSURFACE
| SDL_ASYNCBLIT
| SDL_HWACCEL
;
101 if (gui_fullscreen
) {
102 flags
|= SDL_FULLSCREEN
;
104 flags
|= SDL_RESIZABLE
;
107 flags
|= SDL_NOFRAME
;
109 real_screen
= SDL_SetVideoMode(width
, height
, bpp
, flags
);
111 fprintf(stderr
, "Could not open SDL display (%dx%dx%d): %s\n", width
,
112 height
, bpp
, SDL_GetError());
117 static void sdl_resize(DisplayState
*ds
)
119 if (!scaling_active
) {
120 do_sdl_resize(ds_get_width(ds
), ds_get_height(ds
), 0);
121 } else if (real_screen
->format
->BitsPerPixel
!= ds_get_bits_per_pixel(ds
)) {
122 do_sdl_resize(real_screen
->w
, real_screen
->h
,
123 ds_get_bits_per_pixel(ds
));
128 /* generic keyboard conversion */
130 #include "sdl_keysym.h"
132 static kbd_layout_t
*kbd_layout
= NULL
;
134 static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent
*ev
)
137 /* workaround for X11+SDL bug with AltGR */
138 keysym
= ev
->keysym
.sym
;
139 if (keysym
== 0 && ev
->keysym
.scancode
== 113)
141 /* For Japanese key '\' and '|' */
142 if (keysym
== 92 && ev
->keysym
.scancode
== 133) {
145 return keysym2scancode(kbd_layout
, keysym
) & SCANCODE_KEYMASK
;
148 /* specific keyboard conversions from scan codes */
152 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
154 return ev
->keysym
.scancode
;
159 #if defined(SDL_VIDEO_DRIVER_X11)
160 #include <X11/XKBlib.h>
162 static int check_for_evdev(void)
165 XkbDescPtr desc
= NULL
;
167 char *keycodes
= NULL
;
169 SDL_VERSION(&info
.version
);
170 if (!SDL_GetWMInfo(&info
)) {
173 desc
= XkbGetKeyboard(info
.info
.x11
.display
,
174 XkbGBN_AllComponentsMask
,
176 if (desc
&& desc
->names
) {
177 keycodes
= XGetAtomName(info
.info
.x11
.display
, desc
->names
->keycodes
);
178 if (keycodes
== NULL
) {
179 fprintf(stderr
, "could not lookup keycode name\n");
180 } else if (strstart(keycodes
, "evdev", NULL
)) {
182 } else if (!strstart(keycodes
, "xfree86", NULL
)) {
183 fprintf(stderr
, "unknown keycodes `%s', please report to "
184 "qemu-devel@nongnu.org\n", keycodes
);
189 XkbFreeKeyboard(desc
, XkbGBN_AllComponentsMask
, True
);
197 static int check_for_evdev(void)
203 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
206 static int has_evdev
= -1;
209 has_evdev
= check_for_evdev();
211 keycode
= ev
->keysym
.scancode
;
215 } else if (keycode
< 97) {
216 keycode
-= 8; /* just an offset */
217 } else if (keycode
< 158) {
218 /* use conversion table */
220 keycode
= translate_evdev_keycode(keycode
- 97);
222 keycode
= translate_xfree86_keycode(keycode
- 97);
223 } else if (keycode
== 208) { /* Hiragana_Katakana */
225 } else if (keycode
== 211) { /* backslash */
235 static void reset_keys(void)
238 for(i
= 0; i
< 256; i
++) {
239 if (modifiers_state
[i
]) {
240 if (i
& SCANCODE_GREY
)
241 kbd_put_keycode(SCANCODE_EMUL0
);
242 kbd_put_keycode(i
| SCANCODE_UP
);
243 modifiers_state
[i
] = 0;
248 static void sdl_process_key(SDL_KeyboardEvent
*ev
)
252 if (ev
->keysym
.sym
== SDLK_PAUSE
) {
255 if (ev
->type
== SDL_KEYUP
)
257 kbd_put_keycode(0xe1);
258 kbd_put_keycode(0x1d | v
);
259 kbd_put_keycode(0x45 | v
);
264 keycode
= sdl_keyevent_to_keycode_generic(ev
);
266 keycode
= sdl_keyevent_to_keycode(ev
);
271 /* sent when leaving window: reset the modifiers state */
274 case 0x2a: /* Left Shift */
275 case 0x36: /* Right Shift */
276 case 0x1d: /* Left CTRL */
277 case 0x9d: /* Right CTRL */
278 case 0x38: /* Left ALT */
279 case 0xb8: /* Right ALT */
280 if (ev
->type
== SDL_KEYUP
)
281 modifiers_state
[keycode
] = 0;
283 modifiers_state
[keycode
] = 1;
285 #define QEMU_SDL_VERSION ((SDL_MAJOR_VERSION << 8) + SDL_MINOR_VERSION)
286 #if QEMU_SDL_VERSION < 0x102 || QEMU_SDL_VERSION == 0x102 && SDL_PATCHLEVEL < 14
287 /* SDL versions before 1.2.14 don't support key up for caps/num lock. */
288 case 0x45: /* num lock */
289 case 0x3a: /* caps lock */
290 /* SDL does not send the key up event, so we generate it */
291 kbd_put_keycode(keycode
);
292 kbd_put_keycode(keycode
| SCANCODE_UP
);
297 /* now send the key code */
298 if (keycode
& SCANCODE_GREY
)
299 kbd_put_keycode(SCANCODE_EMUL0
);
300 if (ev
->type
== SDL_KEYUP
)
301 kbd_put_keycode(keycode
| SCANCODE_UP
);
303 kbd_put_keycode(keycode
& SCANCODE_KEYCODEMASK
);
306 static void sdl_update_caption(void)
308 char win_title
[1024];
309 char icon_title
[1024];
310 const char *status
= "";
312 if (!runstate_is_running())
313 status
= " [Stopped]";
316 status
= " - Press Ctrl-Alt-Shift to exit mouse grab";
318 status
= " - Press Right-Ctrl to exit mouse grab";
320 status
= " - Press Ctrl-Alt to exit mouse grab";
324 snprintf(win_title
, sizeof(win_title
), "QEMU (%s)%s", qemu_name
, status
);
325 snprintf(icon_title
, sizeof(icon_title
), "QEMU (%s)", qemu_name
);
327 snprintf(win_title
, sizeof(win_title
), "QEMU%s", status
);
328 snprintf(icon_title
, sizeof(icon_title
), "QEMU");
331 SDL_WM_SetCaption(win_title
, icon_title
);
334 static void sdl_hide_cursor(void)
339 if (kbd_mouse_is_absolute()) {
341 SDL_SetCursor(sdl_cursor_hidden
);
347 static void sdl_show_cursor(void)
352 if (!kbd_mouse_is_absolute() || !is_graphic_console()) {
355 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
356 SDL_SetCursor(guest_sprite
);
358 SDL_SetCursor(sdl_cursor_normal
);
362 static void sdl_grab_start(void)
365 * If the application is not active, do not try to enter grab state. This
366 * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
367 * application (SDL bug).
369 if (!(SDL_GetAppState() & SDL_APPINPUTFOCUS
)) {
373 SDL_SetCursor(guest_sprite
);
374 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
375 SDL_WarpMouse(guest_x
, guest_y
);
378 SDL_WM_GrabInput(SDL_GRAB_ON
);
380 sdl_update_caption();
383 static void sdl_grab_end(void)
385 SDL_WM_GrabInput(SDL_GRAB_OFF
);
388 sdl_update_caption();
391 static void absolute_mouse_grab(void)
393 int mouse_x
, mouse_y
;
395 SDL_GetMouseState(&mouse_x
, &mouse_y
);
396 if (mouse_x
> 0 && mouse_x
< real_screen
->w
- 1 &&
397 mouse_y
> 0 && mouse_y
< real_screen
->h
- 1) {
402 static void sdl_mouse_mode_change(Notifier
*notify
, void *data
)
404 if (kbd_mouse_is_absolute()) {
405 if (!absolute_enabled
) {
406 absolute_enabled
= 1;
407 if (is_graphic_console()) {
408 absolute_mouse_grab();
411 } else if (absolute_enabled
) {
412 if (!gui_fullscreen
) {
415 absolute_enabled
= 0;
419 static void sdl_send_mouse_event(int dx
, int dy
, int dz
, int x
, int y
, int state
)
423 if (state
& SDL_BUTTON(SDL_BUTTON_LEFT
)) {
424 buttons
|= MOUSE_EVENT_LBUTTON
;
426 if (state
& SDL_BUTTON(SDL_BUTTON_RIGHT
)) {
427 buttons
|= MOUSE_EVENT_RBUTTON
;
429 if (state
& SDL_BUTTON(SDL_BUTTON_MIDDLE
)) {
430 buttons
|= MOUSE_EVENT_MBUTTON
;
433 if (kbd_mouse_is_absolute()) {
434 dx
= x
* 0x7FFF / (real_screen
->w
- 1);
435 dy
= y
* 0x7FFF / (real_screen
->h
- 1);
436 } else if (guest_cursor
) {
445 kbd_mouse_event(dx
, dy
, dz
, buttons
);
448 static void sdl_scale(DisplayState
*ds
, int width
, int height
)
450 int bpp
= real_screen
->format
->BitsPerPixel
;
452 if (bpp
!= 16 && bpp
!= 32) {
455 do_sdl_resize(width
, height
, bpp
);
457 if (!is_buffer_shared(ds
->surface
)) {
458 ds
->surface
= qemu_resize_displaysurface(ds
, ds_get_width(ds
),
464 static void toggle_full_screen(DisplayState
*ds
)
466 gui_fullscreen
= !gui_fullscreen
;
467 if (gui_fullscreen
) {
468 gui_saved_width
= real_screen
->w
;
469 gui_saved_height
= real_screen
->h
;
470 gui_saved_scaling
= scaling_active
;
472 do_sdl_resize(ds_get_width(ds
), ds_get_height(ds
),
473 ds_get_bits_per_pixel(ds
));
476 gui_saved_grab
= gui_grab
;
479 if (gui_saved_scaling
) {
480 sdl_scale(ds
, gui_saved_width
, gui_saved_height
);
482 do_sdl_resize(ds_get_width(ds
), ds_get_height(ds
), 0);
484 if (!gui_saved_grab
|| !is_graphic_console()) {
492 static void handle_keydown(DisplayState
*ds
, SDL_Event
*ev
)
498 mod_state
= (SDL_GetModState() & (gui_grab_code
| KMOD_LSHIFT
)) ==
499 (gui_grab_code
| KMOD_LSHIFT
);
500 } else if (ctrl_grab
) {
501 mod_state
= (SDL_GetModState() & KMOD_RCTRL
) == KMOD_RCTRL
;
503 mod_state
= (SDL_GetModState() & gui_grab_code
) == gui_grab_code
;
505 gui_key_modifier_pressed
= mod_state
;
507 if (gui_key_modifier_pressed
) {
508 keycode
= sdl_keyevent_to_keycode(&ev
->key
);
510 case 0x21: /* 'f' key on US keyboard */
511 toggle_full_screen(ds
);
514 case 0x16: /* 'u' key on US keyboard */
515 if (scaling_active
) {
523 case 0x02 ... 0x0a: /* '1' to '9' keys */
524 /* Reset the modifiers sent to the current console */
526 console_select(keycode
- 0x02);
528 if (gui_fullscreen
) {
531 if (!is_graphic_console()) {
532 /* release grab if going to a text console */
535 } else if (absolute_enabled
) {
538 } else if (absolute_enabled
) {
540 absolute_mouse_grab();
545 if (!gui_fullscreen
) {
546 int width
= MAX(real_screen
->w
+ (keycode
== 0x1b ? 50 : -50),
548 int height
= (ds_get_height(ds
) * width
) / ds_get_width(ds
);
550 sdl_scale(ds
, width
, height
);
558 } else if (!is_graphic_console()) {
561 if (ev
->key
.keysym
.mod
& (KMOD_LCTRL
| KMOD_RCTRL
)) {
562 switch (ev
->key
.keysym
.sym
) {
564 keysym
= QEMU_KEY_CTRL_UP
;
567 keysym
= QEMU_KEY_CTRL_DOWN
;
570 keysym
= QEMU_KEY_CTRL_LEFT
;
573 keysym
= QEMU_KEY_CTRL_RIGHT
;
576 keysym
= QEMU_KEY_CTRL_HOME
;
579 keysym
= QEMU_KEY_CTRL_END
;
582 keysym
= QEMU_KEY_CTRL_PAGEUP
;
585 keysym
= QEMU_KEY_CTRL_PAGEDOWN
;
591 switch (ev
->key
.keysym
.sym
) {
593 keysym
= QEMU_KEY_UP
;
596 keysym
= QEMU_KEY_DOWN
;
599 keysym
= QEMU_KEY_LEFT
;
602 keysym
= QEMU_KEY_RIGHT
;
605 keysym
= QEMU_KEY_HOME
;
608 keysym
= QEMU_KEY_END
;
611 keysym
= QEMU_KEY_PAGEUP
;
614 keysym
= QEMU_KEY_PAGEDOWN
;
617 keysym
= QEMU_KEY_BACKSPACE
;
620 keysym
= QEMU_KEY_DELETE
;
627 kbd_put_keysym(keysym
);
628 } else if (ev
->key
.keysym
.unicode
!= 0) {
629 kbd_put_keysym(ev
->key
.keysym
.unicode
);
632 if (is_graphic_console() && !gui_keysym
) {
633 sdl_process_key(&ev
->key
);
637 static void handle_keyup(DisplayState
*ds
, SDL_Event
*ev
)
642 mod_state
= (ev
->key
.keysym
.mod
& gui_grab_code
);
644 mod_state
= (ev
->key
.keysym
.mod
& (gui_grab_code
| KMOD_LSHIFT
));
646 if (!mod_state
&& gui_key_modifier_pressed
) {
647 gui_key_modifier_pressed
= 0;
648 if (gui_keysym
== 0) {
649 /* exit/enter grab if pressing Ctrl-Alt */
651 if (is_graphic_console()) {
654 } else if (!gui_fullscreen
) {
657 /* SDL does not send back all the modifiers key, so we must
664 if (is_graphic_console() && !gui_keysym
) {
665 sdl_process_key(&ev
->key
);
669 static void handle_mousemotion(DisplayState
*ds
, SDL_Event
*ev
)
673 if (is_graphic_console() &&
674 (kbd_mouse_is_absolute() || absolute_enabled
)) {
675 max_x
= real_screen
->w
- 1;
676 max_y
= real_screen
->h
- 1;
677 if (gui_grab
&& (ev
->motion
.x
== 0 || ev
->motion
.y
== 0 ||
678 ev
->motion
.x
== max_x
|| ev
->motion
.y
== max_y
)) {
682 (ev
->motion
.x
> 0 && ev
->motion
.x
< max_x
&&
683 ev
->motion
.y
> 0 && ev
->motion
.y
< max_y
)) {
687 if (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
) {
688 sdl_send_mouse_event(ev
->motion
.xrel
, ev
->motion
.yrel
, 0,
689 ev
->motion
.x
, ev
->motion
.y
, ev
->motion
.state
);
693 static void handle_mousebutton(DisplayState
*ds
, SDL_Event
*ev
)
695 int buttonstate
= SDL_GetMouseState(NULL
, NULL
);
696 SDL_MouseButtonEvent
*bev
;
699 if (!is_graphic_console()) {
704 if (!gui_grab
&& !kbd_mouse_is_absolute()) {
705 if (ev
->type
== SDL_MOUSEBUTTONUP
&& bev
->button
== SDL_BUTTON_LEFT
) {
706 /* start grabbing all events */
711 if (ev
->type
== SDL_MOUSEBUTTONDOWN
) {
712 buttonstate
|= SDL_BUTTON(bev
->button
);
714 buttonstate
&= ~SDL_BUTTON(bev
->button
);
716 #ifdef SDL_BUTTON_WHEELUP
717 if (bev
->button
== SDL_BUTTON_WHEELUP
&&
718 ev
->type
== SDL_MOUSEBUTTONDOWN
) {
720 } else if (bev
->button
== SDL_BUTTON_WHEELDOWN
&&
721 ev
->type
== SDL_MOUSEBUTTONDOWN
) {
725 sdl_send_mouse_event(0, 0, dz
, bev
->x
, bev
->y
, buttonstate
);
729 static void handle_activation(DisplayState
*ds
, SDL_Event
*ev
)
732 /* Disable grab if the window no longer has the focus
733 * (Windows-only workaround) */
734 if (gui_grab
&& ev
->active
.state
== SDL_APPINPUTFOCUS
&&
735 !ev
->active
.gain
&& !gui_fullscreen
) {
739 if (!gui_grab
&& ev
->active
.gain
&& is_graphic_console() &&
740 (kbd_mouse_is_absolute() || absolute_enabled
)) {
741 absolute_mouse_grab();
743 if (ev
->active
.state
& SDL_APPACTIVE
) {
744 if (ev
->active
.gain
) {
745 /* Back to default interval */
746 dcl
->gui_timer_interval
= 0;
749 /* Sleeping interval */
750 dcl
->gui_timer_interval
= 500;
756 static void sdl_refresh(DisplayState
*ds
)
758 SDL_Event ev1
, *ev
= &ev1
;
760 if (last_vm_running
!= runstate_is_running()) {
761 last_vm_running
= runstate_is_running();
762 sdl_update_caption();
766 SDL_EnableUNICODE(!is_graphic_console());
768 while (SDL_PollEvent(ev
)) {
770 case SDL_VIDEOEXPOSE
:
771 sdl_update(ds
, 0, 0, real_screen
->w
, real_screen
->h
);
774 handle_keydown(ds
, ev
);
777 handle_keyup(ds
, ev
);
782 qemu_system_shutdown_request();
785 case SDL_MOUSEMOTION
:
786 handle_mousemotion(ds
, ev
);
788 case SDL_MOUSEBUTTONDOWN
:
789 case SDL_MOUSEBUTTONUP
:
790 handle_mousebutton(ds
, ev
);
792 case SDL_ACTIVEEVENT
:
793 handle_activation(ds
, ev
);
795 case SDL_VIDEORESIZE
:
796 sdl_scale(ds
, ev
->resize
.w
, ev
->resize
.h
);
806 static void sdl_mouse_warp(DisplayState
*ds
, int x
, int y
, int on
)
811 if (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
) {
812 SDL_SetCursor(guest_sprite
);
813 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
819 guest_x
= x
, guest_y
= y
;
822 static void sdl_mouse_define(DisplayState
*ds
, QEMUCursor
*c
)
824 uint8_t *image
, *mask
;
828 SDL_FreeCursor(guest_sprite
);
830 bpl
= cursor_get_mono_bpl(c
);
831 image
= g_malloc0(bpl
* c
->height
);
832 mask
= g_malloc0(bpl
* c
->height
);
833 cursor_get_mono_image(c
, 0x000000, image
);
834 cursor_get_mono_mask(c
, 0, mask
);
835 guest_sprite
= SDL_CreateCursor(image
, mask
, c
->width
, c
->height
,
841 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
842 SDL_SetCursor(guest_sprite
);
845 static void sdl_cleanup(void)
848 SDL_FreeCursor(guest_sprite
);
849 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
852 void sdl_display_init(DisplayState
*ds
, int full_screen
, int no_frame
)
856 const SDL_VideoInfo
*vi
;
859 #if defined(__APPLE__)
860 /* always use generic keymaps */
861 if (!keyboard_layout
)
862 keyboard_layout
= "en-us";
864 if(keyboard_layout
) {
865 kbd_layout
= init_keyboard_layout(name2keysym
, keyboard_layout
);
874 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0);
877 /* on Linux, SDL may use fbcon|directfb|svgalib when run without
878 * accessible $DISPLAY to open X11 window. This is often the case
879 * when qemu is run using sudo. But in this case, and when actually
880 * run in X11 environment, SDL fights with X11 for the video card,
881 * making current display unavailable, often until reboot.
882 * So make x11 the default SDL video driver if this variable is unset.
883 * This is a bit hackish but saves us from bigger problem.
884 * Maybe it's a good idea to fix this in SDL instead.
886 setenv("SDL_VIDEODRIVER", "x11", 0);
889 /* Enable normal up/down events for Caps-Lock and Num-Lock keys.
890 * This requires SDL >= 1.2.14. */
891 setenv("SDL_DISABLE_LOCK_KEYS", "1", 1);
893 flags
= SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
;
894 if (SDL_Init (flags
)) {
895 fprintf(stderr
, "Could not initialize SDL(%s) - exiting\n",
899 vi
= SDL_GetVideoInfo();
900 host_format
= *(vi
->vfmt
);
902 /* Load a 32x32x4 image. White pixels are transparent. */
903 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, "qemu-icon.bmp");
905 SDL_Surface
*image
= SDL_LoadBMP(filename
);
907 uint32_t colorkey
= SDL_MapRGB(image
->format
, 255, 255, 255);
908 SDL_SetColorKey(image
, SDL_SRCCOLORKEY
, colorkey
);
909 SDL_WM_SetIcon(image
, NULL
);
919 dcl
= g_malloc0(sizeof(DisplayChangeListener
));
920 dcl
->dpy_gfx_update
= sdl_update
;
921 dcl
->dpy_gfx_resize
= sdl_resize
;
922 dcl
->dpy_refresh
= sdl_refresh
;
923 dcl
->dpy_gfx_setdata
= sdl_setdata
;
924 dcl
->dpy_mouse_set
= sdl_mouse_warp
;
925 dcl
->dpy_cursor_define
= sdl_mouse_define
;
926 register_displaychangelistener(ds
, dcl
);
928 mouse_mode_notifier
.notify
= sdl_mouse_mode_change
;
929 qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier
);
931 sdl_update_caption();
932 SDL_EnableKeyRepeat(250, 50);
935 sdl_cursor_hidden
= SDL_CreateCursor(&data
, &data
, 8, 1, 0, 0);
936 sdl_cursor_normal
= SDL_GetCursor();