| 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/platform/x11/x11_hotplug_event_handler.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 <algorithm> |
| 11 #include <cmath> | 11 #include <cmath> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.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/devices/device_hotplug_event_observer.h" |
| 22 #include "ui/events/device_util_linux.h" | 22 #include "ui/events/devices/device_util_linux.h" |
| 23 #include "ui/events/input_device.h" | 23 #include "ui/events/devices/input_device.h" |
| 24 #include "ui/events/keyboard_device.h" | 24 #include "ui/events/devices/keyboard_device.h" |
| 25 #include "ui/events/touchscreen_device.h" | 25 #include "ui/events/devices/touchscreen_device.h" |
| 26 #include "ui/gfx/x/x11_types.h" | 26 #include "ui/gfx/x/x11_types.h" |
| 27 | 27 |
| 28 namespace ui { | 28 namespace ui { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // The name of the xinput device corresponding to the AT internal keyboard. | 32 // The name of the xinput device corresponding to the AT internal keyboard. |
| 33 const char kATKeyboardName[] = "AT Translated Set 2 keyboard"; | 33 const char kATKeyboardName[] = "AT Translated Set 2 keyboard"; |
| 34 | 34 |
| 35 // The prefix of xinput devices corresponding to CrOS EC internal keyboards. | 35 // The prefix of xinput devices corresponding to CrOS EC internal keyboards. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 base::FilePath dev_node_path(reinterpret_cast<char*>(data)); | 103 base::FilePath dev_node_path(reinterpret_cast<char*>(data)); |
| 104 XFree(data); | 104 XFree(data); |
| 105 XCloseDevice(dpy, dev); | 105 XCloseDevice(dpy, dev); |
| 106 | 106 |
| 107 return ui::IsTouchscreenInternal(dev_node_path); | 107 return ui::IsTouchscreenInternal(dev_node_path); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace | 110 } // namespace |
| 111 | 111 |
| 112 HotplugEventHandlerX11::HotplugEventHandlerX11( | 112 X11HotplugEventHandler::X11HotplugEventHandler( |
| 113 DeviceHotplugEventObserver* delegate) | 113 DeviceHotplugEventObserver* delegate) |
| 114 : delegate_(delegate) { | 114 : delegate_(delegate) { |
| 115 } | 115 } |
| 116 | 116 |
| 117 HotplugEventHandlerX11::~HotplugEventHandlerX11() { | 117 X11HotplugEventHandler::~X11HotplugEventHandler() { |
| 118 } | 118 } |
| 119 | 119 |
| 120 void HotplugEventHandlerX11::OnHotplugEvent() { | 120 void X11HotplugEventHandler::OnHotplugEvent() { |
| 121 const XIDeviceList& device_list = | 121 const XIDeviceList& device_list = |
| 122 DeviceListCacheX::GetInstance()->GetXI2DeviceList(gfx::GetXDisplay()); | 122 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(gfx::GetXDisplay()); |
| 123 HandleTouchscreenDevices(device_list); | 123 HandleTouchscreenDevices(device_list); |
| 124 HandleKeyboardDevices(device_list); | 124 HandleKeyboardDevices(device_list); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void HotplugEventHandlerX11::HandleKeyboardDevices( | 127 void X11HotplugEventHandler::HandleKeyboardDevices( |
| 128 const XIDeviceList& x11_devices) { | 128 const XIDeviceList& x11_devices) { |
| 129 std::vector<KeyboardDevice> devices; | 129 std::vector<KeyboardDevice> devices; |
| 130 | 130 |
| 131 for (int i = 0; i < x11_devices.count; i++) { | 131 for (int i = 0; i < x11_devices.count; i++) { |
| 132 if (!x11_devices[i].enabled || x11_devices[i].use != XISlaveKeyboard) | 132 if (!x11_devices[i].enabled || x11_devices[i].use != XISlaveKeyboard) |
| 133 continue; // Assume all keyboards are keyboard slaves | 133 continue; // Assume all keyboards are keyboard slaves |
| 134 std::string device_name(x11_devices[i].name); | 134 std::string device_name(x11_devices[i].name); |
| 135 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); | 135 base::TrimWhitespaceASCII(device_name, base::TRIM_TRAILING, &device_name); |
| 136 if (IsTestKeyboard(device_name)) | 136 if (IsTestKeyboard(device_name)) |
| 137 continue; // Skip test devices. | 137 continue; // Skip test devices. |
| 138 InputDeviceType type; | 138 InputDeviceType type; |
| 139 if (IsInternalKeyboard(device_name)) { | 139 if (IsInternalKeyboard(device_name)) { |
| 140 type = InputDeviceType::INPUT_DEVICE_INTERNAL; | 140 type = InputDeviceType::INPUT_DEVICE_INTERNAL; |
| 141 } else if (IsKnownKeyboard(device_name)) { | 141 } else if (IsKnownKeyboard(device_name)) { |
| 142 type = InputDeviceType::INPUT_DEVICE_EXTERNAL; | 142 type = InputDeviceType::INPUT_DEVICE_EXTERNAL; |
| 143 } else { | 143 } else { |
| 144 type = InputDeviceType::INPUT_DEVICE_UNKNOWN; | 144 type = InputDeviceType::INPUT_DEVICE_UNKNOWN; |
| 145 } | 145 } |
| 146 devices.push_back( | 146 devices.push_back( |
| 147 KeyboardDevice(x11_devices[i].deviceid, type, device_name)); | 147 KeyboardDevice(x11_devices[i].deviceid, type, device_name)); |
| 148 } | 148 } |
| 149 delegate_->OnKeyboardDevicesUpdated(devices); | 149 delegate_->OnKeyboardDevicesUpdated(devices); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void HotplugEventHandlerX11::HandleTouchscreenDevices( | 152 void X11HotplugEventHandler::HandleTouchscreenDevices( |
| 153 const XIDeviceList& x11_devices) { | 153 const XIDeviceList& x11_devices) { |
| 154 std::vector<TouchscreenDevice> devices; | 154 std::vector<TouchscreenDevice> devices; |
| 155 Display* display = gfx::GetXDisplay(); | 155 Display* display = gfx::GetXDisplay(); |
| 156 Atom valuator_x = XInternAtom(display, "Abs MT Position X", False); | 156 Atom valuator_x = XInternAtom(display, "Abs MT Position X", False); |
| 157 Atom valuator_y = XInternAtom(display, "Abs MT Position Y", False); | 157 Atom valuator_y = XInternAtom(display, "Abs MT Position Y", False); |
| 158 if (valuator_x == None || valuator_y == None) | 158 if (valuator_x == None || valuator_y == None) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 std::set<int> no_match_touchscreen; | 161 std::set<int> no_match_touchscreen; |
| 162 for (int i = 0; i < x11_devices.count; i++) { | 162 for (int i = 0; i < x11_devices.count; i++) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 type, | 212 type, |
| 213 name, | 213 name, |
| 214 gfx::Size(max_x + 1, max_y + 1))); | 214 gfx::Size(max_x + 1, max_y + 1))); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 delegate_->OnTouchscreenDevicesUpdated(devices); | 218 delegate_->OnTouchscreenDevicesUpdated(devices); |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace ui | 221 } // namespace ui |
| OLD | NEW |