Initialize Tizen 2.3
[adaptation/xorg/driver/xserver-xorg-input-evdev.git] / src / evdev.h
1 /*
2  * Copyright © 2004-2008 Red Hat, Inc.
3  * Copyright © 2008 University of South Australia
4  *
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
14  * warranty.
15  *
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.
23  *
24  * Authors:
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)
29  */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #ifndef EVDEV_H
36 #define EVDEV_H
37
38 #include <linux/input.h>
39 #include <linux/types.h>
40
41 #include <xorg-server.h>
42 #include <xf86Xinput.h>
43 #include <xf86_OSproc.h>
44 #include <xkbstr.h>
45
46 #ifdef MULTITOUCH
47 #include <mtdev.h>
48 #endif
49
50 #ifdef _F_GESTURE_EXTENSION_
51 typedef enum _MTSyncType
52 {
53         MTOUCH_FRAME_SYNC_END,
54         MTOUCH_FRAME_SYNC_BEGIN
55 } MTSyncType;
56
57 enum EventType
58 {
59     ET_MTSync = 0x7E,
60     ET_Internal = 0xFF /* First byte */
61 };
62
63 typedef struct _AnyEvent AnyEvent;
64 struct _AnyEvent
65 {
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 */
70     int deviceid;
71     MTSyncType sync;
72     int x;
73     int y;
74 };
75
76 union _InternalEvent {
77         struct {
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. */
82         } any;
83         AnyEvent any_event;
84 };
85 #endif /* #ifdef _F_GESTURE_EXTENSION_ */
86
87 #ifndef EV_CNT /* linux 2.6.23 kernels and earlier lack _CNT defines */
88 #define EV_CNT (EV_MAX+1)
89 #endif
90 #ifndef KEY_CNT
91 #define KEY_CNT (KEY_MAX+1)
92 #endif
93 #ifndef REL_CNT
94 #define REL_CNT (REL_MAX+1)
95 #endif
96 #ifndef ABS_CNT
97 #define ABS_CNT (ABS_MAX+1)
98 #endif
99 #ifndef LED_CNT
100 #define LED_CNT (LED_MAX+1)
101 #endif
102
103 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 14
104 #define HAVE_SMOOTH_SCROLLING 1
105 #endif
106
107 #define EVDEV_MAXBUTTONS 32
108 #define EVDEV_MAXQUEUE 32
109
110 /* evdev flags */
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_ */
126
127 #ifndef MAX_VALUATORS
128 #define MAX_VALUATORS 36
129 #endif
130
131 #ifndef XI_PROP_DEVICE_NODE
132 #define XI_PROP_DEVICE_NODE "Device Node"
133 #endif
134
135 #ifndef XI_PROP_DEVICE_TYPE
136 #define XI_PROP_DEVICE_TYPE "Device Type"
137 #endif
138
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_ */
143
144 #define LONG_BITS (sizeof(long) * 8)
145
146 /* Number of longs needed to hold the given number of bits */
147 #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
148
149 /* Function key mode */
150 enum fkeymode {
151     FKEYMODE_UNKNOWN = 0,
152     FKEYMODE_FKEYS,       /* function keys send function keys */
153     FKEYMODE_MMKEYS,      /* function keys send multimedia keys */
154 };
155
156 enum SlotState {
157     SLOTSTATE_OPEN = 8,
158     SLOTSTATE_CLOSE,
159     SLOTSTATE_UPDATE,
160     SLOTSTATE_EMPTY,
161 };
162
163 enum ButtonAction {
164     BUTTON_RELEASE = 0,
165     BUTTON_PRESS = 1
166 };
167
168 /* axis specific data for wheel emulation */
169 typedef struct {
170     int up_button;
171     int down_button;
172     int traveled_distance;
173 } WheelAxis, *WheelAxisPtr;
174
175 /* Event queue used to defer keyboard/button events until EV_SYN time. */
176 typedef struct {
177     enum {
178         EV_QUEUE_KEY,   /* xf86PostKeyboardEvent() */
179         EV_QUEUE_BTN,   /* xf86PostButtonEvent() */
180         EV_QUEUE_PROXIMITY, /* xf86PostProximityEvent() */
181 #ifdef MULTITOUCH
182         EV_QUEUE_TOUCH, /*xf86PostTouchEvent() */
183 #endif
184     } type;
185     union {
186         int key;        /* May be either a key code or button number. */
187 #ifdef MULTITOUCH
188         unsigned int touch; /* Touch ID */
189 #endif
190     } detail;
191     int val;    /* State of the key/button/touch; pressed or released. */
192 #ifdef MULTITOUCH
193     ValuatorMask *touchMask;
194 #endif
195 } EventQueueRec, *EventQueuePtr;
196
197 typedef struct {
198     unsigned short id_vendor;
199     unsigned short id_product;
200
201     char *device;
202     int grabDevice;         /* grab the event device? */
203
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;
211     int cur_slot;
212     enum SlotState slot_state;
213 #ifdef MULTITOUCH
214     struct mtdev *mtdev;
215 #endif
216
217     int flags;
218     int in_proximity;           /* device in proximity */
219     int use_proximity;          /* using the proximity bit? */
220     int num_buttons;            /* number of buttons */
221     BOOL swap_axes;
222     BOOL invert_x;
223     BOOL invert_y;
224
225     int delta[REL_CNT];
226     unsigned int abs_queued, rel_queued, prox_queued;
227
228     /* XKB stuff has to be per-device rather than per-driver */
229     XkbRMLVOSet rmlvo;
230
231     /* Middle mouse button emulation */
232     struct {
233         BOOL                enabled;
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 */
238         Time                timeout;
239     } emulateMB;
240     /* Third mouse button emulation */
241     struct emulate3B {
242         BOOL                enabled;
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 */
248         OsTimerPtr          timer;
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 */
252     } emulate3B;
253     struct {
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 */
258     } dragLock;
259     struct {
260         BOOL                enabled;
261         int                 button;
262         int                 button_state;
263         int                 inertia;
264         WheelAxis           X;
265         WheelAxis           Y;
266         Time                expires;     /* time of expiry */
267         Time                timeout;
268     } emulateWheel;
269     /* run-time calibration */
270     struct {
271         int                 min_x;
272         int                 max_x;
273         int                 min_y;
274         int                 max_y;
275     } calibration;
276
277     unsigned char btnmap[32];           /* config-file specified button mapping */
278
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;
282
283 #ifdef _F_EVDEV_CONFINE_REGION_
284     //Backup pointer(s) for cursor
285     CursorLimitsProcPtr pOrgCursorLimits;
286     ConstrainCursorProcPtr pOrgConstrainCursor;
287
288     //Confining information
289     int confined_id;
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;
295     BOOL rel_move_ack;
296     OsTimerPtr rel_move_timer;
297 #endif /* #ifdef _F_ENABLE_REL_MOVE_STATUS_PROP_ */
298 #ifdef _F_GESTURE_EXTENSION_
299     int *mt_status;
300 #endif /* #ifdef _F_GESTURE_EXTENSION_ */
301
302 #ifdef _F_TOUCH_TRANSFORM_MATRIX_
303     float transform[9];
304     BOOL use_transform;
305     struct pixman_transform inv_transform;
306 #endif /* #ifdef _F_TOUCH_TRANSFORM_MATRIX_ */
307
308     /* Cached info from device. */
309     char name[1024];
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];
316
317     /* minor/major number */
318     dev_t min_maj;
319
320     /* Event queue used to defer keyboard/button events until EV_SYN time. */
321     int                     num_queue;
322     EventQueueRec           queue[EVDEV_MAXQUEUE];
323
324     enum fkeymode           fkeymode;
325 } EvdevRec, *EvdevPtr;
326
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);
331 #ifdef MULTITOUCH
332 void EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch,
333                           ValuatorMask *mask, uint16_t type);
334 #endif
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);
342
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);
351
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);
360
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);
365
366 /* Draglock code */
367 void EvdevDragLockPreInit(InputInfoPtr pInfo);
368 BOOL EvdevDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value);
369
370 void EvdevMBEmuInitProperty(DeviceIntPtr);
371 void Evdev3BEmuInitProperty(DeviceIntPtr);
372 void EvdevWheelEmuInitProperty(DeviceIntPtr);
373 void EvdevDragLockInitProperty(DeviceIntPtr);
374 void EvdevAppleInitProperty(DeviceIntPtr);
375 #endif