From d2b3e385652945f70bde9e5ea80c7f1c5a7c08f2 Mon Sep 17 00:00:00 2001 From: Mia Herkt Date: Mon, 18 Jan 2021 03:20:57 +0100 Subject: [PATCH] visual typesetting: limit event frequency This change makes Aegisub a lot more responsive on platforms like X11 where mouse events may come in at very high frequencies and/or in bursts. --- src/visual_tool.cpp | 7 +++++++ src/visual_tool.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/visual_tool.cpp b/src/visual_tool.cpp index 24d1f40bb..e27a3c2b1 100644 --- a/src/visual_tool.cpp +++ b/src/visual_tool.cpp @@ -170,6 +170,13 @@ VisualTool::VisualTool(VideoDisplay *parent, agi::Context *context) template void VisualTool::OnMouseEvent(wxMouseEvent &event) { + // wx doesn’t throttle for us, updating the video view is + // very expensive, and aegisub’s work queue handling is bad, + // so limit mouse event rate to ~200 Hz + long ts = event.GetTimestamp(); + if ((ts - lastEvent) < 5) return; + lastEvent = ts; + bool left_click = event.LeftDown(); bool left_double = event.LeftDClick(); shift_down = event.ShiftDown(); diff --git a/src/visual_tool.h b/src/visual_tool.h index 5e62920ae..00b4da1c8 100644 --- a/src/visual_tool.h +++ b/src/visual_tool.h @@ -92,6 +92,7 @@ protected: bool holding = false; ///< Is a hold currently in progress? AssDialogue *active_line = nullptr; ///< Active dialogue line; nullptr if it is not visible on the current frame bool dragging = false; ///< Is a drag currently in progress? + long lastEvent = 0; int frame_number; ///< Current frame number