Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: ui/events/ozone/evdev/input_device_factory_evdev.cc

Issue 2805793002: ozone: evdev: Add gamepad support (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
25 26
26 #if defined(USE_EVDEV_GESTURES) 27 #if defined(USE_EVDEV_GESTURES)
27 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" 28 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h"
28 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h" 29 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h"
29 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr os.h" 30 #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" 31 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h"
31 #endif 32 #endif
32 33
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 converter->Initialize(devinfo); 107 converter->Initialize(devinfo);
107 return std::move(converter); 108 return std::move(converter);
108 } 109 }
109 110
110 // Graphics tablet 111 // Graphics tablet
111 if (devinfo.HasTablet()) 112 if (devinfo.HasTablet())
112 return base::WrapUnique<EventConverterEvdev>(new TabletEventConverterEvdev( 113 return base::WrapUnique<EventConverterEvdev>(new TabletEventConverterEvdev(
113 std::move(fd), params.path, params.id, params.cursor, devinfo, 114 std::move(fd), params.path, params.id, params.cursor, devinfo,
114 params.dispatcher)); 115 params.dispatcher));
115 116
117 if (devinfo.HasGamepad())
spang 2017/04/13 00:52:20 The body is multiline; please add braces here.
jkwang 2017/04/19 19:42:23 Done.
118 return base::WrapUnique<EventConverterEvdev>(new GamepadEventConverterEvdev(
119 std::move(fd), params.path, params.id, devinfo, params.dispatcher));
120
116 // Everything else: use EventConverterEvdevImpl. 121 // Everything else: use EventConverterEvdevImpl.
117 return base::WrapUnique<EventConverterEvdevImpl>( 122 return base::WrapUnique<EventConverterEvdevImpl>(
118 new EventConverterEvdevImpl(std::move(fd), params.path, params.id, 123 new EventConverterEvdevImpl(std::move(fd), params.path, params.id,
119 devinfo, params.cursor, params.dispatcher)); 124 devinfo, params.cursor, params.dispatcher));
120 } 125 }
121 126
122 // Open an input device and construct an EventConverterEvdev. 127 // Open an input device and construct an EventConverterEvdev.
123 std::unique_ptr<EventConverterEvdev> OpenInputDevice( 128 std::unique_ptr<EventConverterEvdev> OpenInputDevice(
124 const OpenInputDeviceParams& params) { 129 const OpenInputDeviceParams& params) {
125 const base::FilePath& path = params.path; 130 const base::FilePath& path = params.path;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 touchscreen_list_dirty_ = true; 365 touchscreen_list_dirty_ = true;
361 366
362 if (converter->HasKeyboard()) 367 if (converter->HasKeyboard())
363 keyboard_list_dirty_ = true; 368 keyboard_list_dirty_ = true;
364 369
365 if (converter->HasMouse()) 370 if (converter->HasMouse())
366 mouse_list_dirty_ = true; 371 mouse_list_dirty_ = true;
367 372
368 if (converter->HasTouchpad()) 373 if (converter->HasTouchpad())
369 touchpad_list_dirty_ = true; 374 touchpad_list_dirty_ = true;
375
376 if (converter->HasGamepad())
377 gamepad_list_dirty_ = true;
370 } 378 }
371 379
372 void InputDeviceFactoryEvdev::NotifyDevicesUpdated() { 380 void InputDeviceFactoryEvdev::NotifyDevicesUpdated() {
373 if (!startup_devices_enumerated_ || pending_device_changes_) 381 if (!startup_devices_enumerated_ || pending_device_changes_)
374 return; // No update until full scan done and no pending operations. 382 return; // No update until full scan done and no pending operations.
375 if (touchscreen_list_dirty_) 383 if (touchscreen_list_dirty_)
376 NotifyTouchscreensUpdated(); 384 NotifyTouchscreensUpdated();
377 if (keyboard_list_dirty_) 385 if (keyboard_list_dirty_)
378 NotifyKeyboardsUpdated(); 386 NotifyKeyboardsUpdated();
379 if (mouse_list_dirty_) 387 if (mouse_list_dirty_)
380 NotifyMouseDevicesUpdated(); 388 NotifyMouseDevicesUpdated();
381 if (touchpad_list_dirty_) 389 if (touchpad_list_dirty_)
382 NotifyTouchpadDevicesUpdated(); 390 NotifyTouchpadDevicesUpdated();
391 if (gamepad_list_dirty_)
392 NotifyGamepadDevicesUpdated();
383 if (!startup_devices_opened_) { 393 if (!startup_devices_opened_) {
384 dispatcher_->DispatchDeviceListsComplete(); 394 dispatcher_->DispatchDeviceListsComplete();
385 startup_devices_opened_ = true; 395 startup_devices_opened_ = true;
386 } 396 }
387 touchscreen_list_dirty_ = false; 397 touchscreen_list_dirty_ = false;
388 keyboard_list_dirty_ = false; 398 keyboard_list_dirty_ = false;
389 mouse_list_dirty_ = false; 399 mouse_list_dirty_ = false;
390 touchpad_list_dirty_ = false; 400 touchpad_list_dirty_ = false;
401 gamepad_list_dirty_ = false;
391 } 402 }
392 403
393 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() { 404 void InputDeviceFactoryEvdev::NotifyTouchscreensUpdated() {
394 std::vector<TouchscreenDevice> touchscreens; 405 std::vector<TouchscreenDevice> touchscreens;
395 for (auto it = converters_.begin(); it != converters_.end(); ++it) { 406 for (auto it = converters_.begin(); it != converters_.end(); ++it) {
396 if (it->second->HasTouchscreen()) { 407 if (it->second->HasTouchscreen()) {
397 TouchscreenDevice device(it->second->input_device(), 408 TouchscreenDevice device(it->second->input_device(),
398 it->second->GetTouchscreenSize(), it->second->GetTouchPoints()); 409 it->second->GetTouchscreenSize(), it->second->GetTouchPoints());
399 if (it->second->HasPen()) 410 if (it->second->HasPen())
400 device.is_stylus = true; 411 device.is_stylus = true;
(...skipping 30 matching lines...) Expand all
431 std::vector<InputDevice> touchpads; 442 std::vector<InputDevice> touchpads;
432 for (auto it = converters_.begin(); it != converters_.end(); ++it) { 443 for (auto it = converters_.begin(); it != converters_.end(); ++it) {
433 if (it->second->HasTouchpad()) { 444 if (it->second->HasTouchpad()) {
434 touchpads.push_back(it->second->input_device()); 445 touchpads.push_back(it->second->input_device());
435 } 446 }
436 } 447 }
437 448
438 dispatcher_->DispatchTouchpadDevicesUpdated(touchpads); 449 dispatcher_->DispatchTouchpadDevicesUpdated(touchpads);
439 } 450 }
440 451
452 void InputDeviceFactoryEvdev::NotifyGamepadDevicesUpdated() {
453 std::vector<InputDevice> gamepads;
454 for (auto it = converters_.begin(); it != converters_.end(); ++it) {
455 if (it->second->HasGamepad()) {
456 gamepads.push_back(it->second->input_device());
457 }
458 }
459
460 dispatcher_->DispatchGamepadDevicesUpdated(gamepads);
461 }
462
441 void InputDeviceFactoryEvdev::SetIntPropertyForOneType( 463 void InputDeviceFactoryEvdev::SetIntPropertyForOneType(
442 const EventDeviceType type, 464 const EventDeviceType type,
443 const std::string& name, 465 const std::string& name,
444 int value) { 466 int value) {
445 #if defined(USE_EVDEV_GESTURES) 467 #if defined(USE_EVDEV_GESTURES)
446 std::vector<int> ids; 468 std::vector<int> ids;
447 gesture_property_provider_->GetDeviceIdsByType(type, &ids); 469 gesture_property_provider_->GetDeviceIdsByType(type, &ids);
448 for (size_t i = 0; i < ids.size(); ++i) { 470 for (size_t i = 0; i < ids.size(); ++i) {
449 SetGestureIntProperty(gesture_property_provider_.get(), ids[i], name, 471 SetGestureIntProperty(gesture_property_provider_.get(), ids[i], name,
450 value); 472 value);
(...skipping 22 matching lines...) Expand all
473 if (enabled == palm_suppression_enabled_) 495 if (enabled == palm_suppression_enabled_)
474 return; 496 return;
475 palm_suppression_enabled_ = enabled; 497 palm_suppression_enabled_ = enabled;
476 498
477 for (const auto& it : converters_) { 499 for (const auto& it : converters_) {
478 it.second->SetEnabled(IsDeviceEnabled(it.second.get())); 500 it.second->SetEnabled(IsDeviceEnabled(it.second.get()));
479 } 501 }
480 } 502 }
481 503
482 } // namespace ui 504 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698