1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 use std::collections::BTreeMap;
6
7 use super::constants::*;
8 use super::virtio_input_absinfo;
9 use super::virtio_input_bitmap;
10 use super::virtio_input_device_ids;
11 use super::VirtioInputConfig;
12
13 /// Instantiates a VirtioInputConfig object with the default configuration for a trackpad. It
14 /// supports touch, left button and right button events, as well as X and Y axis.
new_trackpad_config(width: u32, height: u32) -> VirtioInputConfig15 pub fn new_trackpad_config(width: u32, height: u32) -> VirtioInputConfig {
16 VirtioInputConfig::new(
17 virtio_input_device_ids::new(0, 0, 0, 0),
18 b"Crosvm Virtio Trackpad".to_vec(),
19 b"virtio-trackpad".to_vec(),
20 virtio_input_bitmap::new([0u8; 128]),
21 default_trackpad_events(),
22 default_trackpad_absinfo(width, height),
23 )
24 }
25
26 /// Instantiates a VirtioInputConfig object with the default configuration for a mouse.
27 /// It supports left, right and middle buttons, as wel as X, Y and wheel relative axes.
new_mouse_config() -> VirtioInputConfig28 pub fn new_mouse_config() -> VirtioInputConfig {
29 VirtioInputConfig::new(
30 virtio_input_device_ids::new(0, 0, 0, 0),
31 b"Crosvm Virtio Mouse".to_vec(),
32 b"virtio-mouse".to_vec(),
33 virtio_input_bitmap::new([0u8; 128]),
34 default_mouse_events(),
35 BTreeMap::new(),
36 )
37 }
38
39 /// Instantiates a VirtioInputConfig object with the default configuration for a keyboard.
40 /// It supports the same keys as a en-us keyboard and the CAPSLOCK, NUMLOCK and SCROLLLOCK leds.
new_keyboard_config() -> VirtioInputConfig41 pub fn new_keyboard_config() -> VirtioInputConfig {
42 VirtioInputConfig::new(
43 virtio_input_device_ids::new(0, 0, 0, 0),
44 b"Crosvm Virtio Keyboard".to_vec(),
45 b"virtio-keyboard".to_vec(),
46 virtio_input_bitmap::new([0u8; 128]),
47 default_keyboard_events(),
48 BTreeMap::new(),
49 )
50 }
51
52 /// Instantiates a VirtioInputConfig object with the default configuration for a touchscreen (no
53 /// multitouch support).
new_single_touch_config(width: u32, height: u32) -> VirtioInputConfig54 pub fn new_single_touch_config(width: u32, height: u32) -> VirtioInputConfig {
55 VirtioInputConfig::new(
56 virtio_input_device_ids::new(0, 0, 0, 0),
57 b"Crosvm Virtio Touchscreen".to_vec(),
58 b"virtio-touchscreen".to_vec(),
59 virtio_input_bitmap::from_bits(&[INPUT_PROP_DIRECT]),
60 default_touchscreen_events(),
61 default_touchscreen_absinfo(width, height),
62 )
63 }
64
default_touchscreen_absinfo(width: u32, height: u32) -> BTreeMap<u16, virtio_input_absinfo>65 fn default_touchscreen_absinfo(width: u32, height: u32) -> BTreeMap<u16, virtio_input_absinfo> {
66 let mut absinfo: BTreeMap<u16, virtio_input_absinfo> = BTreeMap::new();
67 absinfo.insert(ABS_X, virtio_input_absinfo::new(0, width, 0, 0));
68 absinfo.insert(ABS_Y, virtio_input_absinfo::new(0, height, 0, 0));
69 absinfo
70 }
71
default_touchscreen_events() -> BTreeMap<u16, virtio_input_bitmap>72 fn default_touchscreen_events() -> BTreeMap<u16, virtio_input_bitmap> {
73 let mut supported_events: BTreeMap<u16, virtio_input_bitmap> = BTreeMap::new();
74 supported_events.insert(EV_KEY, virtio_input_bitmap::from_bits(&[BTN_TOUCH]));
75 supported_events.insert(EV_ABS, virtio_input_bitmap::from_bits(&[ABS_X, ABS_Y]));
76 supported_events
77 }
78
default_trackpad_absinfo(width: u32, height: u32) -> BTreeMap<u16, virtio_input_absinfo>79 fn default_trackpad_absinfo(width: u32, height: u32) -> BTreeMap<u16, virtio_input_absinfo> {
80 let mut absinfo: BTreeMap<u16, virtio_input_absinfo> = BTreeMap::new();
81 absinfo.insert(ABS_X, virtio_input_absinfo::new(0, width, 0, 0));
82 absinfo.insert(ABS_Y, virtio_input_absinfo::new(0, height, 0, 0));
83 absinfo
84 }
85
default_trackpad_events() -> BTreeMap<u16, virtio_input_bitmap>86 fn default_trackpad_events() -> BTreeMap<u16, virtio_input_bitmap> {
87 let mut supported_events: BTreeMap<u16, virtio_input_bitmap> = BTreeMap::new();
88 supported_events.insert(
89 EV_KEY,
90 virtio_input_bitmap::from_bits(&[BTN_TOOL_FINGER, BTN_TOUCH, BTN_LEFT, BTN_RIGHT]),
91 );
92 supported_events.insert(EV_ABS, virtio_input_bitmap::from_bits(&[ABS_X, ABS_Y]));
93 supported_events
94 }
95
default_mouse_events() -> BTreeMap<u16, virtio_input_bitmap>96 fn default_mouse_events() -> BTreeMap<u16, virtio_input_bitmap> {
97 let mut supported_events: BTreeMap<u16, virtio_input_bitmap> = BTreeMap::new();
98 supported_events.insert(
99 EV_KEY,
100 virtio_input_bitmap::from_bits(&[BTN_LEFT, BTN_RIGHT, BTN_MIDDLE]),
101 );
102 supported_events.insert(
103 EV_REL,
104 virtio_input_bitmap::from_bits(&[REL_X, REL_Y, REL_WHEEL]),
105 );
106 supported_events
107 }
108
default_keyboard_events() -> BTreeMap<u16, virtio_input_bitmap>109 fn default_keyboard_events() -> BTreeMap<u16, virtio_input_bitmap> {
110 let mut supported_events: BTreeMap<u16, virtio_input_bitmap> = BTreeMap::new();
111 supported_events.insert(
112 EV_KEY,
113 virtio_input_bitmap::from_bits(&[
114 KEY_ESC,
115 KEY_1,
116 KEY_2,
117 KEY_3,
118 KEY_4,
119 KEY_5,
120 KEY_6,
121 KEY_7,
122 KEY_8,
123 KEY_9,
124 KEY_0,
125 KEY_MINUS,
126 KEY_EQUAL,
127 KEY_BACKSPACE,
128 KEY_TAB,
129 KEY_Q,
130 KEY_W,
131 KEY_E,
132 KEY_R,
133 KEY_T,
134 KEY_Y,
135 KEY_U,
136 KEY_I,
137 KEY_O,
138 KEY_P,
139 KEY_LEFTBRACE,
140 KEY_RIGHTBRACE,
141 KEY_ENTER,
142 KEY_LEFTCTRL,
143 KEY_A,
144 KEY_S,
145 KEY_D,
146 KEY_F,
147 KEY_G,
148 KEY_H,
149 KEY_J,
150 KEY_K,
151 KEY_L,
152 KEY_SEMICOLON,
153 KEY_APOSTROPHE,
154 KEY_GRAVE,
155 KEY_LEFTSHIFT,
156 KEY_BACKSLASH,
157 KEY_Z,
158 KEY_X,
159 KEY_C,
160 KEY_V,
161 KEY_B,
162 KEY_N,
163 KEY_M,
164 KEY_COMMA,
165 KEY_DOT,
166 KEY_SLASH,
167 KEY_RIGHTSHIFT,
168 KEY_KPASTERISK,
169 KEY_LEFTALT,
170 KEY_SPACE,
171 KEY_CAPSLOCK,
172 KEY_F1,
173 KEY_F2,
174 KEY_F3,
175 KEY_F4,
176 KEY_F5,
177 KEY_F6,
178 KEY_F7,
179 KEY_F8,
180 KEY_F9,
181 KEY_F10,
182 KEY_NUMLOCK,
183 KEY_SCROLLLOCK,
184 KEY_KP7,
185 KEY_KP8,
186 KEY_KP9,
187 KEY_KPMINUS,
188 KEY_KP4,
189 KEY_KP5,
190 KEY_KP6,
191 KEY_KPPLUS,
192 KEY_KP1,
193 KEY_KP2,
194 KEY_KP3,
195 KEY_KP0,
196 KEY_KPDOT,
197 KEY_F11,
198 KEY_F12,
199 KEY_KPENTER,
200 KEY_RIGHTCTRL,
201 KEY_KPSLASH,
202 KEY_SYSRQ,
203 KEY_RIGHTALT,
204 KEY_HOME,
205 KEY_UP,
206 KEY_PAGEUP,
207 KEY_LEFT,
208 KEY_RIGHT,
209 KEY_END,
210 KEY_DOWN,
211 KEY_PAGEDOWN,
212 KEY_INSERT,
213 KEY_DELETE,
214 KEY_PAUSE,
215 KEY_MENU,
216 KEY_PRINT,
217 KEY_POWER,
218 ]),
219 );
220 supported_events.insert(
221 EV_REP,
222 virtio_input_bitmap::from_bits(&[REP_DELAY, REP_PERIOD]),
223 );
224 supported_events.insert(
225 EV_LED,
226 virtio_input_bitmap::from_bits(&[LED_CAPSL, LED_NUML, LED_SCROLLL]),
227 );
228 supported_events
229 }
230