From 954aea1babc7097bab85d075345041aff82ba7ea Mon Sep 17 00:00:00 2001 From: "Derek J. Clark" Date: Mon, 14 Sep 2026 17:02:34 -0700 Subject: [PATCH] fix(Composite Device): Increase minimum event delay. Some devices, such as the ROG Ally X and various OneXPlayer devices, emit chord events on release of their extra buttons rather than when a down or up action is taken. These typically trigger in fraction of a millisecond and, if translated directly to userspace, are typically to fast to be handled by userspace. Previously an attempt was done to handle this in target device handling to ensure that each input frame had a distinct event. That caused various issues with events getting turned off when held or events getting stuck on, so it was removed. The problem still exists, however, so it is beneficial to find a universal solution. At 4ms, the event delay is equivalent to 1 frame at 250Hz. Increasing that to 16ms is just under 1 frame at 60Hz, which is the baseline frame pacing for most games and at least 2 input frames for target devices running at 125Hz. - Add a global const to that this can be further tweaked later if necessary. - Increase the minimum event delay to 16ms. This was tested on the ROG Ally X and the Lenovo Legion Go S to ensure that: - The primary complaint is resolved. - Regular events never hit the delay threshold and add input latency when not wanted. --- src/input/composite_device/mod.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/input/composite_device/mod.rs b/src/input/composite_device/mod.rs index 144372ad..74e8c40e 100644 --- a/src/input/composite_device/mod.rs +++ b/src/input/composite_device/mod.rs @@ -69,6 +69,10 @@ pub enum InterceptMode { GamepadOnly, } +/// The minimum time permitted between DOWN and UP button events for +/// userspace to see a valid input. +const MIN_EVENT_TIME: Duration = Duration::from_millis(16); + /// A [CompositeDevice] represents any number source input devices that /// can translate input to any target devices #[derive(Debug)] @@ -1138,13 +1142,12 @@ impl CompositeDevice { self.is_new_active_event(&cap, event.pressed()); // Check to see if the event is in recently translated. // If it is, spawn a task to delay emit the event. - let sleep_time = Duration::from_millis(4); let cap = event.as_capability(); - if self.translated_recent_events.contains(&cap) { + if self.translated_recent_events.contains(&cap) && !event.pressed() { log::debug!("Event emitted too quickly. Delaying emission."); let tx = self.tx.clone(); tokio::task::spawn(async move { - tokio::time::sleep(sleep_time).await; + tokio::time::sleep(MIN_EVENT_TIME).await; if let Err(e) = tx.send(CompositeCommand::WriteEvent(event)).await { log::error!("Failed to send delayed event command: {:?}", e); } @@ -1159,7 +1162,7 @@ impl CompositeDevice { // Spawn a task to remove the event from recent translated let tx = self.tx.clone(); tokio::task::spawn(async move { - tokio::time::sleep(sleep_time).await; + tokio::time::sleep(MIN_EVENT_TIME).await; if let Err(e) = tx.send(CompositeCommand::RemoveRecentEvent(cap)).await { log::error!("Failed to send remove recent event command: {:?}", e); } @@ -1434,16 +1437,15 @@ impl CompositeDevice { // Emit the translated events. If this translated event has been emitted // very recently, delay sending subsequent events of the same type. - let sleep_time = Duration::from_millis(4); for event in emit_queue { // Check to see if the event is in recently translated. // If it is, spawn a task to delay emit the event. let cap = event.as_capability(); - if self.translated_recent_events.contains(&cap) { + if self.translated_recent_events.contains(&cap) && !event.pressed() { log::debug!("Event emitted too quickly. Delaying emission."); let tx = self.tx.clone(); tokio::task::spawn(async move { - tokio::time::sleep(sleep_time).await; + tokio::time::sleep(MIN_EVENT_TIME).await; if let Err(e) = tx.send(CompositeCommand::HandleEvent(event)).await { log::error!("Failed to send delayed event command: {:?}", e); } @@ -1458,7 +1460,7 @@ impl CompositeDevice { // Spawn a task to remove the event from recent translated let tx = self.tx.clone(); tokio::task::spawn(async move { - tokio::time::sleep(sleep_time).await; + tokio::time::sleep(MIN_EVENT_TIME).await; if let Err(e) = tx.send(CompositeCommand::RemoveRecentEvent(cap)).await { log::error!("Failed to send remove recent event command: {:?}", e); }