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 | |
61 } // namespace | 43 } // namespace |
62 | 44 |
63 EventDeviceInfo::EventDeviceInfo() { | 45 EventDeviceInfo::EventDeviceInfo() { |
64 memset(ev_bits_, 0, sizeof(ev_bits_)); | 46 memset(ev_bits_, 0, sizeof(ev_bits_)); |
65 memset(key_bits_, 0, sizeof(key_bits_)); | 47 memset(key_bits_, 0, sizeof(key_bits_)); |
66 memset(rel_bits_, 0, sizeof(rel_bits_)); | 48 memset(rel_bits_, 0, sizeof(rel_bits_)); |
67 memset(abs_bits_, 0, sizeof(abs_bits_)); | 49 memset(abs_bits_, 0, sizeof(abs_bits_)); |
68 memset(msc_bits_, 0, sizeof(msc_bits_)); | 50 memset(msc_bits_, 0, sizeof(msc_bits_)); |
69 memset(sw_bits_, 0, sizeof(sw_bits_)); | 51 memset(sw_bits_, 0, sizeof(sw_bits_)); |
70 memset(led_bits_, 0, sizeof(led_bits_)); | 52 memset(led_bits_, 0, sizeof(led_bits_)); |
(...skipping 26 matching lines...) Expand all Loading... |
97 return false; | 79 return false; |
98 | 80 |
99 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_))) | 81 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_))) |
100 return false; | 82 return false; |
101 | 83 |
102 for (unsigned int i = 0; i < ABS_CNT; ++i) | 84 for (unsigned int i = 0; i < ABS_CNT; ++i) |
103 if (HasAbsEvent(i)) | 85 if (HasAbsEvent(i)) |
104 if (!GetAbsInfo(fd, i, &abs_info_[i])) | 86 if (!GetAbsInfo(fd, i, &abs_info_[i])) |
105 return false; | 87 return false; |
106 | 88 |
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 | |
121 return true; | 89 return true; |
122 } | 90 } |
123 | 91 |
124 bool EventDeviceInfo::HasEventType(unsigned int type) const { | 92 bool EventDeviceInfo::HasEventType(unsigned int type) const { |
125 if (type > EV_MAX) | 93 if (type > EV_MAX) |
126 return false; | 94 return false; |
127 return EvdevBitIsSet(ev_bits_, type); | 95 return EvdevBitIsSet(ev_bits_, type); |
128 } | 96 } |
129 | 97 |
130 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { | 98 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 138 } |
171 | 139 |
172 int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const { | 140 int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const { |
173 return abs_info_[code].minimum; | 141 return abs_info_[code].minimum; |
174 } | 142 } |
175 | 143 |
176 int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const { | 144 int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const { |
177 return abs_info_[code].maximum; | 145 return abs_info_[code].maximum; |
178 } | 146 } |
179 | 147 |
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 | |
188 bool EventDeviceInfo::HasAbsXY() const { | 148 bool EventDeviceInfo::HasAbsXY() const { |
189 if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y)) | 149 if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y)) |
190 return true; | 150 return true; |
191 | 151 |
192 if (HasAbsEvent(ABS_MT_POSITION_X) && HasAbsEvent(ABS_MT_POSITION_Y)) | 152 if (HasAbsEvent(ABS_MT_POSITION_X) && HasAbsEvent(ABS_MT_POSITION_Y)) |
193 return true; | 153 return true; |
194 | 154 |
195 return false; | 155 return false; |
196 } | 156 } |
197 | 157 |
(...skipping 17 matching lines...) Expand all Loading... |
215 | 175 |
216 // Touchpads are not mapped to the screen. | 176 // Touchpads are not mapped to the screen. |
217 if (HasKeyEvent(BTN_LEFT) || HasKeyEvent(BTN_MIDDLE) || | 177 if (HasKeyEvent(BTN_LEFT) || HasKeyEvent(BTN_MIDDLE) || |
218 HasKeyEvent(BTN_RIGHT) || HasKeyEvent(BTN_TOOL_FINGER)) | 178 HasKeyEvent(BTN_RIGHT) || HasKeyEvent(BTN_TOOL_FINGER)) |
219 return false; | 179 return false; |
220 | 180 |
221 // Touchscreens are mapped to the screen. | 181 // Touchscreens are mapped to the screen. |
222 return true; | 182 return true; |
223 } | 183 } |
224 | 184 |
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 | |
233 } // namespace ui | 185 } // namespace ui |
OLD | NEW |