Skip to main content

kobo_core/device/
input.rs

1pub const EV_SYN: u16 = 0x00;
2pub const EV_KEY: u16 = 0x01;
3pub const EV_ABS: u16 = 0x03;
4pub const SYN_REPORT: u16 = 0x00;
5pub const ABS_MT_POSITION_X: u16 = 0x35;
6pub const ABS_MT_POSITION_Y: u16 = 0x36;
7pub const BTN_TOUCH_CODE: u16 = 330;
8
9pub const EVIOCGABS_X: libc::c_ulong = 0x80184572;
10pub const EVIOCGABS_Y: libc::c_ulong = 0x80184576;
11
12#[repr(C)]
13#[derive(Default)]
14pub struct InputAbsinfo {
15    pub value: i32,
16    pub minimum: i32,
17    pub maximum: i32,
18    pub fuzz: i32,
19    pub flat: i32,
20    pub resolution: i32,
21}
22
23pub fn query_abs_max(fd: libc::c_int, ioctl: libc::c_ulong) -> i32 {
24    let mut info = InputAbsinfo::default();
25    // SAFETY: ioctl with an EVIOCGABS-class code writes one `struct input_absinfo` into the
26    // supplied &mut. `info` is a valid, initialized, exclusively-borrowed value of exactly
27    // that layout (C-compatible #[repr(C)] struct of 5 i32). fd/ioctl are caller-provided
28    // kernel tokens; a bad fd returns -1 (ignored) and `info` stays default.
29    unsafe {
30        libc::ioctl(fd, ioctl as _, &mut info);
31    }
32    info.maximum
33}