ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_converter_evdev.cc
blobeda2e88527b46ba60b8ddfb4be38c0758d230415
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 <linux/input.h>
7 #include "ui/events/ozone/evdev/event_converter_evdev.h"
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
12 #include "ui/events/devices/input_device.h"
14 namespace ui {
16 EventConverterEvdev::EventConverterEvdev(int fd,
17 const base::FilePath& path,
18 int id,
19 InputDeviceType type)
20 : fd_(fd), path_(path), id_(id), type_(type), ignore_events_(false) {
23 EventConverterEvdev::~EventConverterEvdev() {
24 Stop();
27 void EventConverterEvdev::Start() {
28 base::MessageLoopForUI::current()->WatchFileDescriptor(
29 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this);
32 void EventConverterEvdev::Stop() {
33 // TODO(spang): If we reach here due to an error, we should treat it
34 // as if we have lost sync & release held keys, etc.
35 controller_.StopWatchingFileDescriptor();
38 void EventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd) {
39 NOTREACHED();
42 bool EventConverterEvdev::HasKeyboard() const {
43 return false;
46 bool EventConverterEvdev::HasMouse() const {
47 return false;
50 bool EventConverterEvdev::HasTouchpad() const {
51 return false;
54 bool EventConverterEvdev::HasTouchscreen() const {
55 return false;
58 bool EventConverterEvdev::HasCapsLockLed() const {
59 return false;
62 gfx::Size EventConverterEvdev::GetTouchscreenSize() const {
63 NOTREACHED();
64 return gfx::Size();
67 int EventConverterEvdev::GetTouchPoints() const {
68 NOTREACHED();
69 return 0;
72 void EventConverterEvdev::SetAllowedKeys(
73 scoped_ptr<std::set<DomCode>> allowed_keys) {
74 NOTREACHED();
77 void EventConverterEvdev::AllowAllKeys() {
78 NOTREACHED();
81 void EventConverterEvdev::SetCapsLockLed(bool enabled) {
82 if (!HasCapsLockLed())
83 return;
85 input_event events[2];
86 memset(&events, 0, sizeof(events));
88 events[0].type = EV_LED;
89 events[0].code = LED_CAPSL;
90 events[0].value = enabled;
92 events[1].type = EV_SYN;
93 events[1].code = SYN_REPORT;
94 events[1].value = 0;
96 ssize_t written = write(fd_, events, sizeof(events));
98 if (written < 0) {
99 if (errno != ENODEV)
100 PLOG(ERROR) << "cannot set leds for " << path_.value() << ":";
101 Stop();
102 } else if (written != sizeof(events)) {
103 LOG(ERROR) << "short write setting leds for " << path_.value();
104 Stop();
108 base::TimeDelta EventConverterEvdev::TimeDeltaFromInputEvent(
109 const input_event& event) {
110 return base::TimeDelta::FromMicroseconds(event.time.tv_sec * 1000000 +
111 event.time.tv_usec);
113 } // namespace ui