OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/libgestures_glue/event_reader_libevdev_cros.h" | 5 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <libevdev/libevdev.h> | 8 #include <libevdev/libevdev.h> |
9 #include <linux/input.h> | 9 #include <linux/input.h> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 EventReaderLibevdevCros::EventReaderLibevdevCros(int fd, | 28 EventReaderLibevdevCros::EventReaderLibevdevCros(int fd, |
29 const base::FilePath& path, | 29 const base::FilePath& path, |
30 int id, | 30 int id, |
31 InputDeviceType type, | 31 InputDeviceType type, |
32 const EventDeviceInfo& devinfo, | 32 const EventDeviceInfo& devinfo, |
33 scoped_ptr<Delegate> delegate) | 33 scoped_ptr<Delegate> delegate) |
34 : EventConverterEvdev(fd, path, id, type), | 34 : EventConverterEvdev(fd, path, id, type), |
35 has_keyboard_(devinfo.HasKeyboard()), | 35 has_keyboard_(devinfo.HasKeyboard()), |
| 36 has_touchpad_(devinfo.HasTouchpad()), |
36 delegate_(delegate.Pass()) { | 37 delegate_(delegate.Pass()) { |
37 memset(&evdev_, 0, sizeof(evdev_)); | 38 memset(&evdev_, 0, sizeof(evdev_)); |
38 evdev_.log = OnLogMessage; | 39 evdev_.log = OnLogMessage; |
39 evdev_.log_udata = this; | 40 evdev_.log_udata = this; |
40 evdev_.syn_report = OnSynReport; | 41 evdev_.syn_report = OnSynReport; |
41 evdev_.syn_report_udata = this; | 42 evdev_.syn_report_udata = this; |
42 evdev_.fd = fd; | 43 evdev_.fd = fd; |
43 | 44 |
44 memset(&evstate_, 0, sizeof(evstate_)); | 45 memset(&evstate_, 0, sizeof(evstate_)); |
45 evdev_.evstate = &evstate_; | 46 evdev_.evstate = &evstate_; |
(...skipping 15 matching lines...) Expand all Loading... |
61 if (EvdevRead(&evdev_)) { | 62 if (EvdevRead(&evdev_)) { |
62 if (errno == EINTR || errno == EAGAIN) | 63 if (errno == EINTR || errno == EAGAIN) |
63 return; | 64 return; |
64 if (errno != ENODEV) | 65 if (errno != ENODEV) |
65 PLOG(ERROR) << "error reading device " << path_.value(); | 66 PLOG(ERROR) << "error reading device " << path_.value(); |
66 Stop(); | 67 Stop(); |
67 return; | 68 return; |
68 } | 69 } |
69 } | 70 } |
70 | 71 |
| 72 void EventReaderLibevdevCros::SetAllowedKeys( |
| 73 scoped_ptr<std::set<KeyboardCode>> allowed_keys) { |
| 74 DCHECK(HasKeyboard()); |
| 75 delegate_->SetAllowedKeys(allowed_keys.Pass()); |
| 76 } |
| 77 |
| 78 void EventReaderLibevdevCros::AllowAllKeys() { |
| 79 DCHECK(HasKeyboard()); |
| 80 delegate_->AllowAllKeys(); |
| 81 } |
| 82 |
71 bool EventReaderLibevdevCros::HasKeyboard() const { | 83 bool EventReaderLibevdevCros::HasKeyboard() const { |
72 return has_keyboard_; | 84 return has_keyboard_; |
73 } | 85 } |
74 | 86 |
| 87 bool EventReaderLibevdevCros::HasTouchpad() const { |
| 88 return has_touchpad_; |
| 89 } |
| 90 |
75 // static | 91 // static |
76 void EventReaderLibevdevCros::OnSynReport(void* data, | 92 void EventReaderLibevdevCros::OnSynReport(void* data, |
77 EventStateRec* evstate, | 93 EventStateRec* evstate, |
78 struct timeval* tv) { | 94 struct timeval* tv) { |
79 EventReaderLibevdevCros* reader = static_cast<EventReaderLibevdevCros*>(data); | 95 EventReaderLibevdevCros* reader = static_cast<EventReaderLibevdevCros*>(data); |
| 96 if (reader->ignore_events_) |
| 97 return; |
| 98 |
80 reader->delegate_->OnLibEvdevCrosEvent(&reader->evdev_, evstate, *tv); | 99 reader->delegate_->OnLibEvdevCrosEvent(&reader->evdev_, evstate, *tv); |
81 } | 100 } |
82 | 101 |
83 // static | 102 // static |
84 void EventReaderLibevdevCros::OnLogMessage(void* data, | 103 void EventReaderLibevdevCros::OnLogMessage(void* data, |
85 int level, | 104 int level, |
86 const char* fmt, | 105 const char* fmt, |
87 ...) { | 106 ...) { |
88 va_list args; | 107 va_list args; |
89 va_start(args, fmt); | 108 va_start(args, fmt); |
90 if (level >= LOGLEVEL_ERROR) | 109 if (level >= LOGLEVEL_ERROR) |
91 LOG(ERROR) << "libevdev: " << FormatLog(fmt, args); | 110 LOG(ERROR) << "libevdev: " << FormatLog(fmt, args); |
92 else if (level >= LOGLEVEL_WARNING) | 111 else if (level >= LOGLEVEL_WARNING) |
93 LOG(WARNING) << "libevdev: " << FormatLog(fmt, args); | 112 LOG(WARNING) << "libevdev: " << FormatLog(fmt, args); |
94 else | 113 else |
95 VLOG(3) << "libevdev: " << FormatLog(fmt, args); | 114 VLOG(3) << "libevdev: " << FormatLog(fmt, args); |
96 va_end(args); | 115 va_end(args); |
97 } | 116 } |
98 | 117 |
99 } // namespace ui | 118 } // namespace ui |
OLD | NEW |