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"
16 EventConverterEvdev::EventConverterEvdev(int fd
,
17 const base::FilePath
& path
,
20 : fd_(fd
), path_(path
), id_(id
), type_(type
), ignore_events_(false) {
23 EventConverterEvdev::~EventConverterEvdev() {
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
) {
42 bool EventConverterEvdev::HasKeyboard() const {
46 bool EventConverterEvdev::HasMouse() const {
50 bool EventConverterEvdev::HasTouchpad() const {
54 bool EventConverterEvdev::HasTouchscreen() const {
58 bool EventConverterEvdev::HasCapsLockLed() const {
62 gfx::Size
EventConverterEvdev::GetTouchscreenSize() const {
67 int EventConverterEvdev::GetTouchPoints() const {
72 void EventConverterEvdev::SetAllowedKeys(
73 scoped_ptr
<std::set
<DomCode
>> allowed_keys
) {
77 void EventConverterEvdev::AllowAllKeys() {
81 void EventConverterEvdev::SetCapsLockLed(bool enabled
) {
82 if (!HasCapsLockLed())
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
;
96 ssize_t written
= write(fd_
, events
, sizeof(events
));
100 PLOG(ERROR
) << "cannot set leds for " << path_
.value() << ":";
102 } else if (written
!= sizeof(events
)) {
103 LOG(ERROR
) << "short write setting leds for " << path_
.value();
108 base::TimeDelta
EventConverterEvdev::TimeDeltaFromInputEvent(
109 const input_event
& event
) {
110 return base::TimeDelta::FromMicroseconds(event
.time
.tv_sec
* 1000000 +