]> git.proxmox.com Git - qemu.git/blame - sdl.c
Let the USB tablet reach the far bottom and right pixels
[qemu.git] / sdl.c
CommitLineData
0f0b7264
FB
1/*
2 * QEMU SDL display driver
5fafdf24 3 *
0f0b7264 4 * Copyright (c) 2003 Fabrice Bellard
5fafdf24 5 *
0f0b7264
FB
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
87ecb68b
PB
24#include "qemu-common.h"
25#include "console.h"
26#include "sysemu.h"
0f0b7264
FB
27
28#include <SDL.h>
29
67b915a5
FB
30#ifndef _WIN32
31#include <signal.h>
32#endif
0f0b7264
FB
33
34static SDL_Surface *screen;
35static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
8a7ddc38 36static int last_vm_running;
8e9c4afe
FB
37static int gui_saved_grab;
38static int gui_fullscreen;
43523e93 39static int gui_noframe;
8e9c4afe
FB
40static int gui_key_modifier_pressed;
41static int gui_keysym;
d63d307f 42static int gui_fullscreen_initial_grab;
32ff25bf
FB
43static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
44static uint8_t modifiers_state[256];
09b26c5e
FB
45static int width, height;
46static SDL_Cursor *sdl_cursor_normal;
47static SDL_Cursor *sdl_cursor_hidden;
48static int absolute_enabled = 0;
d34cab9f
TS
49static int guest_cursor = 0;
50static int guest_x, guest_y;
51static SDL_Cursor *guest_sprite = 0;
0f0b7264
FB
52
53static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
54{
898712a8 55 // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
0f0b7264
FB
56 SDL_UpdateRect(screen, x, y, w, h);
57}
58
59static void sdl_resize(DisplayState *ds, int w, int h)
60{
61 int flags;
62
63 // printf("resizing to %d %d\n", w, h);
64
65 flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
8e9c4afe
FB
66 if (gui_fullscreen)
67 flags |= SDL_FULLSCREEN;
43523e93
TS
68 if (gui_noframe)
69 flags |= SDL_NOFRAME;
9903da21 70
09b26c5e
FB
71 width = w;
72 height = h;
73
9903da21 74 again:
0f0b7264
FB
75 screen = SDL_SetVideoMode(w, h, 0, flags);
76 if (!screen) {
77 fprintf(stderr, "Could not open SDL display\n");
78 exit(1);
79 }
9903da21
FB
80 if (!screen->pixels && (flags & SDL_HWSURFACE) && (flags & SDL_FULLSCREEN)) {
81 flags &= ~SDL_HWSURFACE;
82 goto again;
83 }
84
85 if (!screen->pixels) {
86 fprintf(stderr, "Could not open SDL display\n");
87 exit(1);
88 }
0f0b7264
FB
89 ds->data = screen->pixels;
90 ds->linesize = screen->pitch;
91 ds->depth = screen->format->BitsPerPixel;
b29169d2 92 if (screen->format->Bshift > screen->format->Rshift) {
d3079cd2
FB
93 ds->bgr = 1;
94 } else {
95 ds->bgr = 0;
96 }
457831f4
FB
97 ds->width = w;
98 ds->height = h;
0f0b7264
FB
99}
100
3d11d0eb 101/* generic keyboard conversion */
e58d12ed 102
3d11d0eb
FB
103#include "sdl_keysym.h"
104#include "keymaps.c"
105
106static kbd_layout_t *kbd_layout = NULL;
107
108static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev)
e58d12ed 109{
3d11d0eb
FB
110 int keysym;
111 /* workaround for X11+SDL bug with AltGR */
112 keysym = ev->keysym.sym;
113 if (keysym == 0 && ev->keysym.scancode == 113)
114 keysym = SDLK_MODE;
60659e3b
FB
115 /* For Japanese key '\' and '|' */
116 if (keysym == 92 && ev->keysym.scancode == 133) {
117 keysym = 0xa5;
118 }
3d11d0eb 119 return keysym2scancode(kbd_layout, keysym);
e58d12ed
FB
120}
121
3d11d0eb
FB
122/* specific keyboard conversions from scan codes */
123
124#if defined(_WIN32)
e58d12ed
FB
125
126static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
127{
128 return ev->keysym.scancode;
129}
130
131#else
132
e58d12ed
FB
133static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
134{
135 int keycode;
136
137 keycode = ev->keysym.scancode;
138
139 if (keycode < 9) {
140 keycode = 0;
141 } else if (keycode < 97) {
142 keycode -= 8; /* just an offset */
60659e3b 143 } else if (keycode < 212) {
e58d12ed 144 /* use conversion table */
6070dd07 145 keycode = _translate_keycode(keycode - 97);
e58d12ed
FB
146 } else {
147 keycode = 0;
148 }
149 return keycode;
150}
151
152#endif
153
32ff25bf
FB
154static void reset_keys(void)
155{
156 int i;
157 for(i = 0; i < 256; i++) {
158 if (modifiers_state[i]) {
159 if (i & 0x80)
160 kbd_put_keycode(0xe0);
161 kbd_put_keycode(i | 0x80);
162 modifiers_state[i] = 0;
163 }
164 }
165}
166
0f0b7264
FB
167static void sdl_process_key(SDL_KeyboardEvent *ev)
168{
32ff25bf 169 int keycode, v;
de2200d3
FB
170
171 if (ev->keysym.sym == SDLK_PAUSE) {
172 /* specific case */
173 v = 0;
174 if (ev->type == SDL_KEYUP)
175 v |= 0x80;
176 kbd_put_keycode(0xe1);
177 kbd_put_keycode(0x1d | v);
178 kbd_put_keycode(0x45 | v);
179 return;
180 }
181
3d11d0eb
FB
182 if (kbd_layout) {
183 keycode = sdl_keyevent_to_keycode_generic(ev);
184 } else {
185 keycode = sdl_keyevent_to_keycode(ev);
186 }
de2200d3
FB
187
188 switch(keycode) {
189 case 0x00:
190 /* sent when leaving window: reset the modifiers state */
32ff25bf 191 reset_keys();
de2200d3
FB
192 return;
193 case 0x2a: /* Left Shift */
194 case 0x36: /* Right Shift */
195 case 0x1d: /* Left CTRL */
196 case 0x9d: /* Right CTRL */
197 case 0x38: /* Left ALT */
198 case 0xb8: /* Right ALT */
0f0b7264 199 if (ev->type == SDL_KEYUP)
de2200d3
FB
200 modifiers_state[keycode] = 0;
201 else
202 modifiers_state[keycode] = 1;
203 break;
204 case 0x45: /* num lock */
205 case 0x3a: /* caps lock */
206 /* SDL does not send the key up event, so we generate it */
207 kbd_put_keycode(keycode);
208 kbd_put_keycode(keycode | 0x80);
209 return;
0f0b7264 210 }
de2200d3
FB
211
212 /* now send the key code */
213 if (keycode & 0x80)
214 kbd_put_keycode(0xe0);
215 if (ev->type == SDL_KEYUP)
216 kbd_put_keycode(keycode | 0x80);
217 else
218 kbd_put_keycode(keycode & 0x7f);
0f0b7264
FB
219}
220
8a7ddc38
FB
221static void sdl_update_caption(void)
222{
223 char buf[1024];
c35734b2
TS
224 const char *status = "";
225
226 if (!vm_running)
227 status = " [Stopped]";
3780e197
TS
228 else if (gui_grab) {
229 if (!alt_grab)
230 status = " - Press Ctrl-Alt to exit grab";
231 else
232 status = " - Press Ctrl-Alt-Shift to exit grab";
233 }
c35734b2
TS
234
235 if (qemu_name)
236 snprintf(buf, sizeof(buf), "QEMU (%s)%s", qemu_name, status);
237 else
238 snprintf(buf, sizeof(buf), "QEMU%s", status);
239
8a7ddc38
FB
240 SDL_WM_SetCaption(buf, "QEMU");
241}
242
09b26c5e
FB
243static void sdl_hide_cursor(void)
244{
9467cd46
AZ
245 if (!cursor_hide)
246 return;
247
8785a8dd
FB
248 if (kbd_mouse_is_absolute()) {
249 SDL_ShowCursor(1);
250 SDL_SetCursor(sdl_cursor_hidden);
251 } else {
252 SDL_ShowCursor(0);
253 }
09b26c5e
FB
254}
255
256static void sdl_show_cursor(void)
257{
9467cd46
AZ
258 if (!cursor_hide)
259 return;
260
09b26c5e 261 if (!kbd_mouse_is_absolute()) {
8785a8dd 262 SDL_ShowCursor(1);
d34cab9f
TS
263 if (guest_cursor &&
264 (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
265 SDL_SetCursor(guest_sprite);
266 else
267 SDL_SetCursor(sdl_cursor_normal);
09b26c5e
FB
268 }
269}
270
0f0b7264
FB
271static void sdl_grab_start(void)
272{
d34cab9f
TS
273 if (guest_cursor) {
274 SDL_SetCursor(guest_sprite);
275 SDL_WarpMouse(guest_x, guest_y);
276 } else
277 sdl_hide_cursor();
0f0b7264
FB
278 SDL_WM_GrabInput(SDL_GRAB_ON);
279 /* dummy read to avoid moving the mouse */
280 SDL_GetRelativeMouseState(NULL, NULL);
281 gui_grab = 1;
8a7ddc38 282 sdl_update_caption();
0f0b7264
FB
283}
284
285static void sdl_grab_end(void)
286{
0f0b7264 287 SDL_WM_GrabInput(SDL_GRAB_OFF);
0f0b7264 288 gui_grab = 0;
d34cab9f 289 sdl_show_cursor();
8a7ddc38 290 sdl_update_caption();
0f0b7264
FB
291}
292
18a6d284 293static void sdl_send_mouse_event(int dz)
0f0b7264 294{
18a6d284 295 int dx, dy, state, buttons;
0f0b7264
FB
296 state = SDL_GetRelativeMouseState(&dx, &dy);
297 buttons = 0;
298 if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
299 buttons |= MOUSE_EVENT_LBUTTON;
300 if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))
301 buttons |= MOUSE_EVENT_RBUTTON;
302 if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE))
303 buttons |= MOUSE_EVENT_MBUTTON;
09b26c5e
FB
304
305 if (kbd_mouse_is_absolute()) {
306 if (!absolute_enabled) {
307 sdl_hide_cursor();
308 if (gui_grab) {
309 sdl_grab_end();
310 }
311 absolute_enabled = 1;
312 }
313
314 SDL_GetMouseState(&dx, &dy);
b94ed577
AJ
315 dx = dx * 0x7FFF / (width - 1);
316 dy = dy * 0x7FFF / (height - 1);
455204eb
TS
317 } else if (absolute_enabled) {
318 sdl_show_cursor();
319 absolute_enabled = 0;
d34cab9f
TS
320 } else if (guest_cursor) {
321 SDL_GetMouseState(&dx, &dy);
322 dx -= guest_x;
323 dy -= guest_y;
324 guest_x += dx;
325 guest_y += dy;
09b26c5e
FB
326 }
327
0f0b7264
FB
328 kbd_mouse_event(dx, dy, dz, buttons);
329}
330
8e9c4afe
FB
331static void toggle_full_screen(DisplayState *ds)
332{
333 gui_fullscreen = !gui_fullscreen;
334 sdl_resize(ds, screen->w, screen->h);
335 if (gui_fullscreen) {
336 gui_saved_grab = gui_grab;
337 sdl_grab_start();
338 } else {
339 if (!gui_saved_grab)
340 sdl_grab_end();
341 }
95219897
PB
342 vga_hw_invalidate();
343 vga_hw_update();
8e9c4afe
FB
344}
345
0f0b7264
FB
346static void sdl_refresh(DisplayState *ds)
347{
348 SDL_Event ev1, *ev = &ev1;
8e9c4afe 349 int mod_state;
3b46e624 350
8a7ddc38
FB
351 if (last_vm_running != vm_running) {
352 last_vm_running = vm_running;
353 sdl_update_caption();
354 }
355
95219897 356 vga_hw_update();
457831f4 357
0f0b7264
FB
358 while (SDL_PollEvent(ev)) {
359 switch (ev->type) {
360 case SDL_VIDEOEXPOSE:
361 sdl_update(ds, 0, 0, screen->w, screen->h);
362 break;
363 case SDL_KEYDOWN:
364 case SDL_KEYUP:
365 if (ev->type == SDL_KEYDOWN) {
3780e197
TS
366 if (!alt_grab) {
367 mod_state = (SDL_GetModState() & gui_grab_code) ==
368 gui_grab_code;
369 } else {
370 mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
371 (gui_grab_code | KMOD_LSHIFT);
372 }
8e9c4afe 373 gui_key_modifier_pressed = mod_state;
457831f4 374 if (gui_key_modifier_pressed) {
32ff25bf
FB
375 int keycode;
376 keycode = sdl_keyevent_to_keycode(&ev->key);
377 switch(keycode) {
378 case 0x21: /* 'f' key on US keyboard */
457831f4
FB
379 toggle_full_screen(ds);
380 gui_keysym = 1;
381 break;
5fafdf24 382 case 0x02 ... 0x0a: /* '1' to '9' keys */
dfd92d3a
FB
383 /* Reset the modifiers sent to the current console */
384 reset_keys();
32ff25bf 385 console_select(keycode - 0x02);
95219897 386 if (!is_graphic_console()) {
457831f4
FB
387 /* display grab if going to a text console */
388 if (gui_grab)
389 sdl_grab_end();
390 }
391 gui_keysym = 1;
392 break;
393 default:
394 break;
395 }
95219897 396 } else if (!is_graphic_console()) {
457831f4
FB
397 int keysym;
398 keysym = 0;
399 if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
400 switch(ev->key.keysym.sym) {
401 case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break;
402 case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break;
403 case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break;
404 case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break;
405 case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break;
406 case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
407 case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
408 case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
409 default: break;
410 }
411 } else {
412 switch(ev->key.keysym.sym) {
413 case SDLK_UP: keysym = QEMU_KEY_UP; break;
414 case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break;
415 case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break;
416 case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break;
417 case SDLK_HOME: keysym = QEMU_KEY_HOME; break;
418 case SDLK_END: keysym = QEMU_KEY_END; break;
419 case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break;
420 case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break;
e91c8a77
TS
421 case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break;
422 case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break;
457831f4
FB
423 default: break;
424 }
425 }
426 if (keysym) {
427 kbd_put_keysym(keysym);
428 } else if (ev->key.keysym.unicode != 0) {
429 kbd_put_keysym(ev->key.keysym.unicode);
430 }
8e9c4afe
FB
431 }
432 } else if (ev->type == SDL_KEYUP) {
3780e197
TS
433 if (!alt_grab) {
434 mod_state = (ev->key.keysym.mod & gui_grab_code);
435 } else {
436 mod_state = (ev->key.keysym.mod &
437 (gui_grab_code | KMOD_LSHIFT));
438 }
8e9c4afe
FB
439 if (!mod_state) {
440 if (gui_key_modifier_pressed) {
5b311878 441 gui_key_modifier_pressed = 0;
457831f4 442 if (gui_keysym == 0) {
32ff25bf 443 /* exit/enter grab if pressing Ctrl-Alt */
c66b0d4c
FB
444 if (!gui_grab) {
445 /* if the application is not active,
446 do not try to enter grab state. It
447 prevents
448 'SDL_WM_GrabInput(SDL_GRAB_ON)'
449 from blocking all the application
450 (SDL bug). */
451 if (SDL_GetAppState() & SDL_APPACTIVE)
452 sdl_grab_start();
453 } else {
8e9c4afe 454 sdl_grab_end();
c66b0d4c 455 }
32ff25bf
FB
456 /* SDL does not send back all the
457 modifiers key, so we must correct it */
458 reset_keys();
8e9c4afe
FB
459 break;
460 }
8e9c4afe
FB
461 gui_keysym = 0;
462 }
0f0b7264
FB
463 }
464 }
5fafdf24 465 if (is_graphic_console() && !gui_keysym)
457831f4 466 sdl_process_key(&ev->key);
0f0b7264
FB
467 break;
468 case SDL_QUIT:
667accab 469 if (!no_quit) {
731345e1
AZ
470 qemu_system_shutdown_request();
471 vm_start(); /* In case we're paused */
667accab 472 }
0f0b7264
FB
473 break;
474 case SDL_MOUSEMOTION:
455204eb
TS
475 if (gui_grab || kbd_mouse_is_absolute() ||
476 absolute_enabled) {
18a6d284 477 sdl_send_mouse_event(0);
0f0b7264
FB
478 }
479 break;
480 case SDL_MOUSEBUTTONDOWN:
481 case SDL_MOUSEBUTTONUP:
482 {
483 SDL_MouseButtonEvent *bev = &ev->button;
09b26c5e 484 if (!gui_grab && !kbd_mouse_is_absolute()) {
0f0b7264
FB
485 if (ev->type == SDL_MOUSEBUTTONDOWN &&
486 (bev->state & SDL_BUTTON_LMASK)) {
487 /* start grabbing all events */
488 sdl_grab_start();
489 }
490 } else {
18a6d284
FB
491 int dz;
492 dz = 0;
493#ifdef SDL_BUTTON_WHEELUP
09b26c5e 494 if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
18a6d284 495 dz = -1;
09b26c5e 496 } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
18a6d284
FB
497 dz = 1;
498 }
3b46e624 499#endif
18a6d284 500 sdl_send_mouse_event(dz);
0f0b7264
FB
501 }
502 }
503 break;
0294ffb9 504 case SDL_ACTIVEEVENT:
5b311878
PB
505 if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
506 !ev->active.gain && !gui_fullscreen_initial_grab) {
0294ffb9
FB
507 sdl_grab_end();
508 }
509 break;
0f0b7264
FB
510 default:
511 break;
512 }
513 }
514}
515
d34cab9f
TS
516static void sdl_fill(DisplayState *ds, int x, int y, int w, int h, uint32_t c)
517{
518 SDL_Rect dst = { x, y, w, h };
519 SDL_FillRect(screen, &dst, c);
520}
521
522static void sdl_mouse_warp(int x, int y, int on)
523{
524 if (on) {
525 if (!guest_cursor)
526 sdl_show_cursor();
527 if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
528 SDL_SetCursor(guest_sprite);
529 SDL_WarpMouse(x, y);
530 }
531 } else if (gui_grab)
532 sdl_hide_cursor();
533 guest_cursor = on;
534 guest_x = x, guest_y = y;
535}
536
537static void sdl_mouse_define(int width, int height, int bpp,
538 int hot_x, int hot_y,
539 uint8_t *image, uint8_t *mask)
540{
541 uint8_t sprite[256], *line;
542 int x, y, dst, bypl, src = 0;
543 if (guest_sprite)
544 SDL_FreeCursor(guest_sprite);
545
546 memset(sprite, 0, 256);
547 bypl = ((width * bpp + 31) >> 5) << 2;
548 for (y = 0, dst = 0; y < height; y ++, image += bypl) {
549 line = image;
550 for (x = 0; x < width; x ++, dst ++) {
551 switch (bpp) {
552 case 24:
553 src = *(line ++); src |= *(line ++); src |= *(line ++);
554 break;
555 case 16:
556 case 15:
557 src = *(line ++); src |= *(line ++);
558 break;
559 case 8:
560 src = *(line ++);
561 break;
562 case 4:
563 src = 0xf & (line[x >> 1] >> ((x & 1)) << 2);
564 break;
565 case 2:
566 src = 3 & (line[x >> 2] >> ((x & 3)) << 1);
567 break;
568 case 1:
569 src = 1 & (line[x >> 3] >> (x & 7));
570 break;
571 }
572 if (!src)
573 sprite[dst >> 3] |= (1 << (~dst & 7)) & mask[dst >> 3];
574 }
575 }
576 guest_sprite = SDL_CreateCursor(sprite, mask, width, height, hot_x, hot_y);
577
578 if (guest_cursor &&
579 (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
580 SDL_SetCursor(guest_sprite);
581}
582
5fafdf24 583static void sdl_cleanup(void)
898712a8 584{
d34cab9f
TS
585 if (guest_sprite)
586 SDL_FreeCursor(guest_sprite);
898712a8
FB
587 SDL_Quit();
588}
589
43523e93 590void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
0f0b7264
FB
591{
592 int flags;
09b26c5e 593 uint8_t data = 0;
0f0b7264 594
3d11d0eb
FB
595#if defined(__APPLE__)
596 /* always use generic keymaps */
597 if (!keyboard_layout)
598 keyboard_layout = "en-us";
599#endif
600 if(keyboard_layout) {
601 kbd_layout = init_keyboard_layout(keyboard_layout);
602 if (!kbd_layout)
603 exit(1);
604 }
605
43523e93
TS
606 if (no_frame)
607 gui_noframe = 1;
608
0f0b7264
FB
609 flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
610 if (SDL_Init (flags)) {
611 fprintf(stderr, "Could not initialize SDL - exiting\n");
612 exit(1);
613 }
67b915a5 614#ifndef _WIN32
0ae04d73
FB
615 /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */
616 signal(SIGINT, SIG_DFL);
617 signal(SIGQUIT, SIG_DFL);
67b915a5 618#endif
0ae04d73 619
0f0b7264
FB
620 ds->dpy_update = sdl_update;
621 ds->dpy_resize = sdl_resize;
622 ds->dpy_refresh = sdl_refresh;
d34cab9f
TS
623 ds->dpy_fill = sdl_fill;
624 ds->mouse_set = sdl_mouse_warp;
625 ds->cursor_define = sdl_mouse_define;
0f0b7264
FB
626
627 sdl_resize(ds, 640, 400);
8a7ddc38 628 sdl_update_caption();
0f0b7264 629 SDL_EnableKeyRepeat(250, 50);
457831f4 630 SDL_EnableUNICODE(1);
0f0b7264 631 gui_grab = 0;
898712a8 632
09b26c5e
FB
633 sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
634 sdl_cursor_normal = SDL_GetCursor();
635
898712a8 636 atexit(sdl_cleanup);
d63d307f
FB
637 if (full_screen) {
638 gui_fullscreen = 1;
639 gui_fullscreen_initial_grab = 1;
640 sdl_grab_start();
641 }
0f0b7264 642}