aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-07-22 21:25:45 +0200
committerAstatin <[email protected]>2025-07-22 21:25:45 +0200
commitd175756707970532f7bb25358e7fca412b596c66 (patch)
tree71e09ebd7e41abb4cff0c5640b0b63f1f3340a79
parentd630494d65129393645a414cf0ea1adbe9c401c4 (diff)
Disconnect/reconnect gamepads during play
-rw-r--r--src/desktop/input.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/desktop/input.rs b/src/desktop/input.rs
index 55bbfb3..ed604e2 100644
--- a/src/desktop/input.rs
+++ b/src/desktop/input.rs
@@ -42,6 +42,18 @@ impl Gamepad {
impl Input for Gamepad {
fn update_events(&mut self, _cycles: u128) -> Option<u128> {
+ if let Some(gamepad_id) = self.gamepad_id {
+ if self.gilrs.connected_gamepad(gamepad_id).is_none() {
+ println!("Gamepad (id = {:?}) disconnected", gamepad_id);
+ self.gamepad_id = None;
+ }
+ } else {
+ if let Some((gamepad_id, _gamepad)) = self.gilrs.gamepads().next() {
+ println!("Found Gamepad id: {:?}", gamepad_id);
+ self.gamepad_id = Some(gamepad_id);
+ }
+ }
+
while let Some(_) = self.gilrs.next_event() {}
None
}