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,16 +65,19 @@ extern "C" fn main() {
}
fn handle_input(snake: &mut Snake) {
let _ = syscall::send(INPUT_EP, 0, 0, 0, 0);
let (tag, kind, _, _) = syscall::receive(INPUT_EP);
if tag == 1 {
match kind {
0 => snake.set_direction(Direction::Up),
1 => snake.set_direction(Direction::Down),
2 => snake.set_direction(Direction::Left),
3 => snake.set_direction(Direction::Right),
_ => {}
// 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),
1 => snake.set_direction(Direction::Down),
2 => snake.set_direction(Direction::Left),
3 => snake.set_direction(Direction::Right),
_ => {}
}
}
}
}