OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "views/touchui/touch_factory.h" | |
6 | |
7 #if defined(HAVE_XINPUT2) | |
8 #include <gdk/gdkx.h> | |
9 #include <X11/extensions/XInput2.h> | |
10 | |
11 #include "base/logging.h" | |
12 | |
13 namespace views { | |
14 | |
15 // static | |
16 TouchFactory* TouchFactory::GetInstance() { | |
17 return Singleton<TouchFactory>::get(); | |
18 } | |
19 | |
20 TouchFactory::TouchFactory() | |
21 : touch_device_lookup_(), | |
22 touch_device_list_() { | |
23 } | |
24 | |
25 void TouchFactory::SetTouchDeviceList( | |
26 const std::vector<unsigned int>& devices) { | |
27 touch_device_lookup_.reset(); | |
28 touch_device_list_.clear(); | |
29 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | |
30 iter != devices.end(); ++iter) { | |
31 DCHECK(*iter < touch_device_lookup_.size()); | |
32 touch_device_lookup_[*iter] = true; | |
33 touch_device_list_.push_back(*iter); | |
34 } | |
35 } | |
36 | |
37 bool TouchFactory::IsTouchDevice(unsigned deviceid) { | |
38 return deviceid < touch_device_lookup_.size() ? | |
39 touch_device_lookup_[deviceid] : false; | |
40 } | |
41 | |
42 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { | |
43 if (touch_device_list_.empty()) | |
44 return true; | |
45 | |
46 unsigned char mask[(XI_LASTEVENT + 7) / 8]; | |
47 bool success = true; | |
48 | |
49 memset(mask, 0, sizeof(mask)); | |
50 XISetMask(mask, XI_ButtonPress); | |
51 XISetMask(mask, XI_ButtonRelease); | |
52 XISetMask(mask, XI_Motion); | |
53 | |
54 XIEventMask evmask; | |
55 evmask.mask_len = sizeof(mask); | |
56 evmask.mask = mask; | |
57 for (std::vector<int>::const_iterator iter = | |
58 touch_device_list_.begin(); | |
59 iter != touch_device_list_.end(); ++iter) { | |
60 evmask.deviceid = *iter; | |
61 Status status = XIGrabDevice(display, *iter, window, CurrentTime, None, | |
62 GrabModeAsync, GrabModeAsync, False, &evmask); | |
63 success = success && status == GrabSuccess; | |
64 } | |
65 | |
66 return success; | |
67 } | |
68 | |
69 bool TouchFactory::UngrabTouchDevices(Display* display) { | |
70 bool success = true; | |
71 for (std::vector<int>::const_iterator iter = | |
72 touch_device_list_.begin(); | |
73 iter != touch_device_list_.end(); ++iter) { | |
74 Status status = XIUngrabDevice(display, *iter, CurrentTime); | |
75 success = success && status == GrabSuccess; | |
76 } | |
77 return success; | |
78 } | |
79 | |
80 } // namespace views | |
81 | |
82 #endif // defined(HAVE_XINPUT2) | |
sadrul
2011/01/20 02:51:22
I needed this '#if defined' to fix build failures
| |
OLD | NEW |