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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 void TouchFactory::SetPointerDeviceForTest( | 288 void TouchFactory::SetPointerDeviceForTest( |
289 const std::vector<int>& devices) { | 289 const std::vector<int>& devices) { |
290 pointer_device_lookup_.reset(); | 290 pointer_device_lookup_.reset(); |
291 for (std::vector<int>::const_iterator iter = devices.begin(); | 291 for (std::vector<int>::const_iterator iter = devices.begin(); |
292 iter != devices.end(); ++iter) { | 292 iter != devices.end(); ++iter) { |
293 pointer_device_lookup_[*iter] = true; | 293 pointer_device_lookup_[*iter] = true; |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) { | 297 void TouchFactory::CacheTouchscreenIds(int device_id) { |
298 XDevice* device = XOpenDevice(display, device_id); | 298 if (!DeviceDataManager::HasInstance()) |
299 if (!device) | |
300 return; | 299 return; |
301 | 300 std::vector<TouchscreenDevice> touchscreens = |
302 Atom actual_type_return; | 301 DeviceDataManager::GetInstance()->touchscreen_devices(); |
303 int actual_format_return; | 302 const auto it = |
304 unsigned long nitems_return; | 303 std::find_if(touchscreens.begin(), touchscreens.end(), |
305 unsigned long bytes_after_return; | 304 [device_id](const TouchscreenDevice& touchscreen) { |
306 unsigned char *prop_return; | 305 return touchscreen.id == device_id; |
307 | 306 }); |
308 const char kDeviceProductIdString[] = "Device Product ID"; | 307 // Internal displays will have a vid and pid of 0. Ignore them. |
309 Atom device_product_id_atom = | 308 if (it != touchscreens.end() && it->vendor_id && it->product_id) |
310 XInternAtom(display, kDeviceProductIdString, false); | 309 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); |
311 | |
312 if (device_product_id_atom != None && | |
313 XGetDeviceProperty(display, device, device_product_id_atom, 0, 2, | |
314 False, XA_INTEGER, &actual_type_return, | |
315 &actual_format_return, &nitems_return, | |
316 &bytes_after_return, &prop_return) == Success) { | |
317 if (actual_type_return == XA_INTEGER && | |
318 actual_format_return == 32 && | |
319 nitems_return == 2) { | |
320 // An actual_format_return of 32 implies that the returned data is an | |
321 // array of longs. See the description of |prop_return| in `man | |
322 // XGetDeviceProperty` for details. | |
323 long* ptr = reinterpret_cast<long*>(prop_return); | |
324 | |
325 // Internal displays will have a vid and pid of 0. Ignore them. | |
326 // ptr[0] is the vid, and ptr[1] is the pid. | |
327 if (ptr[0] || ptr[1]) | |
328 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | |
329 } | |
330 XFree(prop_return); | |
331 } | |
332 | |
333 XCloseDevice(display, device); | |
334 } | 310 } |
335 | 311 |
336 } // namespace ui | 312 } // namespace ui |
OLD | NEW |