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/ozone/evdev/input_controller_evdev.h" | 5 #include "ui/events/ozone/evdev/input_controller_evdev.h" |
6 | 6 |
| 7 #include <algorithm> |
7 #include <linux/input.h> | 8 #include <linux/input.h> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
| 11 #include "base/strings/stringprintf.h" |
10 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 12 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
11 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" | 13 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h" |
12 | 14 |
13 #if defined(USE_EVDEV_GESTURES) | 15 #if defined(USE_EVDEV_GESTURES) |
14 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 16 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
15 #endif | 17 #endif |
16 | 18 |
17 namespace ui { | 19 namespace ui { |
18 | 20 |
19 namespace { | 21 namespace { |
(...skipping 13 matching lines...) Expand all Loading... |
33 void SetGestureBoolProperty(GesturePropertyProvider* provider, | 35 void SetGestureBoolProperty(GesturePropertyProvider* provider, |
34 int id, | 36 int id, |
35 const std::string& name, | 37 const std::string& name, |
36 bool value) { | 38 bool value) { |
37 GesturesProp* property = provider->GetProperty(id, name); | 39 GesturesProp* property = provider->GetProperty(id, name); |
38 if (property) { | 40 if (property) { |
39 std::vector<bool> values(1, value); | 41 std::vector<bool> values(1, value); |
40 property->SetBoolValue(values); | 42 property->SetBoolValue(values); |
41 } | 43 } |
42 } | 44 } |
| 45 |
| 46 // Return the values in an array in one string. Used for touch logging. |
| 47 template <typename T> |
| 48 std::string DumpArrayProperty(const std::vector<T>& value, const char* format) { |
| 49 std::string ret; |
| 50 for (size_t i = 0; i < value.size(); ++i) { |
| 51 if (i > 0) |
| 52 ret.append(", "); |
| 53 ret.append(base::StringPrintf(format, value[i])); |
| 54 } |
| 55 return ret; |
| 56 } |
| 57 |
| 58 // Return the values in a gesture property in one string. Used for touch |
| 59 // logging. |
| 60 std::string DumpGesturePropertyValue(GesturesProp* property) { |
| 61 switch (property->type()) { |
| 62 case GesturePropertyProvider::PT_INT: |
| 63 return DumpArrayProperty(property->GetIntValue(), "%d"); |
| 64 break; |
| 65 case GesturePropertyProvider::PT_SHORT: |
| 66 return DumpArrayProperty(property->GetShortValue(), "%d"); |
| 67 break; |
| 68 case GesturePropertyProvider::PT_BOOL: |
| 69 return DumpArrayProperty(property->GetBoolValue(), "%d"); |
| 70 break; |
| 71 case GesturePropertyProvider::PT_STRING: |
| 72 return "\"" + property->GetStringValue() + "\""; |
| 73 break; |
| 74 case GesturePropertyProvider::PT_REAL: |
| 75 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); |
| 76 break; |
| 77 default: |
| 78 NOTREACHED(); |
| 79 break; |
| 80 } |
| 81 return std::string(); |
| 82 } |
| 83 |
43 #endif | 84 #endif |
44 | 85 |
45 } // namespace | 86 } // namespace |
46 | 87 |
47 InputControllerEvdev::InputControllerEvdev( | 88 InputControllerEvdev::InputControllerEvdev( |
48 EventFactoryEvdev* event_factory, | 89 EventFactoryEvdev* event_factory, |
49 KeyboardEvdev* keyboard, | 90 KeyboardEvdev* keyboard, |
50 MouseButtonMapEvdev* button_map | 91 MouseButtonMapEvdev* button_map |
51 #if defined(USE_EVDEV_GESTURES) | 92 #if defined(USE_EVDEV_GESTURES) |
52 , | 93 , |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 218 |
178 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { | 219 void InputControllerEvdev::SetPrimaryButtonRight(bool right) { |
179 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); | 220 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT); |
180 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); | 221 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT); |
181 } | 222 } |
182 | 223 |
183 void InputControllerEvdev::SetTapToClickPaused(bool state) { | 224 void InputControllerEvdev::SetTapToClickPaused(bool state) { |
184 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 225 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
185 } | 226 } |
186 | 227 |
| 228 std::string InputControllerEvdev::GetGestureDeviceStatus() { |
| 229 std::string ret; |
| 230 #if defined(USE_EVDEV_GESTURES) |
| 231 // We use DT_ALL since we want gesture property values for all devices that |
| 232 // run with the gesture library, not just mice or touchpads. |
| 233 std::vector<int> ids; |
| 234 event_factory_->GetDeviceIdsByType(DT_ALL, &ids); |
| 235 |
| 236 // Dump the property names and values for each device. |
| 237 for (size_t i = 0; i < ids.size(); ++i) { |
| 238 std::vector<std::string> names = |
| 239 gesture_property_provider_->GetPropertyNamesById(ids[i]); |
| 240 ret.append("\n"); |
| 241 ret.append(base::StringPrintf("ID %d:\n", ids[i])); |
| 242 ret.append(base::StringPrintf( |
| 243 "Device \'%s\':\n", |
| 244 gesture_property_provider_->GetDeviceNameById(ids[i]).c_str())); |
| 245 |
| 246 // Note that, unlike X11, we don't maintain the "atom" concept here. |
| 247 // Therefore, the property name indices we output here shouldn't be treated |
| 248 // as unique identifiers of the properties. |
| 249 std::sort(names.begin(), names.end()); |
| 250 for (size_t j = 0; j < names.size(); ++j) { |
| 251 ret.append(base::StringPrintf("\t%s (%lu):", names[j].c_str(), j)); |
| 252 GesturesProp* property = |
| 253 gesture_property_provider_->GetProperty(ids[i], names[j]); |
| 254 ret.append("\t" + DumpGesturePropertyValue(property) + '\n'); |
| 255 } |
| 256 } |
| 257 #endif |
| 258 return ret; |
| 259 } |
| 260 |
187 } // namespace ui | 261 } // namespace ui |
OLD | NEW |