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:
@@ -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),
|
||||
@@ -78,6 +80,7 @@ fn handle_input(snake: &mut Snake) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn wait_tick() {
|
||||
let start = syscall::get_time();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user