Revision 09b26c5e sdl.c
b/sdl.c | ||
---|---|---|
39 | 39 |
static int gui_fullscreen_initial_grab; |
40 | 40 |
static int gui_grab_code = KMOD_LALT | KMOD_LCTRL; |
41 | 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; |
|
42 | 46 |
|
43 | 47 |
static void sdl_update(DisplayState *ds, int x, int y, int w, int h) |
44 | 48 |
{ |
... | ... | |
56 | 60 |
if (gui_fullscreen) |
57 | 61 |
flags |= SDL_FULLSCREEN; |
58 | 62 |
|
63 |
width = w; |
|
64 |
height = h; |
|
65 |
|
|
59 | 66 |
again: |
60 | 67 |
screen = SDL_SetVideoMode(w, h, 0, flags); |
61 | 68 |
if (!screen) { |
... | ... | |
271 | 278 |
SDL_WM_SetCaption(buf, "QEMU"); |
272 | 279 |
} |
273 | 280 |
|
281 |
static void sdl_hide_cursor(void) |
|
282 |
{ |
|
283 |
SDL_SetCursor(sdl_cursor_hidden); |
|
284 |
} |
|
285 |
|
|
286 |
static void sdl_show_cursor(void) |
|
287 |
{ |
|
288 |
if (!kbd_mouse_is_absolute()) { |
|
289 |
SDL_SetCursor(sdl_cursor_normal); |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
274 | 293 |
static void sdl_grab_start(void) |
275 | 294 |
{ |
276 |
SDL_ShowCursor(0);
|
|
295 |
sdl_hide_cursor();
|
|
277 | 296 |
SDL_WM_GrabInput(SDL_GRAB_ON); |
278 | 297 |
/* dummy read to avoid moving the mouse */ |
279 | 298 |
SDL_GetRelativeMouseState(NULL, NULL); |
... | ... | |
284 | 303 |
static void sdl_grab_end(void) |
285 | 304 |
{ |
286 | 305 |
SDL_WM_GrabInput(SDL_GRAB_OFF); |
287 |
SDL_ShowCursor(1);
|
|
306 |
sdl_show_cursor();
|
|
288 | 307 |
gui_grab = 0; |
289 | 308 |
sdl_update_caption(); |
290 | 309 |
} |
... | ... | |
300 | 319 |
buttons |= MOUSE_EVENT_RBUTTON; |
301 | 320 |
if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) |
302 | 321 |
buttons |= MOUSE_EVENT_MBUTTON; |
322 |
|
|
323 |
if (kbd_mouse_is_absolute()) { |
|
324 |
if (!absolute_enabled) { |
|
325 |
sdl_hide_cursor(); |
|
326 |
if (gui_grab) { |
|
327 |
sdl_grab_end(); |
|
328 |
} |
|
329 |
absolute_enabled = 1; |
|
330 |
} |
|
331 |
|
|
332 |
SDL_GetMouseState(&dx, &dy); |
|
333 |
dx = dx * 0x7FFF / width; |
|
334 |
dy = dy * 0x7FFF / height; |
|
335 |
} |
|
336 |
|
|
303 | 337 |
kbd_mouse_event(dx, dy, dz, buttons); |
304 | 338 |
} |
305 | 339 |
|
... | ... | |
423 | 457 |
qemu_system_shutdown_request(); |
424 | 458 |
break; |
425 | 459 |
case SDL_MOUSEMOTION: |
426 |
if (gui_grab) { |
|
460 |
if (gui_grab || kbd_mouse_is_absolute()) {
|
|
427 | 461 |
sdl_send_mouse_event(0); |
428 | 462 |
} |
429 | 463 |
break; |
... | ... | |
431 | 465 |
case SDL_MOUSEBUTTONUP: |
432 | 466 |
{ |
433 | 467 |
SDL_MouseButtonEvent *bev = &ev->button; |
434 |
if (!gui_grab) { |
|
468 |
if (!gui_grab && !kbd_mouse_is_absolute()) {
|
|
435 | 469 |
if (ev->type == SDL_MOUSEBUTTONDOWN && |
436 | 470 |
(bev->state & SDL_BUTTON_LMASK)) { |
437 | 471 |
/* start grabbing all events */ |
... | ... | |
441 | 475 |
int dz; |
442 | 476 |
dz = 0; |
443 | 477 |
#ifdef SDL_BUTTON_WHEELUP |
444 |
if (bev->button == SDL_BUTTON_WHEELUP) { |
|
478 |
if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
|
|
445 | 479 |
dz = -1; |
446 |
} else if (bev->button == SDL_BUTTON_WHEELDOWN) { |
|
480 |
} else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
|
|
447 | 481 |
dz = 1; |
448 | 482 |
} |
449 | 483 |
#endif |
... | ... | |
471 | 505 |
void sdl_display_init(DisplayState *ds, int full_screen) |
472 | 506 |
{ |
473 | 507 |
int flags; |
508 |
uint8_t data = 0; |
|
474 | 509 |
|
475 | 510 |
#if defined(__APPLE__) |
476 | 511 |
/* always use generic keymaps */ |
... | ... | |
504 | 539 |
SDL_EnableUNICODE(1); |
505 | 540 |
gui_grab = 0; |
506 | 541 |
|
542 |
sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0); |
|
543 |
sdl_cursor_normal = SDL_GetCursor(); |
|
544 |
|
|
507 | 545 |
atexit(sdl_cleanup); |
508 | 546 |
if (full_screen) { |
509 | 547 |
gui_fullscreen = 1; |
Also available in: Unified diff