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 10
136 #define DEFAULT_TIMEOUT 100
138 #define EVDEVMULTITOUCH_PROP_TRACKING_ID "EvdevMultitouch Tracking ID"
139 #define EVDEVMULTITOUCH_PROP_MULTITOUCH_SUBDEVICES "EvdevMultitouch MultiTouch"
140 #define EVDEVMULTITOUCH_PROP_TRANSFORM "EvdevMultitouch Transform Matrix"
141 #define EVDEVMULTITOUCH_PROP_GRABINFO "EvdevMultitouch Grab Info"
143 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
154 #define LONG_BITS (sizeof(long) * 8)
156 /* Number of longs needed to hold the given number of bits */
157 #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
159 /* axis specific data for wheel emulation */
163 int traveled_distance;
164 } WheelAxis, *WheelAxisPtr;
166 /* Event queue used to defer keyboard/button events until EV_SYN time. */
169 EV_QUEUE_KEY, /* xf86PostKeyboardEvent() */
170 EV_QUEUE_BTN, /* xf86PostButtonEvent() */
172 int key; /* May be either a key code or button number. */
173 int val; /* State of the key/button; pressed or released. */
174 } EventQueueRec, *EventQueuePtr;
176 typedef struct _EvdevMultitouchDataMTRec{
182 int vals[MAX_VALUATORS];
184 } EvdevMultitouchDataMTRec, *EvdevMultitouchDataMTPtr;
188 * EvdevMultitouch device information, including list of current object
192 int grabDevice; /* grab the event device? */
194 int num_vals; /* number of valuators */
195 int axis_map[max(ABS_CNT, REL_CNT)]; /* Map evdevmultitouch <axis> to index */
196 int vals[MAX_VALUATORS];
197 int old_vals[MAX_VALUATORS]; /* Translate absolute inputs to relative */
198 EvdevMultitouchDataMTRec vals_mt[MAX_VALUATORS_MT];
202 int num_buttons; /* number of buttons */
207 OsTimerPtr multitouch_setting_timer;
210 unsigned int abs, rel, mt;
212 /* XKB stuff has to be per-device rather than per-driver */
213 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
214 XkbComponentNamesRec xkbnames;
218 /* Middle mouse button emulation */
221 BOOL pending; /* timer waiting? */
222 int buttonstate; /* phys. button state */
223 int state; /* state machine (see bt3emu.c) */
224 Time expires; /* time of expiry */
228 int meta; /* meta key to lock any button */
229 BOOL meta_state; /* meta_button state */
230 unsigned int lock_pair[EVDEVMULTITOUCH_MAXBUTTONS]; /* specify a meta/lock pair */
231 BOOL lock_state[EVDEVMULTITOUCH_MAXBUTTONS]; /* state of any locked buttons */
240 Time expires; /* time of expiry */
243 /* run-time calibration */
258 unsigned char btnmap[32]; /* config-file specified button mapping */
260 int reopen_attempts; /* max attempts to re-open after read failure */
261 int reopen_left; /* number of attempts left to re-open the device */
262 OsTimerPtr reopen_timer;
264 /* Cached info from device. */
266 unsigned long bitmask[NLONGS(EV_CNT)];
267 unsigned long key_bitmask[NLONGS(KEY_CNT)];
268 unsigned long rel_bitmask[NLONGS(REL_CNT)];
269 unsigned long abs_bitmask[NLONGS(ABS_CNT)];
270 unsigned long led_bitmask[NLONGS(LED_CNT)];
271 struct input_absinfo absinfo[ABS_CNT];
273 /* minor/major number */
276 /* Event queue used to defer keyboard/button events until EV_SYN time. */
278 EventQueueRec queue[EVDEVMULTITOUCH_MAXQUEUE];
280 Time timeout; /* Maximum difference between consecutive fseq values
281 that will allow a packet to be dropped */
283 OsTimerPtr subdevice_timer;
288 BOOL mt_slot_supported;
294 struct pixman_transform inv_transform;
298 InputInfoPtr core_device;
300 } EvdevMultitouchRec, *EvdevMultitouchPtr;
302 /* Event posting functions */
303 void EvdevMultitouchQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
304 void EvdevMultitouchQueueButtonEvent(InputInfoPtr pInfo, int button, int value);
305 void EvdevMultitouchPostButtonEvent(InputInfoPtr pInfo, int button, int value);
306 void EvdevMultitouchQueueButtonClicks(InputInfoPtr pInfo, int button, int count);
307 void EvdevMultitouchPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
308 int v[MAX_VALUATORS]);
309 void EvdevMultitouchPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
310 int v[MAX_VALUATORS]);
311 unsigned int EvdevMultitouchUtilButtonEventToButtonNumber(EvdevMultitouchPtr pEvdevMultitouch, int code);
313 /* Middle Button emulation */
314 int EvdevMultitouchMBEmuTimer(InputInfoPtr);
315 BOOL EvdevMultitouchMBEmuFilterEvent(InputInfoPtr, int, BOOL);
316 void EvdevMultitouchMBEmuWakeupHandler(pointer, int, pointer);
317 void EvdevMultitouchMBEmuBlockHandler(pointer, struct timeval**, pointer);
318 void EvdevMultitouchMBEmuPreInit(InputInfoPtr);
319 void EvdevMultitouchMBEmuOn(InputInfoPtr);
320 void EvdevMultitouchMBEmuFinalize(InputInfoPtr);
321 void EvdevMultitouchMBEmuEnable(InputInfoPtr, BOOL);
323 /* Mouse Wheel emulation */
324 void EvdevMultitouchWheelEmuPreInit(InputInfoPtr pInfo);
325 BOOL EvdevMultitouchWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value);
326 BOOL EvdevMultitouchWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv);
329 void EvdevMultitouchDragLockPreInit(InputInfoPtr pInfo);
330 BOOL EvdevMultitouchDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value);
332 #ifdef HAVE_PROPERTIES
333 void EvdevMultitouchMBEmuInitProperty(DeviceIntPtr);
334 void EvdevMultitouchWheelEmuInitProperty(DeviceIntPtr);
335 void EvdevMultitouchDragLockInitProperty(DeviceIntPtr);