| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/event_device_info.h" | 5 #include "ui/events/ozone/evdev/event_device_info.h" |
| 6 | 6 |
| 7 #include <linux/input.h> | 7 #include <linux/input.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 | 11 |
| 12 #if !defined(EVIOCGMTSLOTS) | 12 #if !defined(EVIOCGMTSLOTS) |
| 13 #define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len) | 13 #define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len) |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // USB vendor and product strings are pragmatically limited to 126 | |
| 21 // characters each, so device names more than twice that should be | |
| 22 // unusual. | |
| 23 const size_t kMaximumDeviceNameLength = 256; | |
| 24 | |
| 25 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) { | 20 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) { |
| 26 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) { | 21 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) { |
| 27 PLOG(ERROR) << "EVIOCGBIT(" << type << ", " << size << ") on fd " << fd; | 22 PLOG(ERROR) << "EVIOCGBIT(" << type << ", " << size << ") on fd " << fd; |
| 28 return false; | 23 return false; |
| 29 } | 24 } |
| 30 | 25 |
| 31 return true; | 26 return true; |
| 32 } | 27 } |
| 33 | 28 |
| 34 bool GetPropBits(int fd, void* buf, unsigned int size) { | 29 bool GetPropBits(int fd, void* buf, unsigned int size) { |
| 35 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) { | 30 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) { |
| 36 PLOG(ERROR) << "EVIOCGPROP(" << size << ") on fd " << fd; | 31 PLOG(ERROR) << "EVIOCGPROP(" << size << ") on fd " << fd; |
| 37 return false; | 32 return false; |
| 38 } | 33 } |
| 39 | 34 |
| 40 return true; | 35 return true; |
| 41 } | 36 } |
| 42 | 37 |
| 43 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { | 38 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { |
| 44 if (ioctl(fd, EVIOCGABS(code), absinfo)) { | 39 if (ioctl(fd, EVIOCGABS(code), absinfo)) { |
| 45 PLOG(ERROR) << "EVIOCGABS(" << code << ") on fd " << fd; | 40 PLOG(ERROR) << "EVIOCGABS(" << code << ") on fd " << fd; |
| 46 return false; | 41 return false; |
| 47 } | 42 } |
| 48 return true; | 43 return true; |
| 49 } | 44 } |
| 50 | 45 |
| 51 bool GetDeviceName(int fd, std::string* name) { | |
| 52 char device_name[kMaximumDeviceNameLength]; | |
| 53 if (ioctl(fd, EVIOCGNAME(kMaximumDeviceNameLength - 1), &device_name) < 0) { | |
| 54 PLOG(INFO) << "Can't read device name on fd " << fd; | |
| 55 return false; | |
| 56 } | |
| 57 *name = device_name; | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 bool GetDeviceIdentifiers(int fd, uint16_t* vendor, uint16_t* product) { | |
| 62 struct input_id evdev_id; | |
| 63 if (ioctl(fd, EVIOCGID, &evdev_id) < 0) { | |
| 64 PLOG(INFO) << "Can't read device name on fd " << fd; | |
| 65 return false; | |
| 66 } | |
| 67 *vendor = evdev_id.vendor; | |
| 68 *product = evdev_id.product; | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 // |request| needs to be the equivalent to: | 46 // |request| needs to be the equivalent to: |
| 73 // struct input_mt_request_layout { | 47 // struct input_mt_request_layout { |
| 74 // uint32_t code; | 48 // uint32_t code; |
| 75 // int32_t values[num_slots]; | 49 // int32_t values[num_slots]; |
| 76 // }; | 50 // }; |
| 77 // | 51 // |
| 78 // |size| is num_slots + 1 (for code). | 52 // |size| is num_slots + 1 (for code). |
| 79 bool GetSlotValues(int fd, int32_t* request, unsigned int size) { | 53 bool GetSlotValues(int fd, int32_t* request, unsigned int size) { |
| 80 size_t data_size = size * sizeof(*request); | 54 size_t data_size = size * sizeof(*request); |
| 81 | 55 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 128 |
| 155 memset(request, 0, sizeof(request)); | 129 memset(request, 0, sizeof(request)); |
| 156 *request_code = i; | 130 *request_code = i; |
| 157 if (!GetSlotValues(fd, request, max_num_slots + 1)) | 131 if (!GetSlotValues(fd, request, max_num_slots + 1)) |
| 158 LOG(WARNING) << "Failed to get multitouch values for code " << i; | 132 LOG(WARNING) << "Failed to get multitouch values for code " << i; |
| 159 | 133 |
| 160 std::vector<int32_t>* slots = &slot_values_[i - EVDEV_ABS_MT_FIRST]; | 134 std::vector<int32_t>* slots = &slot_values_[i - EVDEV_ABS_MT_FIRST]; |
| 161 slots->assign(request_slots, request_slots + max_num_slots); | 135 slots->assign(request_slots, request_slots + max_num_slots); |
| 162 } | 136 } |
| 163 | 137 |
| 164 if (!GetDeviceName(fd, &name_)) | |
| 165 return false; | |
| 166 | |
| 167 if (!GetDeviceIdentifiers(fd, &vendor_id_, &product_id_)) | |
| 168 return false; | |
| 169 | |
| 170 return true; | 138 return true; |
| 171 } | 139 } |
| 172 | 140 |
| 173 void EventDeviceInfo::SetEventTypes(const unsigned long* ev_bits, size_t len) { | 141 void EventDeviceInfo::SetEventTypes(const unsigned long* ev_bits, size_t len) { |
| 174 AssignBitset(ev_bits, len, ev_bits_, arraysize(ev_bits_)); | 142 AssignBitset(ev_bits, len, ev_bits_, arraysize(ev_bits_)); |
| 175 } | 143 } |
| 176 | 144 |
| 177 void EventDeviceInfo::SetKeyEvents(const unsigned long* key_bits, size_t len) { | 145 void EventDeviceInfo::SetKeyEvents(const unsigned long* key_bits, size_t len) { |
| 178 AssignBitset(key_bits, len, key_bits_, arraysize(key_bits_)); | 146 AssignBitset(key_bits, len, key_bits_, arraysize(key_bits_)); |
| 179 } | 147 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 if (HasKeyEvent(BTN_TOOL_FINGER) && HasKeyEvent(BTN_TOUCH)) | 379 if (HasKeyEvent(BTN_TOOL_FINGER) && HasKeyEvent(BTN_TOUCH)) |
| 412 return LegacyAbsoluteDeviceType::LADT_TOUCHPAD; | 380 return LegacyAbsoluteDeviceType::LADT_TOUCHPAD; |
| 413 | 381 |
| 414 if (HasKeyEvent(BTN_TOUCH)) | 382 if (HasKeyEvent(BTN_TOUCH)) |
| 415 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; | 383 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; |
| 416 | 384 |
| 417 return LegacyAbsoluteDeviceType::LADT_NONE; | 385 return LegacyAbsoluteDeviceType::LADT_NONE; |
| 418 } | 386 } |
| 419 | 387 |
| 420 } // namespace ui | 388 } // namespace ui |
| OLD | NEW |