Commit 4c44bdcb704945980898a04c556d1377c267a3f1

Authored by aurel32
1 parent 80621676

SDL mouse events smoothness

(Samuel Thibault)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4049 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 20 additions and 16 deletions
... ... @@ -276,8 +276,6 @@ static void sdl_grab_start(void)
276 276 } else
277 277 sdl_hide_cursor();
278 278 SDL_WM_GrabInput(SDL_GRAB_ON);
279   - /* dummy read to avoid moving the mouse */
280   - SDL_GetRelativeMouseState(NULL, NULL);
281 279 gui_grab = 1;
282 280 sdl_update_caption();
283 281 }
... ... @@ -290,10 +288,9 @@ static void sdl_grab_end(void)
290 288 sdl_update_caption();
291 289 }
292 290  
293   -static void sdl_send_mouse_event(int dz)
  291 +static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state)
294 292 {
295   - int dx, dy, state, buttons;
296   - state = SDL_GetRelativeMouseState(&dx, &dy);
  293 + int buttons;
297 294 buttons = 0;
298 295 if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
299 296 buttons |= MOUSE_EVENT_LBUTTON;
... ... @@ -311,18 +308,18 @@ static void sdl_send_mouse_event(int dz)
311 308 absolute_enabled = 1;
312 309 }
313 310  
314   - SDL_GetMouseState(&dx, &dy);
315   - dx = dx * 0x7FFF / (width - 1);
316   - dy = dy * 0x7FFF / (height - 1);
  311 + dx = x * 0x7FFF / (width - 1);
  312 + dy = y * 0x7FFF / (height - 1);
317 313 } else if (absolute_enabled) {
318 314 sdl_show_cursor();
319 315 absolute_enabled = 0;
320 316 } 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;
  317 + x -= guest_x;
  318 + y -= guest_y;
  319 + guest_x += x;
  320 + guest_y += y;
  321 + dx = x;
  322 + dy = y;
326 323 }
327 324  
328 325 kbd_mouse_event(dx, dy, dz, buttons);
... ... @@ -347,6 +344,7 @@ static void sdl_refresh(DisplayState *ds)
347 344 {
348 345 SDL_Event ev1, *ev = &ev1;
349 346 int mod_state;
  347 + int buttonstate = SDL_GetMouseState(NULL, NULL);
350 348  
351 349 if (last_vm_running != vm_running) {
352 350 last_vm_running = vm_running;
... ... @@ -474,7 +472,8 @@ static void sdl_refresh(DisplayState *ds)
474 472 case SDL_MOUSEMOTION:
475 473 if (gui_grab || kbd_mouse_is_absolute() ||
476 474 absolute_enabled) {
477   - sdl_send_mouse_event(0);
  475 + sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
  476 + ev->motion.x, ev->motion.y, ev->motion.state);
478 477 }
479 478 break;
480 479 case SDL_MOUSEBUTTONDOWN:
... ... @@ -483,13 +482,18 @@ static void sdl_refresh(DisplayState *ds)
483 482 SDL_MouseButtonEvent *bev = &ev->button;
484 483 if (!gui_grab && !kbd_mouse_is_absolute()) {
485 484 if (ev->type == SDL_MOUSEBUTTONDOWN &&
486   - (bev->state & SDL_BUTTON_LMASK)) {
  485 + (bev->button == SDL_BUTTON_LEFT)) {
487 486 /* start grabbing all events */
488 487 sdl_grab_start();
489 488 }
490 489 } else {
491 490 int dz;
492 491 dz = 0;
  492 + if (ev->type == SDL_MOUSEBUTTONDOWN) {
  493 + buttonstate |= SDL_BUTTON(bev->button);
  494 + } else {
  495 + buttonstate &= ~SDL_BUTTON(bev->button);
  496 + }
493 497 #ifdef SDL_BUTTON_WHEELUP
494 498 if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
495 499 dz = -1;
... ... @@ -497,7 +501,7 @@ static void sdl_refresh(DisplayState *ds)
497 501 dz = 1;
498 502 }
499 503 #endif
500   - sdl_send_mouse_event(dz);
  504 + sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
501 505 }
502 506 }
503 507 break;
... ...