| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 name(device.name), | 93 name(device.name), |
| 94 use(device.use), | 94 use(device.use), |
| 95 enabled(device.enabled), | 95 enabled(device.enabled), |
| 96 path(path) { | 96 path(path) { |
| 97 for (int i = 0; i < device.num_classes; ++i) { | 97 for (int i = 0; i < device.num_classes; ++i) { |
| 98 switch (device.classes[i]->type) { | 98 switch (device.classes[i]->type) { |
| 99 case XIValuatorClass: | 99 case XIValuatorClass: |
| 100 valuator_class_infos.push_back(ValuatorClassInfo( | 100 valuator_class_infos.push_back(ValuatorClassInfo( |
| 101 *reinterpret_cast<XIValuatorClassInfo*>(device.classes[i]))); | 101 *reinterpret_cast<XIValuatorClassInfo*>(device.classes[i]))); |
| 102 break; | 102 break; |
| 103 #if defined(USE_XI2_MT) | |
| 104 case XITouchClass: | 103 case XITouchClass: |
| 105 touch_class_infos.push_back(TouchClassInfo( | 104 touch_class_infos.push_back(TouchClassInfo( |
| 106 *reinterpret_cast<XITouchClassInfo*>(device.classes[i]))); | 105 *reinterpret_cast<XITouchClassInfo*>(device.classes[i]))); |
| 107 break; | 106 break; |
| 108 #endif | |
| 109 default: | 107 default: |
| 110 break; | 108 break; |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 } | 111 } |
| 114 | 112 |
| 115 // Unique device identifier. | 113 // Unique device identifier. |
| 116 int id; | 114 int id; |
| 117 | 115 |
| 118 // Internal device name. | 116 // Internal device name. |
| 119 std::string name; | 117 std::string name; |
| 120 | 118 |
| 121 // Device type (ie: XIMasterPointer) | 119 // Device type (ie: XIMasterPointer) |
| 122 int use; | 120 int use; |
| 123 | 121 |
| 124 // Specifies if the device is enabled and can send events. | 122 // Specifies if the device is enabled and can send events. |
| 125 bool enabled; | 123 bool enabled; |
| 126 | 124 |
| 127 // Path to the actual device (ie: /dev/input/eventXX) | 125 // Path to the actual device (ie: /dev/input/eventXX) |
| 128 base::FilePath path; | 126 base::FilePath path; |
| 129 | 127 |
| 130 std::vector<ValuatorClassInfo> valuator_class_infos; | 128 std::vector<ValuatorClassInfo> valuator_class_infos; |
| 131 | 129 |
| 132 #if defined(USE_XI2_MT) | |
| 133 std::vector<TouchClassInfo> touch_class_infos; | 130 std::vector<TouchClassInfo> touch_class_infos; |
| 134 #endif | |
| 135 }; | 131 }; |
| 136 | 132 |
| 137 // X11 display cache used on worker threads. This is filled on the UI thread and | 133 // X11 display cache used on worker threads. This is filled on the UI thread and |
| 138 // passed in to the worker threads. | 134 // passed in to the worker threads. |
| 139 struct DisplayState { | 135 struct DisplayState { |
| 140 Atom mt_position_x; | 136 Atom mt_position_x; |
| 141 Atom mt_position_y; | 137 Atom mt_position_y; |
| 142 }; | 138 }; |
| 143 | 139 |
| 144 // Returns true if |name| is the name of a known keyboard device. Note, this may | 140 // Returns true if |name| is the name of a known keyboard device. Note, this may |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 270 } |
| 275 } else if (display_state.mt_position_y == valuator.label) { | 271 } else if (display_state.mt_position_y == valuator.label) { |
| 276 // Ignore Y axis valuator with unexpected properties | 272 // Ignore Y axis valuator with unexpected properties |
| 277 if (valuator.number == 1 && valuator.mode == Absolute && | 273 if (valuator.number == 1 && valuator.mode == Absolute && |
| 278 valuator.min == 0.0) { | 274 valuator.min == 0.0) { |
| 279 max_y = valuator.max; | 275 max_y = valuator.max; |
| 280 } | 276 } |
| 281 } | 277 } |
| 282 } | 278 } |
| 283 | 279 |
| 284 #if defined(USE_XI2_MT) | |
| 285 for (const TouchClassInfo& info : device_info.touch_class_infos) { | 280 for (const TouchClassInfo& info : device_info.touch_class_infos) { |
| 286 is_direct_touch = info.mode == XIDirectTouch; | 281 is_direct_touch = info.mode == XIDirectTouch; |
| 287 } | 282 } |
| 288 #endif | |
| 289 | 283 |
| 290 // Touchscreens should have absolute X and Y axes, and be direct touch | 284 // Touchscreens should have absolute X and Y axes, and be direct touch |
| 291 // devices. | 285 // devices. |
| 292 if (max_x > 0.0 && max_y > 0.0 && is_direct_touch) { | 286 if (max_x > 0.0 && max_y > 0.0 && is_direct_touch) { |
| 293 InputDeviceType type = IsTouchscreenInternal(device_info.path) | 287 InputDeviceType type = IsTouchscreenInternal(device_info.path) |
| 294 ? InputDeviceType::INPUT_DEVICE_INTERNAL | 288 ? InputDeviceType::INPUT_DEVICE_INTERNAL |
| 295 : InputDeviceType::INPUT_DEVICE_EXTERNAL; | 289 : InputDeviceType::INPUT_DEVICE_EXTERNAL; |
| 296 // |max_x| and |max_y| are inclusive values, so we need to add 1 to get | 290 // |max_x| and |max_y| are inclusive values, so we need to add 1 to get |
| 297 // the size. | 291 // the size. |
| 298 devices.push_back(TouchscreenDevice( | 292 devices.push_back(TouchscreenDevice( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 base::WorkerPool::PostTask(FROM_HERE, | 358 base::WorkerPool::PostTask(FROM_HERE, |
| 365 base::Bind(&HandleHotplugEventInWorker, | 359 base::Bind(&HandleHotplugEventInWorker, |
| 366 device_infos, | 360 device_infos, |
| 367 display_state, | 361 display_state, |
| 368 base::ThreadTaskRunnerHandle::Get(), | 362 base::ThreadTaskRunnerHandle::Get(), |
| 369 callbacks), | 363 callbacks), |
| 370 true /* task_is_slow */); | 364 true /* task_is_slow */); |
| 371 } | 365 } |
| 372 | 366 |
| 373 } // namespace ui | 367 } // namespace ui |
| OLD | NEW |