move sdl init (#848)

* move sdl init

* more

* more

* more

* more
This commit is contained in:
Logan McNaughton 2026-05-06 22:09:21 +02:00 committed by GitHub
parent a69a74bf37
commit 61532f7b45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 26 deletions

View File

@ -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 {

View File

@ -220,6 +220,8 @@ fn clear_gb_paths(weak: &slint::Weak<AppWindow>, 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(

View File

@ -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<sdl3_sys::joystick::SDL_JoystickID> {
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<sdl3_sys::joystick::SDL_JoystickID> {
}
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() {