OLD | NEW |
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 | 123 |
124 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { | 124 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { |
125 for (int k = 0; k < devinfo.num_classes; ++k) { | 125 for (int k = 0; k < devinfo.num_classes; ++k) { |
126 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; | 126 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; |
127 if (xiclassinfo->type == XITouchClass) { | 127 if (xiclassinfo->type == XITouchClass) { |
128 XITouchClassInfo* tci = | 128 XITouchClassInfo* tci = |
129 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 129 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
130 // Only care direct touch device (such as touch screen) right now | 130 // Only care direct touch device (such as touch screen) right now |
131 if (tci->mode == XIDirectTouch) | 131 if (tci->mode == XIDirectTouch) |
132 CacheTouchscreenIds(display, devinfo.deviceid); | 132 CacheTouchscreenIds(devinfo.deviceid); |
133 } | 133 } |
134 } | 134 } |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { | 139 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { |
140 DCHECK_EQ(GenericEvent, xev->type); | 140 DCHECK_EQ(GenericEvent, xev->type); |
141 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); | 141 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); |
142 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); | 142 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 void TouchFactory::SetPointerDeviceForTest( | 286 void TouchFactory::SetPointerDeviceForTest( |
287 const std::vector<int>& devices) { | 287 const std::vector<int>& devices) { |
288 pointer_device_lookup_.reset(); | 288 pointer_device_lookup_.reset(); |
289 for (std::vector<int>::const_iterator iter = devices.begin(); | 289 for (std::vector<int>::const_iterator iter = devices.begin(); |
290 iter != devices.end(); ++iter) { | 290 iter != devices.end(); ++iter) { |
291 pointer_device_lookup_[*iter] = true; | 291 pointer_device_lookup_[*iter] = true; |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) { | 295 void TouchFactory::CacheTouchscreenIds(int device_id) { |
296 XDevice* device = XOpenDevice(display, device_id); | 296 if (!DeviceDataManager::HasInstance()) |
297 if (!device) | |
298 return; | 297 return; |
299 | 298 std::vector<TouchscreenDevice> touchscreens = |
300 Atom actual_type_return; | 299 DeviceDataManager::GetInstance()->touchscreen_devices(); |
301 int actual_format_return; | 300 const auto it = |
302 unsigned long nitems_return; | 301 std::find_if(touchscreens.begin(), touchscreens.end(), |
303 unsigned long bytes_after_return; | 302 [device_id](const TouchscreenDevice& touchscreen) { |
304 unsigned char *prop_return; | 303 return touchscreen.id == device_id; |
305 | 304 }); |
306 const char kDeviceProductIdString[] = "Device Product ID"; | 305 // Internal displays will have a vid and pid of 0. Ignore them. |
307 Atom device_product_id_atom = | 306 if (it != touchscreens.end() && it->vendor_id && it->product_id) |
308 XInternAtom(display, kDeviceProductIdString, false); | 307 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); |
309 | |
310 if (device_product_id_atom != None && | |
311 XGetDeviceProperty(display, device, device_product_id_atom, 0, 2, | |
312 False, XA_INTEGER, &actual_type_return, | |
313 &actual_format_return, &nitems_return, | |
314 &bytes_after_return, &prop_return) == Success) { | |
315 if (actual_type_return == XA_INTEGER && | |
316 actual_format_return == 32 && | |
317 nitems_return == 2) { | |
318 // An actual_format_return of 32 implies that the returned data is an | |
319 // array of longs. See the description of |prop_return| in `man | |
320 // XGetDeviceProperty` for details. | |
321 long* ptr = reinterpret_cast<long*>(prop_return); | |
322 | |
323 // Internal displays will have a vid and pid of 0. Ignore them. | |
324 // ptr[0] is the vid, and ptr[1] is the pid. | |
325 if (ptr[0] || ptr[1]) | |
326 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | |
327 } | |
328 XFree(prop_return); | |
329 } | |
330 | |
331 XCloseDevice(display, device); | |
332 } | 308 } |
333 | 309 |
334 } // namespace ui | 310 } // namespace ui |
OLD | NEW |