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 "base/trace_event/trace_event.h"
13 #include "ui/events/devices/input_device.h"
17 EventConverterEvdev::EventConverterEvdev(int fd
,
18 const base::FilePath
& path
,
21 const std::string
& name
,
26 input_device_(id
, type
, name
, vendor_id
, product_id
) {
29 EventConverterEvdev::~EventConverterEvdev() {
36 void EventConverterEvdev::Start() {
37 base::MessageLoopForUI::current()->WatchFileDescriptor(
38 fd_
, true, base::MessagePumpLibevent::WATCH_READ
, &controller_
, this);
42 void EventConverterEvdev::Stop() {
43 controller_
.StopWatchingFileDescriptor();
47 void EventConverterEvdev::SetEnabled(bool enabled
) {
48 if (enabled
== enabled_
)
51 TRACE_EVENT1("evdev", "EventConverterEvdev::OnEnabled", "path",
55 TRACE_EVENT1("evdev", "EventConverterEvdev::OnDisabled", "path",
62 void EventConverterEvdev::OnStopped() {
65 void EventConverterEvdev::OnEnabled() {
68 void EventConverterEvdev::OnDisabled() {
71 void EventConverterEvdev::DumpTouchEventLog(const char* filename
) {
74 void EventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd
) {
78 bool EventConverterEvdev::HasKeyboard() const {
82 bool EventConverterEvdev::HasMouse() const {
86 bool EventConverterEvdev::HasTouchpad() const {
90 bool EventConverterEvdev::HasTouchscreen() const {
94 bool EventConverterEvdev::HasCapsLockLed() const {
98 gfx::Size
EventConverterEvdev::GetTouchscreenSize() const {
103 int EventConverterEvdev::GetTouchPoints() const {
108 void EventConverterEvdev::SetKeyFilter(bool enable_filter
,
109 std::vector
<DomCode
> allowed_keys
) {
113 void EventConverterEvdev::SetCapsLockLed(bool enabled
) {
114 if (!HasCapsLockLed())
117 input_event events
[2];
118 memset(&events
, 0, sizeof(events
));
120 events
[0].type
= EV_LED
;
121 events
[0].code
= LED_CAPSL
;
122 events
[0].value
= enabled
;
124 events
[1].type
= EV_SYN
;
125 events
[1].code
= SYN_REPORT
;
128 ssize_t written
= write(fd_
, events
, sizeof(events
));
132 PLOG(ERROR
) << "cannot set leds for " << path_
.value() << ":";
134 } else if (written
!= sizeof(events
)) {
135 LOG(ERROR
) << "short write setting leds for " << path_
.value();
140 void EventConverterEvdev::SetTouchEventLoggingEnabled(bool enabled
) {
143 base::TimeDelta
EventConverterEvdev::TimeDeltaFromInputEvent(
144 const input_event
& event
) {
145 return base::TimeDelta::FromMicroseconds(event
.time
.tv_sec
* 1000000 +