Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: ui/events/ozone/evdev/event_device_info.cc

Issue 1073573002: Ozone support for device special cases in keyboard event rewriting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crash (thanks spang) Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/ozone/evdev/event_device_info.h ('k') | ui/events/ozone/evdev/event_factory_evdev.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
20 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) { 25 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) {
21 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) { 26 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) {
22 PLOG(ERROR) << "EVIOCGBIT(" << type << ", " << size << ") on fd " << fd; 27 PLOG(ERROR) << "EVIOCGBIT(" << type << ", " << size << ") on fd " << fd;
23 return false; 28 return false;
24 } 29 }
25 30
26 return true; 31 return true;
27 } 32 }
28 33
29 bool GetPropBits(int fd, void* buf, unsigned int size) { 34 bool GetPropBits(int fd, void* buf, unsigned int size) {
30 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) { 35 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) {
31 PLOG(ERROR) << "EVIOCGPROP(" << size << ") on fd " << fd; 36 PLOG(ERROR) << "EVIOCGPROP(" << size << ") on fd " << fd;
32 return false; 37 return false;
33 } 38 }
34 39
35 return true; 40 return true;
36 } 41 }
37 42
38 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { 43 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) {
39 if (ioctl(fd, EVIOCGABS(code), absinfo)) { 44 if (ioctl(fd, EVIOCGABS(code), absinfo)) {
40 PLOG(ERROR) << "EVIOCGABS(" << code << ") on fd " << fd; 45 PLOG(ERROR) << "EVIOCGABS(" << code << ") on fd " << fd;
41 return false; 46 return false;
42 } 47 }
43 return true; 48 return true;
44 } 49 }
45 50
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
46 // |request| needs to be the equivalent to: 72 // |request| needs to be the equivalent to:
47 // struct input_mt_request_layout { 73 // struct input_mt_request_layout {
48 // uint32_t code; 74 // uint32_t code;
49 // int32_t values[num_slots]; 75 // int32_t values[num_slots];
50 // }; 76 // };
51 // 77 //
52 // |size| is num_slots + 1 (for code). 78 // |size| is num_slots + 1 (for code).
53 bool GetSlotValues(int fd, int32_t* request, unsigned int size) { 79 bool GetSlotValues(int fd, int32_t* request, unsigned int size) {
54 size_t data_size = size * sizeof(*request); 80 size_t data_size = size * sizeof(*request);
55 81
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 154
129 memset(request, 0, sizeof(request)); 155 memset(request, 0, sizeof(request));
130 *request_code = i; 156 *request_code = i;
131 if (!GetSlotValues(fd, request, max_num_slots + 1)) 157 if (!GetSlotValues(fd, request, max_num_slots + 1))
132 LOG(WARNING) << "Failed to get multitouch values for code " << i; 158 LOG(WARNING) << "Failed to get multitouch values for code " << i;
133 159
134 std::vector<int32_t>* slots = &slot_values_[i - EVDEV_ABS_MT_FIRST]; 160 std::vector<int32_t>* slots = &slot_values_[i - EVDEV_ABS_MT_FIRST];
135 slots->assign(request_slots, request_slots + max_num_slots); 161 slots->assign(request_slots, request_slots + max_num_slots);
136 } 162 }
137 163
164 if (!GetDeviceName(fd, &name_))
165 return false;
166
167 if (!GetDeviceIdentifiers(fd, &vendor_id_, &product_id_))
168 return false;
169
138 return true; 170 return true;
139 } 171 }
140 172
141 void EventDeviceInfo::SetEventTypes(const unsigned long* ev_bits, size_t len) { 173 void EventDeviceInfo::SetEventTypes(const unsigned long* ev_bits, size_t len) {
142 AssignBitset(ev_bits, len, ev_bits_, arraysize(ev_bits_)); 174 AssignBitset(ev_bits, len, ev_bits_, arraysize(ev_bits_));
143 } 175 }
144 176
145 void EventDeviceInfo::SetKeyEvents(const unsigned long* key_bits, size_t len) { 177 void EventDeviceInfo::SetKeyEvents(const unsigned long* key_bits, size_t len) {
146 AssignBitset(key_bits, len, key_bits_, arraysize(key_bits_)); 178 AssignBitset(key_bits, len, key_bits_, arraysize(key_bits_));
147 } 179 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 if (HasKeyEvent(BTN_TOOL_FINGER) && HasKeyEvent(BTN_TOUCH)) 411 if (HasKeyEvent(BTN_TOOL_FINGER) && HasKeyEvent(BTN_TOUCH))
380 return LegacyAbsoluteDeviceType::LADT_TOUCHPAD; 412 return LegacyAbsoluteDeviceType::LADT_TOUCHPAD;
381 413
382 if (HasKeyEvent(BTN_TOUCH)) 414 if (HasKeyEvent(BTN_TOUCH))
383 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; 415 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN;
384 416
385 return LegacyAbsoluteDeviceType::LADT_NONE; 417 return LegacyAbsoluteDeviceType::LADT_NONE;
386 } 418 }
387 419
388 } // namespace ui 420 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/event_device_info.h ('k') | ui/events/ozone/evdev/event_factory_evdev.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698