root / sdl.c @ 455204eb
History | View | Annotate | Download (18.1 kB)
1 |
/*
|
---|---|
2 |
* QEMU SDL display driver
|
3 |
*
|
4 |
* Copyright (c) 2003 Fabrice Bellard
|
5 |
*
|
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 |
*/
|
24 |
#include "vl.h" |
25 |
|
26 |
#include <SDL.h> |
27 |
|
28 |
#ifndef _WIN32
|
29 |
#include <signal.h> |
30 |
#endif
|
31 |
|
32 |
static SDL_Surface *screen;
|
33 |
static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ |
34 |
static int last_vm_running; |
35 |
static int gui_saved_grab; |
36 |
static int gui_fullscreen; |
37 |
static int gui_key_modifier_pressed; |
38 |
static int gui_keysym; |
39 |
static int gui_fullscreen_initial_grab; |
40 |
static int gui_grab_code = KMOD_LALT | KMOD_LCTRL; |
41 |
static uint8_t modifiers_state[256]; |
42 |
static int width, height; |
43 |
static SDL_Cursor *sdl_cursor_normal;
|
44 |
static SDL_Cursor *sdl_cursor_hidden;
|
45 |
static int absolute_enabled = 0; |
46 |
|
47 |
static void sdl_update(DisplayState *ds, int x, int y, int w, int h) |
48 |
{ |
49 |
// printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
|
50 |
SDL_UpdateRect(screen, x, y, w, h); |
51 |
} |
52 |
|
53 |
static void sdl_resize(DisplayState *ds, int w, int h) |
54 |
{ |
55 |
int flags;
|
56 |
|
57 |
// printf("resizing to %d %d\n", w, h);
|
58 |
|
59 |
flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL; |
60 |
if (gui_fullscreen)
|
61 |
flags |= SDL_FULLSCREEN; |
62 |
|
63 |
width = w; |
64 |
height = h; |
65 |
|
66 |
again:
|
67 |
screen = SDL_SetVideoMode(w, h, 0, flags);
|
68 |
if (!screen) {
|
69 |
fprintf(stderr, "Could not open SDL display\n");
|
70 |
exit(1);
|
71 |
} |
72 |
if (!screen->pixels && (flags & SDL_HWSURFACE) && (flags & SDL_FULLSCREEN)) {
|
73 |
flags &= ~SDL_HWSURFACE; |
74 |
goto again;
|
75 |
} |
76 |
|
77 |
if (!screen->pixels) {
|
78 |
fprintf(stderr, "Could not open SDL display\n");
|
79 |
exit(1);
|
80 |
} |
81 |
ds->data = screen->pixels; |
82 |
ds->linesize = screen->pitch; |
83 |
ds->depth = screen->format->BitsPerPixel; |
84 |
if (ds->depth == 32 && screen->format->Rshift == 0) { |
85 |
ds->bgr = 1;
|
86 |
} else {
|
87 |
ds->bgr = 0;
|
88 |
} |
89 |
ds->width = w; |
90 |
ds->height = h; |
91 |
} |
92 |
|
93 |
/* generic keyboard conversion */
|
94 |
|
95 |
#include "sdl_keysym.h" |
96 |
#include "keymaps.c" |
97 |
|
98 |
static kbd_layout_t *kbd_layout = NULL; |
99 |
|
100 |
static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev) |
101 |
{ |
102 |
int keysym;
|
103 |
/* workaround for X11+SDL bug with AltGR */
|
104 |
keysym = ev->keysym.sym; |
105 |
if (keysym == 0 && ev->keysym.scancode == 113) |
106 |
keysym = SDLK_MODE; |
107 |
/* For Japanese key '\' and '|' */
|
108 |
if (keysym == 92 && ev->keysym.scancode == 133) { |
109 |
keysym = 0xa5;
|
110 |
} |
111 |
return keysym2scancode(kbd_layout, keysym);
|
112 |
} |
113 |
|
114 |
/* specific keyboard conversions from scan codes */
|
115 |
|
116 |
#if defined(_WIN32)
|
117 |
|
118 |
static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) |
119 |
{ |
120 |
return ev->keysym.scancode;
|
121 |
} |
122 |
|
123 |
#else
|
124 |
|
125 |
static const uint8_t x_keycode_to_pc_keycode[115] = { |
126 |
0xc7, /* 97 Home */ |
127 |
0xc8, /* 98 Up */ |
128 |
0xc9, /* 99 PgUp */ |
129 |
0xcb, /* 100 Left */ |
130 |
0x4c, /* 101 KP-5 */ |
131 |
0xcd, /* 102 Right */ |
132 |
0xcf, /* 103 End */ |
133 |
0xd0, /* 104 Down */ |
134 |
0xd1, /* 105 PgDn */ |
135 |
0xd2, /* 106 Ins */ |
136 |
0xd3, /* 107 Del */ |
137 |
0x9c, /* 108 Enter */ |
138 |
0x9d, /* 109 Ctrl-R */ |
139 |
0x0, /* 110 Pause */ |
140 |
0xb7, /* 111 Print */ |
141 |
0xb5, /* 112 Divide */ |
142 |
0xb8, /* 113 Alt-R */ |
143 |
0xc6, /* 114 Break */ |
144 |
0x0, /* 115 */ |
145 |
0x0, /* 116 */ |
146 |
0x0, /* 117 */ |
147 |
0x0, /* 118 */ |
148 |
0x0, /* 119 */ |
149 |
0x0, /* 120 */ |
150 |
0x0, /* 121 */ |
151 |
0x0, /* 122 */ |
152 |
0x0, /* 123 */ |
153 |
0x0, /* 124 */ |
154 |
0x0, /* 125 */ |
155 |
0x0, /* 126 */ |
156 |
0x0, /* 127 */ |
157 |
0x0, /* 128 */ |
158 |
0x79, /* 129 Henkan */ |
159 |
0x0, /* 130 */ |
160 |
0x7b, /* 131 Muhenkan */ |
161 |
0x0, /* 132 */ |
162 |
0x7d, /* 133 Yen */ |
163 |
0x0, /* 134 */ |
164 |
0x0, /* 135 */ |
165 |
0x47, /* 136 KP_7 */ |
166 |
0x48, /* 137 KP_8 */ |
167 |
0x49, /* 138 KP_9 */ |
168 |
0x4b, /* 139 KP_4 */ |
169 |
0x4c, /* 140 KP_5 */ |
170 |
0x4d, /* 141 KP_6 */ |
171 |
0x4f, /* 142 KP_1 */ |
172 |
0x50, /* 143 KP_2 */ |
173 |
0x51, /* 144 KP_3 */ |
174 |
0x52, /* 145 KP_0 */ |
175 |
0x53, /* 146 KP_. */ |
176 |
0x47, /* 147 KP_HOME */ |
177 |
0x48, /* 148 KP_UP */ |
178 |
0x49, /* 149 KP_PgUp */ |
179 |
0x4b, /* 150 KP_Left */ |
180 |
0x4c, /* 151 KP_ */ |
181 |
0x4d, /* 152 KP_Right */ |
182 |
0x4f, /* 153 KP_End */ |
183 |
0x50, /* 154 KP_Down */ |
184 |
0x51, /* 155 KP_PgDn */ |
185 |
0x52, /* 156 KP_Ins */ |
186 |
0x53, /* 157 KP_Del */ |
187 |
0x0, /* 158 */ |
188 |
0x0, /* 159 */ |
189 |
0x0, /* 160 */ |
190 |
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 170 */ |
191 |
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 180 */ |
192 |
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 190 */ |
193 |
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 200 */ |
194 |
0x0, /* 201 */ |
195 |
0x0, /* 202 */ |
196 |
0x0, /* 203 */ |
197 |
0x0, /* 204 */ |
198 |
0x0, /* 205 */ |
199 |
0x0, /* 206 */ |
200 |
0x0, /* 207 */ |
201 |
0x70, /* 208 Hiragana_Katakana */ |
202 |
0x0, /* 209 */ |
203 |
0x0, /* 210 */ |
204 |
0x73, /* 211 backslash */ |
205 |
}; |
206 |
|
207 |
static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) |
208 |
{ |
209 |
int keycode;
|
210 |
|
211 |
keycode = ev->keysym.scancode; |
212 |
|
213 |
if (keycode < 9) { |
214 |
keycode = 0;
|
215 |
} else if (keycode < 97) { |
216 |
keycode -= 8; /* just an offset */ |
217 |
} else if (keycode < 212) { |
218 |
/* use conversion table */
|
219 |
keycode = x_keycode_to_pc_keycode[keycode - 97];
|
220 |
} else {
|
221 |
keycode = 0;
|
222 |
} |
223 |
return keycode;
|
224 |
} |
225 |
|
226 |
#endif
|
227 |
|
228 |
static void reset_keys(void) |
229 |
{ |
230 |
int i;
|
231 |
for(i = 0; i < 256; i++) { |
232 |
if (modifiers_state[i]) {
|
233 |
if (i & 0x80) |
234 |
kbd_put_keycode(0xe0);
|
235 |
kbd_put_keycode(i | 0x80);
|
236 |
modifiers_state[i] = 0;
|
237 |
} |
238 |
} |
239 |
} |
240 |
|
241 |
static void sdl_process_key(SDL_KeyboardEvent *ev) |
242 |
{ |
243 |
int keycode, v;
|
244 |
|
245 |
if (ev->keysym.sym == SDLK_PAUSE) {
|
246 |
/* specific case */
|
247 |
v = 0;
|
248 |
if (ev->type == SDL_KEYUP)
|
249 |
v |= 0x80;
|
250 |
kbd_put_keycode(0xe1);
|
251 |
kbd_put_keycode(0x1d | v);
|
252 |
kbd_put_keycode(0x45 | v);
|
253 |
return;
|
254 |
} |
255 |
|
256 |
if (kbd_layout) {
|
257 |
keycode = sdl_keyevent_to_keycode_generic(ev); |
258 |
} else {
|
259 |
keycode = sdl_keyevent_to_keycode(ev); |
260 |
} |
261 |
|
262 |
switch(keycode) {
|
263 |
case 0x00: |
264 |
/* sent when leaving window: reset the modifiers state */
|
265 |
reset_keys(); |
266 |
return;
|
267 |
case 0x2a: /* Left Shift */ |
268 |
case 0x36: /* Right Shift */ |
269 |
case 0x1d: /* Left CTRL */ |
270 |
case 0x9d: /* Right CTRL */ |
271 |
case 0x38: /* Left ALT */ |
272 |
case 0xb8: /* Right ALT */ |
273 |
if (ev->type == SDL_KEYUP)
|
274 |
modifiers_state[keycode] = 0;
|
275 |
else
|
276 |
modifiers_state[keycode] = 1;
|
277 |
break;
|
278 |
case 0x45: /* num lock */ |
279 |
case 0x3a: /* caps lock */ |
280 |
/* SDL does not send the key up event, so we generate it */
|
281 |
kbd_put_keycode(keycode); |
282 |
kbd_put_keycode(keycode | 0x80);
|
283 |
return;
|
284 |
} |
285 |
|
286 |
/* now send the key code */
|
287 |
if (keycode & 0x80) |
288 |
kbd_put_keycode(0xe0);
|
289 |
if (ev->type == SDL_KEYUP)
|
290 |
kbd_put_keycode(keycode | 0x80);
|
291 |
else
|
292 |
kbd_put_keycode(keycode & 0x7f);
|
293 |
} |
294 |
|
295 |
static void sdl_update_caption(void) |
296 |
{ |
297 |
char buf[1024]; |
298 |
strcpy(buf, "QEMU");
|
299 |
if (!vm_running) {
|
300 |
strcat(buf, " [Stopped]");
|
301 |
} |
302 |
if (gui_grab) {
|
303 |
strcat(buf, " - Press Ctrl-Alt to exit grab");
|
304 |
} |
305 |
SDL_WM_SetCaption(buf, "QEMU");
|
306 |
} |
307 |
|
308 |
static void sdl_hide_cursor(void) |
309 |
{ |
310 |
if (kbd_mouse_is_absolute()) {
|
311 |
SDL_ShowCursor(1);
|
312 |
SDL_SetCursor(sdl_cursor_hidden); |
313 |
} else {
|
314 |
SDL_ShowCursor(0);
|
315 |
} |
316 |
} |
317 |
|
318 |
static void sdl_show_cursor(void) |
319 |
{ |
320 |
if (!kbd_mouse_is_absolute()) {
|
321 |
SDL_ShowCursor(1);
|
322 |
SDL_SetCursor(sdl_cursor_normal); |
323 |
} |
324 |
} |
325 |
|
326 |
static void sdl_grab_start(void) |
327 |
{ |
328 |
sdl_hide_cursor(); |
329 |
SDL_WM_GrabInput(SDL_GRAB_ON); |
330 |
/* dummy read to avoid moving the mouse */
|
331 |
SDL_GetRelativeMouseState(NULL, NULL); |
332 |
gui_grab = 1;
|
333 |
sdl_update_caption(); |
334 |
} |
335 |
|
336 |
static void sdl_grab_end(void) |
337 |
{ |
338 |
SDL_WM_GrabInput(SDL_GRAB_OFF); |
339 |
sdl_show_cursor(); |
340 |
gui_grab = 0;
|
341 |
sdl_update_caption(); |
342 |
} |
343 |
|
344 |
static void sdl_send_mouse_event(int dz) |
345 |
{ |
346 |
int dx, dy, state, buttons;
|
347 |
state = SDL_GetRelativeMouseState(&dx, &dy); |
348 |
buttons = 0;
|
349 |
if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
|
350 |
buttons |= MOUSE_EVENT_LBUTTON; |
351 |
if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))
|
352 |
buttons |= MOUSE_EVENT_RBUTTON; |
353 |
if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE))
|
354 |
buttons |= MOUSE_EVENT_MBUTTON; |
355 |
|
356 |
if (kbd_mouse_is_absolute()) {
|
357 |
if (!absolute_enabled) {
|
358 |
sdl_hide_cursor(); |
359 |
if (gui_grab) {
|
360 |
sdl_grab_end(); |
361 |
} |
362 |
absolute_enabled = 1;
|
363 |
} |
364 |
|
365 |
SDL_GetMouseState(&dx, &dy); |
366 |
dx = dx * 0x7FFF / width;
|
367 |
dy = dy * 0x7FFF / height;
|
368 |
} else if (absolute_enabled) { |
369 |
sdl_show_cursor(); |
370 |
absolute_enabled = 0;
|
371 |
} |
372 |
|
373 |
kbd_mouse_event(dx, dy, dz, buttons); |
374 |
} |
375 |
|
376 |
static void toggle_full_screen(DisplayState *ds) |
377 |
{ |
378 |
gui_fullscreen = !gui_fullscreen; |
379 |
sdl_resize(ds, screen->w, screen->h); |
380 |
if (gui_fullscreen) {
|
381 |
gui_saved_grab = gui_grab; |
382 |
sdl_grab_start(); |
383 |
} else {
|
384 |
if (!gui_saved_grab)
|
385 |
sdl_grab_end(); |
386 |
} |
387 |
vga_hw_invalidate(); |
388 |
vga_hw_update(); |
389 |
} |
390 |
|
391 |
static void sdl_refresh(DisplayState *ds) |
392 |
{ |
393 |
SDL_Event ev1, *ev = &ev1; |
394 |
int mod_state;
|
395 |
|
396 |
if (last_vm_running != vm_running) {
|
397 |
last_vm_running = vm_running; |
398 |
sdl_update_caption(); |
399 |
} |
400 |
|
401 |
vga_hw_update(); |
402 |
|
403 |
while (SDL_PollEvent(ev)) {
|
404 |
switch (ev->type) {
|
405 |
case SDL_VIDEOEXPOSE:
|
406 |
sdl_update(ds, 0, 0, screen->w, screen->h); |
407 |
break;
|
408 |
case SDL_KEYDOWN:
|
409 |
case SDL_KEYUP:
|
410 |
if (ev->type == SDL_KEYDOWN) {
|
411 |
mod_state = (SDL_GetModState() & gui_grab_code) == |
412 |
gui_grab_code; |
413 |
gui_key_modifier_pressed = mod_state; |
414 |
if (gui_key_modifier_pressed) {
|
415 |
int keycode;
|
416 |
keycode = sdl_keyevent_to_keycode(&ev->key); |
417 |
switch(keycode) {
|
418 |
case 0x21: /* 'f' key on US keyboard */ |
419 |
toggle_full_screen(ds); |
420 |
gui_keysym = 1;
|
421 |
break;
|
422 |
case 0x02 ... 0x0a: /* '1' to '9' keys */ |
423 |
/* Reset the modifiers sent to the current console */
|
424 |
reset_keys(); |
425 |
console_select(keycode - 0x02);
|
426 |
if (!is_graphic_console()) {
|
427 |
/* display grab if going to a text console */
|
428 |
if (gui_grab)
|
429 |
sdl_grab_end(); |
430 |
} |
431 |
gui_keysym = 1;
|
432 |
break;
|
433 |
default:
|
434 |
break;
|
435 |
} |
436 |
} else if (!is_graphic_console()) { |
437 |
int keysym;
|
438 |
keysym = 0;
|
439 |
if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
|
440 |
switch(ev->key.keysym.sym) {
|
441 |
case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break; |
442 |
case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break; |
443 |
case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break; |
444 |
case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break; |
445 |
case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break; |
446 |
case SDLK_END: keysym = QEMU_KEY_CTRL_END; break; |
447 |
case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break; |
448 |
case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break; |
449 |
default: break; |
450 |
} |
451 |
} else {
|
452 |
switch(ev->key.keysym.sym) {
|
453 |
case SDLK_UP: keysym = QEMU_KEY_UP; break; |
454 |
case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break; |
455 |
case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break; |
456 |
case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break; |
457 |
case SDLK_HOME: keysym = QEMU_KEY_HOME; break; |
458 |
case SDLK_END: keysym = QEMU_KEY_END; break; |
459 |
case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break; |
460 |
case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break; |
461 |
case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break; case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break; |
462 |
default: break; |
463 |
} |
464 |
} |
465 |
if (keysym) {
|
466 |
kbd_put_keysym(keysym); |
467 |
} else if (ev->key.keysym.unicode != 0) { |
468 |
kbd_put_keysym(ev->key.keysym.unicode); |
469 |
} |
470 |
} |
471 |
} else if (ev->type == SDL_KEYUP) { |
472 |
mod_state = (ev->key.keysym.mod & gui_grab_code); |
473 |
if (!mod_state) {
|
474 |
if (gui_key_modifier_pressed) {
|
475 |
gui_key_modifier_pressed = 0;
|
476 |
if (gui_keysym == 0) { |
477 |
/* exit/enter grab if pressing Ctrl-Alt */
|
478 |
if (!gui_grab) {
|
479 |
/* if the application is not active,
|
480 |
do not try to enter grab state. It
|
481 |
prevents
|
482 |
'SDL_WM_GrabInput(SDL_GRAB_ON)'
|
483 |
from blocking all the application
|
484 |
(SDL bug). */
|
485 |
if (SDL_GetAppState() & SDL_APPACTIVE)
|
486 |
sdl_grab_start(); |
487 |
} else {
|
488 |
sdl_grab_end(); |
489 |
} |
490 |
/* SDL does not send back all the
|
491 |
modifiers key, so we must correct it */
|
492 |
reset_keys(); |
493 |
break;
|
494 |
} |
495 |
gui_keysym = 0;
|
496 |
} |
497 |
} |
498 |
} |
499 |
if (is_graphic_console() && !gui_keysym)
|
500 |
sdl_process_key(&ev->key); |
501 |
break;
|
502 |
case SDL_QUIT:
|
503 |
if (!no_quit) {
|
504 |
qemu_system_shutdown_request(); |
505 |
} |
506 |
break;
|
507 |
case SDL_MOUSEMOTION:
|
508 |
if (gui_grab || kbd_mouse_is_absolute() ||
|
509 |
absolute_enabled) { |
510 |
sdl_send_mouse_event(0);
|
511 |
} |
512 |
break;
|
513 |
case SDL_MOUSEBUTTONDOWN:
|
514 |
case SDL_MOUSEBUTTONUP:
|
515 |
{ |
516 |
SDL_MouseButtonEvent *bev = &ev->button; |
517 |
if (!gui_grab && !kbd_mouse_is_absolute()) {
|
518 |
if (ev->type == SDL_MOUSEBUTTONDOWN &&
|
519 |
(bev->state & SDL_BUTTON_LMASK)) { |
520 |
/* start grabbing all events */
|
521 |
sdl_grab_start(); |
522 |
} |
523 |
} else {
|
524 |
int dz;
|
525 |
dz = 0;
|
526 |
#ifdef SDL_BUTTON_WHEELUP
|
527 |
if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
|
528 |
dz = -1;
|
529 |
} else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) { |
530 |
dz = 1;
|
531 |
} |
532 |
#endif
|
533 |
sdl_send_mouse_event(dz); |
534 |
} |
535 |
} |
536 |
break;
|
537 |
case SDL_ACTIVEEVENT:
|
538 |
if (gui_grab && ev->active.state == SDL_APPINPUTFOCUS &&
|
539 |
!ev->active.gain && !gui_fullscreen_initial_grab) { |
540 |
sdl_grab_end(); |
541 |
} |
542 |
break;
|
543 |
default:
|
544 |
break;
|
545 |
} |
546 |
} |
547 |
} |
548 |
|
549 |
static void sdl_cleanup(void) |
550 |
{ |
551 |
SDL_Quit(); |
552 |
} |
553 |
|
554 |
void sdl_display_init(DisplayState *ds, int full_screen) |
555 |
{ |
556 |
int flags;
|
557 |
uint8_t data = 0;
|
558 |
|
559 |
#if defined(__APPLE__)
|
560 |
/* always use generic keymaps */
|
561 |
if (!keyboard_layout)
|
562 |
keyboard_layout = "en-us";
|
563 |
#endif
|
564 |
if(keyboard_layout) {
|
565 |
kbd_layout = init_keyboard_layout(keyboard_layout); |
566 |
if (!kbd_layout)
|
567 |
exit(1);
|
568 |
} |
569 |
|
570 |
flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; |
571 |
if (SDL_Init (flags)) {
|
572 |
fprintf(stderr, "Could not initialize SDL - exiting\n");
|
573 |
exit(1);
|
574 |
} |
575 |
#ifndef _WIN32
|
576 |
/* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */
|
577 |
signal(SIGINT, SIG_DFL); |
578 |
signal(SIGQUIT, SIG_DFL); |
579 |
#endif
|
580 |
|
581 |
ds->dpy_update = sdl_update; |
582 |
ds->dpy_resize = sdl_resize; |
583 |
ds->dpy_refresh = sdl_refresh; |
584 |
|
585 |
sdl_resize(ds, 640, 400); |
586 |
sdl_update_caption(); |
587 |
SDL_EnableKeyRepeat(250, 50); |
588 |
SDL_EnableUNICODE(1);
|
589 |
gui_grab = 0;
|
590 |
|
591 |
sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0); |
592 |
sdl_cursor_normal = SDL_GetCursor(); |
593 |
|
594 |
atexit(sdl_cleanup); |
595 |
if (full_screen) {
|
596 |
gui_fullscreen = 1;
|
597 |
gui_fullscreen_initial_grab = 1;
|
598 |
sdl_grab_start(); |
599 |
} |
600 |
} |