| 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/touch_event_converter_evdev.h" | 5 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <linux/input.h> | 9 #include <linux/input.h> |
| 10 #include <poll.h> | 10 #include <poll.h> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 namespace ui { | 73 namespace ui { |
| 74 | 74 |
| 75 TouchEventConverterEvdev::TouchEventConverterEvdev( | 75 TouchEventConverterEvdev::TouchEventConverterEvdev( |
| 76 int fd, | 76 int fd, |
| 77 base::FilePath path, | 77 base::FilePath path, |
| 78 const EventDeviceInfo& info, | 78 const EventDeviceInfo& info, |
| 79 const EventDispatchCallback& callback) | 79 const EventDispatchCallback& callback) |
| 80 : EventConverterEvdev(callback), | 80 : EventConverterEvdev(fd, path), |
| 81 callback_(callback), |
| 81 syn_dropped_(false), | 82 syn_dropped_(false), |
| 82 is_type_a_(false), | 83 is_type_a_(false), |
| 83 current_slot_(0), | 84 current_slot_(0) { |
| 84 fd_(fd), | |
| 85 path_(path) { | |
| 86 Init(info); | 85 Init(info); |
| 87 } | 86 } |
| 88 | 87 |
| 89 TouchEventConverterEvdev::~TouchEventConverterEvdev() { | 88 TouchEventConverterEvdev::~TouchEventConverterEvdev() { |
| 90 Stop(); | 89 Stop(); |
| 91 close(fd_); | 90 close(fd_); |
| 92 } | 91 } |
| 93 | 92 |
| 94 void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) { | 93 void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) { |
| 95 gfx::Screen *screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); | 94 gfx::Screen *screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom; | 126 y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom; |
| 128 | 127 |
| 129 VLOG(1) << "applying touch calibration: " | 128 VLOG(1) << "applying touch calibration: " |
| 130 << base::StringPrintf("[%d, %d, %d, %d]", | 129 << base::StringPrintf("[%d, %d, %d, %d]", |
| 131 cal.bezel_left, | 130 cal.bezel_left, |
| 132 cal.bezel_right, | 131 cal.bezel_right, |
| 133 cal.bezel_top, | 132 cal.bezel_top, |
| 134 cal.bezel_bottom); | 133 cal.bezel_bottom); |
| 135 } | 134 } |
| 136 | 135 |
| 137 void TouchEventConverterEvdev::Start() { | |
| 138 base::MessageLoopForUI::current()->WatchFileDescriptor( | |
| 139 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); | |
| 140 } | |
| 141 | |
| 142 void TouchEventConverterEvdev::Stop() { | |
| 143 controller_.StopWatchingFileDescriptor(); | |
| 144 } | |
| 145 | |
| 146 bool TouchEventConverterEvdev::Reinitialize() { | 136 bool TouchEventConverterEvdev::Reinitialize() { |
| 147 EventDeviceInfo info; | 137 EventDeviceInfo info; |
| 148 if (info.Initialize(fd_)) { | 138 if (info.Initialize(fd_)) { |
| 149 Init(info); | 139 Init(info); |
| 150 return true; | 140 return true; |
| 151 } | 141 } |
| 152 return false; | 142 return false; |
| 153 } | 143 } |
| 154 | 144 |
| 155 void TouchEventConverterEvdev::OnFileCanWriteWithoutBlocking(int /* fd */) { | |
| 156 // Read-only file-descriptors. | |
| 157 NOTREACHED(); | |
| 158 } | |
| 159 | |
| 160 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { | 145 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { |
| 161 input_event inputs[MAX_FINGERS * 6 + 1]; | 146 input_event inputs[MAX_FINGERS * 6 + 1]; |
| 162 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 147 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
| 163 if (read_size < 0) { | 148 if (read_size < 0) { |
| 164 if (errno == EINTR || errno == EAGAIN) | 149 if (errno == EINTR || errno == EAGAIN) |
| 165 return; | 150 return; |
| 166 if (errno != ENODEV) | 151 if (errno != ENODEV) |
| 167 PLOG(ERROR) << "error reading device " << path_.value(); | 152 PLOG(ERROR) << "error reading device " << path_.value(); |
| 168 Stop(); | 153 Stop(); |
| 169 return; | 154 return; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // TODO(rikroege): Support elliptical finger regions. | 276 // TODO(rikroege): Support elliptical finger regions. |
| 292 TouchEvent evt(events_[i].type_, | 277 TouchEvent evt(events_[i].type_, |
| 293 gfx::PointF(events_[i].x_, events_[i].y_), | 278 gfx::PointF(events_[i].x_, events_[i].y_), |
| 294 /* flags */ 0, | 279 /* flags */ 0, |
| 295 /* touch_id */ i, | 280 /* touch_id */ i, |
| 296 delta, | 281 delta, |
| 297 /* radius_x */ events_[i].radius_x_, | 282 /* radius_x */ events_[i].radius_x_, |
| 298 /* radius_y */ events_[i].radius_y_, | 283 /* radius_y */ events_[i].radius_y_, |
| 299 /* angle */ 0., | 284 /* angle */ 0., |
| 300 events_[i].pressure_); | 285 events_[i].pressure_); |
| 301 DispatchEventToCallback(&evt); | 286 callback_.Run(&evt); |
| 302 | 287 |
| 303 // Subsequent events for this finger will be touch-move until it | 288 // Subsequent events for this finger will be touch-move until it |
| 304 // is released. | 289 // is released. |
| 305 events_[i].type_ = ET_TOUCH_MOVED; | 290 events_[i].type_ = ET_TOUCH_MOVED; |
| 306 } | 291 } |
| 307 } | 292 } |
| 308 altered_slots_.reset(); | 293 altered_slots_.reset(); |
| 309 } | 294 } |
| 310 | 295 |
| 311 } // namespace ui | 296 } // namespace ui |
| OLD | NEW |