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"
34 #include "sysemu/sysemu.h"
38 static DisplayChangeListener
*dcl
;
39 static DisplaySurface
*surface
;
40 static SDL_Surface
*real_screen
;
41 static SDL_Surface
*guest_screen
= NULL
;
42 static int gui_grab
; /* if true, all keyboard/mouse events are grabbed */
43 static int last_vm_running
;
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 uint8_t modifiers_state
[256];
54 static SDL_Cursor
*sdl_cursor_normal
;
55 static SDL_Cursor
*sdl_cursor_hidden
;
56 static int absolute_enabled
= 0;
57 static int guest_cursor
= 0;
58 static int guest_x
, guest_y
;
59 static SDL_Cursor
*guest_sprite
= NULL
;
60 static SDL_PixelFormat host_format
;
61 static int scaling_active
= 0;
62 static Notifier mouse_mode_notifier
;
64 static void sdl_update(DisplayChangeListener
*dcl
,
65 int x
, int y
, int w
, int h
)
67 // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
75 if (!scaling_active
) {
76 SDL_BlitSurface(guest_screen
, &rec
, real_screen
, &rec
);
78 if (sdl_zoom_blit(guest_screen
, real_screen
, SMOOTHING_ON
, &rec
) < 0) {
79 fprintf(stderr
, "Zoom blit failed\n");
84 SDL_UpdateRect(real_screen
, rec
.x
, rec
.y
, rec
.w
, rec
.h
);
87 static void do_sdl_resize(int width
, int height
, int bpp
)
90 SDL_Surface
*tmp_screen
;
92 // printf("resizing to %d %d\n", w, h);
94 flags
= SDL_HWSURFACE
| SDL_ASYNCBLIT
| SDL_HWACCEL
;
96 flags
|= SDL_FULLSCREEN
;
98 flags
|= SDL_RESIZABLE
;
101 flags
|= SDL_NOFRAME
;
103 tmp_screen
= SDL_SetVideoMode(width
, height
, bpp
, flags
);
106 fprintf(stderr
, "Could not open SDL display (%dx%dx%d): %s\n",
107 width
, height
, bpp
, SDL_GetError());
112 * Revert to the previous video mode if the change of resizing or
116 fprintf(stderr
, "Failed to set SDL display (%dx%dx%d): %s\n",
117 width
, height
, bpp
, SDL_GetError());
122 real_screen
= tmp_screen
;
125 static void sdl_switch(DisplayChangeListener
*dcl
,
126 DisplaySurface
*new_surface
)
129 /* temporary hack: allows to call sdl_switch to handle scaling changes */
131 surface
= new_surface
;
134 if (!scaling_active
) {
135 do_sdl_resize(surface_width(surface
), surface_height(surface
), 0);
136 } else if (real_screen
->format
->BitsPerPixel
!=
137 surface_bits_per_pixel(surface
)) {
138 do_sdl_resize(real_screen
->w
, real_screen
->h
,
139 surface_bits_per_pixel(surface
));
142 if (guest_screen
!= NULL
) {
143 SDL_FreeSurface(guest_screen
);
145 guest_screen
= SDL_CreateRGBSurfaceFrom
146 (surface_data(surface
),
147 surface_width(surface
), surface_height(surface
),
148 surface_bits_per_pixel(surface
), surface_stride(surface
),
149 surface
->pf
.rmask
, surface
->pf
.gmask
,
150 surface
->pf
.bmask
, surface
->pf
.amask
);
153 /* generic keyboard conversion */
155 #include "sdl_keysym.h"
157 static kbd_layout_t
*kbd_layout
= NULL
;
159 static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent
*ev
)
162 /* workaround for X11+SDL bug with AltGR */
163 keysym
= ev
->keysym
.sym
;
164 if (keysym
== 0 && ev
->keysym
.scancode
== 113)
166 /* For Japanese key '\' and '|' */
167 if (keysym
== 92 && ev
->keysym
.scancode
== 133) {
170 return keysym2scancode(kbd_layout
, keysym
) & SCANCODE_KEYMASK
;
173 /* specific keyboard conversions from scan codes */
177 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
179 return ev
->keysym
.scancode
;
184 #if defined(SDL_VIDEO_DRIVER_X11)
185 #include <X11/XKBlib.h>
187 static int check_for_evdev(void)
190 XkbDescPtr desc
= NULL
;
192 char *keycodes
= NULL
;
194 SDL_VERSION(&info
.version
);
195 if (!SDL_GetWMInfo(&info
)) {
198 desc
= XkbGetKeyboard(info
.info
.x11
.display
,
199 XkbGBN_AllComponentsMask
,
201 if (desc
&& desc
->names
) {
202 keycodes
= XGetAtomName(info
.info
.x11
.display
, desc
->names
->keycodes
);
203 if (keycodes
== NULL
) {
204 fprintf(stderr
, "could not lookup keycode name\n");
205 } else if (strstart(keycodes
, "evdev", NULL
)) {
207 } else if (!strstart(keycodes
, "xfree86", NULL
)) {
208 fprintf(stderr
, "unknown keycodes `%s', please report to "
209 "qemu-devel@nongnu.org\n", keycodes
);
214 XkbFreeKeyboard(desc
, XkbGBN_AllComponentsMask
, True
);
222 static int check_for_evdev(void)
228 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
231 static int has_evdev
= -1;
234 has_evdev
= check_for_evdev();
236 keycode
= ev
->keysym
.scancode
;
240 } else if (keycode
< 97) {
241 keycode
-= 8; /* just an offset */
242 } else if (keycode
< 158) {
243 /* use conversion table */
245 keycode
= translate_evdev_keycode(keycode
- 97);
247 keycode
= translate_xfree86_keycode(keycode
- 97);
248 } else if (keycode
== 208) { /* Hiragana_Katakana */
250 } else if (keycode
== 211) { /* backslash */
260 static void reset_keys(void)
263 for(i
= 0; i
< 256; i
++) {
264 if (modifiers_state
[i
]) {
265 qemu_input_event_send_key_number(dcl
->con
, i
, false);
266 modifiers_state
[i
] = 0;
271 static void sdl_process_key(SDL_KeyboardEvent
*ev
)
275 if (ev
->keysym
.sym
== SDLK_PAUSE
) {
277 qemu_input_event_send_key_qcode(dcl
->con
, Q_KEY_CODE_PAUSE
,
278 ev
->type
== SDL_KEYDOWN
);
283 keycode
= sdl_keyevent_to_keycode_generic(ev
);
285 keycode
= sdl_keyevent_to_keycode(ev
);
290 /* sent when leaving window: reset the modifiers state */
293 case 0x2a: /* Left Shift */
294 case 0x36: /* Right Shift */
295 case 0x1d: /* Left CTRL */
296 case 0x9d: /* Right CTRL */
297 case 0x38: /* Left ALT */
298 case 0xb8: /* Right ALT */
299 if (ev
->type
== SDL_KEYUP
)
300 modifiers_state
[keycode
] = 0;
302 modifiers_state
[keycode
] = 1;
304 #define QEMU_SDL_VERSION ((SDL_MAJOR_VERSION << 8) + SDL_MINOR_VERSION)
305 #if QEMU_SDL_VERSION < 0x102 || QEMU_SDL_VERSION == 0x102 && SDL_PATCHLEVEL < 14
306 /* SDL versions before 1.2.14 don't support key up for caps/num lock. */
307 case 0x45: /* num lock */
308 case 0x3a: /* caps lock */
309 /* SDL does not send the key up event, so we generate it */
310 qemu_input_event_send_key_number(dcl
->con
, keycode
, true);
311 qemu_input_event_send_key_number(dcl
->con
, keycode
, false);
316 /* now send the key code */
317 qemu_input_event_send_key_number(dcl
->con
, keycode
,
318 ev
->type
== SDL_KEYDOWN
);
321 static void sdl_update_caption(void)
323 char win_title
[1024];
324 char icon_title
[1024];
325 const char *status
= "";
327 if (!runstate_is_running())
328 status
= " [Stopped]";
331 status
= " - Press Ctrl-Alt-Shift to exit mouse grab";
333 status
= " - Press Right-Ctrl to exit mouse grab";
335 status
= " - Press Ctrl-Alt to exit mouse grab";
339 snprintf(win_title
, sizeof(win_title
), "QEMU (%s)%s", qemu_name
, status
);
340 snprintf(icon_title
, sizeof(icon_title
), "QEMU (%s)", qemu_name
);
342 snprintf(win_title
, sizeof(win_title
), "QEMU%s", status
);
343 snprintf(icon_title
, sizeof(icon_title
), "QEMU");
346 SDL_WM_SetCaption(win_title
, icon_title
);
349 static void sdl_hide_cursor(void)
354 if (kbd_mouse_is_absolute()) {
356 SDL_SetCursor(sdl_cursor_hidden
);
362 static void sdl_show_cursor(void)
367 if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL
)) {
370 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
371 SDL_SetCursor(guest_sprite
);
373 SDL_SetCursor(sdl_cursor_normal
);
377 static void sdl_grab_start(void)
380 * If the application is not active, do not try to enter grab state. This
381 * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
382 * application (SDL bug).
384 if (!(SDL_GetAppState() & SDL_APPINPUTFOCUS
)) {
388 SDL_SetCursor(guest_sprite
);
389 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
390 SDL_WarpMouse(guest_x
, guest_y
);
393 SDL_WM_GrabInput(SDL_GRAB_ON
);
395 sdl_update_caption();
398 static void sdl_grab_end(void)
400 SDL_WM_GrabInput(SDL_GRAB_OFF
);
403 sdl_update_caption();
406 static void absolute_mouse_grab(void)
408 int mouse_x
, mouse_y
;
410 SDL_GetMouseState(&mouse_x
, &mouse_y
);
411 if (mouse_x
> 0 && mouse_x
< real_screen
->w
- 1 &&
412 mouse_y
> 0 && mouse_y
< real_screen
->h
- 1) {
417 static void sdl_mouse_mode_change(Notifier
*notify
, void *data
)
419 if (kbd_mouse_is_absolute()) {
420 if (!absolute_enabled
) {
421 absolute_enabled
= 1;
422 if (qemu_console_is_graphic(NULL
)) {
423 absolute_mouse_grab();
426 } else if (absolute_enabled
) {
427 if (!gui_fullscreen
) {
430 absolute_enabled
= 0;
434 static void sdl_send_mouse_event(int dx
, int dy
, int dz
, int x
, int y
, int state
)
438 if (state
& SDL_BUTTON(SDL_BUTTON_LEFT
)) {
439 buttons
|= MOUSE_EVENT_LBUTTON
;
441 if (state
& SDL_BUTTON(SDL_BUTTON_RIGHT
)) {
442 buttons
|= MOUSE_EVENT_RBUTTON
;
444 if (state
& SDL_BUTTON(SDL_BUTTON_MIDDLE
)) {
445 buttons
|= MOUSE_EVENT_MBUTTON
;
448 if (kbd_mouse_is_absolute()) {
449 dx
= x
* 0x7FFF / (real_screen
->w
- 1);
450 dy
= y
* 0x7FFF / (real_screen
->h
- 1);
451 } else if (guest_cursor
) {
460 kbd_mouse_event(dx
, dy
, dz
, buttons
);
463 static void sdl_scale(int width
, int height
)
465 int bpp
= real_screen
->format
->BitsPerPixel
;
467 if (bpp
!= 16 && bpp
!= 32) {
470 do_sdl_resize(width
, height
, bpp
);
474 static void toggle_full_screen(void)
476 int width
= surface_width(surface
);
477 int height
= surface_height(surface
);
478 int bpp
= surface_bits_per_pixel(surface
);
480 gui_fullscreen
= !gui_fullscreen
;
481 if (gui_fullscreen
) {
482 gui_saved_width
= real_screen
->w
;
483 gui_saved_height
= real_screen
->h
;
484 gui_saved_scaling
= scaling_active
;
486 do_sdl_resize(width
, height
, bpp
);
489 gui_saved_grab
= gui_grab
;
492 if (gui_saved_scaling
) {
493 sdl_scale(gui_saved_width
, gui_saved_height
);
495 do_sdl_resize(width
, height
, 0);
497 if (!gui_saved_grab
|| !qemu_console_is_graphic(NULL
)) {
501 graphic_hw_invalidate(NULL
);
502 graphic_hw_update(NULL
);
505 static void handle_keydown(SDL_Event
*ev
)
511 mod_state
= (SDL_GetModState() & (gui_grab_code
| KMOD_LSHIFT
)) ==
512 (gui_grab_code
| KMOD_LSHIFT
);
513 } else if (ctrl_grab
) {
514 mod_state
= (SDL_GetModState() & KMOD_RCTRL
) == KMOD_RCTRL
;
516 mod_state
= (SDL_GetModState() & gui_grab_code
) == gui_grab_code
;
518 gui_key_modifier_pressed
= mod_state
;
520 if (gui_key_modifier_pressed
) {
521 keycode
= sdl_keyevent_to_keycode(&ev
->key
);
523 case 0x21: /* 'f' key on US keyboard */
524 toggle_full_screen();
527 case 0x16: /* 'u' key on US keyboard */
528 if (scaling_active
) {
530 sdl_switch(dcl
, NULL
);
531 graphic_hw_invalidate(NULL
);
532 graphic_hw_update(NULL
);
536 case 0x02 ... 0x0a: /* '1' to '9' keys */
537 /* Reset the modifiers sent to the current console */
539 console_select(keycode
- 0x02);
541 if (gui_fullscreen
) {
544 if (!qemu_console_is_graphic(NULL
)) {
545 /* release grab if going to a text console */
548 } else if (absolute_enabled
) {
551 } else if (absolute_enabled
) {
553 absolute_mouse_grab();
558 if (!gui_fullscreen
) {
559 int width
= MAX(real_screen
->w
+ (keycode
== 0x1b ? 50 : -50),
561 int height
= (surface_height(surface
) * width
) /
562 surface_width(surface
);
564 sdl_scale(width
, height
);
565 graphic_hw_invalidate(NULL
);
566 graphic_hw_update(NULL
);
572 } else if (!qemu_console_is_graphic(NULL
)) {
575 if (ev
->key
.keysym
.mod
& (KMOD_LCTRL
| KMOD_RCTRL
)) {
576 switch (ev
->key
.keysym
.sym
) {
578 keysym
= QEMU_KEY_CTRL_UP
;
581 keysym
= QEMU_KEY_CTRL_DOWN
;
584 keysym
= QEMU_KEY_CTRL_LEFT
;
587 keysym
= QEMU_KEY_CTRL_RIGHT
;
590 keysym
= QEMU_KEY_CTRL_HOME
;
593 keysym
= QEMU_KEY_CTRL_END
;
596 keysym
= QEMU_KEY_CTRL_PAGEUP
;
599 keysym
= QEMU_KEY_CTRL_PAGEDOWN
;
605 switch (ev
->key
.keysym
.sym
) {
607 keysym
= QEMU_KEY_UP
;
610 keysym
= QEMU_KEY_DOWN
;
613 keysym
= QEMU_KEY_LEFT
;
616 keysym
= QEMU_KEY_RIGHT
;
619 keysym
= QEMU_KEY_HOME
;
622 keysym
= QEMU_KEY_END
;
625 keysym
= QEMU_KEY_PAGEUP
;
628 keysym
= QEMU_KEY_PAGEDOWN
;
631 keysym
= QEMU_KEY_BACKSPACE
;
634 keysym
= QEMU_KEY_DELETE
;
641 kbd_put_keysym(keysym
);
642 } else if (ev
->key
.keysym
.unicode
!= 0) {
643 kbd_put_keysym(ev
->key
.keysym
.unicode
);
646 if (qemu_console_is_graphic(NULL
) && !gui_keysym
) {
647 sdl_process_key(&ev
->key
);
651 static void handle_keyup(SDL_Event
*ev
)
656 mod_state
= (ev
->key
.keysym
.mod
& gui_grab_code
);
658 mod_state
= (ev
->key
.keysym
.mod
& (gui_grab_code
| KMOD_LSHIFT
));
660 if (!mod_state
&& gui_key_modifier_pressed
) {
661 gui_key_modifier_pressed
= 0;
662 if (gui_keysym
== 0) {
663 /* exit/enter grab if pressing Ctrl-Alt */
665 if (qemu_console_is_graphic(NULL
)) {
668 } else if (!gui_fullscreen
) {
671 /* SDL does not send back all the modifiers key, so we must
678 if (qemu_console_is_graphic(NULL
) && !gui_keysym
) {
679 sdl_process_key(&ev
->key
);
683 static void handle_mousemotion(SDL_Event
*ev
)
687 if (qemu_console_is_graphic(NULL
) &&
688 (kbd_mouse_is_absolute() || absolute_enabled
)) {
689 max_x
= real_screen
->w
- 1;
690 max_y
= real_screen
->h
- 1;
691 if (gui_grab
&& (ev
->motion
.x
== 0 || ev
->motion
.y
== 0 ||
692 ev
->motion
.x
== max_x
|| ev
->motion
.y
== max_y
)) {
696 (ev
->motion
.x
> 0 && ev
->motion
.x
< max_x
&&
697 ev
->motion
.y
> 0 && ev
->motion
.y
< max_y
)) {
701 if (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
) {
702 sdl_send_mouse_event(ev
->motion
.xrel
, ev
->motion
.yrel
, 0,
703 ev
->motion
.x
, ev
->motion
.y
, ev
->motion
.state
);
707 static void handle_mousebutton(SDL_Event
*ev
)
709 int buttonstate
= SDL_GetMouseState(NULL
, NULL
);
710 SDL_MouseButtonEvent
*bev
;
713 if (!qemu_console_is_graphic(NULL
)) {
718 if (!gui_grab
&& !kbd_mouse_is_absolute()) {
719 if (ev
->type
== SDL_MOUSEBUTTONUP
&& bev
->button
== SDL_BUTTON_LEFT
) {
720 /* start grabbing all events */
725 if (ev
->type
== SDL_MOUSEBUTTONDOWN
) {
726 buttonstate
|= SDL_BUTTON(bev
->button
);
728 buttonstate
&= ~SDL_BUTTON(bev
->button
);
730 #ifdef SDL_BUTTON_WHEELUP
731 if (bev
->button
== SDL_BUTTON_WHEELUP
&&
732 ev
->type
== SDL_MOUSEBUTTONDOWN
) {
734 } else if (bev
->button
== SDL_BUTTON_WHEELDOWN
&&
735 ev
->type
== SDL_MOUSEBUTTONDOWN
) {
739 sdl_send_mouse_event(0, 0, dz
, bev
->x
, bev
->y
, buttonstate
);
743 static void handle_activation(SDL_Event
*ev
)
746 /* Disable grab if the window no longer has the focus
747 * (Windows-only workaround) */
748 if (gui_grab
&& ev
->active
.state
== SDL_APPINPUTFOCUS
&&
749 !ev
->active
.gain
&& !gui_fullscreen
) {
753 if (!gui_grab
&& ev
->active
.gain
&& qemu_console_is_graphic(NULL
) &&
754 (kbd_mouse_is_absolute() || absolute_enabled
)) {
755 absolute_mouse_grab();
757 if (ev
->active
.state
& SDL_APPACTIVE
) {
758 if (ev
->active
.gain
) {
759 /* Back to default interval */
760 update_displaychangelistener(dcl
, GUI_REFRESH_INTERVAL_DEFAULT
);
762 /* Sleeping interval. Not using the long default here as
763 * sdl_refresh does not only update the guest screen, but
764 * also checks for gui events. */
765 update_displaychangelistener(dcl
, 500);
770 static void sdl_refresh(DisplayChangeListener
*dcl
)
772 SDL_Event ev1
, *ev
= &ev1
;
774 if (last_vm_running
!= runstate_is_running()) {
775 last_vm_running
= runstate_is_running();
776 sdl_update_caption();
779 graphic_hw_update(NULL
);
780 SDL_EnableUNICODE(!qemu_console_is_graphic(NULL
));
782 while (SDL_PollEvent(ev
)) {
784 case SDL_VIDEOEXPOSE
:
785 sdl_update(dcl
, 0, 0, real_screen
->w
, real_screen
->h
);
796 qemu_system_shutdown_request();
799 case SDL_MOUSEMOTION
:
800 handle_mousemotion(ev
);
802 case SDL_MOUSEBUTTONDOWN
:
803 case SDL_MOUSEBUTTONUP
:
804 handle_mousebutton(ev
);
806 case SDL_ACTIVEEVENT
:
807 handle_activation(ev
);
809 case SDL_VIDEORESIZE
:
810 sdl_scale(ev
->resize
.w
, ev
->resize
.h
);
811 graphic_hw_invalidate(NULL
);
812 graphic_hw_update(NULL
);
820 static void sdl_mouse_warp(DisplayChangeListener
*dcl
,
821 int x
, int y
, int on
)
826 if (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
) {
827 SDL_SetCursor(guest_sprite
);
828 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
834 guest_x
= x
, guest_y
= y
;
837 static void sdl_mouse_define(DisplayChangeListener
*dcl
,
840 uint8_t *image
, *mask
;
844 SDL_FreeCursor(guest_sprite
);
846 bpl
= cursor_get_mono_bpl(c
);
847 image
= g_malloc0(bpl
* c
->height
);
848 mask
= g_malloc0(bpl
* c
->height
);
849 cursor_get_mono_image(c
, 0x000000, image
);
850 cursor_get_mono_mask(c
, 0, mask
);
851 guest_sprite
= SDL_CreateCursor(image
, mask
, c
->width
, c
->height
,
857 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
858 SDL_SetCursor(guest_sprite
);
861 static void sdl_cleanup(void)
864 SDL_FreeCursor(guest_sprite
);
865 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
868 static const DisplayChangeListenerOps dcl_ops
= {
870 .dpy_gfx_update
= sdl_update
,
871 .dpy_gfx_switch
= sdl_switch
,
872 .dpy_refresh
= sdl_refresh
,
873 .dpy_mouse_set
= sdl_mouse_warp
,
874 .dpy_cursor_define
= sdl_mouse_define
,
877 void sdl_display_init(DisplayState
*ds
, int full_screen
, int no_frame
)
881 const SDL_VideoInfo
*vi
;
884 #if defined(__APPLE__)
885 /* always use generic keymaps */
886 if (!keyboard_layout
)
887 keyboard_layout
= "en-us";
889 if(keyboard_layout
) {
890 kbd_layout
= init_keyboard_layout(name2keysym
, keyboard_layout
);
899 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0);
902 /* on Linux, SDL may use fbcon|directfb|svgalib when run without
903 * accessible $DISPLAY to open X11 window. This is often the case
904 * when qemu is run using sudo. But in this case, and when actually
905 * run in X11 environment, SDL fights with X11 for the video card,
906 * making current display unavailable, often until reboot.
907 * So make x11 the default SDL video driver if this variable is unset.
908 * This is a bit hackish but saves us from bigger problem.
909 * Maybe it's a good idea to fix this in SDL instead.
911 setenv("SDL_VIDEODRIVER", "x11", 0);
914 /* Enable normal up/down events for Caps-Lock and Num-Lock keys.
915 * This requires SDL >= 1.2.14. */
916 setenv("SDL_DISABLE_LOCK_KEYS", "1", 1);
918 flags
= SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
;
919 if (SDL_Init (flags
)) {
920 fprintf(stderr
, "Could not initialize SDL(%s) - exiting\n",
924 vi
= SDL_GetVideoInfo();
925 host_format
= *(vi
->vfmt
);
927 /* Load a 32x32x4 image. White pixels are transparent. */
928 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, "qemu-icon.bmp");
930 SDL_Surface
*image
= SDL_LoadBMP(filename
);
932 uint32_t colorkey
= SDL_MapRGB(image
->format
, 255, 255, 255);
933 SDL_SetColorKey(image
, SDL_SRCCOLORKEY
, colorkey
);
934 SDL_WM_SetIcon(image
, NULL
);
944 dcl
= g_malloc0(sizeof(DisplayChangeListener
));
946 register_displaychangelistener(dcl
);
948 mouse_mode_notifier
.notify
= sdl_mouse_mode_change
;
949 qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier
);
951 sdl_update_caption();
952 SDL_EnableKeyRepeat(250, 50);
955 sdl_cursor_hidden
= SDL_CreateCursor(&data
, &data
, 8, 1, 0, 0);
956 sdl_cursor_normal
= SDL_GetCursor();