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) )
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
167 ET_Internal = 0xFF /* First byte */
172 unsigned char header; /**< Always ET_Internal */
173 enum EventType type; /**< One of EventType */
174 int length; /**< Length in bytes */
175 Time time; /**< Time in ms */
176 int deviceid; /**< Device to post this event for */
177 int sourceid; /**< The physical source device */
179 uint32_t button; /**< Button number */
180 uint32_t key; /**< Key code */
182 int16_t root_x; /**< Pos relative to root window in integral data */
183 float root_x_frac; /**< Pos relative to root window in frac part */
184 int16_t root_y; /**< Pos relative to root window in integral part */
185 float root_y_frac; /**< Pos relative to root window in frac part */
186 uint8_t buttons[(MAX_BUTTONS + 7)/8]; /**< Button mask */
188 uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
189 uint8_t mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/
190 int32_t data[MAX_VALUATORS]; /**< Valuator data */
191 int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */
194 uint32_t base; /**< XKB base modifiers */
195 uint32_t latched; /**< XKB latched modifiers */
196 uint32_t locked; /**< XKB locked modifiers */
197 uint32_t effective;/**< XKB effective modifiers */
200 uint8_t base; /**< XKB base group */
201 uint8_t latched; /**< XKB latched group */
202 uint8_t locked; /**< XKB locked group */
203 uint8_t effective;/**< XKB effective group */
205 Window root; /**< Root window of the event */
206 int corestate; /**< Core key/button state BEFORE the event */
207 int key_repeat; /**< Internally-generated key repeat event */
210 typedef struct _AnyEvent AnyEvent;
213 unsigned char header; /**< Always ET_Internal */
214 enum EventType type; /**< One of EventType */
215 int length; /**< Length in bytes */
216 Time time; /**< Time in ms */
223 union _InternalEvent {
225 unsigned char header; /**< Always ET_Internal */
226 enum EventType type; /**< One of ET_* */
227 int length; /**< Length in bytes */
228 Time time; /**< Time in ms. */
231 DeviceEvent device_event;
234 #define wUseDefault(w,field,def) ((w)->optional ? (w)->optional->field : def)
235 #define wBoundingShape(w) wUseDefault(w, boundingShape, NULL)
236 #define wInputShape(w) wUseDefault(w, inputShape, NULL)
237 #define wBorderWidth(w) ((int) (w)->borderWidth)
239 /* used as NULL-terminated list */
240 typedef struct _DevCursorNode {
243 struct _DevCursorNode* next;
244 } DevCursNodeRec, *DevCursNodePtr, *DevCursorList;
246 typedef struct _WindowOpt {
247 VisualID visual; /* default: same as parent */
248 CursorPtr cursor; /* default: window.cursorNone */
249 Colormap colormap; /* default: same as parent */
250 Mask dontPropagateMask; /* default: window.dontPropagate */
251 Mask otherEventMasks; /* default: 0 */
252 struct _OtherClients *otherClients; /* default: NULL */
253 struct _GrabRec *passiveGrabs; /* default: NULL */
254 PropertyPtr userProps; /* default: NULL */
255 unsigned long backingBitPlanes; /* default: ~0L */
256 unsigned long backingPixel; /* default: 0 */
257 RegionPtr boundingShape; /* default: NULL */
258 RegionPtr clipShape; /* default: NULL */
259 RegionPtr inputShape; /* default: NULL */
260 struct _OtherInputMasks *inputMasks; /* default: NULL */
261 DevCursorList deviceCursors; /* default: NULL */
262 } WindowOptRec, *WindowOptPtr;
264 typedef struct _Window {
265 DrawableRec drawable;
266 PrivateRec *devPrivates;
267 WindowPtr parent; /* ancestor chain */
268 WindowPtr nextSib; /* next lower sibling */
269 WindowPtr prevSib; /* next higher sibling */
270 WindowPtr firstChild; /* top-most child */
271 WindowPtr lastChild; /* bottom-most child */
272 RegionRec clipList; /* clipping rectangle for output */
273 RegionRec borderClip; /* NotClippedByChildren + border */
274 union _Validate *valdata;
276 RegionRec borderSize;
277 DDXPointRec origin; /* position relative to parent */
278 unsigned short borderWidth;
279 unsigned short deliverableEvents; /* all masks from all clients */
280 Mask eventMask; /* mask from the creating client */
283 pointer backStorage; /* null when BS disabled */
284 WindowOptPtr optional;
285 unsigned backgroundState:2; /* None, Relative, Pixel, Pixmap */
286 unsigned borderIsPixel:1;
287 unsigned cursorIsNone:1; /* else real cursor (might inherit) */
288 unsigned backingStore:2;
289 unsigned saveUnder:1;
290 unsigned DIXsaveUnder:1;
291 unsigned bitGravity:4;
292 unsigned winGravity:4;
293 unsigned overrideRedirect:1;
294 unsigned visibility:2;
296 unsigned realized:1; /* ancestors are all mapped */
297 unsigned viewable:1; /* realized && InputOutput */
298 unsigned dontPropagate:3;/* index into DontPropagateMasks */
299 unsigned forcedBS:1; /* system-supplied backingStore */
300 unsigned redirectDraw:2; /* COMPOSITE rendering redirect */
301 unsigned forcedBG:1; /* must have an opaque background */
303 unsigned rootlessUnhittable:1; /* doesn't hit-test */
307 typedef struct _IEvent {
308 InternalEvent *event;
311 } IEventRec, *IEventPtr;
320 #define PressFlagFlick 0x01//(1 << 0)
321 #define PressFlagPan 0x02//(1 << 1)
322 #define PressFlagPinchRotation 0x04//(1 << 2)
323 #define PressFlagTap 0x08//(1 << 3)
324 #define PressFlagTapNHold 0x10//(1 << 4)
325 #define PressFlagHold 0x20//(1 << 5)
327 #define FlickFilterMask 0x01//(1 << 0)
328 #define PanFilterMask 0x02//(1 << 1)
329 #define PinchRotationFilterMask 0x04//(1 << 2)
330 #define TapFilterMask 0x08//(1 << 3)
331 #define TapNHoldFilterMask 0x10//(1 << 4)
332 #define HoldFilterMask 0x20//(1 << 5)
334 #define GESTURE_FILTER_MASK_ALL 0x3f//(FlickFilterMask | PanFilterMask | PinchRotationFilterMask | TapFilterMask |TapNHoldFilterMask | HoldFilterMask)
336 typedef struct _tagTouchStatus
338 int status;//One of BTN_RELEASED, BTN_PRESSED and BTN_MOVING
347 Time ptime; //press time
348 Time mtime; //motion time
349 Time rtime; //current/previous release time
352 typedef struct _GestureDeviceRec
355 int version; /* Driver version */
356 OsTimerPtr device_setting_timer;
366 GestureGrabEventPtr GrabEvents;
368 EventHandleType ehtype;
373 pixman_region16_t area;
374 pixman_region16_t finger_rects[MAX_MT_DEVICES];
381 TouchStatus fingers[MAX_MT_DEVICES];
383 int event_sum[MAX_MT_DEVICES];
384 uint32_t recognized_gesture;
385 uint32_t filter_mask;
387 DeviceIntPtr this_device;
388 DeviceIntPtr mt_devices[MAX_MT_DEVICES];
389 DeviceIntPtr master_pointer;
390 DeviceIntPtr xtest_pointer;
391 } GestureDeviceRec, *GestureDevicePtr ;