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
3 // found in the LICENSE file.
5 #include "ui/events/ozone/evdev/input_controller_evdev.h"
8 #include <linux/input.h>
10 #include "base/thread_task_runner_handle.h"
11 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h"
12 #include "ui/events/ozone/evdev/keyboard_evdev.h"
13 #include "ui/events/ozone/evdev/mouse_button_map_evdev.h"
17 InputControllerEvdev::InputControllerEvdev(KeyboardEvdev
* keyboard
,
18 MouseButtonMapEvdev
* button_map
)
19 : keyboard_(keyboard
), button_map_(button_map
), weak_ptr_factory_(this) {
22 InputControllerEvdev::~InputControllerEvdev() {
25 void InputControllerEvdev::SetInputDeviceFactory(
26 InputDeviceFactoryEvdevProxy
* input_device_factory
) {
27 input_device_factory_
= input_device_factory
;
29 UpdateDeviceSettings();
33 void InputControllerEvdev::set_has_mouse(bool has_mouse
) {
34 has_mouse_
= has_mouse
;
37 void InputControllerEvdev::set_has_touchpad(bool has_touchpad
) {
38 has_touchpad_
= has_touchpad
;
41 void InputControllerEvdev::SetInputDevicesEnabled(bool enabled
) {
42 input_device_settings_
.enable_devices
= enabled
;
43 ScheduleUpdateDeviceSettings();
46 bool InputControllerEvdev::HasMouse() {
50 bool InputControllerEvdev::HasTouchpad() {
54 bool InputControllerEvdev::IsCapsLockEnabled() {
55 return keyboard_
->IsCapsLockEnabled();
58 void InputControllerEvdev::SetCapsLockEnabled(bool enabled
) {
59 keyboard_
->SetCapsLockEnabled(enabled
);
63 void InputControllerEvdev::SetNumLockEnabled(bool enabled
) {
64 // No num lock on Chrome OS.
67 bool InputControllerEvdev::IsAutoRepeatEnabled() {
68 return keyboard_
->IsAutoRepeatEnabled();
71 void InputControllerEvdev::SetAutoRepeatEnabled(bool enabled
) {
72 keyboard_
->SetAutoRepeatEnabled(enabled
);
75 void InputControllerEvdev::SetAutoRepeatRate(const base::TimeDelta
& delay
,
76 const base::TimeDelta
& interval
) {
77 keyboard_
->SetAutoRepeatRate(delay
, interval
);
80 void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta
* delay
,
81 base::TimeDelta
* interval
) {
82 keyboard_
->GetAutoRepeatRate(delay
, interval
);
85 void InputControllerEvdev::SetInternalTouchpadEnabled(bool enabled
) {
86 input_device_settings_
.enable_internal_touchpad
= enabled
;
87 ScheduleUpdateDeviceSettings();
90 void InputControllerEvdev::SetTouchEventLoggingEnabled(bool enabled
) {
91 input_device_settings_
.touch_event_logging_enabled
= enabled
;
92 ScheduleUpdateDeviceSettings();
95 void InputControllerEvdev::SetInternalKeyboardFilter(
97 std::vector
<DomCode
> allowed_keys
) {
98 input_device_settings_
.enable_internal_keyboard_filter
= enable_filter
;
99 input_device_settings_
.internal_keyboard_allowed_keys
= allowed_keys
;
100 ScheduleUpdateDeviceSettings();
103 void InputControllerEvdev::SetTouchpadSensitivity(int value
) {
104 input_device_settings_
.touchpad_sensitivity
= value
;
105 ScheduleUpdateDeviceSettings();
108 void InputControllerEvdev::SetTapToClick(bool enabled
) {
109 input_device_settings_
.tap_to_click_enabled
= enabled
;
110 ScheduleUpdateDeviceSettings();
113 void InputControllerEvdev::SetThreeFingerClick(bool enabled
) {
114 input_device_settings_
.three_finger_click_enabled
= enabled
;
115 ScheduleUpdateDeviceSettings();
118 void InputControllerEvdev::SetTapDragging(bool enabled
) {
119 input_device_settings_
.tap_dragging_enabled
= enabled
;
120 ScheduleUpdateDeviceSettings();
123 void InputControllerEvdev::SetNaturalScroll(bool enabled
) {
124 input_device_settings_
.natural_scroll_enabled
= enabled
;
125 ScheduleUpdateDeviceSettings();
128 void InputControllerEvdev::SetMouseSensitivity(int value
) {
129 input_device_settings_
.mouse_sensitivity
= value
;
130 ScheduleUpdateDeviceSettings();
133 void InputControllerEvdev::SetPrimaryButtonRight(bool right
) {
134 button_map_
->UpdateButtonMap(BTN_LEFT
, right
? BTN_RIGHT
: BTN_LEFT
);
135 button_map_
->UpdateButtonMap(BTN_RIGHT
, right
? BTN_LEFT
: BTN_RIGHT
);
138 void InputControllerEvdev::SetTapToClickPaused(bool state
) {
139 input_device_settings_
.tap_to_click_paused
= state
;
140 ScheduleUpdateDeviceSettings();
143 void InputControllerEvdev::GetTouchDeviceStatus(
144 const GetTouchDeviceStatusReply
& reply
) {
145 if (input_device_factory_
)
146 input_device_factory_
->GetTouchDeviceStatus(reply
);
148 reply
.Run(make_scoped_ptr(new std::string
));
151 void InputControllerEvdev::GetTouchEventLog(
152 const base::FilePath
& out_dir
,
153 const GetTouchEventLogReply
& reply
) {
154 if (input_device_factory_
)
155 input_device_factory_
->GetTouchEventLog(out_dir
, reply
);
157 reply
.Run(make_scoped_ptr(new std::vector
<base::FilePath
>));
160 void InputControllerEvdev::ScheduleUpdateDeviceSettings() {
161 if (!input_device_factory_
|| settings_update_pending_
)
163 base::ThreadTaskRunnerHandle::Get()->PostTask(
164 FROM_HERE
, base::Bind(&InputControllerEvdev::UpdateDeviceSettings
,
165 weak_ptr_factory_
.GetWeakPtr()));
166 settings_update_pending_
= true;
169 void InputControllerEvdev::UpdateDeviceSettings() {
170 input_device_factory_
->UpdateInputDeviceSettings(input_device_settings_
);
171 settings_update_pending_
= false;
174 void InputControllerEvdev::UpdateCapsLockLed() {
175 if (!input_device_factory_
)
177 bool caps_lock_state
= IsCapsLockEnabled();
178 if (caps_lock_state
!= caps_lock_led_state_
)
179 input_device_factory_
->SetCapsLockLed(caps_lock_state
);
180 caps_lock_led_state_
= caps_lock_state
;