From 203b2fcaca2851d4232a1b152b830569736f10d7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 4 Sep 2018 00:37:21 -0400 Subject: [PATCH] Batch mouse move events for high DPI mice --- app/streaming/input.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/streaming/input.cpp b/app/streaming/input.cpp index 1674a16e..9977041b 100644 --- a/app/streaming/input.cpp +++ b/app/streaming/input.cpp @@ -388,10 +388,29 @@ void SdlInputHandler::handleMouseMotionEvent(SDL_MouseMotionEvent* event) // Not capturing return; } + short xdelta = (short)event->xrel; + short ydelta = (short)event->yrel; - if (event->xrel != 0 || event->yrel != 0) { - LiSendMouseMoveEvent((short)event->xrel, - (short)event->yrel); + // Delay for 1 ms to allow batching of mouse move + // events from high DPI mice. + SDL_Delay(1); + SDL_PumpEvents(); + + SDL_Event nextEvent; + while (SDL_PeepEvents(&nextEvent, + 1, + SDL_GETEVENT, + SDL_MOUSEMOTION, + SDL_MOUSEMOTION) == 1) { + // In theory, these can overflow but in practice + // it should be highly unlikely since it would require + // moving 64K pixels in 1 ms. + xdelta += nextEvent.motion.xrel; + ydelta += nextEvent.motion.yrel; + } + + if (xdelta != 0 || ydelta != 0) { + LiSendMouseMoveEvent(xdelta, ydelta); } }