OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 5 #ifndef VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
6 #define VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 6 #define VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <bitset> | 9 #include <bitset> |
10 #include <vector> | 10 #include <vector> |
(...skipping 24 matching lines...) Expand all Loading... |
35 // touch event, we need to determine which point triggered the event. | 35 // touch event, we need to determine which point triggered the event. |
36 // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can | 36 // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can |
37 // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and | 37 // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and |
38 // (X - 1), where X is the maximum touch points supported by the device. The | 38 // (X - 1), where X is the maximum touch points supported by the device. The |
39 // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion | 39 // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion |
40 // event that comes from a currently-unused 'Slot ID' indicates the creation | 40 // event that comes from a currently-unused 'Slot ID' indicates the creation |
41 // of a new touch point, and any event that comes with a 0 value for | 41 // of a new touch point, and any event that comes with a 0 value for |
42 // 'Tracking ID' marks the removal of a touch point. During the lifetime of | 42 // 'Tracking ID' marks the removal of a touch point. During the lifetime of |
43 // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress | 43 // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress |
44 // and XI_ButtonRelease events are ignored. | 44 // and XI_ButtonRelease events are ignored. |
| 45 #if !defined(USE_XI2_MT) |
45 TP_SLOT_ID, // ID of the finger that triggered a touch event | 46 TP_SLOT_ID, // ID of the finger that triggered a touch event |
46 // (useful when tracking multiple simultaneous | 47 // (useful when tracking multiple simultaneous |
47 // touches) | 48 // touches) |
| 49 #endif |
| 50 // NOTE for XInput MT: 'Tracking ID' is provided in every touch event to |
| 51 // track individual touch. 'Tracking ID' is an unsigned 32-bit value and |
| 52 // is increased for each new touch. It will wrap back to 0 when reaching |
| 53 // the numerical limit. |
48 TP_TRACKING_ID, // ID of the touch point. | 54 TP_TRACKING_ID, // ID of the touch point. |
49 | 55 |
50 TP_LAST_ENTRY | 56 TP_LAST_ENTRY |
51 }; | 57 }; |
52 | 58 |
53 // Returns the TouchFactory singleton. | 59 // Returns the TouchFactory singleton. |
54 static TouchFactory* GetInstance(); | 60 static TouchFactory* GetInstance(); |
55 | 61 |
56 // Updates the list of devices. | 62 // Updates the list of devices. |
57 void UpdateDeviceList(Display* display); | 63 void UpdateDeviceList(Display* display); |
58 | 64 |
59 // Checks whether an XI2 event should be processed or not (i.e. if the event | 65 // Checks whether an XI2 event should be processed or not (i.e. if the event |
60 // originated from a device we are interested in). | 66 // originated from a device we are interested in). |
61 bool ShouldProcessXI2Event(XEvent* xevent); | 67 bool ShouldProcessXI2Event(XEvent* xevent); |
62 | 68 |
63 // Setup an X Window for XInput2 events. | 69 // Setup an X Window for XInput2 events. |
64 void SetupXI2ForXWindow(::Window xid); | 70 void SetupXI2ForXWindow(::Window xid); |
65 | 71 |
66 // Keeps a list of touch devices so that it is possible to determine if a | 72 // Keeps a list of touch devices so that it is possible to determine if a |
67 // pointer event is a touch-event or a mouse-event. The list is reset each | 73 // pointer event is a touch-event or a mouse-event. The list is reset each |
68 // time this is called. | 74 // time this is called. |
69 void SetTouchDeviceList(const std::vector<unsigned int>& devices); | 75 void SetTouchDeviceList(const std::vector<unsigned int>& devices); |
70 | 76 |
71 // Is the device a touch-device? | 77 // Is the device a touch-device? |
72 bool IsTouchDevice(unsigned int deviceid) const; | 78 bool IsTouchDevice(unsigned int deviceid) const; |
73 | 79 |
| 80 #if !defined(USE_XI2_MT) |
74 // Is the slot ID currently used? | 81 // Is the slot ID currently used? |
75 bool IsSlotUsed(int slot) const; | 82 bool IsSlotUsed(int slot) const; |
76 | 83 |
77 // Marks a slot as being used/unused. | 84 // Marks a slot as being used/unused. |
78 void SetSlotUsed(int slot, bool used); | 85 void SetSlotUsed(int slot, bool used); |
| 86 #endif |
79 | 87 |
80 // Grabs the touch devices for the specified window on the specified display. | 88 // Grabs the touch devices for the specified window on the specified display. |
81 // Returns if grab was successful for all touch devices. | 89 // Returns if grab was successful for all touch devices. |
82 bool GrabTouchDevices(Display* display, ::Window window); | 90 bool GrabTouchDevices(Display* display, ::Window window); |
83 | 91 |
84 // Ungrabs the touch devices. Returns if ungrab was successful for all touch | 92 // Ungrabs the touch devices. Returns if ungrab was successful for all touch |
85 // devices. | 93 // devices. |
86 bool UngrabTouchDevices(Display* display); | 94 bool UngrabTouchDevices(Display* display); |
87 | 95 |
88 // Updates the root window to show (or hide) the cursor. Also indicate whether | 96 // Updates the root window to show (or hide) the cursor. Also indicate whether |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // index at the expense of space. If the kMaxDeviceNum grows larger that the | 183 // index at the expense of space. If the kMaxDeviceNum grows larger that the |
176 // space waste becomes a concern, the 2D lookup table can be replaced by a | 184 // space waste becomes a concern, the 2D lookup table can be replaced by a |
177 // hash map. | 185 // hash map. |
178 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; | 186 signed char valuator_lookup_[kMaxDeviceNum][TP_LAST_ENTRY]; |
179 | 187 |
180 // Index table to find the min & max value of the TouchParam on a specific | 188 // Index table to find the min & max value of the TouchParam on a specific |
181 // device. | 189 // device. |
182 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; | 190 int touch_param_min_[kMaxDeviceNum][TP_LAST_ENTRY]; |
183 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; | 191 int touch_param_max_[kMaxDeviceNum][TP_LAST_ENTRY]; |
184 | 192 |
| 193 #if !defined(USE_XI2_MT) |
185 // Maximum simultaneous touch points. | 194 // Maximum simultaneous touch points. |
186 static const int kMaxTouchPoints = 32; | 195 static const int kMaxTouchPoints = 32; |
187 | 196 |
188 // A lookup table for slots in use for a touch event. | 197 // A lookup table for slots in use for a touch event. |
189 std::bitset<kMaxTouchPoints> slots_used_; | 198 std::bitset<kMaxTouchPoints> slots_used_; |
| 199 #endif |
190 | 200 |
191 DISALLOW_COPY_AND_ASSIGN(TouchFactory); | 201 DISALLOW_COPY_AND_ASSIGN(TouchFactory); |
192 }; | 202 }; |
193 | 203 |
194 } // namespace views | 204 } // namespace views |
195 | 205 |
196 #endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_ | 206 #endif // VIEWS_TOUCHUI_TOUCH_FACTORY_H_ |
OLD | NEW |