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/platform/x11/x11_hotplug_event_handler.h" | 5 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "ui/events/devices/device_util_linux.h" | 29 #include "ui/events/devices/device_util_linux.h" |
30 #include "ui/events/devices/input_device.h" | 30 #include "ui/events/devices/input_device.h" |
31 #include "ui/events/devices/keyboard_device.h" | 31 #include "ui/events/devices/keyboard_device.h" |
32 #include "ui/events/devices/touchscreen_device.h" | 32 #include "ui/events/devices/touchscreen_device.h" |
33 #include "ui/gfx/x/x11_types.h" | 33 #include "ui/gfx/x/x11_types.h" |
34 | 34 |
35 namespace ui { | 35 namespace ui { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // The name of the xinput device corresponding to the AT internal keyboard. | |
40 const char kATKeyboardName[] = "AT Translated Set 2 keyboard"; | |
41 | |
42 // The prefix of xinput devices corresponding to CrOS EC internal keyboards. | |
43 const char kCrosEcKeyboardPrefix[] = "cros-ec"; | |
44 | |
45 // Names of all known internal devices that should not be considered as | 39 // Names of all known internal devices that should not be considered as |
46 // keyboards. | 40 // keyboards. |
47 // TODO(rsadam@): Identify these devices using udev rules. (Crbug.com/420728.) | 41 // TODO(rsadam@): Identify these devices using udev rules. (Crbug.com/420728.) |
48 const char* kKnownInvalidKeyboardDeviceNames[] = {"Power Button", | 42 const char* kKnownInvalidKeyboardDeviceNames[] = {"Power Button", |
49 "Sleep Button", | 43 "Sleep Button", |
50 "Video Bus"}; | 44 "Video Bus"}; |
51 | 45 |
52 const char* kCachedAtomList[] = { | 46 const char* kCachedAtomList[] = { |
53 "Abs MT Position X", | 47 "Abs MT Position X", |
54 "Abs MT Position Y", | 48 "Abs MT Position Y", |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Returns true if |name| is the name of a known invalid keyboard device. Note, | 141 // Returns true if |name| is the name of a known invalid keyboard device. Note, |
148 // this may return false negatives. | 142 // this may return false negatives. |
149 bool IsKnownInvalidKeyboardDevice(const std::string& name) { | 143 bool IsKnownInvalidKeyboardDevice(const std::string& name) { |
150 for (const char* device_name : kKnownInvalidKeyboardDeviceNames) { | 144 for (const char* device_name : kKnownInvalidKeyboardDeviceNames) { |
151 if (name == device_name) | 145 if (name == device_name) |
152 return true; | 146 return true; |
153 } | 147 } |
154 return false; | 148 return false; |
155 } | 149 } |
156 | 150 |
157 // Returns true if |name| is the name of a known internal keyboard device. Note, | |
158 // this may return false negatives. | |
159 bool IsInternalKeyboard(const std::string& name) { | |
160 // TODO(rsadam@): Come up with a more generic way of identifying internal | |
161 // keyboards. See crbug.com/420728. | |
162 if (name == kATKeyboardName) | |
163 return true; | |
164 return name.compare( | |
165 0u, strlen(kCrosEcKeyboardPrefix), kCrosEcKeyboardPrefix) == 0; | |
166 } | |
167 | |
168 // Returns true if |name| is the name of a known XTEST device. Note, this may | 151 // Returns true if |name| is the name of a known XTEST device. Note, this may |
169 // return false negatives. | 152 // return false negatives. |
170 bool IsTestKeyboard(const std::string& name) { | 153 bool IsTestKeyboard(const std::string& name) { |
171 return name.find("XTEST") != std::string::npos; | 154 return name.find("XTEST") != std::string::npos; |
172 } | 155 } |
173 | 156 |
174 base::FilePath GetDevicePath(XDisplay* dpy, const XIDeviceInfo& device) { | 157 base::FilePath GetDevicePath(XDisplay* dpy, const XIDeviceInfo& device) { |
175 #if !defined(OS_CHROMEOS) | 158 #if !defined(OS_CHROMEOS) |
176 return base::FilePath(); | 159 return base::FilePath(); |
177 #else | 160 #else |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 const KeyboardDeviceCallback& callback) { | 216 const KeyboardDeviceCallback& callback) { |
234 std::vector<KeyboardDevice> devices; | 217 std::vector<KeyboardDevice> devices; |
235 | 218 |
236 for (const DeviceInfo& device_info : device_infos) { | 219 for (const DeviceInfo& device_info : device_infos) { |
237 if (!device_info.enabled || device_info.use != XISlaveKeyboard) | 220 if (!device_info.enabled || device_info.use != XISlaveKeyboard) |
238 continue; // Assume all keyboards are keyboard slaves | 221 continue; // Assume all keyboards are keyboard slaves |
239 std::string device_name(device_info.name); | 222 std::string device_name(device_info.name); |
240 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); | 223 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); |
241 if (IsTestKeyboard(device_name)) | 224 if (IsTestKeyboard(device_name)) |
242 continue; // Skip test devices. | 225 continue; // Skip test devices. |
243 InputDeviceType type; | 226 if (IsKnownInvalidKeyboardDevice(device_name)) |
244 if (IsInternalKeyboard(device_name)) { | 227 continue; // Skip invalid devices. |
245 type = InputDeviceType::INPUT_DEVICE_INTERNAL; | 228 InputDeviceType type = GetInputDeviceTypeFromPath(device_info.path); |
246 } else if (IsKnownInvalidKeyboardDevice(device_name)) { | |
247 type = InputDeviceType::INPUT_DEVICE_UNKNOWN; | |
248 } else { | |
249 type = InputDeviceType::INPUT_DEVICE_EXTERNAL; | |
250 } | |
251 devices.push_back( | 229 devices.push_back( |
252 KeyboardDevice(device_info.id, type, device_name)); | 230 KeyboardDevice(device_info.id, type, device_name)); |
253 } | 231 } |
254 | 232 |
255 reply_runner->PostTask(FROM_HERE, base::Bind(callback, devices)); | 233 reply_runner->PostTask(FROM_HERE, base::Bind(callback, devices)); |
256 } | 234 } |
257 | 235 |
258 // Helper used to parse touchscreen information. When it is done it uses | 236 // Helper used to parse touchscreen information. When it is done it uses |
259 // |reply_runner| and |callback| to update the state on the UI thread. | 237 // |reply_runner| and |callback| to update the state on the UI thread. |
260 void HandleTouchscreenDevicesInWorker( | 238 void HandleTouchscreenDevicesInWorker( |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 base::WorkerPool::PostTask(FROM_HERE, | 350 base::WorkerPool::PostTask(FROM_HERE, |
373 base::Bind(&HandleHotplugEventInWorker, | 351 base::Bind(&HandleHotplugEventInWorker, |
374 device_infos, | 352 device_infos, |
375 display_state, | 353 display_state, |
376 base::ThreadTaskRunnerHandle::Get(), | 354 base::ThreadTaskRunnerHandle::Get(), |
377 callbacks), | 355 callbacks), |
378 true /* task_is_slow */); | 356 true /* task_is_slow */); |
379 } | 357 } |
380 | 358 |
381 } // namespace ui | 359 } // namespace ui |
OLD | NEW |