#[cfg(target_os = "windows")]
use crate::input::backends::{Backend, ControllerInfo, ControllerType, HatState, RawInput};
#[cfg(target_os = "windows")]
use anyhow::Result;
#[cfg(target_os = "windows")]
pub struct XInputBackend {
controllers: Vec<bool>, }
#[cfg(target_os = "windows")]
impl XInputBackend {
pub fn new() -> Result<Self> {
Ok(Self {
controllers: vec![false; 4], })
}
}
#[cfg(target_os = "windows")]
impl Backend for XInputBackend {
fn update(&mut self) -> Result<()> {
Ok(())
}
fn enumerate_controllers(&mut self) -> Result<Vec<ControllerInfo>> {
let mut controllers = Vec::new();
for i in 0..4 {
controllers.push(ControllerInfo {
id: i,
name: format!("Xbox Controller {}", i + 1),
controller_type: ControllerType::Xbox,
button_count: 10,
axis_count: 6,
});
}
Ok(controllers)
}
fn get_input(&self, controller_id: usize) -> Result<RawInput> {
if controller_id >= 4 {
anyhow::bail!("Invalid XInput controller ID: {}", controller_id);
}
Ok(RawInput {
buttons: vec![false; 10],
axes: vec![0.0; 6],
triggers: vec![0.0; 2],
hat: None,
})
}
}