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/x/hotplug_event_handler_x11.h" | 5 #include "ui/events/x/hotplug_event_handler_x11.h" |
6 | 6 |
7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 | 9 |
10 #include <algorithm> | |
10 #include <cmath> | 11 #include <cmath> |
11 #include <set> | 12 #include <set> |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/files/file_enumerator.h" | 17 #include "base/files/file_enumerator.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/process/launch.h" | 19 #include "base/process/launch.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
21 #include "ui/events/device_hotplug_event_observer.h" | 22 #include "ui/events/device_hotplug_event_observer.h" |
23 #include "ui/events/keyboard_device.h" | |
22 #include "ui/events/touchscreen_device.h" | 24 #include "ui/events/touchscreen_device.h" |
23 #include "ui/gfx/x/x11_types.h" | 25 #include "ui/gfx/x/x11_types.h" |
24 | 26 |
25 namespace ui { | 27 namespace ui { |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
31 // The name of the xinput device corresponding to the internal keyboard. | |
32 const char kInternalKeyboardName[] = "AT Translated Set 2 keyboard"; | |
sadrul
2014/10/02 15:53:53
Is this only on chromeos? (i.e. does x11/linux dev
rsadam
2014/10/02 22:52:27
I believe this is Unix wide. (http://unix.stackexc
| |
33 | |
34 // The name of the xinput device corresponding to the test keyboard. | |
35 const char kTestKeyboardName[] = "Virtual core XTEST keyboard"; | |
36 | |
37 // Filters our all devices that do not contain the substring "keyboard". | |
38 bool IsKnownKeyboard(std::string name) { | |
sadrul
2014/10/02 15:53:53
const &, and make an internal copy if you need to
rsadam
2014/10/02 22:52:27
Done.
| |
39 std::transform(name.begin(), name.end(), name.begin(), ::tolower); | |
40 return name.find("keyboard") != std::string::npos; | |
41 } | |
42 | |
29 // We consider the touchscreen to be internal if it is an I2c device. | 43 // We consider the touchscreen to be internal if it is an I2c device. |
30 // With the device id, we can query X to get the device's dev input | 44 // With the device id, we can query X to get the device's dev input |
31 // node eventXXX. Then we search all the dev input nodes registered | 45 // node eventXXX. Then we search all the dev input nodes registered |
32 // by I2C devices to see if we can find eventXXX. | 46 // by I2C devices to see if we can find eventXXX. |
33 bool IsTouchscreenInternal(XDisplay* dpy, int device_id) { | 47 bool IsTouchscreenInternal(XDisplay* dpy, int device_id) { |
34 using base::FileEnumerator; | 48 using base::FileEnumerator; |
35 using base::FilePath; | 49 using base::FilePath; |
36 | 50 |
37 #if !defined(CHROMEOS) | 51 #if !defined(CHROMEOS) |
38 return false; | 52 return false; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 : delegate_(delegate) { | 123 : delegate_(delegate) { |
110 } | 124 } |
111 | 125 |
112 HotplugEventHandlerX11::~HotplugEventHandlerX11() { | 126 HotplugEventHandlerX11::~HotplugEventHandlerX11() { |
113 } | 127 } |
114 | 128 |
115 void HotplugEventHandlerX11::OnHotplugEvent() { | 129 void HotplugEventHandlerX11::OnHotplugEvent() { |
116 const XIDeviceList& device_list = | 130 const XIDeviceList& device_list = |
117 DeviceListCacheX::GetInstance()->GetXI2DeviceList(gfx::GetXDisplay()); | 131 DeviceListCacheX::GetInstance()->GetXI2DeviceList(gfx::GetXDisplay()); |
118 HandleTouchscreenDevices(device_list); | 132 HandleTouchscreenDevices(device_list); |
133 HandleKeyboardDevices(device_list); | |
134 delegate_->OnInputDeviceConfigurationChanged(); | |
135 } | |
136 | |
137 void HotplugEventHandlerX11::HandleKeyboardDevices( | |
138 const XIDeviceList& x11_devices) { | |
139 std::vector<KeyboardDevice> devices; | |
140 | |
141 for (int i = 0; i < x11_devices.count; i++) { | |
142 if (!x11_devices[i].enabled || x11_devices[i].use != XISlaveKeyboard) | |
143 continue; // Assume all keyboards are keyboard slaves | |
144 std::string device_name(x11_devices[i].name); | |
145 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, | |
146 &device_name); | |
147 KeyboardDeviceType type; | |
148 if (device_name == kInternalKeyboardName) { | |
149 type = KeyboardDeviceType::INTERNAL; | |
150 } else if (device_name == kTestKeyboardName) { | |
151 type = KeyboardDeviceType::TEST; | |
152 } else if (IsKnownKeyboard(device_name)) { | |
153 type = KeyboardDeviceType::EXTERNAL; | |
154 } else { | |
155 type = KeyboardDeviceType::UNKNOWN; | |
156 } | |
157 devices.push_back(KeyboardDevice(x11_devices[i].deviceid, type)); | |
158 } | |
159 delegate_->OnKeyboardDevicesUpdated(devices); | |
119 } | 160 } |
120 | 161 |
121 void HotplugEventHandlerX11::HandleTouchscreenDevices( | 162 void HotplugEventHandlerX11::HandleTouchscreenDevices( |
122 const XIDeviceList& x11_devices) { | 163 const XIDeviceList& x11_devices) { |
123 std::vector<TouchscreenDevice> devices; | 164 std::vector<TouchscreenDevice> devices; |
124 Display* display = gfx::GetXDisplay(); | 165 Display* display = gfx::GetXDisplay(); |
125 Atom valuator_x = XInternAtom(display, "Abs MT Position X", False); | 166 Atom valuator_x = XInternAtom(display, "Abs MT Position X", False); |
126 Atom valuator_y = XInternAtom(display, "Abs MT Position Y", False); | 167 Atom valuator_y = XInternAtom(display, "Abs MT Position Y", False); |
127 if (valuator_x == None || valuator_y == None) | 168 if (valuator_x == None || valuator_y == None) |
128 return; | 169 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 IsTouchscreenInternal(display, x11_devices[i].deviceid); | 214 IsTouchscreenInternal(display, x11_devices[i].deviceid); |
174 devices.push_back(TouchscreenDevice( | 215 devices.push_back(TouchscreenDevice( |
175 x11_devices[i].deviceid, gfx::Size(width, height), is_internal)); | 216 x11_devices[i].deviceid, gfx::Size(width, height), is_internal)); |
176 } | 217 } |
177 } | 218 } |
178 | 219 |
179 delegate_->OnTouchscreenDevicesUpdated(devices); | 220 delegate_->OnTouchscreenDevicesUpdated(devices); |
180 } | 221 } |
181 | 222 |
182 } // namespace ui | 223 } // namespace ui |
OLD | NEW |