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 #include <SDL_syswm.h>
31 #include "qemu-common.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 int gui_saved_grab
;
43 static int gui_fullscreen
;
44 static int gui_noframe
;
45 static int gui_key_modifier_pressed
;
46 static int gui_keysym
;
47 static int gui_fullscreen_initial_grab
;
48 static int gui_grab_code
= KMOD_LALT
| KMOD_LCTRL
;
49 static uint8_t modifiers_state
[256];
50 static int width
, height
;
51 static SDL_Cursor
*sdl_cursor_normal
;
52 static SDL_Cursor
*sdl_cursor_hidden
;
53 static int absolute_enabled
= 0;
54 static int guest_cursor
= 0;
55 static int guest_x
, guest_y
;
56 static SDL_Cursor
*guest_sprite
= NULL
;
57 static uint8_t allocator
;
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
)
89 rec
.w
= real_screen
->w
;
90 rec
.h
= real_screen
->h
;
92 if (guest_screen
!= NULL
) SDL_FreeSurface(guest_screen
);
94 guest_screen
= SDL_CreateRGBSurfaceFrom(ds_get_data(ds
), ds_get_width(ds
), ds_get_height(ds
),
95 ds_get_bits_per_pixel(ds
), ds_get_linesize(ds
),
96 ds
->surface
->pf
.rmask
, ds
->surface
->pf
.gmask
,
97 ds
->surface
->pf
.bmask
, ds
->surface
->pf
.amask
);
100 static void do_sdl_resize(int new_width
, int new_height
, int bpp
)
104 // printf("resizing to %d %d\n", w, h);
106 flags
= SDL_HWSURFACE
|SDL_ASYNCBLIT
|SDL_HWACCEL
|SDL_RESIZABLE
;
108 flags
|= SDL_FULLSCREEN
;
110 flags
|= SDL_NOFRAME
;
114 real_screen
= SDL_SetVideoMode(width
, height
, bpp
, flags
);
116 fprintf(stderr
, "Could not open SDL display (%dx%dx%d): %s\n", width
,
117 height
, bpp
, SDL_GetError());
122 static void sdl_resize(DisplayState
*ds
)
126 do_sdl_resize(ds_get_width(ds
), ds_get_height(ds
), 0);
127 else if (real_screen
->format
->BitsPerPixel
!= ds_get_bits_per_pixel(ds
))
128 do_sdl_resize(real_screen
->w
, real_screen
->h
, ds_get_bits_per_pixel(ds
));
131 if (guest_screen
!= NULL
) {
132 SDL_FreeSurface(guest_screen
);
138 static PixelFormat
sdl_to_qemu_pixelformat(SDL_PixelFormat
*sdl_pf
)
142 memset(&qemu_pf
, 0x00, sizeof(PixelFormat
));
144 qemu_pf
.bits_per_pixel
= sdl_pf
->BitsPerPixel
;
145 qemu_pf
.bytes_per_pixel
= sdl_pf
->BytesPerPixel
;
146 qemu_pf
.depth
= (qemu_pf
.bits_per_pixel
) == 32 ? 24 : (qemu_pf
.bits_per_pixel
);
148 qemu_pf
.rmask
= sdl_pf
->Rmask
;
149 qemu_pf
.gmask
= sdl_pf
->Gmask
;
150 qemu_pf
.bmask
= sdl_pf
->Bmask
;
151 qemu_pf
.amask
= sdl_pf
->Amask
;
153 qemu_pf
.rshift
= sdl_pf
->Rshift
;
154 qemu_pf
.gshift
= sdl_pf
->Gshift
;
155 qemu_pf
.bshift
= sdl_pf
->Bshift
;
156 qemu_pf
.ashift
= sdl_pf
->Ashift
;
158 qemu_pf
.rbits
= 8 - sdl_pf
->Rloss
;
159 qemu_pf
.gbits
= 8 - sdl_pf
->Gloss
;
160 qemu_pf
.bbits
= 8 - sdl_pf
->Bloss
;
161 qemu_pf
.abits
= 8 - sdl_pf
->Aloss
;
163 qemu_pf
.rmax
= ((1 << qemu_pf
.rbits
) - 1);
164 qemu_pf
.gmax
= ((1 << qemu_pf
.gbits
) - 1);
165 qemu_pf
.bmax
= ((1 << qemu_pf
.bbits
) - 1);
166 qemu_pf
.amax
= ((1 << qemu_pf
.abits
) - 1);
171 static DisplaySurface
* sdl_create_displaysurface(int width
, int height
)
173 DisplaySurface
*surface
= (DisplaySurface
*) qemu_mallocz(sizeof(DisplaySurface
));
174 if (surface
== NULL
) {
175 fprintf(stderr
, "sdl_create_displaysurface: malloc failed\n");
179 surface
->width
= width
;
180 surface
->height
= height
;
182 if (scaling_active
) {
183 if (host_format
.BytesPerPixel
!= 2 && host_format
.BytesPerPixel
!= 4) {
184 surface
->linesize
= width
* 4;
185 surface
->pf
= qemu_default_pixelformat(32);
187 surface
->linesize
= width
* host_format
.BytesPerPixel
;
188 surface
->pf
= sdl_to_qemu_pixelformat(&host_format
);
190 #ifdef HOST_WORDS_BIGENDIAN
191 surface
->flags
= QEMU_ALLOCATED_FLAG
| QEMU_BIG_ENDIAN_FLAG
;
193 surface
->flags
= QEMU_ALLOCATED_FLAG
;
195 surface
->data
= (uint8_t*) qemu_mallocz(surface
->linesize
* surface
->height
);
200 if (host_format
.BitsPerPixel
== 16)
201 do_sdl_resize(width
, height
, 16);
203 do_sdl_resize(width
, height
, 32);
205 surface
->pf
= sdl_to_qemu_pixelformat(real_screen
->format
);
206 surface
->linesize
= real_screen
->pitch
;
207 surface
->data
= real_screen
->pixels
;
209 #ifdef HOST_WORDS_BIGENDIAN
210 surface
->flags
= QEMU_REALPIXELS_FLAG
| QEMU_BIG_ENDIAN_FLAG
;
212 surface
->flags
= QEMU_REALPIXELS_FLAG
;
219 static void sdl_free_displaysurface(DisplaySurface
*surface
)
225 if (surface
->flags
& QEMU_ALLOCATED_FLAG
)
226 qemu_free(surface
->data
);
230 static DisplaySurface
* sdl_resize_displaysurface(DisplaySurface
*surface
, int width
, int height
)
232 sdl_free_displaysurface(surface
);
233 return sdl_create_displaysurface(width
, height
);
236 /* generic keyboard conversion */
238 #include "sdl_keysym.h"
240 static kbd_layout_t
*kbd_layout
= NULL
;
242 static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent
*ev
)
245 /* workaround for X11+SDL bug with AltGR */
246 keysym
= ev
->keysym
.sym
;
247 if (keysym
== 0 && ev
->keysym
.scancode
== 113)
249 /* For Japanese key '\' and '|' */
250 if (keysym
== 92 && ev
->keysym
.scancode
== 133) {
253 return keysym2scancode(kbd_layout
, keysym
) & SCANCODE_KEYMASK
;
256 /* specific keyboard conversions from scan codes */
260 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
262 return ev
->keysym
.scancode
;
267 #if defined(SDL_VIDEO_DRIVER_X11)
268 #include <X11/XKBlib.h>
270 static int check_for_evdev(void)
273 XkbDescPtr desc
= NULL
;
275 char *keycodes
= NULL
;
277 SDL_VERSION(&info
.version
);
278 if (!SDL_GetWMInfo(&info
)) {
281 desc
= XkbGetKeyboard(info
.info
.x11
.display
,
282 XkbGBN_AllComponentsMask
,
284 if (desc
&& desc
->names
) {
285 keycodes
= XGetAtomName(info
.info
.x11
.display
, desc
->names
->keycodes
);
286 if (keycodes
== NULL
) {
287 fprintf(stderr
, "could not lookup keycode name\n");
288 } else if (strstart(keycodes
, "evdev", NULL
)) {
290 } else if (!strstart(keycodes
, "xfree86", NULL
)) {
291 fprintf(stderr
, "unknown keycodes `%s', please report to "
292 "qemu-devel@nongnu.org\n", keycodes
);
297 XkbFreeKeyboard(desc
, XkbGBN_AllComponentsMask
, True
);
305 static int check_for_evdev(void)
311 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent
*ev
)
314 static int has_evdev
= -1;
317 has_evdev
= check_for_evdev();
319 keycode
= ev
->keysym
.scancode
;
323 } else if (keycode
< 97) {
324 keycode
-= 8; /* just an offset */
325 } else if (keycode
< 158) {
326 /* use conversion table */
328 keycode
= translate_evdev_keycode(keycode
- 97);
330 keycode
= translate_xfree86_keycode(keycode
- 97);
331 } else if (keycode
== 208) { /* Hiragana_Katakana */
333 } else if (keycode
== 211) { /* backslash */
343 static void reset_keys(void)
346 for(i
= 0; i
< 256; i
++) {
347 if (modifiers_state
[i
]) {
348 if (i
& SCANCODE_GREY
)
349 kbd_put_keycode(SCANCODE_EMUL0
);
350 kbd_put_keycode(i
| SCANCODE_UP
);
351 modifiers_state
[i
] = 0;
356 static void sdl_process_key(SDL_KeyboardEvent
*ev
)
360 if (ev
->keysym
.sym
== SDLK_PAUSE
) {
363 if (ev
->type
== SDL_KEYUP
)
365 kbd_put_keycode(0xe1);
366 kbd_put_keycode(0x1d | v
);
367 kbd_put_keycode(0x45 | v
);
372 keycode
= sdl_keyevent_to_keycode_generic(ev
);
374 keycode
= sdl_keyevent_to_keycode(ev
);
379 /* sent when leaving window: reset the modifiers state */
382 case 0x2a: /* Left Shift */
383 case 0x36: /* Right Shift */
384 case 0x1d: /* Left CTRL */
385 case 0x9d: /* Right CTRL */
386 case 0x38: /* Left ALT */
387 case 0xb8: /* Right ALT */
388 if (ev
->type
== SDL_KEYUP
)
389 modifiers_state
[keycode
] = 0;
391 modifiers_state
[keycode
] = 1;
393 case 0x45: /* num lock */
394 case 0x3a: /* caps lock */
395 /* SDL does not send the key up event, so we generate it */
396 kbd_put_keycode(keycode
);
397 kbd_put_keycode(keycode
| SCANCODE_UP
);
401 /* now send the key code */
402 if (keycode
& SCANCODE_GREY
)
403 kbd_put_keycode(SCANCODE_EMUL0
);
404 if (ev
->type
== SDL_KEYUP
)
405 kbd_put_keycode(keycode
| SCANCODE_UP
);
407 kbd_put_keycode(keycode
& SCANCODE_KEYCODEMASK
);
410 static void sdl_update_caption(void)
412 char win_title
[1024];
413 char icon_title
[1024];
414 const char *status
= "";
417 status
= " [Stopped]";
420 status
= " - Press Ctrl-Alt-Shift to exit mouse grab";
422 status
= " - Press Right-Ctrl to exit mouse grab";
424 status
= " - Press Ctrl-Alt to exit mouse grab";
428 snprintf(win_title
, sizeof(win_title
), "QEMU (%s)%s", qemu_name
, status
);
429 snprintf(icon_title
, sizeof(icon_title
), "QEMU (%s)", qemu_name
);
431 snprintf(win_title
, sizeof(win_title
), "QEMU%s", status
);
432 snprintf(icon_title
, sizeof(icon_title
), "QEMU");
435 SDL_WM_SetCaption(win_title
, icon_title
);
438 static void sdl_hide_cursor(void)
443 if (kbd_mouse_is_absolute()) {
445 SDL_SetCursor(sdl_cursor_hidden
);
451 static void sdl_show_cursor(void)
456 if (!kbd_mouse_is_absolute()) {
459 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
460 SDL_SetCursor(guest_sprite
);
462 SDL_SetCursor(sdl_cursor_normal
);
466 static void sdl_grab_start(void)
469 SDL_SetCursor(guest_sprite
);
470 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
471 SDL_WarpMouse(guest_x
, guest_y
);
475 if (SDL_WM_GrabInput(SDL_GRAB_ON
) == SDL_GRAB_ON
) {
477 sdl_update_caption();
482 static void sdl_grab_end(void)
484 SDL_WM_GrabInput(SDL_GRAB_OFF
);
487 sdl_update_caption();
490 static void sdl_mouse_mode_change(Notifier
*notify
)
492 if (kbd_mouse_is_absolute()) {
493 if (!absolute_enabled
) {
498 absolute_enabled
= 1;
500 } else if (absolute_enabled
) {
502 absolute_enabled
= 0;
506 static void sdl_send_mouse_event(int dx
, int dy
, int dz
, int x
, int y
, int state
)
510 if (state
& SDL_BUTTON(SDL_BUTTON_LEFT
))
511 buttons
|= MOUSE_EVENT_LBUTTON
;
512 if (state
& SDL_BUTTON(SDL_BUTTON_RIGHT
))
513 buttons
|= MOUSE_EVENT_RBUTTON
;
514 if (state
& SDL_BUTTON(SDL_BUTTON_MIDDLE
))
515 buttons
|= MOUSE_EVENT_MBUTTON
;
517 if (kbd_mouse_is_absolute()) {
518 dx
= x
* 0x7FFF / (width
- 1);
519 dy
= y
* 0x7FFF / (height
- 1);
520 } else if (guest_cursor
) {
529 kbd_mouse_event(dx
, dy
, dz
, buttons
);
532 static void toggle_full_screen(DisplayState
*ds
)
534 gui_fullscreen
= !gui_fullscreen
;
535 do_sdl_resize(real_screen
->w
, real_screen
->h
, real_screen
->format
->BitsPerPixel
);
536 if (gui_fullscreen
) {
538 gui_saved_grab
= gui_grab
;
548 static void sdl_refresh(DisplayState
*ds
)
550 SDL_Event ev1
, *ev
= &ev1
;
552 int buttonstate
= SDL_GetMouseState(NULL
, NULL
);
554 if (last_vm_running
!= vm_running
) {
555 last_vm_running
= vm_running
;
556 sdl_update_caption();
560 SDL_EnableUNICODE(!is_graphic_console());
562 while (SDL_PollEvent(ev
)) {
564 case SDL_VIDEOEXPOSE
:
565 sdl_update(ds
, 0, 0, real_screen
->w
, real_screen
->h
);
569 if (ev
->type
== SDL_KEYDOWN
) {
571 mod_state
= (SDL_GetModState() & (gui_grab_code
| KMOD_LSHIFT
)) ==
572 (gui_grab_code
| KMOD_LSHIFT
);
573 } else if (ctrl_grab
) {
574 mod_state
= (SDL_GetModState() & KMOD_RCTRL
) == KMOD_RCTRL
;
576 mod_state
= (SDL_GetModState() & gui_grab_code
) ==
579 gui_key_modifier_pressed
= mod_state
;
580 if (gui_key_modifier_pressed
) {
582 keycode
= sdl_keyevent_to_keycode(&ev
->key
);
584 case 0x21: /* 'f' key on US keyboard */
585 toggle_full_screen(ds
);
588 case 0x16: /* 'u' key on US keyboard */
594 case 0x02 ... 0x0a: /* '1' to '9' keys */
595 /* Reset the modifiers sent to the current console */
597 console_select(keycode
- 0x02);
598 if (!is_graphic_console()) {
599 /* display grab if going to a text console */
608 } else if (!is_graphic_console()) {
611 if (ev
->key
.keysym
.mod
& (KMOD_LCTRL
| KMOD_RCTRL
)) {
612 switch(ev
->key
.keysym
.sym
) {
613 case SDLK_UP
: keysym
= QEMU_KEY_CTRL_UP
; break;
614 case SDLK_DOWN
: keysym
= QEMU_KEY_CTRL_DOWN
; break;
615 case SDLK_LEFT
: keysym
= QEMU_KEY_CTRL_LEFT
; break;
616 case SDLK_RIGHT
: keysym
= QEMU_KEY_CTRL_RIGHT
; break;
617 case SDLK_HOME
: keysym
= QEMU_KEY_CTRL_HOME
; break;
618 case SDLK_END
: keysym
= QEMU_KEY_CTRL_END
; break;
619 case SDLK_PAGEUP
: keysym
= QEMU_KEY_CTRL_PAGEUP
; break;
620 case SDLK_PAGEDOWN
: keysym
= QEMU_KEY_CTRL_PAGEDOWN
; break;
624 switch(ev
->key
.keysym
.sym
) {
625 case SDLK_UP
: keysym
= QEMU_KEY_UP
; break;
626 case SDLK_DOWN
: keysym
= QEMU_KEY_DOWN
; break;
627 case SDLK_LEFT
: keysym
= QEMU_KEY_LEFT
; break;
628 case SDLK_RIGHT
: keysym
= QEMU_KEY_RIGHT
; break;
629 case SDLK_HOME
: keysym
= QEMU_KEY_HOME
; break;
630 case SDLK_END
: keysym
= QEMU_KEY_END
; break;
631 case SDLK_PAGEUP
: keysym
= QEMU_KEY_PAGEUP
; break;
632 case SDLK_PAGEDOWN
: keysym
= QEMU_KEY_PAGEDOWN
; break;
633 case SDLK_BACKSPACE
: keysym
= QEMU_KEY_BACKSPACE
; break;
634 case SDLK_DELETE
: keysym
= QEMU_KEY_DELETE
; break;
639 kbd_put_keysym(keysym
);
640 } else if (ev
->key
.keysym
.unicode
!= 0) {
641 kbd_put_keysym(ev
->key
.keysym
.unicode
);
644 } else if (ev
->type
== SDL_KEYUP
) {
646 mod_state
= (ev
->key
.keysym
.mod
& gui_grab_code
);
648 mod_state
= (ev
->key
.keysym
.mod
&
649 (gui_grab_code
| KMOD_LSHIFT
));
652 if (gui_key_modifier_pressed
) {
653 gui_key_modifier_pressed
= 0;
654 if (gui_keysym
== 0) {
655 /* exit/enter grab if pressing Ctrl-Alt */
657 /* if the application is not active,
658 do not try to enter grab state. It
660 'SDL_WM_GrabInput(SDL_GRAB_ON)'
661 from blocking all the application
663 if (SDL_GetAppState() & SDL_APPACTIVE
)
668 /* SDL does not send back all the
669 modifiers key, so we must correct it */
677 if (is_graphic_console() && !gui_keysym
)
678 sdl_process_key(&ev
->key
);
682 qemu_system_shutdown_request();
684 case SDL_MOUSEMOTION
:
685 if (gui_grab
|| kbd_mouse_is_absolute() ||
687 sdl_send_mouse_event(ev
->motion
.xrel
, ev
->motion
.yrel
, 0,
688 ev
->motion
.x
, ev
->motion
.y
, ev
->motion
.state
);
691 case SDL_MOUSEBUTTONDOWN
:
692 case SDL_MOUSEBUTTONUP
:
694 SDL_MouseButtonEvent
*bev
= &ev
->button
;
695 if (!gui_grab
&& !kbd_mouse_is_absolute()) {
696 if (ev
->type
== SDL_MOUSEBUTTONDOWN
&&
697 (bev
->button
== SDL_BUTTON_LEFT
)) {
698 /* start grabbing all events */
704 if (ev
->type
== SDL_MOUSEBUTTONDOWN
) {
705 buttonstate
|= SDL_BUTTON(bev
->button
);
707 buttonstate
&= ~SDL_BUTTON(bev
->button
);
709 #ifdef SDL_BUTTON_WHEELUP
710 if (bev
->button
== SDL_BUTTON_WHEELUP
&& ev
->type
== SDL_MOUSEBUTTONDOWN
) {
712 } else if (bev
->button
== SDL_BUTTON_WHEELDOWN
&& ev
->type
== SDL_MOUSEBUTTONDOWN
) {
716 sdl_send_mouse_event(0, 0, dz
, bev
->x
, bev
->y
, buttonstate
);
720 case SDL_ACTIVEEVENT
:
721 if (gui_grab
&& ev
->active
.state
== SDL_APPINPUTFOCUS
&&
722 !ev
->active
.gain
&& !gui_fullscreen_initial_grab
) {
725 if (ev
->active
.state
& SDL_APPACTIVE
) {
726 if (ev
->active
.gain
) {
727 /* Back to default interval */
728 dcl
->gui_timer_interval
= 0;
731 /* Sleeping interval */
732 dcl
->gui_timer_interval
= 500;
737 case SDL_VIDEORESIZE
:
739 SDL_ResizeEvent
*rev
= &ev
->resize
;
740 int bpp
= real_screen
->format
->BitsPerPixel
;
741 if (bpp
!= 16 && bpp
!= 32)
743 do_sdl_resize(rev
->w
, rev
->h
, bpp
);
745 if (!is_buffer_shared(ds
->surface
)) {
746 ds
->surface
= qemu_resize_displaysurface(ds
, ds_get_width(ds
), ds_get_height(ds
));
759 static void sdl_fill(DisplayState
*ds
, int x
, int y
, int w
, int h
, uint32_t c
)
761 SDL_Rect dst
= { x
, y
, w
, h
};
762 SDL_FillRect(real_screen
, &dst
, c
);
765 static void sdl_mouse_warp(int x
, int y
, int on
)
770 if (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
) {
771 SDL_SetCursor(guest_sprite
);
772 if (!kbd_mouse_is_absolute() && !absolute_enabled
)
778 guest_x
= x
, guest_y
= y
;
781 static void sdl_mouse_define(int width
, int height
, int bpp
,
782 int hot_x
, int hot_y
,
783 uint8_t *image
, uint8_t *mask
)
785 uint8_t sprite
[256], *line
;
786 int x
, y
, dst
, bypl
, src
= 0;
788 SDL_FreeCursor(guest_sprite
);
790 memset(sprite
, 0, 256);
791 bypl
= ((width
* bpp
+ 31) >> 5) << 2;
792 for (y
= 0, dst
= 0; y
< height
; y
++, image
+= bypl
) {
794 for (x
= 0; x
< width
; x
++, dst
++) {
797 src
= *(line
++); src
|= *(line
++); src
|= *(line
++); line
++;
800 src
= *(line
++); src
|= *(line
++); src
|= *(line
++);
804 src
= *(line
++); src
|= *(line
++);
810 src
= 0xf & (line
[x
>> 1] >> ((x
& 1)) << 2);
813 src
= 3 & (line
[x
>> 2] >> ((x
& 3)) << 1);
816 src
= 1 & (line
[x
>> 3] >> (x
& 7));
820 sprite
[dst
>> 3] |= (1 << (~dst
& 7)) & mask
[dst
>> 3];
823 guest_sprite
= SDL_CreateCursor(sprite
, mask
, width
, height
, hot_x
, hot_y
);
826 (gui_grab
|| kbd_mouse_is_absolute() || absolute_enabled
))
827 SDL_SetCursor(guest_sprite
);
830 static void sdl_cleanup(Notifier
*notifier
)
833 SDL_FreeCursor(guest_sprite
);
834 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
837 void sdl_display_init(DisplayState
*ds
, int full_screen
, int no_frame
)
841 DisplayAllocator
*da
;
842 const SDL_VideoInfo
*vi
;
843 static Notifier exit_notifier
= { .notify
= sdl_cleanup
};
845 #if defined(__APPLE__)
846 /* always use generic keymaps */
847 if (!keyboard_layout
)
848 keyboard_layout
= "en-us";
850 if(keyboard_layout
) {
851 kbd_layout
= init_keyboard_layout(name2keysym
, keyboard_layout
);
859 flags
= SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
;
860 if (SDL_Init (flags
)) {
861 fprintf(stderr
, "Could not initialize SDL(%s) - exiting\n",
865 vi
= SDL_GetVideoInfo();
866 host_format
= *(vi
->vfmt
);
868 dcl
= qemu_mallocz(sizeof(DisplayChangeListener
));
869 dcl
->dpy_update
= sdl_update
;
870 dcl
->dpy_resize
= sdl_resize
;
871 dcl
->dpy_refresh
= sdl_refresh
;
872 dcl
->dpy_setdata
= sdl_setdata
;
873 dcl
->dpy_fill
= sdl_fill
;
874 ds
->mouse_set
= sdl_mouse_warp
;
875 ds
->cursor_define
= sdl_mouse_define
;
876 register_displaychangelistener(ds
, dcl
);
878 da
= qemu_mallocz(sizeof(DisplayAllocator
));
879 da
->create_displaysurface
= sdl_create_displaysurface
;
880 da
->resize_displaysurface
= sdl_resize_displaysurface
;
881 da
->free_displaysurface
= sdl_free_displaysurface
;
882 if (register_displayallocator(ds
, da
) == da
) {
886 mouse_mode_notifier
.notify
= sdl_mouse_mode_change
;
887 qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier
);
889 sdl_update_caption();
890 SDL_EnableKeyRepeat(250, 50);
893 sdl_cursor_hidden
= SDL_CreateCursor(&data
, &data
, 8, 1, 0, 0);
894 sdl_cursor_normal
= SDL_GetCursor();
896 exit_notifier_add(&exit_notifier
);
899 gui_fullscreen_initial_grab
= 1;