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

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

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 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_device_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/events/ozone/evdev/event_device_info.h"
6
7 #include <linux/input.h>
8
9 #include "base/logging.h"
10 #include "base/threading/thread_restrictions.h"
11
12 namespace ui {
13
14 namespace {
15
16 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) {
17 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) {
18 DLOG(ERROR) << "failed EVIOCGBIT(" << type << ", " << size << ") on fd "
19 << fd;
20 return false;
21 }
22
23 return true;
24 }
25
26 bool GetPropBits(int fd, void* buf, unsigned int size) {
27 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) {
28 DLOG(ERROR) << "failed EVIOCGPROP(" << size << ") on fd " << fd;
29 return false;
30 }
31
32 return true;
33 }
34
35 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) {
36 if (ioctl(fd, EVIOCGABS(code), absinfo)) {
37 DLOG(ERROR) << "failed EVIOCGABS(" << code << ") on fd " << fd;
38 return false;
39 }
40 return true;
41 }
42
43 } // namespace
44
45 EventDeviceInfo::EventDeviceInfo() {
46 memset(ev_bits_, 0, sizeof(ev_bits_));
47 memset(key_bits_, 0, sizeof(key_bits_));
48 memset(rel_bits_, 0, sizeof(rel_bits_));
49 memset(abs_bits_, 0, sizeof(abs_bits_));
50 memset(msc_bits_, 0, sizeof(msc_bits_));
51 memset(sw_bits_, 0, sizeof(sw_bits_));
52 memset(led_bits_, 0, sizeof(led_bits_));
53 memset(prop_bits_, 0, sizeof(prop_bits_));
54 memset(abs_info_, 0, sizeof(abs_info_));
55 }
56
57 EventDeviceInfo::~EventDeviceInfo() {}
58
59 bool EventDeviceInfo::Initialize(int fd) {
60 if (!GetEventBits(fd, 0, ev_bits_, sizeof(ev_bits_)))
61 return false;
62
63 if (!GetEventBits(fd, EV_KEY, key_bits_, sizeof(key_bits_)))
64 return false;
65
66 if (!GetEventBits(fd, EV_REL, rel_bits_, sizeof(rel_bits_)))
67 return false;
68
69 if (!GetEventBits(fd, EV_ABS, abs_bits_, sizeof(abs_bits_)))
70 return false;
71
72 if (!GetEventBits(fd, EV_MSC, msc_bits_, sizeof(msc_bits_)))
73 return false;
74
75 if (!GetEventBits(fd, EV_SW, sw_bits_, sizeof(sw_bits_)))
76 return false;
77
78 if (!GetEventBits(fd, EV_LED, led_bits_, sizeof(led_bits_)))
79 return false;
80
81 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_)))
82 return false;
83
84 for (unsigned int i = 0; i < ABS_CNT; ++i)
85 if (HasAbsEvent(i))
86 if (!GetAbsInfo(fd, i, &abs_info_[i]))
87 return false;
88
89 return true;
90 }
91
92 bool EventDeviceInfo::HasEventType(unsigned int type) const {
93 if (type > EV_MAX)
94 return false;
95 return EvdevBitIsSet(ev_bits_, type);
96 }
97
98 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const {
99 if (code > KEY_MAX)
100 return false;
101 return EvdevBitIsSet(key_bits_, code);
102 }
103
104 bool EventDeviceInfo::HasRelEvent(unsigned int code) const {
105 if (code > REL_MAX)
106 return false;
107 return EvdevBitIsSet(rel_bits_, code);
108 }
109
110 bool EventDeviceInfo::HasAbsEvent(unsigned int code) const {
111 if (code > ABS_MAX)
112 return false;
113 return EvdevBitIsSet(abs_bits_, code);
114 }
115
116 bool EventDeviceInfo::HasMscEvent(unsigned int code) const {
117 if (code > MSC_MAX)
118 return false;
119 return EvdevBitIsSet(msc_bits_, code);
120 }
121
122 bool EventDeviceInfo::HasSwEvent(unsigned int code) const {
123 if (code > SW_MAX)
124 return false;
125 return EvdevBitIsSet(sw_bits_, code);
126 }
127
128 bool EventDeviceInfo::HasLedEvent(unsigned int code) const {
129 if (code > LED_MAX)
130 return false;
131 return EvdevBitIsSet(led_bits_, code);
132 }
133
134 bool EventDeviceInfo::HasProp(unsigned int code) const {
135 if (code > INPUT_PROP_MAX)
136 return false;
137 return EvdevBitIsSet(prop_bits_, code);
138 }
139
140 int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const {
141 return abs_info_[code].minimum;
142 }
143
144 int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const {
145 return abs_info_[code].maximum;
146 }
147
148 bool EventDeviceInfo::HasAbsXY() const {
149 if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y))
150 return true;
151
152 if (HasAbsEvent(ABS_MT_POSITION_X) && HasAbsEvent(ABS_MT_POSITION_Y))
153 return true;
154
155 return false;
156 }
157
158 bool EventDeviceInfo::HasRelXY() const {
159 return HasRelEvent(REL_X) && HasRelEvent(REL_Y);
160 }
161
162 bool EventDeviceInfo::IsMappedToScreen() const {
163 // Device position is mapped directly to the screen.
164 if (HasProp(INPUT_PROP_DIRECT))
165 return true;
166
167 // Device position moves the cursor.
168 if (HasProp(INPUT_PROP_POINTER))
169 return false;
170
171 // Tablets are mapped to the screen.
172 if (HasKeyEvent(BTN_TOOL_PEN) || HasKeyEvent(BTN_STYLUS) ||
173 HasKeyEvent(BTN_STYLUS2))
174 return true;
175
176 // Touchpads are not mapped to the screen.
177 if (HasKeyEvent(BTN_LEFT) || HasKeyEvent(BTN_MIDDLE) ||
178 HasKeyEvent(BTN_RIGHT) || HasKeyEvent(BTN_TOOL_FINGER))
179 return false;
180
181 // Touchscreens are mapped to the screen.
182 return true;
183 }
184
185 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/event_device_info.h ('k') | ui/events/ozone/evdev/event_device_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698