fix: VirtIO keyboard input latency and direction accuracy

- Driver now drains SYN/repeat/unknown events in a loop instead of
  returning None on the first non-key event
- Snake drains all pending input events per tick, applies only the
  latest direction change (prevents stale event accumulation)
This commit is contained in:
2026-10-19 00:34:13 +02:00
parent 0a47b5489a
commit 2792387348
2 changed files with 30 additions and 26 deletions

View File

@@ -129,28 +129,29 @@ fn linux_keycode_to_key(code: u16) -> Option<Key> {
impl InputDevice for VirtioInputDevice {
fn poll(&mut self) -> Option<InputEvent> {
let current_used = self.used_idx();
if current_used == self.last_used {
return None;
}
loop {
let current_used = self.used_idx();
if current_used == self.last_used {
return None;
}
let desc_idx = self.used_entry_id(self.last_used);
self.last_used = self.last_used.wrapping_add(1);
let desc_idx = self.used_entry_id(self.last_used);
self.last_used = self.last_used.wrapping_add(1);
let (ev_type, ev_code, ev_value) = self.read_event(desc_idx);
self.resubmit(desc_idx);
let (ev_type, ev_code, ev_value) = self.read_event(desc_idx);
self.resubmit(desc_idx);
if ev_type == EV_KEY {
if let Some(key) = linux_keycode_to_key(ev_code) {
if ev_value == KEY_PRESS {
return Some(InputEvent::KeyDown(key));
} else if ev_value == 0 {
return Some(InputEvent::KeyUp(key));
if ev_type == EV_KEY {
if let Some(key) = linux_keycode_to_key(ev_code) {
if ev_value == KEY_PRESS {
return Some(InputEvent::KeyDown(key));
} else if ev_value == 0 {
return Some(InputEvent::KeyUp(key));
}
}
}
// Skip SYN events, repeats, and unknown keys — keep draining
}
None
}
fn has_event(&self) -> bool {