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

Side by Side Diff: ui/events/devices/x11/touch_factory_x11.cc

Issue 706763003: x11: Always require XI2.2 for X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tot-merge Created 6 years, 1 month 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/devices/x11/device_data_manager_x11.cc ('k') | ui/events/event_switches.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/devices/x11/touch_factory_x11.h" 5 #include "ui/events/devices/x11/touch_factory_x11.h"
6 6
7 #include <X11/Xatom.h> 7 #include <X11/Xatom.h>
8 #include <X11/cursorfont.h> 8 #include <X11/cursorfont.h>
9 #include <X11/extensions/XInput.h> 9 #include <X11/extensions/XInput.h>
10 #include <X11/extensions/XInput2.h> 10 #include <X11/extensions/XInput2.h>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 } 79 }
80 80
81 void TouchFactory::UpdateDeviceList(Display* display) { 81 void TouchFactory::UpdateDeviceList(Display* display) {
82 // Detect touch devices. 82 // Detect touch devices.
83 touch_device_lookup_.reset(); 83 touch_device_lookup_.reset();
84 touch_device_list_.clear(); 84 touch_device_list_.clear();
85 touchscreen_ids_.clear(); 85 touchscreen_ids_.clear();
86 max_touch_points_ = -1; 86 max_touch_points_ = -1;
87 87
88 #if !defined(USE_XI2_MT)
89 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does 88 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does
90 // not provide enough information to detect a touch device. As a result, the 89 // not provide enough information to detect a touch device. As a result, the
91 // old version of query function (XListInputDevices) is used instead. 90 // old version of query function (XListInputDevices) is used instead.
92 // If XInput2 is not supported, this will return null (with count of -1) so 91 // If XInput2 is not supported, this will return null (with count of -1) so
93 // we assume there cannot be any touch devices. 92 // we assume there cannot be any touch devices.
94 // With XI2.1 or older, we allow only single touch devices. 93 // With XI2.1 or older, we allow only single touch devices.
95 XDeviceList dev_list = 94 XDeviceList dev_list =
96 DeviceListCacheX11::GetInstance()->GetXDeviceList(display); 95 DeviceListCacheX11::GetInstance()->GetXDeviceList(display);
97 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); 96 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false);
98 for (int i = 0; i < dev_list.count; i++) { 97 for (int i = 0; i < dev_list.count; i++) {
99 if (dev_list[i].type == xi_touchscreen) { 98 if (dev_list[i].type == xi_touchscreen) {
100 touch_device_lookup_[dev_list[i].id] = true; 99 touch_device_lookup_[dev_list[i].id] = true;
101 touch_device_list_[dev_list[i].id] = false; 100 touch_device_list_[dev_list[i].id] = false;
102 } 101 }
103 } 102 }
104 #endif
105 103
106 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) 104 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available())
107 return; 105 return;
108 106
109 // Instead of asking X for the list of devices all the time, let's maintain a 107 // Instead of asking X for the list of devices all the time, let's maintain a
110 // list of pointer devices we care about. 108 // list of pointer devices we care about.
111 // It should not be necessary to select for slave devices. XInput2 provides 109 // It should not be necessary to select for slave devices. XInput2 provides
112 // enough information to the event callback to decide which slave device 110 // enough information to the event callback to decide which slave device
113 // triggered the event, thus decide whether the 'pointer event' is a 111 // triggered the event, thus decide whether the 'pointer event' is a
114 // 'mouse event' or a 'touch event'. 112 // 'mouse event' or a 'touch event'.
115 // However, on some desktops, some events from a master pointer are 113 // However, on some desktops, some events from a master pointer are
116 // not delivered to the client. So we select for slave devices instead. 114 // not delivered to the client. So we select for slave devices instead.
117 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which 115 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which
118 // is possible), then the device is detected as a floating device, and a 116 // is possible), then the device is detected as a floating device, and a
119 // floating device is not connected to a master device. So it is necessary to 117 // floating device is not connected to a master device. So it is necessary to
120 // also select on the floating devices. 118 // also select on the floating devices.
121 pointer_device_lookup_.reset(); 119 pointer_device_lookup_.reset();
122 XIDeviceList xi_dev_list = 120 XIDeviceList xi_dev_list =
123 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); 121 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display);
124 for (int i = 0; i < xi_dev_list.count; i++) { 122 for (int i = 0; i < xi_dev_list.count; i++) {
125 XIDeviceInfo* devinfo = xi_dev_list.devices + i; 123 XIDeviceInfo* devinfo = xi_dev_list.devices + i;
126 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { 124 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) {
127 #if defined(USE_XI2_MT)
128 for (int k = 0; k < devinfo->num_classes; ++k) { 125 for (int k = 0; k < devinfo->num_classes; ++k) {
129 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; 126 XIAnyClassInfo* xiclassinfo = devinfo->classes[k];
130 if (xiclassinfo->type == XITouchClass) { 127 if (xiclassinfo->type == XITouchClass) {
131 XITouchClassInfo* tci = 128 XITouchClassInfo* tci =
132 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); 129 reinterpret_cast<XITouchClassInfo*>(xiclassinfo);
133 // Only care direct touch device (such as touch screen) right now 130 // Only care direct touch device (such as touch screen) right now
134 if (tci->mode == XIDirectTouch) { 131 if (tci->mode == XIDirectTouch) {
135 touch_device_lookup_[devinfo->deviceid] = true; 132 touch_device_lookup_[devinfo->deviceid] = true;
136 touch_device_list_[devinfo->deviceid] = true; 133 touch_device_list_[devinfo->deviceid] = true;
137 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) 134 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_)
138 max_touch_points_ = tci->num_touches; 135 max_touch_points_ = tci->num_touches;
139 } 136 }
140 } 137 }
141 } 138 }
142 #endif
143 pointer_device_lookup_[devinfo->deviceid] = true; 139 pointer_device_lookup_[devinfo->deviceid] = true;
144 } else if (devinfo->use == XIMasterKeyboard) { 140 } else if (devinfo->use == XIMasterKeyboard) {
145 virtual_core_keyboard_device_ = devinfo->deviceid; 141 virtual_core_keyboard_device_ = devinfo->deviceid;
146 } 142 }
147 143
148 #if defined(USE_XI2_MT)
149 if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) { 144 if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) {
150 for (int k = 0; k < devinfo->num_classes; ++k) { 145 for (int k = 0; k < devinfo->num_classes; ++k) {
151 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; 146 XIAnyClassInfo* xiclassinfo = devinfo->classes[k];
152 if (xiclassinfo->type == XITouchClass) { 147 if (xiclassinfo->type == XITouchClass) {
153 XITouchClassInfo* tci = 148 XITouchClassInfo* tci =
154 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); 149 reinterpret_cast<XITouchClassInfo*>(xiclassinfo);
155 // Only care direct touch device (such as touch screen) right now 150 // Only care direct touch device (such as touch screen) right now
156 if (tci->mode == XIDirectTouch) 151 if (tci->mode == XIDirectTouch)
157 CacheTouchscreenIds(display, devinfo->deviceid); 152 CacheTouchscreenIds(display, devinfo->deviceid);
158 } 153 }
159 } 154 }
160 } 155 }
161 #endif
162 } 156 }
163 } 157 }
164 158
165 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { 159 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) {
166 DCHECK_EQ(GenericEvent, xev->type); 160 DCHECK_EQ(GenericEvent, xev->type);
167 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); 161 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data);
168 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); 162 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event);
169 163
170 #if defined(USE_XI2_MT)
171 if (event->evtype == XI_TouchBegin || 164 if (event->evtype == XI_TouchBegin ||
172 event->evtype == XI_TouchUpdate || 165 event->evtype == XI_TouchUpdate ||
173 event->evtype == XI_TouchEnd) { 166 event->evtype == XI_TouchEnd) {
174 return !touch_events_disabled_ && IsTouchDevice(xiev->deviceid); 167 return !touch_events_disabled_ && IsTouchDevice(xiev->deviceid);
175 } 168 }
176 #endif 169
177 // Make sure only key-events from the virtual core keyboard are processed. 170 // Make sure only key-events from the virtual core keyboard are processed.
178 if (event->evtype == XI_KeyPress || event->evtype == XI_KeyRelease) { 171 if (event->evtype == XI_KeyPress || event->evtype == XI_KeyRelease) {
179 return (virtual_core_keyboard_device_ < 0) || 172 return (virtual_core_keyboard_device_ < 0) ||
180 (virtual_core_keyboard_device_ == xiev->deviceid); 173 (virtual_core_keyboard_device_ == xiev->deviceid);
181 } 174 }
182 175
183 if (event->evtype != XI_ButtonPress && 176 if (event->evtype != XI_ButtonPress &&
184 event->evtype != XI_ButtonRelease && 177 event->evtype != XI_ButtonRelease &&
185 event->evtype != XI_Motion) 178 event->evtype != XI_Motion)
186 return true; 179 return true;
(...skipping 10 matching lines...) Expand all
197 // either resetup XInput2 for the window, so that we get events from the new 190 // either resetup XInput2 for the window, so that we get events from the new
198 // device, or we need to listen to events from all devices, and then filter 191 // device, or we need to listen to events from all devices, and then filter
199 // the events from uninteresting devices. We do the latter because that's 192 // the events from uninteresting devices. We do the latter because that's
200 // simpler. 193 // simpler.
201 194
202 XDisplay* display = gfx::GetXDisplay(); 195 XDisplay* display = gfx::GetXDisplay();
203 196
204 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; 197 unsigned char mask[XIMaskLen(XI_LASTEVENT)];
205 memset(mask, 0, sizeof(mask)); 198 memset(mask, 0, sizeof(mask));
206 199
207 #if defined(USE_XI2_MT)
208 XISetMask(mask, XI_TouchBegin); 200 XISetMask(mask, XI_TouchBegin);
209 XISetMask(mask, XI_TouchUpdate); 201 XISetMask(mask, XI_TouchUpdate);
210 XISetMask(mask, XI_TouchEnd); 202 XISetMask(mask, XI_TouchEnd);
211 #endif 203
212 XISetMask(mask, XI_ButtonPress); 204 XISetMask(mask, XI_ButtonPress);
213 XISetMask(mask, XI_ButtonRelease); 205 XISetMask(mask, XI_ButtonRelease);
214 XISetMask(mask, XI_Motion); 206 XISetMask(mask, XI_Motion);
215 #if defined(OS_CHROMEOS) 207 #if defined(OS_CHROMEOS)
216 if (base::SysInfo::IsRunningOnChromeOS()) { 208 if (base::SysInfo::IsRunningOnChromeOS()) {
217 XISetMask(mask, XI_KeyPress); 209 XISetMask(mask, XI_KeyPress);
218 XISetMask(mask, XI_KeyRelease); 210 XISetMask(mask, XI_KeyRelease);
219 } 211 }
220 #endif 212 #endif
221 213
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (ptr[0] || ptr[1]) 338 if (ptr[0] || ptr[1])
347 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); 339 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1]));
348 } 340 }
349 XFree(prop_return); 341 XFree(prop_return);
350 } 342 }
351 343
352 XCloseDevice(display, device); 344 XCloseDevice(display, device);
353 } 345 }
354 346
355 } // namespace ui 347 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/devices/x11/device_data_manager_x11.cc ('k') | ui/events/event_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698