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

@@ -65,9 +65,11 @@ extern "C" fn main() {
}
fn handle_input(snake: &mut Snake) {
// Drain all pending events, apply the latest direction
loop {
let _ = syscall::send(INPUT_EP, 0, 0, 0, 0);
let (tag, kind, _, _) = syscall::receive(INPUT_EP);
if tag == 0 { break; } // NoEvent — queue drained
if tag == 1 {
match kind {
0 => snake.set_direction(Direction::Up),
@@ -77,6 +79,7 @@ fn handle_input(snake: &mut Snake) {
_ => {}
}
}
}
}
fn wait_tick() {

View File

@@ -129,6 +129,7 @@ fn linux_keycode_to_key(code: u16) -> Option<Key> {
impl InputDevice for VirtioInputDevice {
fn poll(&mut self) -> Option<InputEvent> {
loop {
let current_used = self.used_idx();
if current_used == self.last_used {
return None;
@@ -149,8 +150,8 @@ impl InputDevice for VirtioInputDevice {
}
}
}
None
// Skip SYN events, repeats, and unknown keys — keep draining
}
}
fn has_event(&self) -> bool {