| 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 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "ui/events/devices/device_data_manager.h" | 18 #include "ui/events/devices/device_data_manager.h" |
| 19 #include "ui/events/devices/device_util_linux.h" | 19 #include "ui/events/devices/device_util_linux.h" |
| 20 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | 20 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
| 21 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 21 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| 22 #include "ui/events/ozone/evdev/event_device_info.h" | 22 #include "ui/events/ozone/evdev/event_device_info.h" |
| 23 #include "ui/events/ozone/evdev/gamepad_event_converter_evdev.h" |
| 23 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 24 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
| 24 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 25 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| 26 #include "ui/events/ozone/gamepad/gamepad_provider_ozone.h" |
| 25 | 27 |
| 26 #if defined(USE_EVDEV_GESTURES) | 28 #if defined(USE_EVDEV_GESTURES) |
| 27 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" | 29 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
| 28 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h" | 30 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h" |
| 29 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 31 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
| 30 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 32 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| 31 #endif | 33 #endif |
| 32 | 34 |
| 33 #ifndef EVIOCSCLOCKID | 35 #ifndef EVIOCSCLOCKID |
| 34 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) | 36 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 converter->Initialize(devinfo); | 108 converter->Initialize(devinfo); |
| 107 return std::move(converter); | 109 return std::move(converter); |
| 108 } | 110 } |
| 109 | 111 |
| 110 // Graphics tablet | 112 // Graphics tablet |
| 111 if (devinfo.HasTablet()) | 113 if (devinfo.HasTablet()) |
| 112 return base::WrapUnique<EventConverterEvdev>(new TabletEventConverterEvdev( | 114 return base::WrapUnique<EventConverterEvdev>(new TabletEventConverterEvdev( |
| 113 std::move(fd), params.path, params.id, params.cursor, devinfo, | 115 std::move(fd), params.path, params.id, params.cursor, devinfo, |
| 114 params.dispatcher)); | 116 params.dispatcher)); |
| 115 | 117 |
| 118 if (devinfo.HasGamepad()) { |
| 119 return base::WrapUnique<EventConverterEvdev>(new GamepadEventConverterEvdev( |
| 120 std::move(fd), params.path, params.id, devinfo, params.dispatcher)); |
| 121 } |
| 122 |
| 116 // Everything else: use EventConverterEvdevImpl. | 123 // Everything else: use EventConverterEvdevImpl. |
| 117 return base::WrapUnique<EventConverterEvdevImpl>( | 124 return base::WrapUnique<EventConverterEvdevImpl>( |
| 118 new EventConverterEvdevImpl(std::move(fd), params.path, params.id, | 125 new EventConverterEvdevImpl(std::move(fd), params.path, params.id, |
| 119 devinfo, params.cursor, params.dispatcher)); | 126 devinfo, params.cursor, params.dispatcher)); |
| 120 } | 127 } |
| 121 | 128 |
| 122 // Open an input device and construct an EventConverterEvdev. | 129 // Open an input device and construct an EventConverterEvdev. |
| 123 std::unique_ptr<EventConverterEvdev> OpenInputDevice( | 130 std::unique_ptr<EventConverterEvdev> OpenInputDevice( |
| 124 const OpenInputDeviceParams& params) { | 131 const OpenInputDeviceParams& params) { |
| 125 const base::FilePath& path = params.path; | 132 const base::FilePath& path = params.path; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 touchscreen_list_dirty_ = true; | 367 touchscreen_list_dirty_ = true; |
| 361 | 368 |
| 362 if (converter->HasKeyboard()) | 369 if (converter->HasKeyboard()) |
| 363 keyboard_list_dirty_ = true; | 370 keyboard_list_dirty_ = true; |
| 364 | 371 |
| 365 if (converter->HasMouse()) | 372 if (converter->HasMouse()) |
| 366 mouse_list_dirty_ = true; | 373 mouse_list_dirty_ = true; |
| 367 | 374 |
| 368 if (converter->HasTouchpad()) | 375 if (converter->HasTouchpad()) |
| 369 touchpad_list_dirty_ = true; | 376 touchpad_list_dirty_ = true; |
| 377 |
| 378 if (converter->HasGamepad()) |
| 379 gamepad_list_dirty_ = true; |
| 370 } | 380 } |
| 371 | 381 |
| 372 void InputDeviceFactoryEvdev::NotifyDevicesUpdated() { | 382 void InputDeviceFactoryEvdev::NotifyDevicesUpdated() { |
| 373 if (!startup_devices_enumerated_ || pending_device_changes_) | 383 if (!startup_devices_enumerated_ || pending_device_changes_) |
| 374 return; // No update until full scan done and no pending operations. | 384 return; // No update until full scan done and no pending operations. |
| 375 if (touchscreen_list_dirty_) | 385 if (touchscreen_list_dirty_) |
| 376 NotifyTouchscreensUpdated(); | 386 NotifyTouchscreensUpdated(); |
| 377 if (keyboard_list_dirty_) | 387 if (keyboard_list_dirty_) |
| 378 NotifyKeyboardsUpdated(); | 388 NotifyKeyboardsUpdated(); |
| 379 if (mouse_list_dirty_) | 389 if (mouse_list_dirty_) |
| 380 NotifyMouseDevicesUpdated(); | 390 NotifyMouseDevicesUpdated(); |
| 381 if (touchpad_list_dirty_) | 391 if (touchpad_list_dirty_) |
| 382 NotifyTouchpadDevicesUpdated(); | 392 NotifyTouchpadDevicesUpdated(); |
| 393 if (gamepad_list_dirty_) |
| 394 NotifyGamepadDevicesUpdated(); |
| 383 if (!startup_devices_opened_) { | 395 if (!startup_devices_opened_) { |
| 384 dispatcher_->DispatchDeviceListsComplete(); | 396 dispatcher_->DispatchDeviceListsComplete(); |
| 385 startup_devices_opened_ = true; | 397 startup_devices_opened_ = true; |
| 386 } | 398 } |
| 387 touchscreen_list_dirty_ = false; | 399 touchscreen_list_dirty_ = false; |
| 388 keyboard_list_dirty_ = false; | 400 keyboard_list_dirty_ = false; |
| 389 mouse_list_dirty_ = false; | 401 mouse_list_dirty_ = false; |
| 390 touchpad_list_dirty_ = false; | 402 touchpad_list_dirty_ = false; |
| 403 gamepad_list_dirty_ = false; |
| 391 } | 404 } |
| 392 | 405 |
| 393 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { | 406 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { |
| 394 std::vector<TouchscreenDevice> touchscreens; | 407 std::vector<TouchscreenDevice> touchscreens; |
| 395 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 408 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 396 if (it->second->HasTouchscreen()) { | 409 if (it->second->HasTouchscreen()) { |
| 397 TouchscreenDevice device(it->second->input_device(), | 410 TouchscreenDevice device(it->second->input_device(), |
| 398 it->second->GetTouchscreenSize(), it->second->GetTouchPoints()); | 411 it->second->GetTouchscreenSize(), it->second->GetTouchPoints()); |
| 399 if (it->second->HasPen()) | 412 if (it->second->HasPen()) |
| 400 device.is_stylus = true; | 413 device.is_stylus = true; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 431 std::vector<InputDevice> touchpads; | 444 std::vector<InputDevice> touchpads; |
| 432 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 445 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 433 if (it->second->HasTouchpad()) { | 446 if (it->second->HasTouchpad()) { |
| 434 touchpads.push_back(it->second->input_device()); | 447 touchpads.push_back(it->second->input_device()); |
| 435 } | 448 } |
| 436 } | 449 } |
| 437 | 450 |
| 438 dispatcher_->DispatchTouchpadDevicesUpdated(touchpads); | 451 dispatcher_->DispatchTouchpadDevicesUpdated(touchpads); |
| 439 } | 452 } |
| 440 | 453 |
| 454 void InputDeviceFactoryEvdev::NotifyGamepadDevicesUpdated() { |
| 455 std::vector<InputDevice> gamepads; |
| 456 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 457 if (it->second->HasGamepad()) { |
| 458 gamepads.push_back(it->second->input_device()); |
| 459 } |
| 460 } |
| 461 |
| 462 dispatcher_->DispatchGamepadDevicesUpdated(gamepads); |
| 463 } |
| 464 |
| 441 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( | 465 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( |
| 442 const EventDeviceType type, | 466 const EventDeviceType type, |
| 443 const std::string& name, | 467 const std::string& name, |
| 444 int value) { | 468 int value) { |
| 445 #if defined(USE_EVDEV_GESTURES) | 469 #if defined(USE_EVDEV_GESTURES) |
| 446 std::vector<int> ids; | 470 std::vector<int> ids; |
| 447 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 471 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
| 448 for (size_t i = 0; i < ids.size(); ++i) { | 472 for (size_t i = 0; i < ids.size(); ++i) { |
| 449 SetGestureIntProperty(gesture_property_provider_.get(), ids[i], name, | 473 SetGestureIntProperty(gesture_property_provider_.get(), ids[i], name, |
| 450 value); | 474 value); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 473 if (enabled == palm_suppression_enabled_) | 497 if (enabled == palm_suppression_enabled_) |
| 474 return; | 498 return; |
| 475 palm_suppression_enabled_ = enabled; | 499 palm_suppression_enabled_ = enabled; |
| 476 | 500 |
| 477 for (const auto& it : converters_) { | 501 for (const auto& it : converters_) { |
| 478 it.second->SetEnabled(IsDeviceEnabled(it.second.get())); | 502 it.second->SetEnabled(IsDeviceEnabled(it.second.get())); |
| 479 } | 503 } |
| 480 } | 504 } |
| 481 | 505 |
| 482 } // namespace ui | 506 } // namespace ui |
| OLD | NEW |