Skip to content

Commit

Permalink
fix: always process all events in the queue on x11. (#73)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
iwanders and amrbashir authored Apr 22, 2024
1 parent 9af0a80 commit 24f41b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/x11-pending-events-buildup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"global-hotkey": patch
---

Always service all pending events to avoid a queue of events from building up.
3 changes: 2 additions & 1 deletion src/platform_impl/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ fn events_processor(thread_rx: Receiver<ThreadMessage>) {
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 => {
Expand Down

0 comments on commit 24f41b0

Please sign in to comment.