| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { | 35 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { |
| 36 if (ioctl(fd, EVIOCGABS(code), absinfo)) { | 36 if (ioctl(fd, EVIOCGABS(code), absinfo)) { |
| 37 DLOG(ERROR) << "failed EVIOCGABS(" << code << ") on fd " << fd; | 37 DLOG(ERROR) << "failed EVIOCGABS(" << code << ") on fd " << fd; |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 return true; | 40 return true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // |request| needs to be the equivalent to: |
| 44 // struct input_mt_request_layout { |
| 45 // uint32_t code; |
| 46 // int32_t values[num_slots]; |
| 47 // }; |
| 48 // |
| 49 // |size| is num_slots + 1 (for code). |
| 50 bool GetSlotValues(int fd, int32_t* request, unsigned int size) { |
| 51 if (ioctl(fd, |
| 52 EVIOCGMTSLOTS(sizeof(int32_t) * size), |
| 53 request) < 0) { |
| 54 LOG(ERROR) << "failed EVIOCGMTSLOTS(" << request[0] << ") on fd " << fd; |
| 55 return false; |
| 56 } |
| 57 |
| 58 return true; |
| 59 } |
| 60 |
| 43 } // namespace | 61 } // namespace |
| 44 | 62 |
| 45 EventDeviceInfo::EventDeviceInfo() { | 63 EventDeviceInfo::EventDeviceInfo() { |
| 46 memset(ev_bits_, 0, sizeof(ev_bits_)); | 64 memset(ev_bits_, 0, sizeof(ev_bits_)); |
| 47 memset(key_bits_, 0, sizeof(key_bits_)); | 65 memset(key_bits_, 0, sizeof(key_bits_)); |
| 48 memset(rel_bits_, 0, sizeof(rel_bits_)); | 66 memset(rel_bits_, 0, sizeof(rel_bits_)); |
| 49 memset(abs_bits_, 0, sizeof(abs_bits_)); | 67 memset(abs_bits_, 0, sizeof(abs_bits_)); |
| 50 memset(msc_bits_, 0, sizeof(msc_bits_)); | 68 memset(msc_bits_, 0, sizeof(msc_bits_)); |
| 51 memset(sw_bits_, 0, sizeof(sw_bits_)); | 69 memset(sw_bits_, 0, sizeof(sw_bits_)); |
| 52 memset(led_bits_, 0, sizeof(led_bits_)); | 70 memset(led_bits_, 0, sizeof(led_bits_)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 79 return false; | 97 return false; |
| 80 | 98 |
| 81 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_))) | 99 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_))) |
| 82 return false; | 100 return false; |
| 83 | 101 |
| 84 for (unsigned int i = 0; i < ABS_CNT; ++i) | 102 for (unsigned int i = 0; i < ABS_CNT; ++i) |
| 85 if (HasAbsEvent(i)) | 103 if (HasAbsEvent(i)) |
| 86 if (!GetAbsInfo(fd, i, &abs_info_[i])) | 104 if (!GetAbsInfo(fd, i, &abs_info_[i])) |
| 87 return false; | 105 return false; |
| 88 | 106 |
| 107 int max_num_slots = abs_info_[ABS_MT_SLOT].maximum + 1; |
| 108 // |request| is MT code + slots. |
| 109 int32_t request[max_num_slots + 1]; |
| 110 for (unsigned int i = ABS_MT_SLOT + 1; i < ABS_MAX; ++i) { |
| 111 memset(request, 0, sizeof(request)); |
| 112 request[0] = i; |
| 113 if (HasAbsEvent(i)) |
| 114 if (!GetSlotValues(fd, request, max_num_slots + 1)) |
| 115 return false; |
| 116 |
| 117 slot_values_[i - ABS_MT_SLOT - 1].assign( |
| 118 request + 1, request + max_num_slots + 1); |
| 119 } |
| 120 |
| 89 return true; | 121 return true; |
| 90 } | 122 } |
| 91 | 123 |
| 92 bool EventDeviceInfo::HasEventType(unsigned int type) const { | 124 bool EventDeviceInfo::HasEventType(unsigned int type) const { |
| 93 if (type > EV_MAX) | 125 if (type > EV_MAX) |
| 94 return false; | 126 return false; |
| 95 return EvdevBitIsSet(ev_bits_, type); | 127 return EvdevBitIsSet(ev_bits_, type); |
| 96 } | 128 } |
| 97 | 129 |
| 98 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { | 130 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 170 } |
| 139 | 171 |
| 140 int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const { | 172 int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const { |
| 141 return abs_info_[code].minimum; | 173 return abs_info_[code].minimum; |
| 142 } | 174 } |
| 143 | 175 |
| 144 int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const { | 176 int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const { |
| 145 return abs_info_[code].maximum; | 177 return abs_info_[code].maximum; |
| 146 } | 178 } |
| 147 | 179 |
| 180 int32 EventDeviceInfo::GetSlotValue(unsigned int code, |
| 181 unsigned int slot) const { |
| 182 const std::vector<int32_t>& slots = GetMtSlotsForCode(code); |
| 183 DCHECK_LE(0u, slot) << slot << " is an invalid slot"; |
| 184 DCHECK_LT(slot, slots.size()) << slot << " is an invalid slot"; |
| 185 return slots[slot]; |
| 186 } |
| 187 |
| 148 bool EventDeviceInfo::HasAbsXY() const { | 188 bool EventDeviceInfo::HasAbsXY() const { |
| 149 if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y)) | 189 if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y)) |
| 150 return true; | 190 return true; |
| 151 | 191 |
| 152 if (HasAbsEvent(ABS_MT_POSITION_X) && HasAbsEvent(ABS_MT_POSITION_Y)) | 192 if (HasAbsEvent(ABS_MT_POSITION_X) && HasAbsEvent(ABS_MT_POSITION_Y)) |
| 153 return true; | 193 return true; |
| 154 | 194 |
| 155 return false; | 195 return false; |
| 156 } | 196 } |
| 157 | 197 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 175 | 215 |
| 176 // Touchpads are not mapped to the screen. | 216 // Touchpads are not mapped to the screen. |
| 177 if (HasKeyEvent(BTN_LEFT) || HasKeyEvent(BTN_MIDDLE) || | 217 if (HasKeyEvent(BTN_LEFT) || HasKeyEvent(BTN_MIDDLE) || |
| 178 HasKeyEvent(BTN_RIGHT) || HasKeyEvent(BTN_TOOL_FINGER)) | 218 HasKeyEvent(BTN_RIGHT) || HasKeyEvent(BTN_TOOL_FINGER)) |
| 179 return false; | 219 return false; |
| 180 | 220 |
| 181 // Touchscreens are mapped to the screen. | 221 // Touchscreens are mapped to the screen. |
| 182 return true; | 222 return true; |
| 183 } | 223 } |
| 184 | 224 |
| 225 const std::vector<int32_t>& EventDeviceInfo::GetMtSlotsForCode(int code) const { |
| 226 int index = code - ABS_MT_SLOT - 1; |
| 227 DCHECK_LE(0, index) << code << " is not a valid multi-touch code"; |
| 228 DCHECK_LT(index, EVDEV_ABS_MT_COUNT) |
| 229 << code << " is not a valid multi-touch code"; |
| 230 return slot_values_[index]; |
| 231 } |
| 232 |
| 185 } // namespace ui | 233 } // namespace ui |
| OLD | NEW |