use crate::proto::unsafe_protocol;
use crate::{Error, Event, Result, Status, StatusExt};
use uefi_raw::protocol::console::SimplePointerProtocol;
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(SimplePointerProtocol::GUID)]
pub struct Pointer(SimplePointerProtocol);
impl Pointer {
pub fn reset(&mut self, extended_verification: bool) -> Result {
unsafe { (self.0.reset)(&mut self.0, extended_verification.into()) }.to_result()
}
pub fn read_state(&mut self) -> Result<Option<PointerState>> {
let mut pointer_state = PointerState::default();
let pointer_state_ptr: *mut _ = &mut pointer_state;
match unsafe { (self.0.get_state)(&mut self.0, pointer_state_ptr.cast()) } {
Status::NOT_READY => Ok(None),
other => other.to_result_with_val(|| Some(pointer_state)),
}
}
pub fn wait_for_input_event(&self) -> Result<Event> {
unsafe { Event::from_ptr(self.0.wait_for_input) }.ok_or(Error::from(Status::UNSUPPORTED))
}
#[must_use]
pub const fn mode(&self) -> &PointerMode {
unsafe { &*self.0.mode.cast() }
}
}
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[repr(C)]
pub struct PointerMode {
pub resolution: [u64; 3],
pub has_button: [bool; 2],
}
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[repr(C)]
pub struct PointerState {
pub relative_movement: [i32; 3],
pub button: [bool; 2],
}