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

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

Issue 103893005: Include external touchscreen vid/pid in UMA hardware profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address sadrul's comments. Created 7 years 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
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/cursorfont.h> 7 #include <X11/cursorfont.h>
8 #include <X11/extensions/XInput.h> 8 #include <X11/extensions/XInput.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 #include <X11/extensions/XIproto.h> 10 #include <X11/extensions/XIproto.h>
11 #include <X11/Xatom.h>
sadrul 2013/12/12 19:28:59 sort
tdresser 2013/12/12 21:24:22 Done.
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"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
20 #include "ui/events/event_switches.h" 21 #include "ui/events/event_switches.h"
21 #include "ui/events/x/device_data_manager.h" 22 #include "ui/events/x/device_data_manager.h"
22 #include "ui/events/x/device_list_cache_x.h" 23 #include "ui/events/x/device_list_cache_x.h"
23 #include "ui/gfx/x/x11_types.h" 24 #include "ui/gfx/x/x11_types.h"
24 25
25 namespace ui { 26 namespace ui {
26 27
28 const char* TouchFactory::kDeviceProductIdString = "Device Product ID";
29
27 TouchFactory::TouchFactory() 30 TouchFactory::TouchFactory()
28 : pointer_device_lookup_(), 31 : pointer_device_lookup_(),
29 touch_device_available_(false), 32 touch_device_available_(false),
30 touch_events_disabled_(false), 33 touch_events_disabled_(false),
31 touch_device_list_(), 34 touch_device_list_(),
32 max_touch_points_(-1), 35 max_touch_points_(-1),
33 id_generator_(0) { 36 id_generator_(0) {
34 if (!DeviceDataManager::GetInstance()->IsXInput2Available()) 37 if (!DeviceDataManager::GetInstance()->IsXInput2Available())
35 return; 38 return;
36 39
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 77 }
75 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); 78 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids);
76 } 79 }
77 } 80 }
78 81
79 void TouchFactory::UpdateDeviceList(Display* display) { 82 void TouchFactory::UpdateDeviceList(Display* display) {
80 // Detect touch devices. 83 // Detect touch devices.
81 touch_device_available_ = false; 84 touch_device_available_ = false;
82 touch_device_lookup_.reset(); 85 touch_device_lookup_.reset();
83 touch_device_list_.clear(); 86 touch_device_list_.clear();
87 touchscreen_ids_.clear();
84 max_touch_points_ = -1; 88 max_touch_points_ = -1;
85 89
86 #if !defined(USE_XI2_MT) 90 #if !defined(USE_XI2_MT)
87 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does 91 // 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 92 // not provide enough information to detect a touch device. As a result, the
89 // old version of query function (XListInputDevices) is used instead. 93 // old version of query function (XListInputDevices) is used instead.
90 // If XInput2 is not supported, this will return null (with count of -1) so 94 // If XInput2 is not supported, this will return null (with count of -1) so
91 // we assume there cannot be any touch devices. 95 // we assume there cannot be any touch devices.
92 // With XI2.1 or older, we allow only single touch devices. 96 // With XI2.1 or older, we allow only single touch devices.
93 XDeviceList dev_list = 97 XDeviceList dev_list =
(...skipping 26 matching lines...) Expand all
120 pointer_device_lookup_.reset(); 124 pointer_device_lookup_.reset();
121 XIDeviceList xi_dev_list = 125 XIDeviceList xi_dev_list =
122 DeviceListCacheX::GetInstance()->GetXI2DeviceList(display); 126 DeviceListCacheX::GetInstance()->GetXI2DeviceList(display);
123 for (int i = 0; i < xi_dev_list.count; i++) { 127 for (int i = 0; i < xi_dev_list.count; i++) {
124 XIDeviceInfo* devinfo = xi_dev_list.devices + i; 128 XIDeviceInfo* devinfo = xi_dev_list.devices + i;
125 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { 129 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) {
126 #if defined(USE_XI2_MT) 130 #if defined(USE_XI2_MT)
127 for (int k = 0; k < devinfo->num_classes; ++k) { 131 for (int k = 0; k < devinfo->num_classes; ++k) {
128 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; 132 XIAnyClassInfo* xiclassinfo = devinfo->classes[k];
129 if (xiclassinfo->type == XITouchClass) { 133 if (xiclassinfo->type == XITouchClass) {
134 CacheTouchscreenIds(display, devinfo->deviceid);
130 XITouchClassInfo* tci = 135 XITouchClassInfo* tci =
131 reinterpret_cast<XITouchClassInfo *>(xiclassinfo); 136 reinterpret_cast<XITouchClassInfo *>(xiclassinfo);
132 // Only care direct touch device (such as touch screen) right now 137 // Only care direct touch device (such as touch screen) right now
133 if (tci->mode == XIDirectTouch) { 138 if (tci->mode == XIDirectTouch) {
134 touch_device_lookup_[devinfo->deviceid] = true; 139 touch_device_lookup_[devinfo->deviceid] = true;
sadrul 2013/12/12 19:28:59 It should be in here, I think?
tdresser 2013/12/12 21:24:22 Done.
135 touch_device_list_[devinfo->deviceid] = true; 140 touch_device_list_[devinfo->deviceid] = true;
136 touch_device_available_ = true; 141 touch_device_available_ = true;
137 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) 142 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_)
138 max_touch_points_ = tci->num_touches; 143 max_touch_points_ = tci->num_touches;
139 } 144 }
140 } 145 }
141 } 146 }
142 #endif 147 #endif
143 pointer_device_lookup_[devinfo->deviceid] = true; 148 pointer_device_lookup_[devinfo->deviceid] = true;
144 } 149 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 266
262 void TouchFactory::SetPointerDeviceForTest( 267 void TouchFactory::SetPointerDeviceForTest(
263 const std::vector<unsigned int>& devices) { 268 const std::vector<unsigned int>& devices) {
264 pointer_device_lookup_.reset(); 269 pointer_device_lookup_.reset();
265 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); 270 for (std::vector<unsigned int>::const_iterator iter = devices.begin();
266 iter != devices.end(); ++iter) { 271 iter != devices.end(); ++iter) {
267 pointer_device_lookup_[*iter] = true; 272 pointer_device_lookup_[*iter] = true;
268 } 273 }
269 } 274 }
270 275
276 void TouchFactory::CacheTouchscreenIds(Display* display, int id) {
sadrul 2013/12/12 19:28:59 Call this XID device_id
tdresser 2013/12/12 21:24:22 Done.
277 XDevice* device = XOpenDevice(display, id);
278 Atom actual_type_return;
279 int actual_format_return;
280 unsigned long nitems_return;
281 unsigned long bytes_after_return;
282 unsigned char *prop_return;
283
sadrul 2013/12/12 19:28:59 define kDeviceProductIdString in here. (For X11 a
tdresser 2013/12/12 21:24:22 Done.
284 Atom device_product_id_atom =
285 XInternAtom(display, kDeviceProductIdString, false);
286
287 if (XGetDeviceProperty(display, device, device_product_id_atom, 0, 2,
288 False, XA_INTEGER, &actual_type_return,
289 &actual_format_return, &nitems_return,
290 &bytes_after_return, &prop_return) == Success) {
291 // XA_INTEGER, which results in an actual_format_return of 32, implies that
292 // the returned data is an array of longs. See the description of
293 // |prop_return| in `man XGetDeviceProperty` for details.
294 long* ptr = reinterpret_cast<long*>(prop_return);
295
296 // Internal displays will have a vid and pid of 0. Ignore them.
297 // ptr[0] is the pid, and ptr[1] is the vid.
298 if (ptr[0] || ptr[1])
299 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1]));
300 XFree(prop_return);
301 }
302
303 XCloseDevice(display, device);
304 }
305
271 } // namespace ui 306 } // namespace ui
OLDNEW
« ui/events/x/touch_factory_x11.h ('K') | « 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