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 GESTURE_MAX_TOUCH sizeof(unsigned short)
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) )
62 #define AREA_HEIGHT(extents) (((extents)->y2)-((extents)->y1))
63 #define AREA_WIDTH(extents) (((extents)->x2)-((extents)->x1))
64 #define AREA_DIAG_LEN(extents) sqrt((AREA_WIDTH(extents)*AREA_WIDTH(extents))+(AREA_HEIGHT(extents)*AREA_HEIGHT(extents)))
67 #define TAP_THRESHOLD 100//in pixel
68 #define SINGLE_TAP_TIMEOUT 100//in msec
69 #define DOUBLE_TAP_TIMEOUT 250//in msec
72 #define ZOOM_THRESHOLD 0.05f
73 #define ANGLE_THRESHOLD 0.1f
76 typedef double XDouble;
77 #define XDoubleToFixed(f) ((XFixed) ((f) * 65536))
78 #define XFixedToDouble(f) (((XDouble) (f)) / 65536)
80 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
81 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
82 #define ABS(x) (((x) < 0) ? -(x) : (x))
96 #define PAN_AREA_THRESHOLD 10000//=100pixel * 100pixel
97 #define PAN_MOVE_THRESHOLD 5//pixel
98 #define PAN_UPDATE_MOVE_THRESHOLD 3//pixel
99 #define PAN_TIME_THRESHOLD 300//ms
101 #define PINCHROTATION_TIME_THRESHOLD 500//ms
102 #define PINCHROTATION_INIT_DIST_THRESHOLD 25.0f
103 #define PINCHROTATION_INIT_ANGLE_THRESHOLD 0.2f
104 #define PINCHROTATION_DIST_THRESHOLD 25.0f
105 #define PINCHROTATION_ANGLE_THRESHOLD 0.2f
107 #define HOLD_AREA_THRESHOLD 2500//=50pixel * 50pixel
108 #define HOLD_MOVE_THRESHOLD 10//pixel
109 #define HOLD_TIME_THRESHOLD 500//ms
111 #define TAP_AREA_THRESHOLD 10000//= 100pixel * 100pixel
112 #define TAP_MOVE_THRESHOLD 70//pixel
113 #define SGL_TAP_TIME_THRESHOLD 200//ms
114 #define DBL_TAP_TIME_THRESHOLD 200//ms
115 #define MAX_TAP_REPEATS 3
117 #define TAPNHOLD_AREA_THRESHOLD 4900//= 70pixel * 70pixel
118 #define TAPNHOLD_MOVE_THRESHOLD 50//pixel
119 #define TAPNHOLD_TAP_TIME_THRESHOLD 200//ms
120 #define TAPNHOLD_INTV_TIME_THRESHOLD 200//ms
121 #define TAPNHOLD_HOLD_TIME_THRESHOLD 500//ms
123 #define FLICK_AREA_THRESHOLD 22500//=150pixel * 150pixel
124 #define FLICK_AREA_TIMEOUT 700//ms
125 #define FLICK_MOVE_THRESHOLD 100//pixel
126 #define FLICK_MOVE_TIMEOUT 1000//ms
128 #define RAD_90DEG M_PI_2
129 #define RAD_180DEG M_PI
130 #define RAD_270DEG (M_PI_2 * 3)
131 #define RAD_360DEG (M_PI * 2)
132 #define rad2degree(r) ((r) * 180/M_PI)
134 typedef enum _MTSyncType
136 MTOUCH_FRAME_SYNC_END,
137 MTOUCH_FRAME_SYNC_BEGIN
140 typedef enum _EventHandleType
147 typedef enum _ErrorStatus
171 ET_Internal = 0xFF /* First byte */
174 struct _DeviceEvent {
175 unsigned char header; /**< Always ET_Internal */
176 enum EventType type; /**< One of EventType */
177 int length; /**< Length in bytes */
178 Time time; /**< Time in ms */
179 int deviceid; /**< Device to post this event for */
180 int sourceid; /**< The physical source device */
182 uint32_t button; /**< Button number (also used in pointer emulating
184 uint32_t key; /**< Key code */
186 uint32_t touchid; /**< Touch ID (client_id) */
187 int16_t root_x; /**< Pos relative to root window in integral data */
188 float root_x_frac; /**< Pos relative to root window in frac part */
189 int16_t root_y; /**< Pos relative to root window in integral part */
190 float root_y_frac; /**< Pos relative to root window in frac part */
191 uint8_t buttons[(MAX_BUTTONS + 7) / 8]; /**< Button mask */
193 uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */
194 uint8_t mode[(MAX_VALUATORS + 7) / 8];/**< Valuator mode (Abs or Rel)*/
195 double data[MAX_VALUATORS]; /**< Valuator data */
198 uint32_t base; /**< XKB base modifiers */
199 uint32_t latched; /**< XKB latched modifiers */
200 uint32_t locked; /**< XKB locked modifiers */
201 uint32_t effective;/**< XKB effective modifiers */
204 uint8_t base; /**< XKB base group */
205 uint8_t latched; /**< XKB latched group */
206 uint8_t locked; /**< XKB locked group */
207 uint8_t effective;/**< XKB effective group */
209 Window root; /**< Root window of the event */
210 int corestate; /**< Core key/button state BEFORE the event */
211 int key_repeat; /**< Internally-generated key repeat event */
212 uint32_t flags; /**< Flags to be copied into the generated event */
215 typedef struct _AnyEvent AnyEvent;
218 unsigned char header; /**< Always ET_Internal */
219 enum EventType type; /**< One of EventType */
220 int length; /**< Length in bytes */
221 Time time; /**< Time in ms */
228 union _InternalEvent {
230 unsigned char header; /**< Always ET_Internal */
231 enum EventType type; /**< One of ET_* */
232 int length; /**< Length in bytes */
233 Time time; /**< Time in ms. */
236 DeviceEvent device_event;
239 #define wUseDefault(w,field,def) ((w)->optional ? (w)->optional->field : def)
240 #define wBoundingShape(w) wUseDefault(w, boundingShape, NULL)
241 #define wInputShape(w) wUseDefault(w, inputShape, NULL)
242 #define wBorderWidth(w) ((int) (w)->borderWidth)
244 /* used as NULL-terminated list */
245 typedef struct _DevCursorNode {
248 struct _DevCursorNode* next;
249 } DevCursNodeRec, *DevCursNodePtr, *DevCursorList;
251 typedef struct _WindowOpt {
252 VisualID visual; /* default: same as parent */
253 CursorPtr cursor; /* default: window.cursorNone */
254 Colormap colormap; /* default: same as parent */
255 Mask dontPropagateMask; /* default: window.dontPropagate */
256 Mask otherEventMasks; /* default: 0 */
257 struct _OtherClients *otherClients; /* default: NULL */
258 struct _GrabRec *passiveGrabs; /* default: NULL */
259 PropertyPtr userProps; /* default: NULL */
260 unsigned long backingBitPlanes; /* default: ~0L */
261 unsigned long backingPixel; /* default: 0 */
262 RegionPtr boundingShape; /* default: NULL */
263 RegionPtr clipShape; /* default: NULL */
264 RegionPtr inputShape; /* default: NULL */
265 struct _OtherInputMasks *inputMasks; /* default: NULL */
266 DevCursorList deviceCursors; /* default: NULL */
267 } WindowOptRec, *WindowOptPtr;
269 typedef struct _Window {
270 DrawableRec drawable;
271 PrivateRec *devPrivates;
272 WindowPtr parent; /* ancestor chain */
273 WindowPtr nextSib; /* next lower sibling */
274 WindowPtr prevSib; /* next higher sibling */
275 WindowPtr firstChild; /* top-most child */
276 WindowPtr lastChild; /* bottom-most child */
277 RegionRec clipList; /* clipping rectangle for output */
278 RegionRec borderClip; /* NotClippedByChildren + border */
279 union _Validate *valdata;
281 RegionRec borderSize;
282 DDXPointRec origin; /* position relative to parent */
283 unsigned short borderWidth;
284 unsigned short deliverableEvents; /* all masks from all clients */
285 Mask eventMask; /* mask from the creating client */
288 pointer backStorage; /* null when BS disabled */
289 WindowOptPtr optional;
290 unsigned backgroundState:2; /* None, Relative, Pixel, Pixmap */
291 unsigned borderIsPixel:1;
292 unsigned cursorIsNone:1; /* else real cursor (might inherit) */
293 unsigned backingStore:2;
294 unsigned saveUnder:1;
295 unsigned DIXsaveUnder:1;
296 unsigned bitGravity:4;
297 unsigned winGravity:4;
298 unsigned overrideRedirect:1;
299 unsigned visibility:2;
301 unsigned realized:1; /* ancestors are all mapped */
302 unsigned viewable:1; /* realized && InputOutput */
303 unsigned dontPropagate:3;/* index into DontPropagateMasks */
304 unsigned forcedBS:1; /* system-supplied backingStore */
305 unsigned redirectDraw:2; /* COMPOSITE rendering redirect */
306 unsigned forcedBG:1; /* must have an opaque background */
308 unsigned rootlessUnhittable:1; /* doesn't hit-test */
312 typedef struct _IEvent {
313 InternalEvent *event;
316 } IEventRec, *IEventPtr;
325 #define PressFlagFlick 0x01//(1 << 0)
326 #define PressFlagPan 0x02//(1 << 1)
327 #define PressFlagPinchRotation 0x04//(1 << 2)
328 #define PressFlagTap 0x08//(1 << 3)
329 #define PressFlagTapNHold 0x10//(1 << 4)
330 #define PressFlagHold 0x20//(1 << 5)
332 #define FlickFilterMask 0x01//(1 << 0)
333 #define PanFilterMask 0x02//(1 << 1)
334 #define PinchRotationFilterMask 0x04//(1 << 2)
335 #define TapFilterMask 0x08//(1 << 3)
336 #define TapNHoldFilterMask 0x10//(1 << 4)
337 #define HoldFilterMask 0x20//(1 << 5)
339 #define GESTURE_FILTER_MASK_ALL 0x3f//(FlickFilterMask | PanFilterMask | PinchRotationFilterMask | TapFilterMask |TapNHoldFilterMask | HoldFilterMask)
341 typedef struct _tagTouchStatus
343 int status;//One of BTN_RELEASED, BTN_PRESSED and BTN_MOVING
352 Time ptime; //press time
353 Time mtime; //motion time
354 Time rtime; //current/previous release time
355 uint32_t touchid;//touch client_id
358 typedef struct _GestureDeviceRec
361 int version; /* Driver version */
362 OsTimerPtr device_setting_timer;
368 unsigned short num_touches;
372 GestureGrabEventPtr GrabEvents;
373 Mask lastSelectedMask;
374 Window lastSelectedWin;
376 EventHandleType ehtype;
381 pixman_region16_t area;
382 pixman_region16_t *finger_rects;
389 TouchStatus *fingers;
392 uint32_t recognized_gesture;
393 uint32_t filter_mask;
395 DeviceIntPtr this_device;
396 DeviceIntPtr master_pointer;
397 DeviceIntPtr xtest_pointer;
398 } GestureDeviceRec, *GestureDevicePtr ;