Chromium Code Reviews| 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/x/touch_factory_x11.h" | 5 #include "ui/events/x/touch_factory_x11.h" |
| 6 | 6 |
| 7 #include <X11/Xatom.h> | |
| 7 #include <X11/cursorfont.h> | 8 #include <X11/cursorfont.h> |
| 8 #include <X11/extensions/XInput.h> | 9 #include <X11/extensions/XInput.h> |
| 9 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/extensions/XIproto.h> | 11 #include <X11/extensions/XIproto.h> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 75 } |
| 75 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); | 76 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 void TouchFactory::UpdateDeviceList(Display* display) { | 80 void TouchFactory::UpdateDeviceList(Display* display) { |
| 80 // Detect touch devices. | 81 // Detect touch devices. |
| 81 touch_device_available_ = false; | 82 touch_device_available_ = false; |
| 82 touch_device_lookup_.reset(); | 83 touch_device_lookup_.reset(); |
| 83 touch_device_list_.clear(); | 84 touch_device_list_.clear(); |
| 85 touchscreen_ids_.clear(); | |
| 84 max_touch_points_ = -1; | 86 max_touch_points_ = -1; |
| 85 | 87 |
| 86 #if !defined(USE_XI2_MT) | 88 #if !defined(USE_XI2_MT) |
| 87 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 89 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |
| 88 // not provide enough information to detect a touch device. As a result, the | 90 // not provide enough information to detect a touch device. As a result, the |
| 89 // old version of query function (XListInputDevices) is used instead. | 91 // old version of query function (XListInputDevices) is used instead. |
| 90 // If XInput2 is not supported, this will return null (with count of -1) so | 92 // If XInput2 is not supported, this will return null (with count of -1) so |
| 91 // we assume there cannot be any touch devices. | 93 // we assume there cannot be any touch devices. |
| 92 // With XI2.1 or older, we allow only single touch devices. | 94 // With XI2.1 or older, we allow only single touch devices. |
| 93 XDeviceList dev_list = | 95 XDeviceList dev_list = |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 124 XIDeviceInfo* devinfo = xi_dev_list.devices + i; | 126 XIDeviceInfo* devinfo = xi_dev_list.devices + i; |
| 125 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { | 127 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { |
| 126 #if defined(USE_XI2_MT) | 128 #if defined(USE_XI2_MT) |
| 127 for (int k = 0; k < devinfo->num_classes; ++k) { | 129 for (int k = 0; k < devinfo->num_classes; ++k) { |
| 128 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; | 130 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |
| 129 if (xiclassinfo->type == XITouchClass) { | 131 if (xiclassinfo->type == XITouchClass) { |
| 130 XITouchClassInfo* tci = | 132 XITouchClassInfo* tci = |
| 131 reinterpret_cast<XITouchClassInfo *>(xiclassinfo); | 133 reinterpret_cast<XITouchClassInfo *>(xiclassinfo); |
| 132 // Only care direct touch device (such as touch screen) right now | 134 // Only care direct touch device (such as touch screen) right now |
| 133 if (tci->mode == XIDirectTouch) { | 135 if (tci->mode == XIDirectTouch) { |
| 136 CacheTouchscreenIds(display, devinfo->deviceid); | |
| 134 touch_device_lookup_[devinfo->deviceid] = true; | 137 touch_device_lookup_[devinfo->deviceid] = true; |
| 135 touch_device_list_[devinfo->deviceid] = true; | 138 touch_device_list_[devinfo->deviceid] = true; |
| 136 touch_device_available_ = true; | 139 touch_device_available_ = true; |
| 137 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) | 140 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) |
| 138 max_touch_points_ = tci->num_touches; | 141 max_touch_points_ = tci->num_touches; |
| 139 } | 142 } |
| 140 } | 143 } |
| 141 } | 144 } |
| 142 #endif | 145 #endif |
| 143 pointer_device_lookup_[devinfo->deviceid] = true; | 146 pointer_device_lookup_[devinfo->deviceid] = true; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 | 264 |
| 262 void TouchFactory::SetPointerDeviceForTest( | 265 void TouchFactory::SetPointerDeviceForTest( |
| 263 const std::vector<unsigned int>& devices) { | 266 const std::vector<unsigned int>& devices) { |
| 264 pointer_device_lookup_.reset(); | 267 pointer_device_lookup_.reset(); |
| 265 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 268 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
| 266 iter != devices.end(); ++iter) { | 269 iter != devices.end(); ++iter) { |
| 267 pointer_device_lookup_[*iter] = true; | 270 pointer_device_lookup_[*iter] = true; |
| 268 } | 271 } |
| 269 } | 272 } |
| 270 | 273 |
| 274 void TouchFactory::CacheTouchscreenIds(Display* display, int device_id) { | |
| 275 XDevice* device = XOpenDevice(display, device_id); | |
| 276 Atom actual_type_return; | |
| 277 int actual_format_return; | |
| 278 unsigned long nitems_return; | |
| 279 unsigned long bytes_after_return; | |
| 280 unsigned char *prop_return; | |
| 281 | |
| 282 static const char* kDeviceProductIdString = "Device Product ID"; | |
|
sadrul
2014/01/09 13:04:25
(non-static) const char ...[]
tdresser
2014/01/10 16:59:03
Done.
| |
| 283 Atom device_product_id_atom = | |
| 284 XInternAtom(display, kDeviceProductIdString, false); | |
| 285 | |
| 286 if (XGetDeviceProperty(display, device, device_product_id_atom, 0, 2, | |
|
sadrul
2014/01/09 13:04:25
Do you want to check device_product_id_atom != Non
tdresser
2014/01/10 16:59:03
Done.
| |
| 287 False, XA_INTEGER, &actual_type_return, | |
| 288 &actual_format_return, &nitems_return, | |
| 289 &bytes_after_return, &prop_return) == Success) { | |
| 290 // XA_INTEGER, which results in an actual_format_return of 32, implies that | |
| 291 // the returned data is an array of longs. See the description of | |
| 292 // |prop_return| in `man XGetDeviceProperty` for details. | |
| 293 long* ptr = reinterpret_cast<long*>(prop_return); | |
|
sadrul
2014/01/09 13:04:25
Do you need to verify the expected values of actua
tdresser
2014/01/10 16:59:03
Done.
| |
| 294 | |
| 295 // Internal displays will have a vid and pid of 0. Ignore them. | |
| 296 // ptr[0] is the pid, and ptr[1] is the vid. | |
| 297 if (ptr[0] || ptr[1]) | |
| 298 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | |
| 299 XFree(prop_return); | |
| 300 } | |
| 301 | |
| 302 XCloseDevice(display, device); | |
| 303 } | |
| 304 | |
| 271 } // namespace ui | 305 } // namespace ui |
| OLD | NEW |