OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/ozone/evdev/keyboard_evdev.h" | 5 #include "ui/events/ozone/evdev/keyboard_evdev.h" |
6 | 6 |
7 #include "ui/events/event.h" | 7 #include "ui/events/event.h" |
8 #include "ui/events/keycodes/dom4/keycode_converter.h" | 8 #include "ui/events/keycodes/dom4/keycode_converter.h" |
9 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" | 9 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" |
10 | 10 |
11 namespace ui { | 11 namespace ui { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const int kXkbKeycodeOffset = 8; | 15 const int kXkbKeycodeOffset = 8; |
16 | 16 |
17 ui::KeyboardCode KeyboardCodeFromEvdevKey(unsigned int code) { | 17 int ModifierFromEvdevKey(unsigned int code) { |
kpschoedel
2014/12/22 19:17:56
The base version here is fatally out of date now.
| |
18 switch (code) { | |
19 case KEY_CAPSLOCK: | |
20 return EVDEV_MODIFIER_CAPS_LOCK; | |
21 case KEY_LEFTSHIFT: | |
22 case KEY_RIGHTSHIFT: | |
23 return EVDEV_MODIFIER_SHIFT; | |
24 case KEY_LEFTCTRL: | |
25 case KEY_RIGHTCTRL: | |
26 return EVDEV_MODIFIER_CONTROL; | |
27 case KEY_LEFTALT: | |
28 case KEY_RIGHTALT: | |
29 return EVDEV_MODIFIER_ALT; | |
30 case BTN_LEFT: | |
31 return EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; | |
32 case BTN_MIDDLE: | |
33 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | |
34 case BTN_RIGHT: | |
35 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | |
36 case KEY_LEFTMETA: | |
37 case KEY_RIGHTMETA: | |
38 return EVDEV_MODIFIER_COMMAND; | |
39 default: | |
40 return EVDEV_MODIFIER_NONE; | |
41 } | |
42 } | |
43 | |
44 bool IsModifierLockKeyFromEvdevKey(unsigned int code) { | |
45 return code == KEY_CAPSLOCK; | |
46 } | |
47 | |
48 } // namespace | |
49 | |
50 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, | |
51 const EventDispatchCallback& callback) | |
52 : callback_(callback), modifiers_(modifiers) { | |
53 } | |
54 | |
55 KeyboardEvdev::~KeyboardEvdev() { | |
56 } | |
57 | |
58 // static | |
59 ui::KeyboardCode KeyboardEvdev::KeyboardCodeFromEvdevKey(unsigned int code) { | |
18 static const ui::KeyboardCode kLinuxBaseKeyMap[] = { | 60 static const ui::KeyboardCode kLinuxBaseKeyMap[] = { |
19 ui::VKEY_UNKNOWN, // KEY_RESERVED | 61 ui::VKEY_UNKNOWN, // KEY_RESERVED |
20 ui::VKEY_ESCAPE, // KEY_ESC | 62 ui::VKEY_ESCAPE, // KEY_ESC |
21 ui::VKEY_1, // KEY_1 | 63 ui::VKEY_1, // KEY_1 |
22 ui::VKEY_2, // KEY_2 | 64 ui::VKEY_2, // KEY_2 |
23 ui::VKEY_3, // KEY_3 | 65 ui::VKEY_3, // KEY_3 |
24 ui::VKEY_4, // KEY_4 | 66 ui::VKEY_4, // KEY_4 |
25 ui::VKEY_5, // KEY_5 | 67 ui::VKEY_5, // KEY_5 |
26 ui::VKEY_6, // KEY_6 | 68 ui::VKEY_6, // KEY_6 |
27 ui::VKEY_7, // KEY_7 | 69 ui::VKEY_7, // KEY_7 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 ui::VKEY_APPS, // KEY_COMPOSE | 188 ui::VKEY_APPS, // KEY_COMPOSE |
147 }; | 189 }; |
148 | 190 |
149 if (code < arraysize(kLinuxBaseKeyMap)) | 191 if (code < arraysize(kLinuxBaseKeyMap)) |
150 return kLinuxBaseKeyMap[code]; | 192 return kLinuxBaseKeyMap[code]; |
151 | 193 |
152 LOG(ERROR) << "Unknown key code: " << code; | 194 LOG(ERROR) << "Unknown key code: " << code; |
153 return ui::VKEY_UNKNOWN; | 195 return ui::VKEY_UNKNOWN; |
154 } | 196 } |
155 | 197 |
156 int ModifierFromEvdevKey(unsigned int code) { | |
157 switch (code) { | |
158 case KEY_CAPSLOCK: | |
159 return EVDEV_MODIFIER_CAPS_LOCK; | |
160 case KEY_LEFTSHIFT: | |
161 case KEY_RIGHTSHIFT: | |
162 return EVDEV_MODIFIER_SHIFT; | |
163 case KEY_LEFTCTRL: | |
164 case KEY_RIGHTCTRL: | |
165 return EVDEV_MODIFIER_CONTROL; | |
166 case KEY_LEFTALT: | |
167 case KEY_RIGHTALT: | |
168 return EVDEV_MODIFIER_ALT; | |
169 case BTN_LEFT: | |
170 return EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; | |
171 case BTN_MIDDLE: | |
172 return EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | |
173 case BTN_RIGHT: | |
174 return EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | |
175 case KEY_LEFTMETA: | |
176 case KEY_RIGHTMETA: | |
177 return EVDEV_MODIFIER_COMMAND; | |
178 default: | |
179 return EVDEV_MODIFIER_NONE; | |
180 } | |
181 } | |
182 | |
183 bool IsModifierLockKeyFromEvdevKey(unsigned int code) { | |
184 return code == KEY_CAPSLOCK; | |
185 } | |
186 | |
187 } // namespace | |
188 | |
189 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, | |
190 const EventDispatchCallback& callback) | |
191 : callback_(callback), modifiers_(modifiers) { | |
192 } | |
193 | |
194 KeyboardEvdev::~KeyboardEvdev() { | |
195 } | |
196 | |
197 void KeyboardEvdev::OnKeyChange(unsigned int key, bool down) { | 198 void KeyboardEvdev::OnKeyChange(unsigned int key, bool down) { |
198 if (key > KEY_MAX) | 199 if (key > KEY_MAX) |
199 return; | 200 return; |
200 | 201 |
201 if (down != key_state_.test(key)) { | 202 if (down != key_state_.test(key)) { |
202 // State transition: !(down) -> (down) | 203 // State transition: !(down) -> (down) |
203 if (down) | 204 if (down) |
204 key_state_.set(key); | 205 key_state_.set(key); |
205 else | 206 else |
206 key_state_.reset(key); | 207 key_state_.reset(key); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 | 241 |
241 // static | 242 // static |
242 int KeyboardEvdev::NativeCodeToEvdevCode(int native_code) { | 243 int KeyboardEvdev::NativeCodeToEvdevCode(int native_code) { |
243 if (native_code == KeycodeConverter::InvalidNativeKeycode()) { | 244 if (native_code == KeycodeConverter::InvalidNativeKeycode()) { |
244 return KEY_RESERVED; | 245 return KEY_RESERVED; |
245 } | 246 } |
246 return native_code - kXkbKeycodeOffset; | 247 return native_code - kXkbKeycodeOffset; |
247 } | 248 } |
248 | 249 |
249 } // namespace ui | 250 } // namespace ui |
OLD | NEW |