Skip to content

Commit 6a96612

Browse files
authored
Mark all keys as up if the app loses focus (#5743)
In Rerun, pressing `Cmd+S` brings up a save dialog using `rfd`, but we get not key-up event for the `S` key (in winit). This leads to `S` being mistakenly marked as down when we switch back to the app. This PR takes the safe route and marks all keys as up when an egui app loses focus. * Tested with rerun-io/rerun#9103
1 parent 27e7303 commit 6a96612

File tree

1 file changed

+8
-0
lines changed
  • crates/egui/src/input_state

1 file changed

+8
-0
lines changed

crates/egui/src/input_state/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,14 @@ impl InputState {
362362
Event::Zoom(factor) => {
363363
zoom_factor_delta *= *factor;
364364
}
365+
Event::WindowFocused(false) => {
366+
// Example: pressing `Cmd+S` brings up a save-dialog (e.g. using rfd),
367+
// but we get no key-up event for the `S` key (in winit).
368+
// This leads to `S` being mistakenly marked as down when we switch back to the app.
369+
// So we take the safe route and just clear all the keys and modifiers when
370+
// the app loses focus.
371+
keys_down.clear();
372+
}
365373
_ => {}
366374
}
367375
}

0 commit comments

Comments
 (0)