| 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/threading/worker_pool.h" | 12 #include "base/threading/worker_pool.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "ui/events/devices/device_data_manager.h" | 14 #include "ui/events/devices/device_data_manager.h" |
| 15 #include "ui/events/devices/device_util_linux.h" | 15 #include "ui/events/devices/device_util_linux.h" |
| 16 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
| 16 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 17 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| 17 #include "ui/events/ozone/evdev/event_device_info.h" | 18 #include "ui/events/ozone/evdev/event_device_info.h" |
| 18 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 19 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
| 19 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 20 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| 20 | 21 |
| 21 #if defined(USE_EVDEV_GESTURES) | 22 #if defined(USE_EVDEV_GESTURES) |
| 22 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" | 23 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
| 23 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 24 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
| 24 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 25 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| 25 #endif | 26 #endif |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { | 300 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { |
| 300 for (const auto& it : converters_) { | 301 for (const auto& it : converters_) { |
| 301 EventConverterEvdev* converter = it.second; | 302 EventConverterEvdev* converter = it.second; |
| 302 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && | 303 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && |
| 303 converter->HasKeyboard()) { | 304 converter->HasKeyboard()) { |
| 304 converter->AllowAllKeys(); | 305 converter->AllowAllKeys(); |
| 305 } | 306 } |
| 306 } | 307 } |
| 307 } | 308 } |
| 308 | 309 |
| 309 bool InputDeviceFactoryEvdev::HasMouse() { | |
| 310 return GetDeviceIdsByType(DT_MOUSE, NULL); | |
| 311 } | |
| 312 | |
| 313 bool InputDeviceFactoryEvdev::HasTouchpad() { | |
| 314 return GetDeviceIdsByType(DT_TOUCHPAD, NULL); | |
| 315 } | |
| 316 | |
| 317 void InputDeviceFactoryEvdev::SetTouchpadSensitivity(int value) { | 310 void InputDeviceFactoryEvdev::SetTouchpadSensitivity(int value) { |
| 318 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value); | 311 SetIntPropertyForOneType(DT_TOUCHPAD, "Pointer Sensitivity", value); |
| 319 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value); | 312 SetIntPropertyForOneType(DT_TOUCHPAD, "Scroll Sensitivity", value); |
| 320 } | 313 } |
| 321 | 314 |
| 322 void InputDeviceFactoryEvdev::SetTapToClick(bool enabled) { | 315 void InputDeviceFactoryEvdev::SetTapToClick(bool enabled) { |
| 323 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Enable", enabled); | 316 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Enable", enabled); |
| 324 } | 317 } |
| 325 | 318 |
| 326 void InputDeviceFactoryEvdev::SetThreeFingerClick(bool enabled) { | 319 void InputDeviceFactoryEvdev::SetThreeFingerClick(bool enabled) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 345 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); | 338 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", state); |
| 346 } | 339 } |
| 347 | 340 |
| 348 void InputDeviceFactoryEvdev::NotifyDeviceChange( | 341 void InputDeviceFactoryEvdev::NotifyDeviceChange( |
| 349 const EventConverterEvdev& converter) { | 342 const EventConverterEvdev& converter) { |
| 350 if (converter.HasTouchscreen()) | 343 if (converter.HasTouchscreen()) |
| 351 NotifyTouchscreensUpdated(); | 344 NotifyTouchscreensUpdated(); |
| 352 | 345 |
| 353 if (converter.HasKeyboard()) | 346 if (converter.HasKeyboard()) |
| 354 NotifyKeyboardsUpdated(); | 347 NotifyKeyboardsUpdated(); |
| 348 |
| 349 if (converter.HasMouse()) |
| 350 NotifyMouseDevicesUpdated(); |
| 351 |
| 352 if (converter.HasTouchpad()) |
| 353 NotifyMouseDevicesUpdated(); |
| 355 } | 354 } |
| 356 | 355 |
| 357 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { | 356 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { |
| 358 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | |
| 359 std::vector<TouchscreenDevice> touchscreens; | 357 std::vector<TouchscreenDevice> touchscreens; |
| 360 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 358 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 361 if (it->second->HasTouchscreen()) { | 359 if (it->second->HasTouchscreen()) { |
| 362 // TODO(spang): Extract the number of touch-points supported by the | 360 // TODO(spang): Extract the number of touch-points supported by the |
| 363 // device. | 361 // device. |
| 364 const int touch_points = 11; | 362 const int touch_points = 11; |
| 365 touchscreens.push_back(TouchscreenDevice( | 363 touchscreens.push_back(TouchscreenDevice( |
| 366 it->second->id(), it->second->type(), std::string() /* Device name */, | 364 it->second->id(), it->second->type(), std::string() /* Device name */, |
| 367 it->second->GetTouchscreenSize(), touch_points)); | 365 it->second->GetTouchscreenSize(), touch_points)); |
| 368 } | 366 } |
| 369 } | 367 } |
| 370 | 368 |
| 371 observer->OnTouchscreenDevicesUpdated(touchscreens); | 369 dispatcher_->DispatchTouchscreenDevicesUpdated(touchscreens); |
| 372 } | 370 } |
| 373 | 371 |
| 374 void InputDeviceFactoryEvdev::NotifyKeyboardsUpdated() { | 372 void InputDeviceFactoryEvdev::NotifyKeyboardsUpdated() { |
| 375 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | |
| 376 std::vector<KeyboardDevice> keyboards; | 373 std::vector<KeyboardDevice> keyboards; |
| 377 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 374 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 378 if (it->second->HasKeyboard()) { | 375 if (it->second->HasKeyboard()) { |
| 379 keyboards.push_back(KeyboardDevice(it->second->id(), it->second->type(), | 376 keyboards.push_back(KeyboardDevice(it->second->id(), it->second->type(), |
| 380 std::string() /* Device name */)); | 377 std::string() /* Device name */)); |
| 381 } | 378 } |
| 382 } | 379 } |
| 383 | 380 |
| 384 observer->OnKeyboardDevicesUpdated(keyboards); | 381 dispatcher_->DispatchKeyboardDevicesUpdated(keyboards); |
| 385 } | 382 } |
| 386 | 383 |
| 387 bool InputDeviceFactoryEvdev::GetDeviceIdsByType(const EventDeviceType type, | 384 void InputDeviceFactoryEvdev::NotifyMouseDevicesUpdated() { |
| 388 std::vector<int>* device_ids) { | 385 std::vector<InputDevice> mice; |
| 389 if (device_ids) | 386 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 390 device_ids->clear(); | 387 if (it->second->HasMouse()) { |
| 391 std::vector<int> ids; | 388 mice.push_back(InputDevice(it->second->id(), it->second->type(), |
| 389 std::string() /* Device name */)); |
| 390 } |
| 391 } |
| 392 | 392 |
| 393 #if defined(USE_EVDEV_GESTURES) | 393 dispatcher_->DispatchMouseDevicesUpdated(mice); |
| 394 // Ask GesturePropertyProvider for matching devices. | 394 } |
| 395 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | |
| 396 #endif | |
| 397 // In the future we can add other device matching logics here. | |
| 398 | 395 |
| 399 if (device_ids) | 396 void InputDeviceFactoryEvdev::NotifyTouchpadDevicesUpdated() { |
| 400 device_ids->assign(ids.begin(), ids.end()); | 397 std::vector<InputDevice> touchpads; |
| 401 return !ids.empty(); | 398 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 399 if (it->second->HasTouchpad()) { |
| 400 touchpads.push_back(InputDevice(it->second->id(), it->second->type(), |
| 401 std::string() /* Device name */)); |
| 402 } |
| 403 } |
| 404 |
| 405 dispatcher_->DispatchTouchpadDevicesUpdated(touchpads); |
| 402 } | 406 } |
| 403 | 407 |
| 404 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( | 408 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( |
| 405 const EventDeviceType type, | 409 const EventDeviceType type, |
| 406 const std::string& name, | 410 const std::string& name, |
| 407 int value) { | 411 int value) { |
| 408 #if defined(USE_EVDEV_GESTURES) | 412 #if defined(USE_EVDEV_GESTURES) |
| 409 std::vector<int> ids; | 413 std::vector<int> ids; |
| 410 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 414 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
| 411 for (size_t i = 0; i < ids.size(); ++i) { | 415 for (size_t i = 0; i < ids.size(); ++i) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 426 std::vector<int> ids; | 430 std::vector<int> ids; |
| 427 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 431 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
| 428 for (size_t i = 0; i < ids.size(); ++i) { | 432 for (size_t i = 0; i < ids.size(); ++i) { |
| 429 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 433 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
| 430 value); | 434 value); |
| 431 } | 435 } |
| 432 #endif | 436 #endif |
| 433 } | 437 } |
| 434 | 438 |
| 435 } // namespace ui | 439 } // namespace ui |
| OLD | NEW |