1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use crate::proto::Protocol;
use crate::{unsafe_guid, Event, Result, Status};
use core::mem::MaybeUninit;
#[repr(C)]
#[unsafe_guid("31878c87-0b75-11d5-9a4f-0090273fc14d")]
#[derive(Protocol)]
pub struct Pointer<'boot> {
reset: extern "efiapi" fn(this: &mut Pointer, ext_verif: bool) -> Status,
get_state: extern "efiapi" fn(this: &Pointer, state: *mut PointerState) -> Status,
wait_for_input: Event,
mode: &'boot PointerMode,
}
impl<'boot> Pointer<'boot> {
pub fn reset(&mut self, extended_verification: bool) -> Result {
(self.reset)(self, extended_verification).into()
}
pub fn read_state(&mut self) -> Result<Option<PointerState>> {
let mut pointer_state = MaybeUninit::<PointerState>::uninit();
match (self.get_state)(self, pointer_state.as_mut_ptr()) {
Status::NOT_READY => Ok(None.into()),
other => other.into_with_val(|| unsafe { Some(pointer_state.assume_init()) }),
}
}
pub fn wait_for_input_event(&self) -> Event {
self.wait_for_input
}
pub fn mode(&self) -> &PointerMode {
self.mode
}
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct PointerMode {
resolution: (u64, u64, u64),
has_button: (bool, bool),
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct PointerState {
pub relative_movement: (i32, i32, i32),
pub button: (bool, bool),
}