From 61532f7b459aed751da4489d1f050ab909e1d0c5 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Wed, 6 May 2026 22:09:21 +0200 Subject: [PATCH] move sdl init (#848) * move sdl init * more * more * more * more --- src/main.rs | 56 +++++++++++++++++++++++++++---------------------- src/ui/gui.rs | 2 ++ src/ui/input.rs | 4 +++- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index c488057..03294af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,15 +251,6 @@ async fn main() -> std::io::Result<()> { } else if std::env::args().count() > 1 { let mut config = ui::config::Config::new(); - if args.clear_input_bindings { - ui::input::clear_bindings(&mut config); - return Ok(()); - } - if let Some(port) = args.port - && !(1..=4).contains(&port) - { - return Err(Error::other("Port must be between 1 and 4")); - } if let Some(profile) = args.configure_input_profile { ui::input::configure_input_profile( &mut config, @@ -270,24 +261,39 @@ async fn main() -> std::io::Result<()> { ui::sdl_close(); return Ok(()); - } - if args.list_controllers { - let controllers = ui::input::get_controller_names(); - for (i, controller) in controllers.iter().enumerate() { - println!("Controller {i}: {controller}"); - } } else { - if let Some(assign_controller) = args.assign_controller { - let Some(port) = args.port else { - return Err(Error::other("Must specify port number")); - }; - ui::input::assign_controller(&mut config, assign_controller - 1, port); + if args.clear_input_bindings { + ui::input::clear_bindings(&mut config); + return Ok(()); } - if let Some(profile) = args.bind_input_profile { - let Some(port) = args.port else { - return Err(Error::other("Must specify port number")); - }; - ui::input::bind_input_profile(&mut config, profile, port); + if let Some(port) = args.port + && !(1..=4).contains(&port) + { + return Err(Error::other("Port must be between 1 and 4")); + } + + ui::sdl_init(sdl3_sys::init::SDL_INIT_GAMEPAD); + + if args.list_controllers { + let controllers = ui::input::get_controller_names(); + for (i, controller) in controllers.iter().enumerate() { + println!("Controller {i}: {controller}"); + } + } else { + if let Some(assign_controller) = args.assign_controller { + let Some(port) = args.port else { + ui::sdl_close(); + return Err(Error::other("Must specify port number")); + }; + ui::input::assign_controller(&mut config, assign_controller - 1, port); + } + if let Some(profile) = args.bind_input_profile { + let Some(port) = args.port else { + ui::sdl_close(); + return Err(Error::other("Must specify port number")); + }; + ui::input::bind_input_profile(&mut config, profile, port); + } } } } else { diff --git a/src/ui/gui.rs b/src/ui/gui.rs index ad1a31f..9ef1a96 100644 --- a/src/ui/gui.rs +++ b/src/ui/gui.rs @@ -220,6 +220,8 @@ fn clear_gb_paths(weak: &slint::Weak, player: i32) { } fn controller_window(app: &AppWindow, config: &ui::config::Config) { + ui::sdl_init(sdl3_sys::init::SDL_INIT_GAMEPAD); + app.set_emulate_vru(config.input.emulate_vru); app.set_controller_enabled(slint::ModelRc::from(std::rc::Rc::new( diff --git a/src/ui/input.rs b/src/ui/input.rs index 4bcad52..5d9a3f0 100644 --- a/src/ui/input.rs +++ b/src/ui/input.rs @@ -618,6 +618,7 @@ pub fn configure_input_profile( deadzone: i32, ) { ui::sdl_init(sdl3_sys::init::SDL_INIT_VIDEO); + ui::sdl_init(sdl3_sys::init::SDL_INIT_GAMEPAD); ui::ttf_init(); if profile == "default" { @@ -1060,7 +1061,6 @@ pub fn get_default_profile() -> ui::config::InputProfile { } fn get_joysticks() -> Vec { - ui::sdl_init(sdl3_sys::init::SDL_INIT_GAMEPAD); unsafe { sdl3_sys::events::SDL_PumpEvents() }; let mut num_joysticks = 0; let sdl_joysticks = unsafe { sdl3_sys::joystick::SDL_GetJoysticks(&mut num_joysticks) }; @@ -1076,6 +1076,8 @@ fn get_joysticks() -> Vec { } pub fn init(ui: &mut ui::Ui) { + ui::sdl_init(sdl3_sys::init::SDL_INIT_GAMEPAD); + ui.input.keyboard_state = unsafe { sdl3_sys::keyboard::SDL_GetKeyboardState(std::ptr::null_mut()) }; if ui.input.keyboard_state.is_null() {