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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 358 |
424 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( | 359 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( |
425 const GetTouchDeviceStatusReply& reply) { | 360 const GetTouchDeviceStatusReply& reply) { |
426 scoped_ptr<std::string> status(new std::string); | 361 scoped_ptr<std::string> status(new std::string); |
427 #if defined(USE_EVDEV_GESTURES) | 362 #if defined(USE_EVDEV_GESTURES) |
428 DumpTouchDeviceStatus(gesture_property_provider_.get(), status.get()); | 363 DumpTouchDeviceStatus(gesture_property_provider_.get(), status.get()); |
429 #endif | 364 #endif |
430 reply.Run(status.Pass()); | 365 reply.Run(status.Pass()); |
431 } | 366 } |
432 | 367 |
| 368 void InputDeviceFactoryEvdev::GetTouchEventLog( |
| 369 const base::FilePath& out_dir, |
| 370 const GetTouchEventLogReply& reply) { |
| 371 scoped_ptr<std::vector<base::FilePath>> log_paths( |
| 372 new std::vector<base::FilePath>); |
| 373 #if defined(USE_EVDEV_GESTURES) |
| 374 DumpTouchEventLog(gesture_property_provider_.get(), out_dir, log_paths.Pass(), |
| 375 reply); |
| 376 #else |
| 377 reply.Run(log_paths.Pass()); |
| 378 #endif |
| 379 } |
| 380 |
433 base::WeakPtr<InputDeviceFactoryEvdev> InputDeviceFactoryEvdev::GetWeakPtr() { | 381 base::WeakPtr<InputDeviceFactoryEvdev> InputDeviceFactoryEvdev::GetWeakPtr() { |
434 return weak_ptr_factory_.GetWeakPtr(); | 382 return weak_ptr_factory_.GetWeakPtr(); |
435 } | 383 } |
436 | 384 |
437 void InputDeviceFactoryEvdev::UpdateDirtyFlags( | 385 void InputDeviceFactoryEvdev::UpdateDirtyFlags( |
438 const EventConverterEvdev* converter) { | 386 const EventConverterEvdev* converter) { |
439 if (converter->HasTouchscreen()) | 387 if (converter->HasTouchscreen()) |
440 touchscreen_list_dirty_ = true; | 388 touchscreen_list_dirty_ = true; |
441 | 389 |
442 if (converter->HasKeyboard()) | 390 if (converter->HasKeyboard()) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 std::vector<int> ids; | 481 std::vector<int> ids; |
534 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 482 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
535 for (size_t i = 0; i < ids.size(); ++i) { | 483 for (size_t i = 0; i < ids.size(); ++i) { |
536 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 484 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
537 value); | 485 value); |
538 } | 486 } |
539 #endif | 487 #endif |
540 } | 488 } |
541 | 489 |
542 } // namespace ui | 490 } // namespace ui |
OLD | NEW |