sweetacid_evdev/
inputid.rs1use std::fmt;
2
3#[derive(Clone)]
4#[repr(transparent)]
5pub struct InputId(pub(crate) libc::input_id);
6
7impl From<libc::input_id> for InputId {
8 #[inline]
9 fn from(id: libc::input_id) -> Self {
10 Self(id)
11 }
12}
13impl AsRef<libc::input_id> for InputId {
14 #[inline]
15 fn as_ref(&self) -> &libc::input_id {
16 &self.0
17 }
18}
19
20impl InputId {
21 pub fn bus_type(&self) -> BusType {
22 BusType(self.0.bustype)
23 }
24 pub fn vendor(&self) -> u16 {
25 self.0.vendor
26 }
27 pub fn product(&self) -> u16 {
28 self.0.product
29 }
30 pub fn version(&self) -> u16 {
31 self.0.version
32 }
33
34 pub fn new(bus_type: BusType, vendor: u16, product: u16, version: u16) -> Self {
36 Self::from(libc::input_id {
37 bustype: bus_type.0,
38 vendor,
39 product,
40 version,
41 })
42 }
43}
44
45impl fmt::Debug for InputId {
46 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47 f.debug_struct("InputId")
48 .field("bus_type", &self.bus_type())
49 .field("vendor", &format_args!("{:#x}", self.vendor()))
50 .field("product", &format_args!("{:#x}", self.product()))
51 .field("version", &format_args!("{:#x}", self.version()))
52 .finish()
53 }
54}
55
56#[derive(Copy, Clone, PartialEq, Eq)]
57pub struct BusType(pub u16);
58
59evdev_enum!(
60 BusType,
61 BUS_PCI = 0x01,
62 BUS_ISAPNP = 0x02,
63 BUS_USB = 0x03,
64 BUS_HIL = 0x04,
65 BUS_BLUETOOTH = 0x05,
66 BUS_VIRTUAL = 0x06,
67 BUS_ISA = 0x10,
68 BUS_I8042 = 0x11,
69 BUS_XTKBD = 0x12,
70 BUS_RS232 = 0x13,
71 BUS_GAMEPORT = 0x14,
72 BUS_PARPORT = 0x15,
73 BUS_AMIGA = 0x16,
74 BUS_ADB = 0x17,
75 BUS_I2C = 0x18,
76 BUS_HOST = 0x19,
77 BUS_GSC = 0x1A,
78 BUS_ATARI = 0x1B,
79 BUS_SPI = 0x1C,
80 BUS_RMI = 0x1D,
81 BUS_CEC = 0x1E,
82 BUS_INTEL_ISHTP = 0x1F,
83);
84
85impl fmt::Display for BusType {
86 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87 let s = match *self {
88 Self::BUS_PCI => "PCI",
89 Self::BUS_ISAPNP => "ISA Plug 'n Play",
90 Self::BUS_USB => "USB",
91 Self::BUS_HIL => "HIL",
92 Self::BUS_BLUETOOTH => "Bluetooth",
93 Self::BUS_VIRTUAL => "Virtual",
94 Self::BUS_ISA => "ISA",
95 Self::BUS_I8042 => "i8042",
96 Self::BUS_XTKBD => "XTKBD",
97 Self::BUS_RS232 => "RS232",
98 Self::BUS_GAMEPORT => "Gameport",
99 Self::BUS_PARPORT => "Parallel Port",
100 Self::BUS_AMIGA => "Amiga",
101 Self::BUS_ADB => "ADB",
102 Self::BUS_I2C => "I2C",
103 Self::BUS_HOST => "Host",
104 Self::BUS_GSC => "GSC",
105 Self::BUS_ATARI => "Atari",
106 Self::BUS_SPI => "SPI",
107 Self::BUS_RMI => "RMI",
108 Self::BUS_CEC => "CEC",
109 Self::BUS_INTEL_ISHTP => "Intel ISHTP",
110 _ => "Unknown",
111 };
112 f.write_str(s)
113 }
114}