Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: ui/events/x/hotplug_event_handler_x11.cc

Issue 618283003: Adds special support to the device manager for keyboards devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <cmath> 10 #include <cmath>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/files/file_enumerator.h" 16 #include "base/files/file_enumerator.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/process/launch.h" 18 #include "base/process/launch.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/sys_info.h" 20 #include "base/sys_info.h"
21 #include "ui/events/device_hotplug_event_observer.h" 21 #include "ui/events/device_hotplug_event_observer.h"
22 #include "ui/events/keyboard_device.h"
22 #include "ui/events/touchscreen_device.h" 23 #include "ui/events/touchscreen_device.h"
23 #include "ui/gfx/x/x11_types.h" 24 #include "ui/gfx/x/x11_types.h"
24 25
25 namespace ui { 26 namespace ui {
26 27
27 namespace { 28 namespace {
28 29
30 // The name of the xinput device corresponding to the internal keyboard.
31 const char kInternalKeyboardName[] = "AT Translated Set 2 keyboard";
32
33 // The name of the xinput device corresponding to the test keyboard.
34 const char kTestKeyboardName[] = "Virtual core XTEST keyboard";
35
36 // Filters out devices like the power button which are also SlaveKeyboards but
37 // not true keyboards.
38 bool IsKeyboard(std::string name) {
dnicoara 2014/10/02 13:58:20 Not sure if this would cover all keyboard devices.
rsadam 2014/10/02 14:59:31 Added an UNKNOWN Enum, and marked these devices as
flackr 2014/10/02 15:41:10 Agreed. I think false negatives are okay for how w
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
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 if (!IsKeyboard(device_name))
148 continue;
149 KeyboardDeviceType type = KeyboardDeviceType::EXTERNAL;
150 if (device_name == kInternalKeyboardName) {
151 type = KeyboardDeviceType::INTERNAL;
152 } else if (device_name == kTestKeyboardName) {
dnicoara 2014/10/02 13:58:20 Is there anything special about test devices?
rsadam 2014/10/02 14:59:31 Each Master device has a XTEST device associated t
flackr 2014/10/02 15:41:10 This device shouldn't be considered a user accessi
153 type = KeyboardDeviceType::TEST;
154 }
155 devices.push_back(KeyboardDevice(x11_devices[i].deviceid, type));
156 }
157 delegate_->OnKeyboardDevicesUpdated(devices);
119 } 158 }
120 159
121 void HotplugEventHandlerX11::HandleTouchscreenDevices( 160 void HotplugEventHandlerX11::HandleTouchscreenDevices(
122 const XIDeviceList& x11_devices) { 161 const XIDeviceList& x11_devices) {
123 std::vector<TouchscreenDevice> devices; 162 std::vector<TouchscreenDevice> devices;
124 Display* display = gfx::GetXDisplay(); 163 Display* display = gfx::GetXDisplay();
125 Atom valuator_x = XInternAtom(display, "Abs MT Position X", False); 164 Atom valuator_x = XInternAtom(display, "Abs MT Position X", False);
126 Atom valuator_y = XInternAtom(display, "Abs MT Position Y", False); 165 Atom valuator_y = XInternAtom(display, "Abs MT Position Y", False);
127 if (valuator_x == None || valuator_y == None) 166 if (valuator_x == None || valuator_y == None)
128 return; 167 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 IsTouchscreenInternal(display, x11_devices[i].deviceid); 212 IsTouchscreenInternal(display, x11_devices[i].deviceid);
174 devices.push_back(TouchscreenDevice( 213 devices.push_back(TouchscreenDevice(
175 x11_devices[i].deviceid, gfx::Size(width, height), is_internal)); 214 x11_devices[i].deviceid, gfx::Size(width, height), is_internal));
176 } 215 }
177 } 216 }
178 217
179 delegate_->OnTouchscreenDevicesUpdated(devices); 218 delegate_->OnTouchscreenDevicesUpdated(devices);
180 } 219 }
181 220
182 } // namespace ui 221 } // namespace ui
OLDNEW
« ui/events/keyboard_device.h ('K') | « ui/events/x/hotplug_event_handler_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698