From 24e5a3fac4c5fb1b9a3c6491d3b66637f6e70ba8 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Fri, 29 May 2026 16:51:27 +0200 Subject: [PATCH] move joystick update (#985) --- src/device/controller.rs | 4 ++-- src/ui.rs | 7 +++++++ src/ui/input.rs | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/device/controller.rs b/src/device/controller.rs index 1fd76eb6..6a761fd1 100644 --- a/src/device/controller.rs +++ b/src/device/controller.rs @@ -58,12 +58,12 @@ pub fn process(device: &mut device::Device, channel: usize) { let offset = device.pif.channels[channel].rx_buf.unwrap(); let input = if let Some(netplay) = &mut device.netplay { if netplay.player_number as usize == channel { - let local_input = ui::input::get(&mut device.ui, 0); + let local_input = ui::input::get(&mut device.ui, 0, device.vi.vi_counter); netplay::send_input(netplay, local_input); } netplay::get_input(device, channel) } else { - ui::input::get(&mut device.ui, channel) + ui::input::get(&mut device.ui, channel, device.vi.vi_counter) }; device.pif.ram[offset..offset + 4].copy_from_slice(&input.data.to_ne_bytes()); diff --git a/src/ui.rs b/src/ui.rs index 87d6488c..b1a14bfd 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -42,6 +42,7 @@ pub struct Audio { pub struct Input { pub keyboard_state: *const bool, + pub last_polled: u64, pub controllers: [input::Controllers; 4], } @@ -97,6 +98,11 @@ pub fn sdl_hints() { sdl3_sys::everything::SDL_HINT_ANDROID_ALLOW_RECREATE_ACTIVITY, hint.as_ptr(), ); + let hint = std::ffi::CString::new("0").unwrap(); + sdl3_sys::everything::SDL_SetHint( + sdl3_sys::everything::SDL_HINT_AUTO_UPDATE_JOYSTICKS, + hint.as_ptr(), + ); } } @@ -165,6 +171,7 @@ impl Ui { let (vis_tx, vis_rx) = tokio::sync::mpsc::channel(1000); Ui { input: Input { + last_polled: 0, controllers: [ input::Controllers { game_controller: std::ptr::null_mut(), diff --git a/src/ui/input.rs b/src/ui/input.rs index 635716fb..77e06ba5 100644 --- a/src/ui/input.rs +++ b/src/ui/input.rs @@ -490,9 +490,14 @@ fn handle_hotkeys(keys: u32, last_key_state: u32) { } } -pub fn get(ui: &mut ui::Ui, channel: usize) -> InputData { +pub fn get(ui: &mut ui::Ui, channel: usize, vi_counter: u64) -> InputData { handle_joystick_events(ui); + if ui.input.last_polled != vi_counter { + ui.input.last_polled = vi_counter; + unsafe { sdl3_sys::joystick::SDL_UpdateJoysticks() }; + } + let profile_name = &ui.config.input.input_profile_binding[channel]; let Some(profile) = ui.config.input.input_profiles.get(profile_name) else { eprintln!("Invalid profile name: {profile_name}");