| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 base::FilePath path, | 83 base::FilePath path, |
| 84 int id, | 84 int id, |
| 85 InputDeviceType type, | 85 InputDeviceType type, |
| 86 DeviceEventDispatcherEvdev* dispatcher) | 86 DeviceEventDispatcherEvdev* dispatcher) |
| 87 : EventConverterEvdev(fd, path, id, type), | 87 : EventConverterEvdev(fd, path, id, type), |
| 88 dispatcher_(dispatcher), | 88 dispatcher_(dispatcher), |
| 89 syn_dropped_(false), | 89 syn_dropped_(false), |
| 90 has_mt_(false), | 90 has_mt_(false), |
| 91 touch_points_(0), | 91 touch_points_(0), |
| 92 next_tracking_id_(0), | 92 next_tracking_id_(0), |
| 93 current_slot_(0) { | 93 current_slot_(0), |
| 94 touch_id_offset_(0) { |
| 94 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 95 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 95 switches::kExtraTouchNoiseFiltering)) { | 96 switches::kExtraTouchNoiseFiltering)) { |
| 96 touch_noise_finder_.reset(new TouchNoiseFinder); | 97 touch_noise_finder_.reset(new TouchNoiseFinder); |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 TouchEventConverterEvdev::~TouchEventConverterEvdev() { | 101 TouchEventConverterEvdev::~TouchEventConverterEvdev() { |
| 101 Stop(); | 102 Stop(); |
| 102 close(fd_); | 103 close(fd_); |
| 103 } | 104 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 192 } |
| 192 | 193 |
| 193 gfx::Size TouchEventConverterEvdev::GetTouchscreenSize() const { | 194 gfx::Size TouchEventConverterEvdev::GetTouchscreenSize() const { |
| 194 return gfx::Size(x_num_tuxels_, y_num_tuxels_); | 195 return gfx::Size(x_num_tuxels_, y_num_tuxels_); |
| 195 } | 196 } |
| 196 | 197 |
| 197 int TouchEventConverterEvdev::GetTouchPoints() const { | 198 int TouchEventConverterEvdev::GetTouchPoints() const { |
| 198 return touch_points_; | 199 return touch_points_; |
| 199 } | 200 } |
| 200 | 201 |
| 202 void TouchEventConverterEvdev::SetTouchIdOffset(int offset) { |
| 203 touch_id_offset_ = offset; |
| 204 } |
| 205 |
| 201 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { | 206 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { |
| 202 input_event inputs[kNumTouchEvdevSlots * 6 + 1]; | 207 input_event inputs[kNumTouchEvdevSlots * 6 + 1]; |
| 203 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 208 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
| 204 if (read_size < 0) { | 209 if (read_size < 0) { |
| 205 if (errno == EINTR || errno == EAGAIN) | 210 if (errno == EINTR || errno == EAGAIN) |
| 206 return; | 211 return; |
| 207 if (errno != ENODEV) | 212 if (errno != ENODEV) |
| 208 PLOG(ERROR) << "error reading device " << path_.value(); | 213 PLOG(ERROR) << "error reading device " << path_.value(); |
| 209 Stop(); | 214 Stop(); |
| 210 return; | 215 return; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 355 } |
| 351 | 356 |
| 352 if (touch.touching) | 357 if (touch.touching) |
| 353 return touch.was_touching ? ET_TOUCH_MOVED : ET_TOUCH_PRESSED; | 358 return touch.was_touching ? ET_TOUCH_MOVED : ET_TOUCH_PRESSED; |
| 354 return touch.was_touching ? ET_TOUCH_RELEASED : ET_UNKNOWN; | 359 return touch.was_touching ? ET_TOUCH_RELEASED : ET_UNKNOWN; |
| 355 } | 360 } |
| 356 | 361 |
| 357 void TouchEventConverterEvdev::ReportEvent(const InProgressTouchEvdev& event, | 362 void TouchEventConverterEvdev::ReportEvent(const InProgressTouchEvdev& event, |
| 358 EventType event_type, | 363 EventType event_type, |
| 359 const base::TimeDelta& timestamp) { | 364 const base::TimeDelta& timestamp) { |
| 360 dispatcher_->DispatchTouchEvent(TouchEventParams( | 365 dispatcher_->DispatchTouchEvent( |
| 361 id_, event.slot, event_type, gfx::PointF(event.x, event.y), | 366 TouchEventParams(id_, touch_id_offset_ + event.slot, event_type, |
| 362 gfx::Vector2dF(event.radius_x, event.radius_y), event.pressure, | 367 gfx::PointF(event.x, event.y), |
| 363 timestamp)); | 368 gfx::Vector2dF(event.radius_x, event.radius_y), |
| 369 event.pressure, timestamp)); |
| 364 } | 370 } |
| 365 | 371 |
| 366 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { | 372 void TouchEventConverterEvdev::ReportEvents(base::TimeDelta delta) { |
| 367 if (touch_noise_finder_) | 373 if (touch_noise_finder_) |
| 368 touch_noise_finder_->HandleTouches(events_, delta); | 374 touch_noise_finder_->HandleTouches(events_, delta); |
| 369 | 375 |
| 370 for (size_t i = 0; i < events_.size(); i++) { | 376 for (size_t i = 0; i < events_.size(); i++) { |
| 371 InProgressTouchEvdev* event = &events_[i]; | 377 InProgressTouchEvdev* event = &events_[i]; |
| 372 if (!event->altered) | 378 if (!event->altered) |
| 373 continue; | 379 continue; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 389 if (pressure_max_ - pressure_min_) | 395 if (pressure_max_ - pressure_min_) |
| 390 pressure /= pressure_max_ - pressure_min_; | 396 pressure /= pressure_max_ - pressure_min_; |
| 391 return pressure; | 397 return pressure; |
| 392 } | 398 } |
| 393 | 399 |
| 394 int TouchEventConverterEvdev::NextTrackingId() { | 400 int TouchEventConverterEvdev::NextTrackingId() { |
| 395 return next_tracking_id_++ & kMaxTrackingId; | 401 return next_tracking_id_++ & kMaxTrackingId; |
| 396 } | 402 } |
| 397 | 403 |
| 398 } // namespace ui | 404 } // namespace ui |
| OLD | NEW |