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

Side by Side Diff: ui/events/x/touch_factory_x11.cc

Issue 134773004: Include external touchscreen vid/pid in UMA hardware profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't assume a screen exists - it doesn't in some tests. Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « ui/events/x/touch_factory_x11.h ('k') | no next file » | 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/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
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
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
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 if (!device)
277 return;
278
279 Atom actual_type_return;
280 int actual_format_return;
281 unsigned long nitems_return;
282 unsigned long bytes_after_return;
283 unsigned char *prop_return;
284
285 const char kDeviceProductIdString[] = "Device Product ID";
286 Atom device_product_id_atom =
287 XInternAtom(display, kDeviceProductIdString, false);
288
289 if (device_product_id_atom != None &&
290 XGetDeviceProperty(display, device, device_product_id_atom, 0, 2,
291 False, XA_INTEGER, &actual_type_return,
292 &actual_format_return, &nitems_return,
293 &bytes_after_return, &prop_return) == Success) {
294 if (actual_type_return == XA_INTEGER &&
295 actual_format_return == 32 &&
296 nitems_return == 2) {
297 // An actual_format_return of 32 implies that the returned data is an
298 // array of longs. See the description of |prop_return| in `man
299 // XGetDeviceProperty` for details.
300 long* ptr = reinterpret_cast<long*>(prop_return);
301
302 // Internal displays will have a vid and pid of 0. Ignore them.
303 // ptr[0] is the vid, and ptr[1] is the pid.
304 if (ptr[0] || ptr[1])
305 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1]));
306 }
307 XFree(prop_return);
308 }
309
310 XCloseDevice(display, device);
311 }
312
271 } // namespace ui 313 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/x/touch_factory_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698