2 * xserver-xorg-input-evdev-multitouch
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Sung-Jin Park <sj76.park@samsung.com>
7 * Sangjin LEE <lsj119@samsung.com>
9 * Permission to use, copy, modify, distribute, and sell this software
10 * and its documentation for any purpose is hereby granted without
11 * fee, provided that the above copyright notice appear in all copies
12 * and that both that copyright notice and this permission notice
13 * appear in supporting documentation, and that the name of Red Hat
14 * not be used in advertising or publicity pertaining to distribution
15 * of the software without specific, written prior permission. Red
16 * Hat makes no representations about the suitability of this software
17 * for any purpose. It is provided "as is" without express or implied
20 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
22 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
23 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
24 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
25 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 * Copyright © 2004-2008 Red Hat, Inc.
29 * Copyright © 2008 University of South Australia
31 * Permission to use, copy, modify, distribute, and sell this software
32 * and its documentation for any purpose is hereby granted without
33 * fee, provided that the above copyright notice appear in all copies
34 * and that both that copyright notice and this permission notice
35 * appear in supporting documentation, and that the name of Red Hat
36 * not be used in advertising or publicity pertaining to distribution
37 * of the software without specific, written prior permission. Red
38 * Hat makes no representations about the suitability of this software
39 * for any purpose. It is provided "as is" without express or implied
42 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
43 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
44 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
45 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
46 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
47 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
48 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
51 * Kristian Høgsberg (krh@redhat.com)
52 * Adam Jackson (ajax@redhat.com)
53 * Peter Hutterer (peter@cs.unisa.edu.au)
54 * Oliver McFadden (oliver.mcfadden@nokia.com)
55 * Benjamin Tissoires (tissoire@cena.fr)
58 #ifndef EVDEVMULTITOUCH_H
59 #define EVDEVMULTITOUCH_H
61 #include <linux/input.h>
62 #include <linux/types.h>
64 #include <xf86Xinput.h>
65 #include <xf86_OSproc.h>
71 #ifdef _F_GESTURE_EXTENSION_
72 typedef enum _MTSyncType
74 MTOUCH_FRAME_SYNC_END,
75 MTOUCH_FRAME_SYNC_BEGIN
81 ET_Internal = 0xFF /* First byte */
84 typedef struct _AnyEvent AnyEvent;
87 unsigned char header; /**< Always ET_Internal */
88 enum EventType type; /**< One of EventType */
89 int length; /**< Length in bytes */
90 Time time; /**< Time in ms */
97 union _InternalEvent {
99 unsigned char header; /**< Always ET_Internal */
100 enum EventType type; /**< One of ET_* */
101 int length; /**< Length in bytes */
102 Time time; /**< Time in ms. */
106 #endif//_F_GESTURE_EXTENSION_
108 #ifndef EV_CNT /* linux 2.4 kernels and earlier lack _CNT defines */
109 #define EV_CNT (EV_MAX+1)
112 #define KEY_CNT (KEY_MAX+1)
115 #define REL_CNT (REL_MAX+1)
118 #define ABS_CNT (ABS_MAX+1)
121 #define LED_CNT (LED_MAX+1)
124 #define EVDEVMULTITOUCH_MAXBUTTONS 32
125 #define EVDEVMULTITOUCH_MAXQUEUE 32
127 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
128 #define HAVE_PROPERTIES 1
131 #ifndef MAX_VALUATORS
132 #define MAX_VALUATORS 36
135 #define MAX_VALUATORS_MT 5 //currently if MAXDEVICES == 40
137 #define DEFAULT_TIMEOUT 100
139 #define EVDEVMULTITOUCH_PROP_TRACKING_ID "EvdevMultitouch Tracking ID"
140 #define EVDEVMULTITOUCH_PROP_MULTITOUCH_SUBDEVICES "EvdevMultitouch MultiTouch"
141 #define EVDEVMULTITOUCH_PROP_USE_POLL "EvdevMultitouch Use Poll"
142 #define EVDEVMULTITOUCH_PROP_TRANSFORM "EvdevMultitouch Transform Matrix"
143 #define EVDEVMULTITOUCH_PROP_GRABINFO "EvdevMultitouch Grab Info"
145 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
156 #define LONG_BITS (sizeof(long) * 8)
158 /* Number of longs needed to hold the given number of bits */
159 #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
161 /* axis specific data for wheel emulation */
165 int traveled_distance;
166 } WheelAxis, *WheelAxisPtr;
168 /* Event queue used to defer keyboard/button events until EV_SYN time. */
171 EV_QUEUE_KEY, /* xf86PostKeyboardEvent() */
172 EV_QUEUE_BTN, /* xf86PostButtonEvent() */
174 int key; /* May be either a key code or button number. */
175 int val; /* State of the key/button; pressed or released. */
176 } EventQueueRec, *EventQueuePtr;
178 typedef struct _EvdevMultitouchDataMTRec{
184 int vals[MAX_VALUATORS];
186 } EvdevMultitouchDataMTRec, *EvdevMultitouchDataMTPtr;
190 * EvdevMultitouch device information, including list of current object
194 int grabDevice; /* grab the event device? */
196 int num_vals; /* number of valuators */
197 int axis_map[max(ABS_CNT, REL_CNT)]; /* Map evdevmultitouch <axis> to index */
198 int vals[MAX_VALUATORS];
199 int old_vals[MAX_VALUATORS]; /* Translate absolute inputs to relative */
200 EvdevMultitouchDataMTRec vals_mt[MAX_VALUATORS_MT];
204 int num_buttons; /* number of buttons */
209 OsTimerPtr multitouch_setting_timer;
212 unsigned int abs, rel, mt;
214 /* XKB stuff has to be per-device rather than per-driver */
215 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
216 XkbComponentNamesRec xkbnames;
220 /* Middle mouse button emulation */
223 BOOL pending; /* timer waiting? */
224 int buttonstate; /* phys. button state */
225 int state; /* state machine (see bt3emu.c) */
226 Time expires; /* time of expiry */
230 int meta; /* meta key to lock any button */
231 BOOL meta_state; /* meta_button state */
232 unsigned int lock_pair[EVDEVMULTITOUCH_MAXBUTTONS]; /* specify a meta/lock pair */
233 BOOL lock_state[EVDEVMULTITOUCH_MAXBUTTONS]; /* state of any locked buttons */
242 Time expires; /* time of expiry */
245 /* run-time calibration */
260 unsigned char btnmap[32]; /* config-file specified button mapping */
262 int reopen_attempts; /* max attempts to re-open after read failure */
263 int reopen_left; /* number of attempts left to re-open the device */
264 OsTimerPtr reopen_timer;
266 /* Cached info from device. */
268 unsigned long bitmask[NLONGS(EV_CNT)];
269 unsigned long key_bitmask[NLONGS(KEY_CNT)];
270 unsigned long rel_bitmask[NLONGS(REL_CNT)];
271 unsigned long abs_bitmask[NLONGS(ABS_CNT)];
272 unsigned long led_bitmask[NLONGS(LED_CNT)];
273 struct input_absinfo absinfo[ABS_CNT];
275 /* minor/major number */
278 /* Event queue used to defer keyboard/button events until EV_SYN time. */
280 EventQueueRec queue[EVDEVMULTITOUCH_MAXQUEUE];
282 Time timeout; /* Maximum difference between consecutive fseq values
283 that will allow a packet to be dropped */
285 OsTimerPtr subdevice_timer;
291 BOOL mt_slot_supported;
295 BOOL use_poll;//polling_with_vsync
299 InputInfoPtr core_device;
301 } EvdevMultitouchRec, *EvdevMultitouchPtr;
303 /* Event posting functions */
304 void EvdevMultitouchQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
305 void EvdevMultitouchQueueButtonEvent(InputInfoPtr pInfo, int button, int value);
306 void EvdevMultitouchPostButtonEvent(InputInfoPtr pInfo, int button, int value);
307 void EvdevMultitouchQueueButtonClicks(InputInfoPtr pInfo, int button, int count);
308 void EvdevMultitouchPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
309 int v[MAX_VALUATORS]);
310 void EvdevMultitouchPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
311 int v[MAX_VALUATORS]);
312 unsigned int EvdevMultitouchUtilButtonEventToButtonNumber(EvdevMultitouchPtr pEvdevMultitouch, int code);
314 /* Middle Button emulation */
315 int EvdevMultitouchMBEmuTimer(InputInfoPtr);
316 BOOL EvdevMultitouchMBEmuFilterEvent(InputInfoPtr, int, BOOL);
317 void EvdevMultitouchMBEmuWakeupHandler(pointer, int, pointer);
318 void EvdevMultitouchMBEmuBlockHandler(pointer, struct timeval**, pointer);
319 void EvdevMultitouchMBEmuPreInit(InputInfoPtr);
320 void EvdevMultitouchMBEmuOn(InputInfoPtr);
321 void EvdevMultitouchMBEmuFinalize(InputInfoPtr);
322 void EvdevMultitouchMBEmuEnable(InputInfoPtr, BOOL);
324 /* Mouse Wheel emulation */
325 void EvdevMultitouchWheelEmuPreInit(InputInfoPtr pInfo);
326 BOOL EvdevMultitouchWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value);
327 BOOL EvdevMultitouchWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv);
330 void EvdevMultitouchDragLockPreInit(InputInfoPtr pInfo);
331 BOOL EvdevMultitouchDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value);
333 #ifdef HAVE_PROPERTIES
334 void EvdevMultitouchMBEmuInitProperty(DeviceIntPtr);
335 void EvdevMultitouchWheelEmuInitProperty(DeviceIntPtr);
336 void EvdevMultitouchDragLockInitProperty(DeviceIntPtr);