From a1e317f6f57a31a9800f3631dc3f09d7a5b90855 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 30 Jul 2008 16:46:30 +0100 Subject: [PATCH] fix SDL mouse events processing This fixes SDL mouse events processing: - GetRelativeMouseState() always returns the last position, so when the polling loop gets several mouse events in one go, we would send useless 'no move' events, let's avoid that. - So as to make sure we don't miss any mouse click / double click, we should not use GetRelativeMouseState() to get the button state, but rather keep records of the button state ourselves (I've requested SDL developers to provide it directly in the event in SDL 1.3). - bev->state doesn't contain the button state but whether the event is a press or a release. Use bev->button instead. Signed-off-by: Samuel Thibault Signed-off-by: Stefano Stabellini --- sdl.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/sdl.c b/sdl.c index 72e7d821..9afd8840 100644 --- a/sdl.c +++ b/sdl.c @@ -492,8 +492,6 @@ static void sdl_grab_start(void) { sdl_hide_cursor(); SDL_WM_GrabInput(SDL_GRAB_ON); - /* dummy read to avoid moving the mouse */ - SDL_GetRelativeMouseState(NULL, NULL); gui_grab = 1; sdl_update_caption(); } @@ -685,39 +683,37 @@ static void sdl_refresh(DisplayState *ds) absolute_enabled) { int dx, dy, state; state = SDL_GetRelativeMouseState(&dx, &dy); - sdl_send_mouse_event(dx, dy, 0, state); + if (dx || dy) + sdl_send_mouse_event(dx, dy, 0, state); } break; case SDL_MOUSEBUTTONUP: - if (gui_grab || kbd_mouse_is_absolute()) { - int dx, dy, state; - state = SDL_GetRelativeMouseState(&dx, &dy); - sdl_send_mouse_event(dx, dy, 0, state); - } - break; case SDL_MOUSEBUTTONDOWN: { SDL_MouseButtonEvent *bev = &ev->button; if (!gui_grab && !kbd_mouse_is_absolute()) { if (ev->type == SDL_MOUSEBUTTONDOWN && - (bev->state & SDL_BUTTON_LMASK)) { + (bev->button == SDL_BUTTON_LEFT)) { /* start grabbing all events */ sdl_grab_start(); } } else { - int dx, dy, dz, state; + int dz, state; dz = 0; - state = SDL_GetRelativeMouseState(&dx, &dy); + state = SDL_GetMouseState(NULL, NULL); + if (ev->type == SDL_MOUSEBUTTONDOWN) { + state |= SDL_BUTTON(bev->button); + } else { + state &= ~SDL_BUTTON(bev->button); + } #ifdef SDL_BUTTON_WHEELUP - if (bev->button == SDL_BUTTON_WHEELUP) { + if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) { dz = -1; - } else if (bev->button == SDL_BUTTON_WHEELDOWN) { + } else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) { dz = 1; - } else { - state = bev->button | state; } -#endif - sdl_send_mouse_event(dx, dy, dz, state); +#endif + sdl_send_mouse_event(0, 0, dz, state); } } break; -- 2.39.5