From 24f41b0fd9f54e822e6397bc95d9e717c67aab72 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Mon, 22 Apr 2024 10:38:42 -0400 Subject: [PATCH] fix: always process all events in the queue on x11. (#73) * Always process all events in the queue on x11. Previously, there was always a 50ms delay between processing individual events, which could lead to a queue of events building up if the key repeat was higher than 20 Hz. This resulted in the global hotkey release only being detected long after the key is released. * change file --------- Co-authored-by: Amr Bashir --- .changes/x11-pending-events-buildup.md | 5 +++++ src/platform_impl/x11/mod.rs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changes/x11-pending-events-buildup.md diff --git a/.changes/x11-pending-events-buildup.md b/.changes/x11-pending-events-buildup.md new file mode 100644 index 0000000..9ed5ce7 --- /dev/null +++ b/.changes/x11-pending-events-buildup.md @@ -0,0 +1,5 @@ +--- +"global-hotkey": patch +--- + +Always service all pending events to avoid a queue of events from building up. \ No newline at end of file diff --git a/src/platform_impl/x11/mod.rs b/src/platform_impl/x11/mod.rs index 509f1ad..ab8fd85 100644 --- a/src/platform_impl/x11/mod.rs +++ b/src/platform_impl/x11/mod.rs @@ -199,7 +199,8 @@ fn events_processor(thread_rx: Receiver) { let mut event: xlib::XEvent = std::mem::zeroed(); loop { - if (xlib.XPending)(display) > 0 { + // Always service all pending events to avoid a queue of events from building up. + while (xlib.XPending)(display) > 0 { (xlib.XNextEvent)(display, &mut event); match event.get_type() { e @ xlib::KeyPress | e @ xlib::KeyRelease => {