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/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // This takes a TaskRunner and runs the reply on that thread, so that we | 135 // This takes a TaskRunner and runs the reply on that thread, so that we |
136 // can hop threads if necessary (back to the UI thread). | 136 // can hop threads if necessary (back to the UI thread). |
137 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, | 137 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, |
138 scoped_refptr<base::TaskRunner> reply_runner, | 138 scoped_refptr<base::TaskRunner> reply_runner, |
139 const OpenInputDeviceReplyCallback& reply_callback) { | 139 const OpenInputDeviceReplyCallback& reply_callback) { |
140 const base::FilePath& path = params->path; | 140 const base::FilePath& path = params->path; |
141 scoped_ptr<EventConverterEvdev> converter; | 141 scoped_ptr<EventConverterEvdev> converter; |
142 | 142 |
143 TRACE_EVENT1("ozone", "OpenInputDevice", "path", path.value()); | 143 TRACE_EVENT1("ozone", "OpenInputDevice", "path", path.value()); |
144 | 144 |
145 int fd = open(path.value().c_str(), O_RDONLY | O_NONBLOCK); | 145 int fd = open(path.value().c_str(), O_RDWR | O_NONBLOCK); |
146 if (fd < 0) { | 146 if (fd < 0) { |
147 PLOG(ERROR) << "Cannot open '" << path.value(); | 147 PLOG(ERROR) << "Cannot open '" << path.value(); |
148 reply_runner->PostTask( | 148 reply_runner->PostTask( |
149 FROM_HERE, base::Bind(reply_callback, base::Passed(&converter))); | 149 FROM_HERE, base::Bind(reply_callback, base::Passed(&converter))); |
150 return; | 150 return; |
151 } | 151 } |
152 | 152 |
153 // Use monotonic timestamps for events. The touch code in particular | 153 // Use monotonic timestamps for events. The touch code in particular |
154 // expects event timestamps to correlate to the monotonic clock | 154 // expects event timestamps to correlate to the monotonic clock |
155 // (base::TimeTicks). | 155 // (base::TimeTicks). |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 cursor_(cursor), | 193 cursor_(cursor), |
194 #if defined(USE_EVDEV_GESTURES) | 194 #if defined(USE_EVDEV_GESTURES) |
195 gesture_property_provider_(new GesturePropertyProvider), | 195 gesture_property_provider_(new GesturePropertyProvider), |
196 #endif | 196 #endif |
197 dispatcher_(dispatcher.Pass()), | 197 dispatcher_(dispatcher.Pass()), |
198 pending_device_changes_(0), | 198 pending_device_changes_(0), |
199 touchscreen_list_dirty_(false), | 199 touchscreen_list_dirty_(false), |
200 keyboard_list_dirty_(false), | 200 keyboard_list_dirty_(false), |
201 mouse_list_dirty_(false), | 201 mouse_list_dirty_(false), |
202 touchpad_list_dirty_(false), | 202 touchpad_list_dirty_(false), |
| 203 caps_lock_led_enabled_(false), |
203 weak_ptr_factory_(this) { | 204 weak_ptr_factory_(this) { |
204 } | 205 } |
205 | 206 |
206 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { | 207 InputDeviceFactoryEvdev::~InputDeviceFactoryEvdev() { |
207 STLDeleteValues(&converters_); | 208 STLDeleteValues(&converters_); |
208 } | 209 } |
209 | 210 |
210 void InputDeviceFactoryEvdev::AddInputDevice(int id, | 211 void InputDeviceFactoryEvdev::AddInputDevice(int id, |
211 const base::FilePath& path) { | 212 const base::FilePath& path) { |
212 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 213 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (converters_[path]) | 250 if (converters_[path]) |
250 DetachInputDevice(path); | 251 DetachInputDevice(path); |
251 | 252 |
252 // Add initialized device to map. | 253 // Add initialized device to map. |
253 converters_[path] = converter.release(); | 254 converters_[path] = converter.release(); |
254 converters_[path]->Start(); | 255 converters_[path]->Start(); |
255 UpdateDirtyFlags(converters_[path]); | 256 UpdateDirtyFlags(converters_[path]); |
256 | 257 |
257 // Sync settings to new device. | 258 // Sync settings to new device. |
258 ApplyInputDeviceSettings(); | 259 ApplyInputDeviceSettings(); |
| 260 ApplyCapsLockLed(); |
259 } | 261 } |
260 | 262 |
261 if (--pending_device_changes_ == 0) | 263 if (--pending_device_changes_ == 0) |
262 NotifyDevicesUpdated(); | 264 NotifyDevicesUpdated(); |
263 } | 265 } |
264 | 266 |
265 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { | 267 void InputDeviceFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
266 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); | 268 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); |
267 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 269 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
268 | 270 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { | 323 void InputDeviceFactoryEvdev::EnableInternalKeyboard() { |
322 for (const auto& it : converters_) { | 324 for (const auto& it : converters_) { |
323 EventConverterEvdev* converter = it.second; | 325 EventConverterEvdev* converter = it.second; |
324 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && | 326 if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && |
325 converter->HasKeyboard()) { | 327 converter->HasKeyboard()) { |
326 converter->AllowAllKeys(); | 328 converter->AllowAllKeys(); |
327 } | 329 } |
328 } | 330 } |
329 } | 331 } |
330 | 332 |
| 333 void InputDeviceFactoryEvdev::SetCapsLockLed(bool enabled) { |
| 334 caps_lock_led_enabled_ = enabled; |
| 335 ApplyCapsLockLed(); |
| 336 } |
| 337 |
331 void InputDeviceFactoryEvdev::UpdateInputDeviceSettings( | 338 void InputDeviceFactoryEvdev::UpdateInputDeviceSettings( |
332 const InputDeviceSettingsEvdev& settings) { | 339 const InputDeviceSettingsEvdev& settings) { |
333 input_device_settings_ = settings; | 340 input_device_settings_ = settings; |
334 ApplyInputDeviceSettings(); | 341 ApplyInputDeviceSettings(); |
335 } | 342 } |
336 | 343 |
337 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( | 344 void InputDeviceFactoryEvdev::GetTouchDeviceStatus( |
338 const GetTouchDeviceStatusReply& reply) { | 345 const GetTouchDeviceStatusReply& reply) { |
339 scoped_ptr<std::string> status(new std::string); | 346 scoped_ptr<std::string> status(new std::string); |
340 #if defined(USE_EVDEV_GESTURES) | 347 #if defined(USE_EVDEV_GESTURES) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 385 |
379 SetIntPropertyForOneType(DT_MOUSE, "Pointer Sensitivity", | 386 SetIntPropertyForOneType(DT_MOUSE, "Pointer Sensitivity", |
380 input_device_settings_.mouse_sensitivity); | 387 input_device_settings_.mouse_sensitivity); |
381 SetIntPropertyForOneType(DT_MOUSE, "Scroll Sensitivity", | 388 SetIntPropertyForOneType(DT_MOUSE, "Scroll Sensitivity", |
382 input_device_settings_.mouse_sensitivity); | 389 input_device_settings_.mouse_sensitivity); |
383 | 390 |
384 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", | 391 SetBoolPropertyForOneType(DT_TOUCHPAD, "Tap Paused", |
385 input_device_settings_.tap_to_click_paused); | 392 input_device_settings_.tap_to_click_paused); |
386 } | 393 } |
387 | 394 |
| 395 void InputDeviceFactoryEvdev::ApplyCapsLockLed() { |
| 396 for (const auto& it : converters_) { |
| 397 EventConverterEvdev* converter = it.second; |
| 398 converter->SetCapsLockLed(caps_lock_led_enabled_); |
| 399 } |
| 400 } |
| 401 |
388 void InputDeviceFactoryEvdev::UpdateDirtyFlags( | 402 void InputDeviceFactoryEvdev::UpdateDirtyFlags( |
389 const EventConverterEvdev* converter) { | 403 const EventConverterEvdev* converter) { |
390 if (converter->HasTouchscreen()) | 404 if (converter->HasTouchscreen()) |
391 touchscreen_list_dirty_ = true; | 405 touchscreen_list_dirty_ = true; |
392 | 406 |
393 if (converter->HasKeyboard()) | 407 if (converter->HasKeyboard()) |
394 keyboard_list_dirty_ = true; | 408 keyboard_list_dirty_ = true; |
395 | 409 |
396 if (converter->HasMouse()) | 410 if (converter->HasMouse()) |
397 mouse_list_dirty_ = true; | 411 mouse_list_dirty_ = true; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 std::vector<int> ids; | 498 std::vector<int> ids; |
485 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 499 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
486 for (size_t i = 0; i < ids.size(); ++i) { | 500 for (size_t i = 0; i < ids.size(); ++i) { |
487 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, | 501 SetGestureBoolProperty(gesture_property_provider_.get(), ids[i], name, |
488 value); | 502 value); |
489 } | 503 } |
490 #endif | 504 #endif |
491 } | 505 } |
492 | 506 |
493 } // namespace ui | 507 } // namespace ui |
OLD | NEW |