From 50981d418a3b043e361fb218d3b24cf08c09532c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 8 Jun 2015 02:58:46 -0400 Subject: [PATCH] x11: Drop duplicate XInput2 XI_RawMotion events. This happens when the pointer is grabbed, but it's not clear if this is a bug in x.org or my misunderstanding of the XGrabPointer() documentation. At any rate, we'll want to revisit this later for a better solution. Fixes Bugzilla #2963. --- src/video/x11/SDL_x11xinput2.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index db439ba72..c74e027ce 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -136,15 +136,25 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie) case XI_RawMotion: { const XIRawEvent *rawev = (const XIRawEvent*)cookie->data; SDL_Mouse *mouse = SDL_GetMouse(); - double relative_cords[2]; + double relative_coords[2]; + static Time prev_time = 0; + static double prev_rel_coords[2]; if (!mouse->relative_mode || mouse->relative_mode_warp) { return 0; } parse_valuators(rawev->raw_values,rawev->valuators.mask, - rawev->valuators.mask_len,relative_cords,2); - SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(int)relative_cords[0],(int)relative_cords[1]); + rawev->valuators.mask_len,relative_coords,2); + + if ((rawev->time == prev_time) && (relative_coords[0] == prev_rel_coords[0]) && (relative_coords[1] == prev_rel_coords[1])) { + return 0; /* duplicate event, drop it. */ + } + + SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(int)relative_coords[0],(int)relative_coords[1]); + prev_rel_coords[0] = relative_coords[0]; + prev_rel_coords[1] = relative_coords[1]; + prev_time = rawev->time; return 1; } break;