@@ -8,7 +8,7 @@ use lazy_static::lazy_static;
88use num_enum:: IntoPrimitive ;
99use std:: cmp:: min;
1010use std:: collections:: HashMap ;
11-
11+ use fragile :: Fragile ;
1212use argus_wm:: WindowManager ;
1313use sdl3:: event:: Event as SdlEvent ;
1414use sdl3:: gamepad:: Axis as SdlGamepadAxis ;
@@ -251,14 +251,14 @@ fn normalize_axis(val: i16) -> f64 {
251251 }
252252}
253253
254- fn poll_gamepad ( devices_state : & mut GamepadDevicesState , id : HidDeviceInstanceId ) {
254+ fn poll_gamepad ( devices_state : & GamepadDevicesState , id : HidDeviceInstanceId ) {
255255 let Ok ( gamepad) = InputManager :: instance ( ) . get_sdl_gamepad_ss ( ) . unwrap ( ) . open ( id) else {
256256 warn ! ( LOGGER , "Failed to get SDL controller from instance ID {}" , id) ;
257257 return ;
258258 } ;
259259
260260 let controller_opt = devices_state. mapped_gamepads . get ( & id)
261- . map ( |name| InputManager :: instance ( ) . get_controller ( name) ) ;
261+ . map ( |( _ , name) | InputManager :: instance ( ) . get_controller ( name) ) ;
262262
263263 let mut new_button_state: GamepadButtonState = 0 ;
264264 let mut i = 0 ;
@@ -499,7 +499,7 @@ fn handle_gamepad_events(devices_state: &mut GamepadDevicesState) {
499499
500500 let mut devices_state =
501501 InputManager :: instance ( ) . gamepad_devices_state . write ( ) ;
502- if let Some ( controller_name) =
502+ if let Some ( ( _ , controller_name) ) =
503503 devices_state. mapped_gamepads . get ( & instance_id) {
504504 match InputManager :: instance ( ) . controllers . get_mut ( controller_name) {
505505 Some ( mut controller) => {
@@ -554,8 +554,8 @@ pub(crate) fn update_gamepads() {
554554 poll_gamepad ( & mut devices_state, gamepad_id) ;
555555 }
556556
557- for ( gamepad_id, _) in devices_state. mapped_gamepads . clone ( ) {
558- poll_gamepad ( & mut devices_state, gamepad_id) ;
557+ for ( & gamepad_id, _) in & devices_state. mapped_gamepads {
558+ poll_gamepad ( & devices_state, gamepad_id) ;
559559 }
560560}
561561
@@ -578,7 +578,9 @@ pub(crate) fn assoc_gamepad(id: HidDeviceInstanceId, controller_name: impl Into<
578578 } ;
579579
580580 gamepads. remove ( pos) ;
581- devices_state. mapped_gamepads . insert ( id, controller_name. into ( ) ) ;
581+ let gamepad = InputManager :: instance ( ) . get_sdl_gamepad_ss ( ) . unwrap ( ) . open ( id)
582+ . map_err ( |e| e. to_string ( ) ) ?;
583+ devices_state. mapped_gamepads . insert ( id, ( Fragile :: new ( gamepad) , controller_name. into ( ) ) ) ;
582584
583585 Ok ( ( ) )
584586}
0 commit comments