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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "ui/events/devices/device_data_manager.h" | 15 #include "ui/events/devices/device_data_manager.h" |
16 #include "ui/events/devices/device_util_linux.h" | 16 #include "ui/events/devices/device_util_linux.h" |
| 17 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
17 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 18 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
18 #include "ui/events/ozone/evdev/event_device_info.h" | 19 #include "ui/events/ozone/evdev/event_device_info.h" |
19 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 20 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
20 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 21 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
21 | 22 |
22 #if defined(USE_EVDEV_GESTURES) | 23 #if defined(USE_EVDEV_GESTURES) |
23 #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" |
24 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 25 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
25 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 26 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
26 #endif | 27 #endif |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); | 119 return DumpArrayProperty(property->GetDoubleValue(), "%lf"); |
119 break; | 120 break; |
120 default: | 121 default: |
121 NOTREACHED(); | 122 NOTREACHED(); |
122 break; | 123 break; |
123 } | 124 } |
124 return std::string(); | 125 return std::string(); |
125 } | 126 } |
126 | 127 |
127 // Dump touch device property values to a string. | 128 // Dump touch device property values to a string. |
128 void DumpTouchDeviceStatus(InputDeviceFactoryEvdev* device_factory, | 129 void DumpTouchDeviceStatus(GesturePropertyProvider* provider, |
129 GesturePropertyProvider* provider, | |
130 std::string* status) { | 130 std::string* status) { |
131 // We use DT_ALL since we want gesture property values for all devices that | 131 // We use DT_ALL since we want gesture property values for all devices that |
132 // run with the gesture library, not just mice or touchpads. | 132 // run with the gesture library, not just mice or touchpads. |
133 std::vector<int> ids; | 133 std::vector<int> ids; |
134 device_factory->GetDeviceIdsByType(DT_ALL, &ids); | 134 provider->GetDeviceIdsByType(DT_ALL, &ids); |
135 | 135 |
136 // Dump the property names and values for each device. | 136 // Dump the property names and values for each device. |
137 for (size_t i = 0; i < ids.size(); ++i) { | 137 for (size_t i = 0; i < ids.size(); ++i) { |
138 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]); | 138 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]); |
139 status->append("\n"); | 139 status->append("\n"); |
140 status->append(base::StringPrintf("ID %d:\n", ids[i])); | 140 status->append(base::StringPrintf("ID %d:\n", ids[i])); |
141 status->append(base::StringPrintf( | 141 status->append(base::StringPrintf( |
142 "Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str())); | 142 "Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str())); |
143 | 143 |
144 // Note that, unlike X11, we don't maintain the "atom" concept here. | 144 // Note that, unlike X11, we don't maintain the "atom" concept here. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { | 367 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { |
368 for (const auto& it : converters_) { | 368 for (const auto& it : converters_) { |
369 EventConverterEvdev* converter = it.second; | 369 EventConverterEvdev* converter = it.second; |
370 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && | 370 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && |
371 converter->HasKeyboard()) { | 371 converter->HasKeyboard()) { |
372 converter->AllowAllKeys(); | 372 converter->AllowAllKeys(); |
373 } | 373 } |
374 } | 374 } |
375 } | 375 } |
376 | 376 |
377 bool InputDeviceFactoryEvdev::HasMouse() { | |
378 return GetDeviceIdsByType(DT_MOUSE, NULL); | |
379 } | |
380 | |
381 bool InputDeviceFactoryEvdev::HasTouchpad() { | |
382 return GetDeviceIdsByType(DT_TOUCHPAD, NULL); | |
383 } | |
384 | |
385 void InputDeviceFactoryEvdev::SetTouchpadSensitivity(int value) { | 377 void InputDeviceFactoryEvdev::SetTouchpadSensitivity(int value) { |
386 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value); | 378 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value); |
387 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value); | 379 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value); |
388 } | 380 } |
389 | 381 |
390 void InputDeviceFactoryEvdev::SetTapToClick(bool enabled) { | 382 void InputDeviceFactoryEvdev::SetTapToClick(bool enabled) { |
391 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Enable", enabled); | 383 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Enable", enabled); |
392 } | 384 } |
393 | 385 |
394 void InputDeviceFactoryEvdev::SetThreeFingerClick(bool enabled) { | 386 void InputDeviceFactoryEvdev::SetThreeFingerClick(bool enabled) { |
(...skipping 15 matching lines...) Expand all Loading... |
410 } | 402 } |
411 | 403 |
412 void InputDeviceFactoryEvdev::SetTapToClickPaused(bool state) { | 404 void InputDeviceFactoryEvdev::SetTapToClickPaused(bool state) { |
413 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 405 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
414 } | 406 } |
415 | 407 |
416 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( | 408 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( |
417 const GetTouchDeviceStatusReply& reply) { | 409 const GetTouchDeviceStatusReply& reply) { |
418 scoped_ptr<std::string> status(new std::string); | 410 scoped_ptr<std::string> status(new std::string); |
419 #if defined(USE_EVDEV_GESTURES) | 411 #if defined(USE_EVDEV_GESTURES) |
420 DumpTouchDeviceStatus(this, gesture_property_provider_.get(), status.get()); | 412 DumpTouchDeviceStatus(gesture_property_provider_.get(), status.get()); |
421 #endif | 413 #endif |
422 reply.Run(status.Pass()); | 414 reply.Run(status.Pass()); |
423 } | 415 } |
424 | 416 |
425 void InputDeviceFactoryEvdev::NotifyDeviceChange( | 417 void InputDeviceFactoryEvdev::NotifyDeviceChange( |
426 const EventConverterEvdev& converter) { | 418 const EventConverterEvdev& converter) { |
427 if (converter.HasTouchscreen()) | 419 if (converter.HasTouchscreen()) |
428 NotifyTouchscreensUpdated(); | 420 NotifyTouchscreensUpdated(); |
429 | 421 |
430 if (converter.HasKeyboard()) | 422 if (converter.HasKeyboard()) |
431 NotifyKeyboardsUpdated(); | 423 NotifyKeyboardsUpdated(); |
| 424 |
| 425 if (converter.HasMouse()) |
| 426 NotifyMouseDevicesUpdated(); |
| 427 |
| 428 if (converter.HasTouchpad()) |
| 429 NotifyMouseDevicesUpdated(); |
432 } | 430 } |
433 | 431 |
434 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { | 432 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { |
435 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | |
436 std::vector<TouchscreenDevice> touchscreens; | 433 std::vector<TouchscreenDevice> touchscreens; |
437 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 434 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
438 if (it->second->HasTouchscreen()) { | 435 if (it->second->HasTouchscreen()) { |
439 // TODO(spang): Extract the number of touch-points supported by the | 436 // TODO(spang): Extract the number of touch-points supported by the |
440 // device. | 437 // device. |
441 const int touch_points = 11; | 438 const int touch_points = 11; |
442 touchscreens.push_back(TouchscreenDevice( | 439 touchscreens.push_back(TouchscreenDevice( |
443 it->second->id(), it->second->type(), std::string() /* Device name */, | 440 it->second->id(), it->second->type(), std::string() /* Device name */, |
444 it->second->GetTouchscreenSize(), touch_points)); | 441 it->second->GetTouchscreenSize(), touch_points)); |
445 } | 442 } |
446 } | 443 } |
447 | 444 |
448 observer->OnTouchscreenDevicesUpdated(touchscreens); | 445 dispatcher_->DispatchTouchscreenDevicesUpdated(touchscreens); |
449 } | 446 } |
450 | 447 |
451 void InputDeviceFactoryEvdev::NotifyKeyboardsUpdated() { | 448 void InputDeviceFactoryEvdev::NotifyKeyboardsUpdated() { |
452 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | |
453 std::vector<KeyboardDevice> keyboards; | 449 std::vector<KeyboardDevice> keyboards; |
454 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 450 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
455 if (it->second->HasKeyboard()) { | 451 if (it->second->HasKeyboard()) { |
456 keyboards.push_back(KeyboardDevice(it->second->id(), it->second->type(), | 452 keyboards.push_back(KeyboardDevice(it->second->id(), it->second->type(), |
457 std::string() /* Device name */)); | 453 std::string() /* Device name */)); |
458 } | 454 } |
459 } | 455 } |
460 | 456 |
461 observer->OnKeyboardDevicesUpdated(keyboards); | 457 dispatcher_->DispatchKeyboardDevicesUpdated(keyboards); |
462 } | 458 } |
463 | 459 |
464 bool InputDeviceFactoryEvdev::GetDeviceIdsByType(const EventDeviceType type, | 460 void InputDeviceFactoryEvdev::NotifyMouseDevicesUpdated() { |
465 std::vector<int>* device_ids) { | 461 std::vector<InputDevice> mice; |
466 if (device_ids) | 462 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
467 device_ids->clear(); | 463 if (it->second->HasMouse()) { |
468 std::vector<int> ids; | 464 mice.push_back(InputDevice(it->second->id(), it->second->type(), |
| 465 std::string() /* Device name */)); |
| 466 } |
| 467 } |
469 | 468 |
470 #if defined(USE_EVDEV_GESTURES) | 469 dispatcher_->DispatchMouseDevicesUpdated(mice); |
471 // Ask GesturePropertyProvider for matching devices. | 470 } |
472 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | |
473 #endif | |
474 // In the future we can add other device matching logics here. | |
475 | 471 |
476 if (device_ids) | 472 void InputDeviceFactoryEvdev::NotifyTouchpadDevicesUpdated() { |
477 device_ids->assign(ids.begin(), ids.end()); | 473 std::vector<InputDevice> touchpads; |
478 return !ids.empty(); | 474 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 475 if (it->second->HasTouchpad()) { |
| 476 touchpads.push_back(InputDevice(it->second->id(), it->second->type(), |
| 477 std::string() /* Device name */)); |
| 478 } |
| 479 } |
| 480 |
| 481 dispatcher_->DispatchTouchpadDevicesUpdated(touchpads); |
479 } | 482 } |
480 | 483 |
481 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( | 484 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( |
482 const EventDeviceType type, | 485 const EventDeviceType type, |
483 const std::string& name, | 486 const std::string& name, |
484 int value) { | 487 int value) { |
485 #if defined(USE_EVDEV_GESTURES) | 488 #if defined(USE_EVDEV_GESTURES) |
486 std::vector<int> ids; | 489 std::vector<int> ids; |
487 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 490 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
488 for (size_t i = 0; i < ids.size(); ++i) { | 491 for (size_t i = 0; i < ids.size(); ++i) { |
(...skipping 14 matching lines...) Expand all Loading... |
503 std::vector<int> ids; | 506 std::vector<int> ids; |
504 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 507 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
505 for (size_t i = 0; i < ids.size(); ++i) { | 508 for (size_t i = 0; i < ids.size(); ++i) { |
506 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 509 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
507 value); | 510 value); |
508 } | 511 } |
509 #endif | 512 #endif |
510 } | 513 } |
511 | 514 |
512 } // namespace ui | 515 } // namespace ui |
OLD | NEW |