1 /**************************************************************************
3 xserver-xorg-input-gesture
5 Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
7 Contact: Sung-Jin Park <sj76.park@samsung.com>
8 Sangjin LEE <lsj119@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
35 #include <xorg/events.h>
36 #include <xorg/gestureext.h>
37 #include <X11/extensions/gestureconst.h>
40 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
41 #define HAVE_PROPERTIES 1
44 #define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
45 #define RootWindow(dev) dev->spriteInfo->sprite->spriteTrace[0]
46 #define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK)
47 #define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET))
49 #define MAX_MT_DEVICES 3
50 #define GESTURE_EQ_SIZE 256
52 #define GESTURE_RECOGNIZER_ONOFF "GESTURE_RECOGNIZER_ONOFF"
54 #define FINGER_WIDTH 10
55 #define FINGER_HEIGHT 10
56 #define FINGER_WIDTH_2T 20
57 #define FINGER_HEIGHT_2T 20
58 #define AREA_CENTER_X(extents) ((extents)->x1 + (((extents)->x2-(extents)->x1)/2))
59 #define AREA_CENTER_Y(extents) ((extents)->y1 + (((extents)->y2-(extents)->y1)/2))
60 #define AREA_SIZE(extents) (ABS((extents)->x2-(extents)->x1)*ABS((extents)->y2-(extents)->y1))
61 #define INBOX(r,x,y) ( ((r)->x2 > x) && ((r)->x1 <= x) && ((r)->y2 > y) && ((r)->y1 <= y) )
64 #define TAP_THRESHOLD 100//in pixel
65 #define SINGLE_TAP_TIMEOUT 100//in msec
66 #define DOUBLE_TAP_TIMEOUT 250//in msec
69 #define ZOOM_THRESHOLD 0.05f
70 #define ANGLE_THRESHOLD 0.1f
73 typedef double XDouble;
74 #define XDoubleToFixed(f) ((XFixed) ((f) * 65536))
75 #define XFixedToDouble(f) (((XDouble) (f)) / 65536)
77 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
78 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
79 #define ABS(x) (((x) < 0) ? -(x) : (x))
93 #define PAN_AREA_THRESHOLD 10000//=100pixel * 100pixel
94 #define PAN_MOVE_THRESHOLD 5//pixel
95 #define PAN_UPDATE_MOVE_THRESHOLD 3//pixel
96 #define PAN_TIME_THRESHOLD 300//ms
98 #define HOLD_AREA_THRESHOLD 2500//=50pixel * 50pixel
99 #define HOLD_MOVE_THRESHOLD 10//pixel
100 #define HOLD_TIME_THRESHOLD 500//ms
102 #define TAP_AREA_THRESHOLD 10000//= 100pixel * 100pixel
103 #define TAP_MOVE_THRESHOLD 70//pixel
104 #define SGL_TAP_TIME_THRESHOLD 200//ms
105 #define DBL_TAP_TIME_THRESHOLD 200//ms
106 #define MAX_TAP_REPEATS 3
108 #define TAPNHOLD_AREA_THRESHOLD 4900//= 70pixel * 70pixel
109 #define TAPNHOLD_MOVE_THRESHOLD 50//pixel
110 #define TAPNHOLD_TAP_TIME_THRESHOLD 200//ms
111 #define TAPNHOLD_INTV_TIME_THRESHOLD 200//ms
112 #define TAPNHOLD_HOLD_TIME_THRESHOLD 500//ms
114 #define FLICK_AREA_THRESHOLD 22500//=150pixel * 150pixel
115 #define FLICK_AREA_TIMEOUT 700//ms
116 #define FLICK_MOVE_THRESHOLD 100//pixel
117 #define FLICK_MOVE_TIMEOUT 1000//ms
119 typedef enum _MTSyncType
121 MTOUCH_FRAME_SYNC_END,
122 MTOUCH_FRAME_SYNC_BEGIN
125 typedef enum _EventHandleType
132 typedef enum _ErrorStatus
152 ET_Internal = 0xFF /* First byte */
157 unsigned char header; /**< Always ET_Internal */
158 enum EventType type; /**< One of EventType */
159 int length; /**< Length in bytes */
160 Time time; /**< Time in ms */
161 int deviceid; /**< Device to post this event for */
162 int sourceid; /**< The physical source device */
164 uint32_t button; /**< Button number */
165 uint32_t key; /**< Key code */
167 int16_t root_x; /**< Pos relative to root window in integral data */
168 float root_x_frac; /**< Pos relative to root window in frac part */
169 int16_t root_y; /**< Pos relative to root window in integral part */
170 float root_y_frac; /**< Pos relative to root window in frac part */
171 uint8_t buttons[(MAX_BUTTONS + 7)/8]; /**< Button mask */
173 uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
174 uint8_t mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/
175 int32_t data[MAX_VALUATORS]; /**< Valuator data */
176 int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */
179 uint32_t base; /**< XKB base modifiers */
180 uint32_t latched; /**< XKB latched modifiers */
181 uint32_t locked; /**< XKB locked modifiers */
182 uint32_t effective;/**< XKB effective modifiers */
185 uint8_t base; /**< XKB base group */
186 uint8_t latched; /**< XKB latched group */
187 uint8_t locked; /**< XKB locked group */
188 uint8_t effective;/**< XKB effective group */
190 Window root; /**< Root window of the event */
191 int corestate; /**< Core key/button state BEFORE the event */
192 int key_repeat; /**< Internally-generated key repeat event */
195 typedef struct _AnyEvent AnyEvent;
198 unsigned char header; /**< Always ET_Internal */
199 enum EventType type; /**< One of EventType */
200 int length; /**< Length in bytes */
201 Time time; /**< Time in ms */
208 union _InternalEvent {
210 unsigned char header; /**< Always ET_Internal */
211 enum EventType type; /**< One of ET_* */
212 int length; /**< Length in bytes */
213 Time time; /**< Time in ms. */
216 DeviceEvent device_event;
219 #define wUseDefault(w,field,def) ((w)->optional ? (w)->optional->field : def)
220 #define wBoundingShape(w) wUseDefault(w, boundingShape, NULL)
221 #define wInputShape(w) wUseDefault(w, inputShape, NULL)
222 #define wBorderWidth(w) ((int) (w)->borderWidth)
224 /* used as NULL-terminated list */
225 typedef struct _DevCursorNode {
228 struct _DevCursorNode* next;
229 } DevCursNodeRec, *DevCursNodePtr, *DevCursorList;
231 typedef struct _WindowOpt {
232 VisualID visual; /* default: same as parent */
233 CursorPtr cursor; /* default: window.cursorNone */
234 Colormap colormap; /* default: same as parent */
235 Mask dontPropagateMask; /* default: window.dontPropagate */
236 Mask otherEventMasks; /* default: 0 */
237 struct _OtherClients *otherClients; /* default: NULL */
238 struct _GrabRec *passiveGrabs; /* default: NULL */
239 PropertyPtr userProps; /* default: NULL */
240 unsigned long backingBitPlanes; /* default: ~0L */
241 unsigned long backingPixel; /* default: 0 */
242 RegionPtr boundingShape; /* default: NULL */
243 RegionPtr clipShape; /* default: NULL */
244 RegionPtr inputShape; /* default: NULL */
245 struct _OtherInputMasks *inputMasks; /* default: NULL */
246 DevCursorList deviceCursors; /* default: NULL */
247 } WindowOptRec, *WindowOptPtr;
249 typedef struct _Window {
250 DrawableRec drawable;
251 PrivateRec *devPrivates;
252 WindowPtr parent; /* ancestor chain */
253 WindowPtr nextSib; /* next lower sibling */
254 WindowPtr prevSib; /* next higher sibling */
255 WindowPtr firstChild; /* top-most child */
256 WindowPtr lastChild; /* bottom-most child */
257 RegionRec clipList; /* clipping rectangle for output */
258 RegionRec borderClip; /* NotClippedByChildren + border */
259 union _Validate *valdata;
261 RegionRec borderSize;
262 DDXPointRec origin; /* position relative to parent */
263 unsigned short borderWidth;
264 unsigned short deliverableEvents; /* all masks from all clients */
265 Mask eventMask; /* mask from the creating client */
268 pointer backStorage; /* null when BS disabled */
269 WindowOptPtr optional;
270 unsigned backgroundState:2; /* None, Relative, Pixel, Pixmap */
271 unsigned borderIsPixel:1;
272 unsigned cursorIsNone:1; /* else real cursor (might inherit) */
273 unsigned backingStore:2;
274 unsigned saveUnder:1;
275 unsigned DIXsaveUnder:1;
276 unsigned bitGravity:4;
277 unsigned winGravity:4;
278 unsigned overrideRedirect:1;
279 unsigned visibility:2;
281 unsigned realized:1; /* ancestors are all mapped */
282 unsigned viewable:1; /* realized && InputOutput */
283 unsigned dontPropagate:3;/* index into DontPropagateMasks */
284 unsigned forcedBS:1; /* system-supplied backingStore */
285 unsigned redirectDraw:2; /* COMPOSITE rendering redirect */
286 unsigned forcedBG:1; /* must have an opaque background */
288 unsigned rootlessUnhittable:1; /* doesn't hit-test */
292 typedef struct _IEvent {
293 InternalEvent *event;
296 } IEventRec, *IEventPtr;
305 #define PressFlagFlick 0x01//(1 << 0)
306 #define PressFlagPan 0x02//(1 << 1)
307 #define PressFlagPinchRotation 0x04//(1 << 2)
308 #define PressFlagTap 0x08//(1 << 3)
309 #define PressFlagTapNHold 0x10//(1 << 4)
310 #define PressFlagHold 0x20//(1 << 5)
312 #define FlickFilterMask 0x01//(1 << 0)
313 #define PanFilterMask 0x02//(1 << 1)
314 #define PinchRotationFilterMask 0x04//(1 << 2)
315 #define TapFilterMask 0x08//(1 << 3)
316 #define TapNHoldFilterMask 0x10//(1 << 4)
317 #define HoldFilterMask 0x20//(1 << 5)
319 #define GESTURE_FILTER_MASK_ALL 0x3f//(FlickFilterMask | PanFilterMask | PinchRotationFilterMask | TapFilterMask |TapNHoldFilterMask | HoldFilterMask)
321 typedef struct _tagTouchStatus
323 int status;//One of BTN_RELEASED, BTN_PRESSED and BTN_MOVING
332 Time ptime; //press time
333 Time mtime; //motion time
334 Time rtime; //current/previous release time
337 typedef struct _GestureDeviceRec
340 int version; /* Driver version */
341 OsTimerPtr device_setting_timer;
351 GestureGrabEventPtr GrabEvents;
353 EventHandleType ehtype;
358 pixman_region16_t area;
359 pixman_region16_t finger_rects[MAX_MT_DEVICES];
366 TouchStatus fingers[MAX_MT_DEVICES];
368 int event_sum[MAX_MT_DEVICES];
369 uint32_t recognized_gesture;
370 uint32_t filter_mask;
372 DeviceIntPtr this_device;
373 DeviceIntPtr mt_devices[MAX_MT_DEVICES];
374 DeviceIntPtr master_pointer;
375 DeviceIntPtr xtest_pointer;
376 } GestureDeviceRec, *GestureDevicePtr ;