From 9193eab0357a88d2071811aaa6b4fc9805f21103 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Wed, 23 Mar 2022 14:36:41 -0700 Subject: [PATCH] Combine sequential mouse movement events Previously on Linux (not Windows), if you opened Klystrack and dragged with a high polling rate mouse, the program would lag processing SDL_MOUSEMOTION events and redrawing the screen. This fixes the bug. --- klystron | 2 +- src/help.c | 7 ++++--- src/import/hubdialog.c | 7 ++++--- src/main.c | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/klystron b/klystron index 10743245..bd87d618 160000 --- a/klystron +++ b/klystron @@ -1 +1 @@ -Subproject commit 10743245fbaf67fc02b432577dc4d47ad5e459da +Subproject commit bd87d618a48cd7c96ed1f3ee91380afbb2556e02 diff --git a/src/help.c b/src/help.c index 743afaa4..715f933d 100644 --- a/src/help.c +++ b/src/help.c @@ -342,9 +342,10 @@ int helpbox(const char *title, GfxDomain *domain, GfxSurface *gfx, const Font *l if (e.type != SDL_MOUSEMOTION || (e.motion.state)) ++got_event; - // ensure the last event is a mouse click so it gets passed to the draw/event code - - if (e.type == SDL_MOUSEBUTTONDOWN || (e.type == SDL_MOUSEMOTION && e.motion.state)) break; + // Process mouse click events immediately, and batch mouse motion events + // (process the last one) to fix lag with high poll rate mice on Linux. + if (should_process_mouse(&e)) + break; } if (got_event || gfx_domain_is_next_frame(domain)) diff --git a/src/import/hubdialog.c b/src/import/hubdialog.c index 7f2ca18e..da4fdef3 100644 --- a/src/import/hubdialog.c +++ b/src/import/hubdialog.c @@ -221,9 +221,10 @@ int hub_view(hubbard_t *hub) if (e.type != SDL_MOUSEMOTION || (e.motion.state)) ++got_event; - // ensure the last event is a mouse click so it gets passed to the draw/event code - - if (e.type == SDL_MOUSEBUTTONDOWN || (e.type == SDL_MOUSEMOTION && e.motion.state)) break; + // Process mouse click events immediately, and batch mouse motion events + // (process the last one) to fix lag with high poll rate mice on Linux. + if (should_process_mouse(&e)) + break; } if (got_event || gfx_domain_is_next_frame(domain)) diff --git a/src/main.c b/src/main.c index f4aa2b3b..83e9b2c8 100644 --- a/src/main.c +++ b/src/main.c @@ -491,9 +491,9 @@ int main(int argc, char **argv) if (e.type != SDL_MOUSEMOTION || (e.motion.state) || (e.type == SDL_MOUSEMOTION && mused.mode == MENU)) ++got_event; - // ensure the last event is a mouse click so it gets passed to the draw/event code - - if (e.type == SDL_MOUSEBUTTONDOWN || (e.type == SDL_MOUSEMOTION && e.motion.state)) + // Process mouse click events immediately, and batch mouse motion events + // (process the last one) to fix lag with high poll rate mice on Linux. + if (should_process_mouse(&e)) break; }