ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ui / events / ozone / evdev / input_controller_evdev.cc
blob9e65740b7adb5f8b1eb64ee64df2839613618a12
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"
7 #include <algorithm>
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"
15 namespace ui {
17 InputControllerEvdev::InputControllerEvdev(KeyboardEvdev* keyboard,
18 MouseButtonMapEvdev* button_map)
19 : settings_update_pending_(false),
20 input_device_factory_(nullptr),
21 keyboard_(keyboard),
22 button_map_(button_map),
23 has_mouse_(false),
24 has_touchpad_(false),
25 caps_lock_led_state_(false),
26 weak_ptr_factory_(this) {
29 InputControllerEvdev::~InputControllerEvdev() {
32 void InputControllerEvdev::SetInputDeviceFactory(
33 InputDeviceFactoryEvdevProxy* input_device_factory) {
34 input_device_factory_ = input_device_factory;
36 UpdateDeviceSettings();
37 UpdateCapsLockLed();
40 void InputControllerEvdev::set_has_mouse(bool has_mouse) {
41 has_mouse_ = has_mouse;
44 void InputControllerEvdev::set_has_touchpad(bool has_touchpad) {
45 has_touchpad_ = has_touchpad;
48 bool InputControllerEvdev::HasMouse() {
49 return has_mouse_;
52 bool InputControllerEvdev::HasTouchpad() {
53 return has_touchpad_;
56 bool InputControllerEvdev::IsCapsLockEnabled() {
57 return keyboard_->IsCapsLockEnabled();
60 void InputControllerEvdev::SetCapsLockEnabled(bool enabled) {
61 keyboard_->SetCapsLockEnabled(enabled);
62 UpdateCapsLockLed();
65 void InputControllerEvdev::SetNumLockEnabled(bool enabled) {
66 NOTIMPLEMENTED();
69 bool InputControllerEvdev::IsAutoRepeatEnabled() {
70 return keyboard_->IsAutoRepeatEnabled();
73 void InputControllerEvdev::SetAutoRepeatEnabled(bool enabled) {
74 keyboard_->SetAutoRepeatEnabled(enabled);
77 void InputControllerEvdev::SetAutoRepeatRate(const base::TimeDelta& delay,
78 const base::TimeDelta& interval) {
79 keyboard_->SetAutoRepeatRate(delay, interval);
82 void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta* delay,
83 base::TimeDelta* interval) {
84 keyboard_->GetAutoRepeatRate(delay, interval);
87 void InputControllerEvdev::DisableInternalTouchpad() {
88 if (input_device_factory_)
89 input_device_factory_->DisableInternalTouchpad();
92 void InputControllerEvdev::EnableInternalTouchpad() {
93 if (input_device_factory_)
94 input_device_factory_->EnableInternalTouchpad();
97 void InputControllerEvdev::DisableInternalKeyboardExceptKeys(
98 scoped_ptr<std::set<DomCode>> excepted_keys) {
99 if (input_device_factory_) {
100 input_device_factory_->DisableInternalKeyboardExceptKeys(
101 excepted_keys.Pass());
103 // Release keys since we may block key up events.
104 keyboard_->Reset();
108 void InputControllerEvdev::EnableInternalKeyboard() {
109 if (input_device_factory_)
110 input_device_factory_->EnableInternalKeyboard();
113 void InputControllerEvdev::SetTouchpadSensitivity(int value) {
114 input_device_settings_.touchpad_sensitivity = value;
115 ScheduleUpdateDeviceSettings();
118 void InputControllerEvdev::SetTapToClick(bool enabled) {
119 input_device_settings_.tap_to_click_enabled = enabled;
120 ScheduleUpdateDeviceSettings();
123 void InputControllerEvdev::SetThreeFingerClick(bool enabled) {
124 input_device_settings_.three_finger_click_enabled = enabled;
125 ScheduleUpdateDeviceSettings();
128 void InputControllerEvdev::SetTapDragging(bool enabled) {
129 input_device_settings_.tap_dragging_enabled = enabled;
130 ScheduleUpdateDeviceSettings();
133 void InputControllerEvdev::SetNaturalScroll(bool enabled) {
134 input_device_settings_.natural_scroll_enabled = enabled;
135 ScheduleUpdateDeviceSettings();
138 void InputControllerEvdev::SetMouseSensitivity(int value) {
139 input_device_settings_.mouse_sensitivity = value;
140 ScheduleUpdateDeviceSettings();
143 void InputControllerEvdev::SetPrimaryButtonRight(bool right) {
144 button_map_->UpdateButtonMap(BTN_LEFT, right ? BTN_RIGHT : BTN_LEFT);
145 button_map_->UpdateButtonMap(BTN_RIGHT, right ? BTN_LEFT : BTN_RIGHT);
148 void InputControllerEvdev::SetTapToClickPaused(bool state) {
149 input_device_settings_.tap_to_click_paused = state;
150 ScheduleUpdateDeviceSettings();
153 void InputControllerEvdev::GetTouchDeviceStatus(
154 const GetTouchDeviceStatusReply& reply) {
155 if (input_device_factory_)
156 input_device_factory_->GetTouchDeviceStatus(reply);
157 else
158 reply.Run(make_scoped_ptr(new std::string));
161 void InputControllerEvdev::GetTouchEventLog(
162 const base::FilePath& out_dir,
163 const GetTouchEventLogReply& reply) {
164 if (input_device_factory_)
165 input_device_factory_->GetTouchEventLog(out_dir, reply);
166 else
167 reply.Run(make_scoped_ptr(new std::vector<base::FilePath>));
170 void InputControllerEvdev::ScheduleUpdateDeviceSettings() {
171 if (!input_device_factory_ || settings_update_pending_)
172 return;
173 base::ThreadTaskRunnerHandle::Get()->PostTask(
174 FROM_HERE, base::Bind(&InputControllerEvdev::UpdateDeviceSettings,
175 weak_ptr_factory_.GetWeakPtr()));
176 settings_update_pending_ = true;
179 void InputControllerEvdev::UpdateDeviceSettings() {
180 input_device_factory_->UpdateInputDeviceSettings(input_device_settings_);
181 settings_update_pending_ = false;
184 void InputControllerEvdev::UpdateCapsLockLed() {
185 if (!input_device_factory_)
186 return;
187 bool caps_lock_state = IsCapsLockEnabled();
188 if (caps_lock_state != caps_lock_led_state_)
189 input_device_factory_->SetCapsLockLed(caps_lock_state);
190 caps_lock_led_state_ = caps_lock_state;
193 } // namespace ui