OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ozone/evdev/input_device_factory_evdev.h" | 5 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/stringprintf.h" | |
12 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
13 #include "base/threading/worker_pool.h" | 12 #include "base/threading/worker_pool.h" |
14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
15 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
16 #include "ui/events/devices/device_data_manager.h" | 15 #include "ui/events/devices/device_data_manager.h" |
17 #include "ui/events/devices/device_util_linux.h" | 16 #include "ui/events/devices/device_util_linux.h" |
18 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | 17 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
19 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 18 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
20 #include "ui/events/ozone/evdev/event_device_info.h" | 19 #include "ui/events/ozone/evdev/event_device_info.h" |
21 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 20 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
22 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 21 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
23 | 22 |
24 #if defined(USE_EVDEV_GESTURES) | 23 #if defined(USE_EVDEV_GESTURES) |
25 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" | 24 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
| 25 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h" |
26 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 26 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
27 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 27 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
28 #endif | 28 #endif |
29 | 29 |
30 #ifndef EVIOCSCLOCKID | 30 #ifndef EVIOCSCLOCKID |
31 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) | 31 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
32 #endif | 32 #endif |
33 | 33 |
34 namespace ui { | 34 namespace ui { |
35 | 35 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 int id, | 81 int id, |
82 const std::string& name, | 82 const std::string& name, |
83 bool value) { | 83 bool value) { |
84 GesturesProp* property = provider->GetProperty(id, name); | 84 GesturesProp* property = provider->GetProperty(id, name); |
85 if (property) { | 85 if (property) { |
86 std::vector<bool> values(1, value); | 86 std::vector<bool> values(1, value); |
87 property->SetBoolValue(values); | 87 property->SetBoolValue(values); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 // Return the values in an array in one string. Used for touch logging. | |
92 template <typename T> | |
93 std::string DumpArrayProperty(const std::vector<T>& value, const char* format) { | |
94 std::string ret; | |
95 for (size_t i = 0; i < value.size(); ++i) { | |
96 if (i > 0) | |
97 ret.append(", "); | |
98 ret.append(base::StringPrintf(format, value[i])); | |
99 } | |
100 return ret; | |
101 } | |
102 | |
103 // Return the values in a gesture property in one string. Used for touch | |
104 // logging. | |
105 std::string DumpGesturePropertyValue(GesturesProp* property) { | |
106 switch (property->type()) { | |
107 case GesturePropertyProvider::PT_INT: | |
108 return DumpArrayProperty(property->GetIntValue(), "%d"); | |
109 break; | |
110 case GesturePropertyProvider::PT_SHORT: | |
111 return DumpArrayProperty(property->GetShortValue(), "%d"); | |
112 break; | |
113 case GesturePropertyProvider::PT_BOOL: | |
114 return DumpArrayProperty(property->GetBoolValue(), "%d"); | |
115 break; | |
116 case GesturePropertyProvider::PT_STRING: | |
117 return "\"" + property->GetStringValue() + "\""; | |
118 break; | |
119 case GesturePropertyProvider::PT_REAL: | |
120 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); | |
121 break; | |
122 default: | |
123 NOTREACHED(); | |
124 break; | |
125 } | |
126 return std::string(); | |
127 } | |
128 | |
129 // Dump touch device property values to a string. | |
130 void DumpTouchDeviceStatus(GesturePropertyProvider* provider, | |
131 std::string* status) { | |
132 // We use DT_ALL since we want gesture property values for all devices that | |
133 // run with the gesture library, not just mice or touchpads. | |
134 std::vector<int> ids; | |
135 provider->GetDeviceIdsByType(DT_ALL, &ids); | |
136 | |
137 // Dump the property names and values for each device. | |
138 for (size_t i = 0; i < ids.size(); ++i) { | |
139 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]); | |
140 status->append("\n"); | |
141 status->append(base::StringPrintf("ID %d:\n", ids[i])); | |
142 status->append(base::StringPrintf( | |
143 "Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str())); | |
144 | |
145 // Note that, unlike X11, we don't maintain the "atom" concept here. | |
146 // Therefore, the property name indices we output here shouldn't be treated | |
147 // as unique identifiers of the properties. | |
148 std::sort(names.begin(), names.end()); | |
149 for (size_t j = 0; j < names.size(); ++j) { | |
150 status->append(base::StringPrintf("\t%s (%zu):", names[j].c_str(), j)); | |
151 GesturesProp* property = provider->GetProperty(ids[i], names[j]); | |
152 status->append("\t" + DumpGesturePropertyValue(property) + '\n'); | |
153 } | |
154 } | |
155 } | |
156 #endif | 91 #endif |
157 | 92 |
158 scoped_ptr<EventConverterEvdev> CreateConverter( | 93 scoped_ptr<EventConverterEvdev> CreateConverter( |
159 const OpenInputDeviceParams& params, | 94 const OpenInputDeviceParams& params, |
160 int fd, | 95 int fd, |
161 InputDeviceType type, | 96 InputDeviceType type, |
162 const EventDeviceInfo& devinfo) { | 97 const EventDeviceInfo& devinfo) { |
163 #if defined(USE_EVDEV_GESTURES) | 98 #if defined(USE_EVDEV_GESTURES) |
164 // Touchpad or mouse: use gestures library. | 99 // Touchpad or mouse: use gestures library. |
165 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent | 100 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 336 |
402 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( | 337 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( |
403 const GetTouchDeviceStatusReply& reply) { | 338 const GetTouchDeviceStatusReply& reply) { |
404 scoped_ptr<std::string> status(new std::string); | 339 scoped_ptr<std::string> status(new std::string); |
405 #if defined(USE_EVDEV_GESTURES) | 340 #if defined(USE_EVDEV_GESTURES) |
406 DumpTouchDeviceStatus(gesture_property_provider_.get(), status.get()); | 341 DumpTouchDeviceStatus(gesture_property_provider_.get(), status.get()); |
407 #endif | 342 #endif |
408 reply.Run(status.Pass()); | 343 reply.Run(status.Pass()); |
409 } | 344 } |
410 | 345 |
| 346 void InputDeviceFactoryEvdev::GetTouchEventLog( |
| 347 const base::FilePath& out_dir, |
| 348 const GetTouchEventLogReply& reply) { |
| 349 scoped_ptr<std::vector<base::FilePath>> log_paths( |
| 350 new std::vector<base::FilePath>); |
| 351 #if defined(USE_EVDEV_GESTURES) |
| 352 DumpTouchEventLog(gesture_property_provider_.get(), out_dir, log_paths.Pass(), |
| 353 reply); |
| 354 #else |
| 355 reply.Run(log_paths.Pass()); |
| 356 #endif |
| 357 } |
| 358 |
411 base::WeakPtr<InputDeviceFactoryEvdev> InputDeviceFactoryEvdev::GetWeakPtr() { | 359 base::WeakPtr<InputDeviceFactoryEvdev> InputDeviceFactoryEvdev::GetWeakPtr() { |
412 return weak_ptr_factory_.GetWeakPtr(); | 360 return weak_ptr_factory_.GetWeakPtr(); |
413 } | 361 } |
414 | 362 |
415 void InputDeviceFactoryEvdev::ApplyInputDeviceSettings() { | 363 void InputDeviceFactoryEvdev::ApplyInputDeviceSettings() { |
416 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", | 364 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", |
417 input_device_settings_.touchpad_sensitivity); | 365 input_device_settings_.touchpad_sensitivity); |
418 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", | 366 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", |
419 input_device_settings_.touchpad_sensitivity); | 367 input_device_settings_.touchpad_sensitivity); |
420 | 368 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 std::vector<int> ids; | 484 std::vector<int> ids; |
537 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 485 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
538 for (size_t i = 0; i < ids.size(); ++i) { | 486 for (size_t i = 0; i < ids.size(); ++i) { |
539 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 487 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
540 value); | 488 value); |
541 } | 489 } |
542 #endif | 490 #endif |
543 } | 491 } |
544 | 492 |
545 } // namespace ui | 493 } // namespace ui |
OLD | NEW |