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(DisplayChangeListener
*dcl
,
64 int x
, int y
, int w
, int h
)
66 // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
74 if (!scaling_active
) {
75 SDL_BlitSurface(guest_screen
, &rec
, real_screen
, &rec
);
77 if (sdl_zoom_blit(guest_screen
, real_screen
, SMOOTHING_ON
, &rec
) < 0) {
78 fprintf(stderr
, "Zoom blit failed\n");
83 SDL_UpdateRect(real_screen
, rec
.x
, rec
.y
, rec
.w
, rec
.h
);
86 static void sdl_setdata(DisplayChangeListener
*dcl
,
89 if (guest_screen
!= NULL
) SDL_FreeSurface(guest_screen
);
91 guest_screen
= SDL_CreateRGBSurfaceFrom(ds_get_data(ds
), ds_get_width(ds
), ds_get_height(ds
),
92 ds_get_bits_per_pixel(ds
), ds_get_linesize(ds
),
93 ds
->surface
->pf
.rmask
, ds
->surface
->pf
.gmask
,
94 ds
->surface
->pf
.bmask
, ds
->surface
->pf
.amask
);
97 static void do_sdl_resize(int width
, int height
, int bpp
)
101 // printf("resizing to %d %d\n", w, h);
103 flags
= SDL_HWSURFACE
| SDL_ASYNCBLIT
| SDL_HWACCEL
;
104 if (gui_fullscreen
) {
105 flags
|= SDL_FULLSCREEN
;
107 flags
|= SDL_RESIZABLE
;
110 flags
|= SDL_NOFRAME
;
112 real_screen
= SDL_SetVideoMode(width
, height
, bpp
, flags
);
114 fprintf(stderr
, "Could not open SDL display (%dx%dx%d): %s\n", width
,
115 height
, bpp
, SDL_GetError());
120 static void sdl_switch(DisplayChangeListener
*dcl
,
122 DisplaySurface
*surface
)
124 if (!scaling_active
) {
125 do_sdl_resize(ds_get_width(ds
), ds_get_height(ds
), 0);
126 } else if (real_screen
->format
->BitsPerPixel
!= ds_get_bits_per_pixel(ds
)) {
127 do_sdl_resize(real_screen
->w
, real_screen
->h
,
128 ds_get_bits_per_pixel(ds
));
130 sdl_setdata(dcl
, ds
);
133 /* generic keyboard conversion */
135 #include "sdl_keysym.h"
137 static kbd_layout_t
*kbd_layout
= NULL
;
139 static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent
*ev
)
142 /* workaround for X11+SDL bug with AltGR */
143 keysym
= ev
->keysym
.sym
;
144 if (keysym
== 0 && ev
->keysym
.scancode
== 113)
146 /* For Japanese key '\' and '|' */
147 if (keysym
== 92 && ev
->keysym
.scancode
== 133) {
150 return keysym2scancode(kbd_layout
, keysym
) & SCANCODE_KEYMASK
;
153 /* specific keyboard conversions from scan codes */
157 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
159 return ev
->keysym
.scancode
;
164 #if defined(SDL_VIDEO_DRIVER_X11)
165 #include <X11/XKBlib.h>
167 static int check_for_evdev(void)
170 XkbDescPtr desc
= NULL
;
172 char *keycodes
= NULL
;
174 SDL_VERSION(&info
.version
);
175 if (!SDL_GetWMInfo(&info
)) {
178 desc
= XkbGetKeyboard(info
.info
.x11
.display
,
179 XkbGBN_AllComponentsMask
,
181 if (desc
&& desc
->names
) {
182 keycodes
= XGetAtomName(info
.info
.x11
.display
, desc
->names
->keycodes
);
183 if (keycodes
== NULL
) {
184 fprintf(stderr
, "could not lookup keycode name\n");
185 } else if (strstart(keycodes
, "evdev", NULL
)) {
187 } else if (!strstart(keycodes
, "xfree86", NULL
)) {
188 fprintf(stderr
, "unknown keycodes `%s', please report to "
189 "qemu-devel@nongnu.org\n", keycodes
);
194 XkbFreeKeyboard(desc
, XkbGBN_AllComponentsMask
, True
);
202 static int check_for_evdev(void)
208 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
211 static int has_evdev
= -1;
214 has_evdev
= check_for_evdev();
216 keycode
= ev
->keysym
.scancode
;
220 } else if (keycode
< 97) {
221 keycode
-= 8; /* just an offset */
222 } else if (keycode
< 158) {
223 /* use conversion table */
225 keycode
= translate_evdev_keycode(keycode
- 97);
227 keycode
= translate_xfree86_keycode(keycode
- 97);
228 } else if (keycode
== 208) { /* Hiragana_Katakana */
230 } else if (keycode
== 211) { /* backslash */
240 static void reset_keys(void)
243 for(i
= 0; i
< 256; i
++) {
244 if (modifiers_state
[i
]) {
245 if (i
& SCANCODE_GREY
)
246 kbd_put_keycode(SCANCODE_EMUL0
);
247 kbd_put_keycode(i
| SCANCODE_UP
);
248 modifiers_state
[i
] = 0;
253 static void sdl_process_key(SDL_KeyboardEvent
*ev
)
257 if (ev
->keysym
.sym
== SDLK_PAUSE
) {
260 if (ev
->type
== SDL_KEYUP
)
262 kbd_put_keycode(0xe1);
263 kbd_put_keycode(0x1d | v
);
264 kbd_put_keycode(0x45 | v
);
269 keycode
= sdl_keyevent_to_keycode_generic(ev
);
271 keycode
= sdl_keyevent_to_keycode(ev
);
276 /* sent when leaving window: reset the modifiers state */
279 case 0x2a: /* Left Shift */
280 case 0x36: /* Right Shift */
281 case 0x1d: /* Left CTRL */
282 case 0x9d: /* Right CTRL */
283 case 0x38: /* Left ALT */
284 case 0xb8: /* Right ALT */
285 if (ev
->type
== SDL_KEYUP
)
286 modifiers_state
[keycode
] = 0;
288 modifiers_state
[keycode
] = 1;
290 #define QEMU_SDL_VERSION ((SDL_MAJOR_VERSION << 8) + SDL_MINOR_VERSION)
291 #if QEMU_SDL_VERSION < 0x102 || QEMU_SDL_VERSION == 0x102 && SDL_PATCHLEVEL < 14
292 /* SDL versions before 1.2.14 don't support key up for caps/num lock. */
293 case 0x45: /* num lock */
294 case 0x3a: /* caps lock */
295 /* SDL does not send the key up event, so we generate it */
296 kbd_put_keycode(keycode
);
297 kbd_put_keycode(keycode
| SCANCODE_UP
);
302 /* now send the key code */
303 if (keycode
& SCANCODE_GREY
)
304 kbd_put_keycode(SCANCODE_EMUL0
);
305 if (ev
->type
== SDL_KEYUP
)
306 kbd_put_keycode(keycode
| SCANCODE_UP
);
308 kbd_put_keycode(keycode
& SCANCODE_KEYCODEMASK
);
311 static void sdl_update_caption(void)
313 char win_title
[1024];
314 char icon_title
[1024];
315 const char *status
= "";
317 if (!runstate_is_running())
318 status
= " [Stopped]";
321 status
= " - Press Ctrl-Alt-Shift to exit mouse grab";
323 status
= " - Press Right-Ctrl to exit mouse grab";
325 status
= " - Press Ctrl-Alt to exit mouse grab";
329 snprintf(win_title
, sizeof(win_title
), "QEMU (%s)%s", qemu_name
, status
);
330 snprintf(icon_title
, sizeof(icon_title
), "QEMU (%s)", qemu_name
);
332 snprintf(win_title
, sizeof(win_title
), "QEMU%s", status
);
333 snprintf(icon_title
, sizeof(icon_title
), "QEMU");
336 SDL_WM_SetCaption(win_title
, icon_title
);
339 static void sdl_hide_cursor(void)
344 if (kbd_mouse_is_absolute()) {
346 SDL_SetCursor(sdl_cursor_hidden
);
352 static void sdl_show_cursor(void)
357 if (!kbd_mouse_is_absolute() || !is_graphic_console()) {
360 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
361 SDL_SetCursor(guest_sprite
);
363 SDL_SetCursor(sdl_cursor_normal
);
367 static void sdl_grab_start(void)
370 * If the application is not active, do not try to enter grab state. This
371 * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
372 * application (SDL bug).
374 if (!(SDL_GetAppState() & SDL_APPINPUTFOCUS
)) {
378 SDL_SetCursor(guest_sprite
);
379 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
380 SDL_WarpMouse(guest_x
, guest_y
);
383 SDL_WM_GrabInput(SDL_GRAB_ON
);
385 sdl_update_caption();
388 static void sdl_grab_end(void)
390 SDL_WM_GrabInput(SDL_GRAB_OFF
);
393 sdl_update_caption();
396 static void absolute_mouse_grab(void)
398 int mouse_x
, mouse_y
;
400 SDL_GetMouseState(&mouse_x
, &mouse_y
);
401 if (mouse_x
> 0 && mouse_x
< real_screen
->w
- 1 &&
402 mouse_y
> 0 && mouse_y
< real_screen
->h
- 1) {
407 static void sdl_mouse_mode_change(Notifier
*notify
, void *data
)
409 if (kbd_mouse_is_absolute()) {
410 if (!absolute_enabled
) {
411 absolute_enabled
= 1;
412 if (is_graphic_console()) {
413 absolute_mouse_grab();
416 } else if (absolute_enabled
) {
417 if (!gui_fullscreen
) {
420 absolute_enabled
= 0;
424 static void sdl_send_mouse_event(int dx
, int dy
, int dz
, int x
, int y
, int state
)
428 if (state
& SDL_BUTTON(SDL_BUTTON_LEFT
)) {
429 buttons
|= MOUSE_EVENT_LBUTTON
;
431 if (state
& SDL_BUTTON(SDL_BUTTON_RIGHT
)) {
432 buttons
|= MOUSE_EVENT_RBUTTON
;
434 if (state
& SDL_BUTTON(SDL_BUTTON_MIDDLE
)) {
435 buttons
|= MOUSE_EVENT_MBUTTON
;
438 if (kbd_mouse_is_absolute()) {
439 dx
= x
* 0x7FFF / (real_screen
->w
- 1);
440 dy
= y
* 0x7FFF / (real_screen
->h
- 1);
441 } else if (guest_cursor
) {
450 kbd_mouse_event(dx
, dy
, dz
, buttons
);
453 static void sdl_scale(DisplayState
*ds
, int width
, int height
)
455 int bpp
= real_screen
->format
->BitsPerPixel
;
457 if (bpp
!= 16 && bpp
!= 32) {
460 do_sdl_resize(width
, height
, bpp
);
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
) {
517 sdl_switch(dcl
, ds
, ds
->surface
);
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(DisplayChangeListener
*dcl
,
759 SDL_Event ev1
, *ev
= &ev1
;
761 if (last_vm_running
!= runstate_is_running()) {
762 last_vm_running
= runstate_is_running();
763 sdl_update_caption();
767 SDL_EnableUNICODE(!is_graphic_console());
769 while (SDL_PollEvent(ev
)) {
771 case SDL_VIDEOEXPOSE
:
772 sdl_update(dcl
, ds
, 0, 0, real_screen
->w
, real_screen
->h
);
775 handle_keydown(ds
, ev
);
778 handle_keyup(ds
, ev
);
783 qemu_system_shutdown_request();
786 case SDL_MOUSEMOTION
:
787 handle_mousemotion(ds
, ev
);
789 case SDL_MOUSEBUTTONDOWN
:
790 case SDL_MOUSEBUTTONUP
:
791 handle_mousebutton(ds
, ev
);
793 case SDL_ACTIVEEVENT
:
794 handle_activation(ds
, ev
);
796 case SDL_VIDEORESIZE
:
797 sdl_scale(ds
, ev
->resize
.w
, ev
->resize
.h
);
807 static void sdl_mouse_warp(DisplayChangeListener
*dcl
,
809 int x
, int y
, int on
)
814 if (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
) {
815 SDL_SetCursor(guest_sprite
);
816 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
822 guest_x
= x
, guest_y
= y
;
825 static void sdl_mouse_define(DisplayChangeListener
*dcl
,
829 uint8_t *image
, *mask
;
833 SDL_FreeCursor(guest_sprite
);
835 bpl
= cursor_get_mono_bpl(c
);
836 image
= g_malloc0(bpl
* c
->height
);
837 mask
= g_malloc0(bpl
* c
->height
);
838 cursor_get_mono_image(c
, 0x000000, image
);
839 cursor_get_mono_mask(c
, 0, mask
);
840 guest_sprite
= SDL_CreateCursor(image
, mask
, c
->width
, c
->height
,
846 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
847 SDL_SetCursor(guest_sprite
);
850 static void sdl_cleanup(void)
853 SDL_FreeCursor(guest_sprite
);
854 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
857 static const DisplayChangeListenerOps dcl_ops
= {
859 .dpy_gfx_update
= sdl_update
,
860 .dpy_gfx_switch
= sdl_switch
,
861 .dpy_refresh
= sdl_refresh
,
862 .dpy_mouse_set
= sdl_mouse_warp
,
863 .dpy_cursor_define
= sdl_mouse_define
,
866 void sdl_display_init(DisplayState
*ds
, int full_screen
, int no_frame
)
870 const SDL_VideoInfo
*vi
;
873 #if defined(__APPLE__)
874 /* always use generic keymaps */
875 if (!keyboard_layout
)
876 keyboard_layout
= "en-us";
878 if(keyboard_layout
) {
879 kbd_layout
= init_keyboard_layout(name2keysym
, keyboard_layout
);
888 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0);
891 /* on Linux, SDL may use fbcon|directfb|svgalib when run without
892 * accessible $DISPLAY to open X11 window. This is often the case
893 * when qemu is run using sudo. But in this case, and when actually
894 * run in X11 environment, SDL fights with X11 for the video card,
895 * making current display unavailable, often until reboot.
896 * So make x11 the default SDL video driver if this variable is unset.
897 * This is a bit hackish but saves us from bigger problem.
898 * Maybe it's a good idea to fix this in SDL instead.
900 setenv("SDL_VIDEODRIVER", "x11", 0);
903 /* Enable normal up/down events for Caps-Lock and Num-Lock keys.
904 * This requires SDL >= 1.2.14. */
905 setenv("SDL_DISABLE_LOCK_KEYS", "1", 1);
907 flags
= SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
;
908 if (SDL_Init (flags
)) {
909 fprintf(stderr
, "Could not initialize SDL(%s) - exiting\n",
913 vi
= SDL_GetVideoInfo();
914 host_format
= *(vi
->vfmt
);
916 /* Load a 32x32x4 image. White pixels are transparent. */
917 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, "qemu-icon.bmp");
919 SDL_Surface
*image
= SDL_LoadBMP(filename
);
921 uint32_t colorkey
= SDL_MapRGB(image
->format
, 255, 255, 255);
922 SDL_SetColorKey(image
, SDL_SRCCOLORKEY
, colorkey
);
923 SDL_WM_SetIcon(image
, NULL
);
933 dcl
= g_malloc0(sizeof(DisplayChangeListener
));
935 register_displaychangelistener(ds
, dcl
);
937 mouse_mode_notifier
.notify
= sdl_mouse_mode_change
;
938 qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier
);
940 sdl_update_caption();
941 SDL_EnableKeyRepeat(250, 50);
944 sdl_cursor_hidden
= SDL_CreateCursor(&data
, &data
, 8, 1, 0, 0);
945 sdl_cursor_normal
= SDL_GetCursor();