annotate src/uinput.rs @ 18:3f7b7a3ad8fe

Build three binaries instead of using arguments.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 26 Aug 2021 22:15:55 +0200
parents 478cf2a7d577
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 // Tablet emulator, for people who don’t own one
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 // Copyright © 2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 //
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 // This program is free software: you can redistribute it and/or modify
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 // it under the terms of the GNU Affero General Public License as published by
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 // the Free Software Foundation, either version 3 of the License, or
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 // (at your option) any later version.
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 //
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 // This program is distributed in the hope that it will be useful,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 // GNU Affero General Public License for more details.
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 //
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 // You should have received a copy of the GNU Affero General Public License
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 use crate::{MAX_X, MAX_Y};
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 use input_linux::{
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 sys::input_event, sys::timeval, AbsoluteAxis, AbsoluteInfo, AbsoluteInfoSetup, EventKind,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 InputId, InputProperty, Key, MiscKind, SynchronizeKind, UInputHandle,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 };
16
478cf2a7d577 Reformat with rustfmt.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
22 use std::fs::{File, OpenOptions};
12
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 pub fn create_uinput_device() -> std::io::Result<UInputHandle<File>> {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 let file = OpenOptions::new().write(true).open("/dev/uinput")?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 let dev = UInputHandle::new(file);
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 dev.set_evbit(EventKind::Synchronize)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 dev.set_evbit(EventKind::Key)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 dev.set_evbit(EventKind::Absolute)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 dev.set_evbit(EventKind::Misc)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 dev.set_keybit(Key::ButtonToolPen)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 dev.set_keybit(Key::ButtonToolRubber)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 dev.set_keybit(Key::ButtonToolBrush)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 dev.set_keybit(Key::ButtonToolPencil)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 dev.set_keybit(Key::ButtonToolAirbrush)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 dev.set_keybit(Key::ButtonTouch)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 dev.set_keybit(Key::ButtonStylus)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 dev.set_keybit(Key::ButtonStylus2)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 dev.set_keybit(Key::ButtonStylus3)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 dev.set_mscbit(MiscKind::Serial)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 dev.set_propbit(InputProperty::Direct)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 dev.set_absbit(AbsoluteAxis::X)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 dev.set_absbit(AbsoluteAxis::Y)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 dev.set_absbit(AbsoluteAxis::Z)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 dev.set_absbit(AbsoluteAxis::Wheel)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 dev.set_absbit(AbsoluteAxis::Pressure)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 dev.set_absbit(AbsoluteAxis::Distance)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 dev.set_absbit(AbsoluteAxis::TiltX)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 dev.set_absbit(AbsoluteAxis::TiltY)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 dev.set_absbit(AbsoluteAxis::Misc)?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 let id = InputId {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 bustype: 3,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 vendor: 0x56a,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 product: 0x350,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 version: 0xb,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 let x = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 axis: AbsoluteAxis::X,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 minimum: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 maximum: MAX_X,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 resolution: 200,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 let y = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 axis: AbsoluteAxis::Y,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 minimum: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 maximum: MAX_Y,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 resolution: 200,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 let z = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 axis: AbsoluteAxis::Z,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 minimum: -900,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 maximum: 899,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 resolution: 287,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 let wheel = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 axis: AbsoluteAxis::Wheel,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 minimum: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 maximum: 2047,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 resolution: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 let pressure = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 axis: AbsoluteAxis::Pressure,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 minimum: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 maximum: 8196,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 resolution: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 let distance = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 axis: AbsoluteAxis::Distance,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 minimum: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 maximum: 63,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 resolution: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 let tilt_x = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 axis: AbsoluteAxis::TiltX,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 minimum: -64,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 maximum: 63,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 resolution: 57,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 let tilt_y = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 axis: AbsoluteAxis::TiltY,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 minimum: -64,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 maximum: 63,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 resolution: 57,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 let misc = AbsoluteInfoSetup {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 axis: AbsoluteAxis::Misc,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 info: AbsoluteInfo {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152 value: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 minimum: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 maximum: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 fuzz: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 flat: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 resolution: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 };
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 dev.create(
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 &id,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 b"TabletEmu",
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 &[x, y, z, wheel, pressure, distance, tilt_x, tilt_y, misc],
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 )?;
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 Ok(dev)
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 }
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 fn input_event_new(type_: EventKind, code: u16, value: i32) -> input_event {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 input_event {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 time: timeval {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 tv_sec: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 tv_usec: 0,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 },
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 type_: type_ as u16,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 code,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 value,
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 }
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 }
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 pub fn input_axis_new(code: AbsoluteAxis, value: i32) -> input_event {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 input_event_new(EventKind::Absolute, code as u16, value)
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 }
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 pub fn input_key_new(code: Key, value: i32) -> input_event {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 input_event_new(EventKind::Key, code as u16, value)
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 }
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190 pub fn input_misc_new(code: MiscKind, value: i32) -> input_event {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 input_event_new(EventKind::Misc, code as u16, value)
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 }
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 pub fn input_synchronize_new(code: SynchronizeKind, value: i32) -> input_event {
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 input_event_new(EventKind::Synchronize, code as u16, value)
d43c31aff57c Split uinput helpers into another module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 }