2 * Copyright © 2004-2008 Red Hat, Inc.
3 * Copyright © 2008 University of South Australia
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of Red Hat
10 * not be used in advertising or publicity pertaining to distribution
11 * of the software without specific, written prior permission. Red
12 * Hat makes no representations about the suitability of this software
13 * for any purpose. It is provided "as is" without express or implied
16 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
18 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * Kristian Høgsberg (krh@redhat.com)
26 * Adam Jackson (ajax@redhat.com)
27 * Peter Hutterer (peter@cs.unisa.edu.au)
28 * Oliver McFadden (oliver.mcfadden@nokia.com)
38 #include <linux/input.h>
39 #include <linux/types.h>
41 #include <xorg-server.h>
42 #include <xf86Xinput.h>
43 #include <xf86_OSproc.h>
50 #ifdef _F_GESTURE_EXTENSION_
51 typedef enum _MTSyncType
53 MTOUCH_FRAME_SYNC_END,
54 MTOUCH_FRAME_SYNC_BEGIN
60 ET_Internal = 0xFF /* First byte */
63 typedef struct _AnyEvent AnyEvent;
66 unsigned char header; /**< Always ET_Internal */
67 enum EventType type; /**< One of EventType */
68 int length; /**< Length in bytes */
69 Time time; /**< Time in ms */
76 union _InternalEvent {
78 unsigned char header; /**< Always ET_Internal */
79 enum EventType type; /**< One of ET_* */
80 int length; /**< Length in bytes */
81 Time time; /**< Time in ms. */
85 #endif /* #ifdef _F_GESTURE_EXTENSION_ */
87 #ifndef EV_CNT /* linux 2.6.23 kernels and earlier lack _CNT defines */
88 #define EV_CNT (EV_MAX+1)
91 #define KEY_CNT (KEY_MAX+1)
94 #define REL_CNT (REL_MAX+1)
97 #define ABS_CNT (ABS_MAX+1)
100 #define LED_CNT (LED_MAX+1)
103 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 14
104 #define HAVE_SMOOTH_SCROLLING 1
107 #define EVDEV_MAXBUTTONS 32
108 #define EVDEV_MAXQUEUE 32
111 #define EVDEV_KEYBOARD_EVENTS (1 << 0)
112 #define EVDEV_BUTTON_EVENTS (1 << 1)
113 #define EVDEV_RELATIVE_EVENTS (1 << 2)
114 #define EVDEV_ABSOLUTE_EVENTS (1 << 3)
115 #define EVDEV_TOUCHPAD (1 << 4)
116 #define EVDEV_INITIALIZED (1 << 5) /* WheelInit etc. called already? */
117 #define EVDEV_TOUCHSCREEN (1 << 6)
118 #define EVDEV_CALIBRATED (1 << 7) /* run-time calibrated? */
119 #define EVDEV_TABLET (1 << 8) /* device looks like a tablet? */
120 #define EVDEV_UNIGNORE_ABSOLUTE (1 << 9) /* explicitly unignore abs axes */
121 #define EVDEV_UNIGNORE_RELATIVE (1 << 10) /* explicitly unignore rel axes */
122 #define EVDEV_RELATIVE_MODE (1 << 11) /* Force relative events for devices with absolute axes */
123 #ifdef _F_EVDEV_CONFINE_REGION_
124 #define EVDEV_CONFINE_REGION (1 << 12)
125 #endif /* #ifdef _F_EVDEV_CONFINE_REGION_ */
127 #ifndef MAX_VALUATORS
128 #define MAX_VALUATORS 36
131 #ifndef XI_PROP_DEVICE_NODE
132 #define XI_PROP_DEVICE_NODE "Device Node"
135 #ifndef XI_PROP_DEVICE_TYPE
136 #define XI_PROP_DEVICE_TYPE "Device Type"
139 #ifdef _F_ENABLE_REL_MOVE_STATUS_PROP_
140 #define XI_PROP_REL_MOVE_STATUS "Relative Move Status"
141 #define XI_PROP_REL_MOVE_ACK "Relative Move Acknowledge"
142 #endif /* #ifdef _F_ENABLE_REL_MOVE_STATUS_PROP_ */
144 #define LONG_BITS (sizeof(long) * 8)
146 /* Number of longs needed to hold the given number of bits */
147 #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
149 /* Function key mode */
151 FKEYMODE_UNKNOWN = 0,
152 FKEYMODE_FKEYS, /* function keys send function keys */
153 FKEYMODE_MMKEYS, /* function keys send multimedia keys */
168 /* axis specific data for wheel emulation */
172 int traveled_distance;
173 } WheelAxis, *WheelAxisPtr;
175 /* Event queue used to defer keyboard/button events until EV_SYN time. */
178 EV_QUEUE_KEY, /* xf86PostKeyboardEvent() */
179 EV_QUEUE_BTN, /* xf86PostButtonEvent() */
180 EV_QUEUE_PROXIMITY, /* xf86PostProximityEvent() */
182 EV_QUEUE_TOUCH, /*xf86PostTouchEvent() */
186 int key; /* May be either a key code or button number. */
188 unsigned int touch; /* Touch ID */
191 int val; /* State of the key/button/touch; pressed or released. */
193 ValuatorMask *touchMask;
195 } EventQueueRec, *EventQueuePtr;
198 unsigned short id_vendor;
199 unsigned short id_product;
202 int grabDevice; /* grab the event device? */
204 int num_vals; /* number of valuators */
205 int axis_map[max(ABS_CNT, REL_CNT)]; /* Map evdev <axis> to index */
206 ValuatorMask *vals; /* new values coming in */
207 ValuatorMask *old_vals; /* old values for calculating relative motion */
208 ValuatorMask *prox; /* last values set while not in proximity */
209 ValuatorMask *mt_mask;
210 ValuatorMask **last_mt_vals;
212 enum SlotState slot_state;
218 int in_proximity; /* device in proximity */
219 int use_proximity; /* using the proximity bit? */
220 int num_buttons; /* number of buttons */
226 unsigned int abs_queued, rel_queued, prox_queued;
228 /* XKB stuff has to be per-device rather than per-driver */
231 /* Middle mouse button emulation */
234 BOOL pending; /* timer waiting? */
235 int buttonstate; /* phys. button state */
236 int state; /* state machine (see bt3emu.c) */
237 Time expires; /* time of expiry */
240 /* Third mouse button emulation */
243 BOOL state; /* current state */
244 Time timeout; /* timeout until third button press */
245 int buttonstate; /* phys. button state */
246 int button; /* phys button to emit */
247 int threshold; /* move threshold in dev coords */
249 int delta[2]; /* delta x/y, accumulating */
250 int startpos[2]; /* starting pos for abs devices */
251 int flags; /* remember if we had rel or abs movement */
254 int meta; /* meta key to lock any button */
255 BOOL meta_state; /* meta_button state */
256 unsigned int lock_pair[EVDEV_MAXBUTTONS]; /* specify a meta/lock pair */
257 BOOL lock_state[EVDEV_MAXBUTTONS]; /* state of any locked buttons */
266 Time expires; /* time of expiry */
269 /* run-time calibration */
277 unsigned char btnmap[32]; /* config-file specified button mapping */
279 int reopen_attempts; /* max attempts to re-open after read failure */
280 int reopen_left; /* number of attempts left to re-open the device */
281 OsTimerPtr reopen_timer;
283 #ifdef _F_EVDEV_CONFINE_REGION_
284 //Backup pointer(s) for cursor
285 CursorLimitsProcPtr pOrgCursorLimits;
286 ConstrainCursorProcPtr pOrgConstrainCursor;
288 //Confining information
290 BoxPtr pointer_confine_region;
291 #endif /* #ifdef _F_EVDEV_CONFINE_REGION_ */
292 #ifdef _F_ENABLE_REL_MOVE_STATUS_PROP_
293 BOOL rel_move_status;
294 BOOL rel_move_prop_set;
296 OsTimerPtr rel_move_timer;
297 #endif /* #ifdef _F_ENABLE_REL_MOVE_STATUS_PROP_ */
298 #ifdef _F_GESTURE_EXTENSION_
300 #endif /* #ifdef _F_GESTURE_EXTENSION_ */
302 #ifdef _F_TOUCH_TRANSFORM_MATRIX_
305 struct pixman_transform inv_transform;
306 #endif /* #ifdef _F_TOUCH_TRANSFORM_MATRIX_ */
308 /* Cached info from device. */
310 unsigned long bitmask[NLONGS(EV_CNT)];
311 unsigned long key_bitmask[NLONGS(KEY_CNT)];
312 unsigned long rel_bitmask[NLONGS(REL_CNT)];
313 unsigned long abs_bitmask[NLONGS(ABS_CNT)];
314 unsigned long led_bitmask[NLONGS(LED_CNT)];
315 struct input_absinfo absinfo[ABS_CNT];
317 /* minor/major number */
320 /* Event queue used to defer keyboard/button events until EV_SYN time. */
322 EventQueueRec queue[EVDEV_MAXQUEUE];
324 enum fkeymode fkeymode;
325 } EvdevRec, *EvdevPtr;
327 /* Event posting functions */
328 void EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
329 void EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value);
330 void EvdevQueueProximityEvent(InputInfoPtr pInfo, int value);
332 void EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch,
333 ValuatorMask *mask, uint16_t type);
335 void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act);
336 void EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count);
337 void EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
338 int v[MAX_VALUATORS]);
339 void EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
340 int v[MAX_VALUATORS]);
341 unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code);
343 /* Middle Button emulation */
344 int EvdevMBEmuTimer(InputInfoPtr);
345 BOOL EvdevMBEmuFilterEvent(InputInfoPtr, int, BOOL);
346 void EvdevMBEmuWakeupHandler(pointer, int, pointer);
347 void EvdevMBEmuBlockHandler(pointer, struct timeval**, pointer);
348 void EvdevMBEmuPreInit(InputInfoPtr);
349 void EvdevMBEmuOn(InputInfoPtr);
350 void EvdevMBEmuFinalize(InputInfoPtr);
352 /* Third button emulation */
353 CARD32 Evdev3BEmuTimer(OsTimerPtr timer, CARD32 time, pointer arg);
354 BOOL Evdev3BEmuFilterEvent(InputInfoPtr, int, BOOL);
355 void Evdev3BEmuPreInit(InputInfoPtr pInfo);
356 void Evdev3BEmuOn(InputInfoPtr);
357 void Evdev3BEmuFinalize(InputInfoPtr);
358 void Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy);
359 void Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals);
361 /* Mouse Wheel emulation */
362 void EvdevWheelEmuPreInit(InputInfoPtr pInfo);
363 BOOL EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value);
364 BOOL EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv);
367 void EvdevDragLockPreInit(InputInfoPtr pInfo);
368 BOOL EvdevDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value);
370 void EvdevMBEmuInitProperty(DeviceIntPtr);
371 void Evdev3BEmuInitProperty(DeviceIntPtr);
372 void EvdevWheelEmuInitProperty(DeviceIntPtr);
373 void EvdevDragLockInitProperty(DeviceIntPtr);
374 void EvdevAppleInitProperty(DeviceIntPtr);