Debian Codegraph @

src/constants.rs

raw symbols SCIP
1 use crate::compat::{
2 ABS_CNT, EV_CNT, FF_CNT, INPUT_PROP_CNT, LED_CNT, MSC_CNT, REL_CNT, SND_CNT, SW_CNT,
3 };
4
5 /// Event types supported by the device.
6 ///
7 /// Values correspond to [/usr/include/linux/input-event-codes.h](https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h)
8 ///
9 /// This is implemented as a newtype around the u16 "type" field of `input_event`.
10 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
11 pub struct EventType(pub u16);
12
13 evdev_enum!(
14 EventType,
15 Array,
16 /// A bookkeeping event. Usually not important to applications.
17 SYNCHRONIZATION = 0x00,
18 /// A key changed state. A key, or button, is usually a momentary switch (in the circuit sense). It has two
19 /// states: down, or up. There are events for when keys are pressed (become down) and
20 /// released (become up). There are also "key repeats", where multiple events are sent
21 /// while a key is down.
22 KEY = 0x01,
23 /// Movement on a relative axis. There is no absolute coordinate frame, just the fact that
24 /// there was a change of a certain amount of units. Used for things like mouse movement or
25 /// scroll wheels.
26 RELATIVE = 0x02,
27 /// Movement on an absolute axis. Used for things such as touch events and joysticks.
28 ABSOLUTE = 0x03,
29 /// Miscellaneous events that don't fall into other categories. For example, Key presses may
30 /// send `MSC_SCAN` events before each KEY event
31 MISC = 0x04,
32 /// Change in a switch value. Switches are boolean conditions and usually correspond to a
33 /// toggle switch of some kind in hardware.
34 SWITCH = 0x05,
35 /// An LED was toggled.
36 LED = 0x11,
37 /// A sound was made.
38 SOUND = 0x12,
39 /// There are no events of this type, to my knowledge, but represents metadata about key
40 /// repeat configuration.
41 REPEAT = 0x14,
42 /// Looking at the source of [`fftest`](https://github.com/flosse/linuxconsole/blob/master/utils/fftest.c)
43 /// This seems to be sent to the device with a previusly obtained effect id as a code in order to toggle the effect.
44 FORCEFEEDBACK = 0x15,
45 /// I think this is unused?
46 POWER = 0x16,
47 /// A force feedback effect's state changed.
48 FORCEFEEDBACKSTATUS = 0x17,
49 /// An event originating from uinput.
50 UINPUT = 0x0101,
51 );
52
53 impl EventType {
54 pub(crate) const COUNT: usize = EV_CNT;
55 }
56
57 /// A "synchronization" message type published by the kernel into the events stream.
58 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
59 pub struct SynchronizationCode(pub u16);
60
61 evdev_enum!(
62 SynchronizationCode,
63 /// Used to mark the end of a single atomic "reading" from the device.
64 SYN_REPORT = 0,
65 /// Appears to be unused.
66 SYN_CONFIG = 1,
67 /// "Used to synchronize and separate touch events"
68 SYN_MT_REPORT = 2,
69 /// Ring buffer filled, events were dropped.
70 SYN_DROPPED = 3,
71 );
72
73 /// Device properties.
74 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
75 pub struct PropType(pub u16);
76
77 evdev_enum!(
78 PropType,
79 Array,
80 /// This input device needs a pointer ("cursor") for the user to know its state.
81 POINTER = 0x00,
82 /// "direct input devices", according to the header.
83 DIRECT = 0x01,
84 /// "has button(s) under pad", according to the header.
85 BUTTONPAD = 0x02,
86 /// Touch rectangle only (I think this means that if there are multiple touches, then the
87 /// bounding rectangle of all the touches is returned, not each touch).
88 SEMI_MT = 0x03,
89 /// "softbuttons at top of pad", according to the header.
90 TOPBUTTONPAD = 0x04,
91 /// Is a pointing stick ("nub" etc, <https://xkcd.com/243/>)
92 POINTING_STICK = 0x05,
93 /// Has an accelerometer. Probably reports relative events in that case?
94 ACCELEROMETER = 0x06,
95 );
96
97 impl PropType {
98 pub(crate) const COUNT: usize = INPUT_PROP_CNT;
99 }
100
101 /// A type of relative axis measurement, typically produced by mice.
102 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
103 pub struct RelativeAxisCode(pub u16);
104
105 evdev_enum!(
106 RelativeAxisCode,
107 Array,
108 REL_X = 0x00,
109 REL_Y = 0x01,
110 REL_Z = 0x02,
111 REL_RX = 0x03,
112 REL_RY = 0x04,
113 REL_RZ = 0x05,
114 REL_HWHEEL = 0x06,
115 REL_DIAL = 0x07,
116 REL_WHEEL = 0x08,
117 REL_MISC = 0x09,
118 REL_RESERVED = 0x0a,
119 REL_WHEEL_HI_RES = 0x0b,
120 REL_HWHEEL_HI_RES = 0x0c,
121 );
122
123 impl RelativeAxisCode {
124 pub(crate) const COUNT: usize = REL_CNT;
125 }
126
127 /// A type of absolute axis measurement, typically used for touch events and joysticks.
128 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
129 pub struct AbsoluteAxisCode(pub u16);
130
131 evdev_enum!(
132 AbsoluteAxisCode,
133 Array,
134 ABS_X = 0x00,
135 ABS_Y = 0x01,
136 ABS_Z = 0x02,
137 ABS_RX = 0x03,
138 ABS_RY = 0x04,
139 ABS_RZ = 0x05,
140 ABS_THROTTLE = 0x06,
141 ABS_RUDDER = 0x07,
142 ABS_WHEEL = 0x08,
143 ABS_GAS = 0x09,
144 ABS_BRAKE = 0x0a,
145 ABS_HAT0X = 0x10,
146 ABS_HAT0Y = 0x11,
147 ABS_HAT1X = 0x12,
148 ABS_HAT1Y = 0x13,
149 ABS_HAT2X = 0x14,
150 ABS_HAT2Y = 0x15,
151 ABS_HAT3X = 0x16,
152 ABS_HAT3Y = 0x17,
153 ABS_PRESSURE = 0x18,
154 ABS_DISTANCE = 0x19,
155 ABS_TILT_X = 0x1a,
156 ABS_TILT_Y = 0x1b,
157 ABS_TOOL_WIDTH = 0x1c,
158 ABS_VOLUME = 0x20,
159 ABS_MISC = 0x28,
160 /// "MT slot being modified"
161 ABS_MT_SLOT = 0x2f,
162 /// "Major axis of touching ellipse"
163 ABS_MT_TOUCH_MAJOR = 0x30,
164 /// "Minor axis (omit if circular)"
165 ABS_MT_TOUCH_MINOR = 0x31,
166 /// "Major axis of approaching ellipse"
167 ABS_MT_WIDTH_MAJOR = 0x32,
168 /// "Minor axis (omit if circular)"
169 ABS_MT_WIDTH_MINOR = 0x33,
170 /// "Ellipse orientation"
171 ABS_MT_ORIENTATION = 0x34,
172 /// "Center X touch position"
173 ABS_MT_POSITION_X = 0x35,
174 /// "Center Y touch position"
175 ABS_MT_POSITION_Y = 0x36,
176 /// "Type of touching device"
177 ABS_MT_TOOL_TYPE = 0x37,
178 /// "Group a set of packets as a blob"
179 ABS_MT_BLOB_ID = 0x38,
180 /// "Unique ID of the initiated contact"
181 ABS_MT_TRACKING_ID = 0x39,
182 /// "Pressure on contact area"
183 ABS_MT_PRESSURE = 0x3a,
184 /// "Contact over distance"
185 ABS_MT_DISTANCE = 0x3b,
186 /// "Center X tool position"
187 ABS_MT_TOOL_X = 0x3c,
188 /// "Center Y tool position"
189 ABS_MT_TOOL_Y = 0x3d,
190 );
191
192 impl AbsoluteAxisCode {
193 pub(crate) const COUNT: usize = ABS_CNT;
194 }
195
196 /// An event type corresponding to a physical or virtual switch.
197 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
198 pub struct SwitchCode(pub u16);
199
200 evdev_enum!(
201 SwitchCode,
202 Array,
203 /// "set = lid shut"
204 SW_LID = 0x00,
205 /// "set = tablet mode"
206 SW_TABLET_MODE = 0x01,
207 /// "set = inserted"
208 SW_HEADPHONE_INSERT = 0x02,
209 /// "rfkill master switch, type 'any'"
210 SW_RFKILL_ALL = 0x03,
211 /// "set = inserted"
212 SW_MICROPHONE_INSERT = 0x04,
213 /// "set = plugged into doc"
214 SW_DOCK = 0x05,
215 /// "set = inserted"
216 SW_LINEOUT_INSERT = 0x06,
217 /// "set = mechanical switch set"
218 SW_JACK_PHYSICAL_INSERT = 0x07,
219 /// "set = inserted"
220 SW_VIDEOOUT_INSERT = 0x08,
221 /// "set = lens covered"
222 SW_CAMERA_LENS_COVER = 0x09,
223 /// "set = keypad slide out"
224 SW_KEYPAD_SLIDE = 0x0a,
225 /// "set = front proximity sensor active"
226 SW_FRONT_PROXIMITY = 0x0b,
227 /// "set = rotate locked/disabled"
228 SW_ROTATE_LOCK = 0x0c,
229 /// "set = inserted"
230 SW_LINEIN_INSERT = 0x0d,
231 /// "set = device disabled"
232 SW_MUTE_DEVICE = 0x0e,
233 /// "set = pen inserted"
234 SW_PEN_INSERTED = 0x0f,
235 /// "set = cover closed"
236 SW_MACHINE_COVER = 0x10,
237 );
238
239 impl SwitchCode {
240 pub(crate) const COUNT: usize = SW_CNT;
241 }
242
243 /// LEDs specified by USB HID.
244 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
245 pub struct LedCode(pub u16);
246
247 evdev_enum!(
248 LedCode,
249 Array,
250 LED_NUML = 0x00,
251 LED_CAPSL = 0x01,
252 LED_SCROLLL = 0x02,
253 LED_COMPOSE = 0x03,
254 LED_KANA = 0x04,
255 /// "Stand-by"
256 LED_SLEEP = 0x05,
257 LED_SUSPEND = 0x06,
258 LED_MUTE = 0x07,
259 /// "Generic indicator"
260 LED_MISC = 0x08,
261 /// "Message waiting"
262 LED_MAIL = 0x09,
263 /// "External power connected"
264 LED_CHARGING = 0x0a,
265 );
266
267 impl LedCode {
268 pub(crate) const COUNT: usize = LED_CNT;
269 }
270
271 /// Various miscellaneous event types.
272 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
273 pub struct MiscCode(pub u16);
274
275 evdev_enum!(
276 MiscCode,
277 Array,
278 /// Serial number, only exported for tablets ("Transducer Serial Number")
279 MSC_SERIAL = 0x00,
280 /// Only used by the PowerMate driver, right now.
281 MSC_PULSELED = 0x01,
282 /// Completely unused.
283 MSC_GESTURE = 0x02,
284 /// "Raw" event, rarely used.
285 MSC_RAW = 0x03,
286 /// Key scancode
287 MSC_SCAN = 0x04,
288 /// Completely unused.
289 MSC_TIMESTAMP = 0x05,
290 );
291
292 impl MiscCode {
293 pub(crate) const COUNT: usize = MSC_CNT;
294 }
295
296 /// Force feedback effect types
297 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
298 pub struct FFEffectCode(pub u16);
299
300 evdev_enum!(
301 FFEffectCode,
302 Array,
303 /// Rumble effects.
304 FF_RUMBLE = 0x50,
305 /// Can render periodic effects with any of the waveforms.
306 FF_PERIODIC = 0x51,
307 /// Can render constant force effects.
308 FF_CONSTANT = 0x52,
309 /// Can simulate the presence of a spring.
310 FF_SPRING = 0x53,
311 /// Can simulate friction.
312 FF_FRICTION = 0x54,
313 /// Can simulate damper effects.
314 FF_DAMPER = 0x55,
315 /// Can simulate inertia.
316 FF_INERTIA = 0x56,
317 /// Can render ramp effects.
318 FF_RAMP = 0x57,
319 /// Square waveform.
320 FF_SQUARE = 0x58,
321 /// Triangle waveform.
322 FF_TRIANGLE = 0x59,
323 /// Sine waveform.
324 FF_SINE = 0x5a,
325 /// Sawtooth up waveform.
326 FF_SAW_UP = 0x5b,
327 /// Sawtooth down waveform.
328 FF_SAW_DOWN = 0x5c,
329 /// Custom waveform.
330 FF_CUSTOM = 0x5d,
331 /// The gain is adjustable.
332 FF_GAIN = 0x60,
333 /// The autocenter is adjustable.
334 FF_AUTOCENTER = 0x61,
335 );
336
337 impl FFEffectCode {
338 pub(crate) const COUNT: usize = FF_CNT;
339 }
340
341 /// Force feedback effect status
342 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
343 pub struct FFStatusCode(pub u16);
344
345 evdev_enum!(
346 FFStatusCode,
347 Array,
348 /// The force feedback event is currently stopped.
349 FF_STATUS_STOPPED = 0x00,
350 /// The force feedback event is currently playing.
351 FF_STATUS_PLAYING = 0x01,
352 );
353
354 impl FFStatusCode {
355 pub(crate) const COUNT: usize = 2;
356 }
357
358 #[derive(Copy, Clone, PartialEq, Eq)]
359 pub struct RepeatCode(pub u16);
360
361 evdev_enum!(RepeatCode, REP_DELAY = 0x00, REP_PERIOD = 0x01,);
362
363 // impl RepeatType {
364 // pub(crate) const COUNT: usize = libc::REP_CNT;
365 // }
366
367 /// A type associated with simple sounds, such as beeps or tones.
368 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
369 pub struct SoundCode(pub u16);
370
371 evdev_enum!(
372 SoundCode,
373 Array,
374 SND_CLICK = 0x00,
375 SND_BELL = 0x01,
376 SND_TONE = 0x02,
377 );
378
379 impl SoundCode {
380 pub(crate) const COUNT: usize = SND_CNT;
381 }
382
383 /// A uinput event published by the kernel into the events stream for uinput devices.
384 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
385 pub struct UInputCode(pub u16);
386
387 evdev_enum!(
388 UInputCode,
389 /// The virtual uinput device is uploading a force feedback effect.
390 UI_FF_UPLOAD = 1,
391 /// The virtual uinput device is erasing a force feedback event.
392 UI_FF_ERASE = 2,
393 );
394
395 // some more structs without any constats. They are only there to
396 // porvide a consitatnt type system and simple code generation.
397 #[cfg(feature = "serde")]
398 use serde::{Deserialize, Serialize};
399
400 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
401 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
402 pub struct PowerCode(pub u16);
403
404 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
405 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
406 pub struct OtherCode(pub u16, pub u16);