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 10
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 typedef double XDouble;
73 #define XDoubleToFixed(f) ((XFixed) ((f) * 65536))
74 #define XFixedToDouble(f) (((XDouble) (f)) / 65536)
76 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
77 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
78 #define ABS(x) (((x) < 0) ? -(x) : (x))
102 #define TAP_AREA_THRESHOLD 10000//= 100pixel * 100pixel
103 #define TAP_MOVE_THRESHOLD 70//pixel
104 #define SGL_TAP_TIME_THRESHOLD 300//ms
105 #define DBL_TAP_TIME_THRESHOLD 200//ms
106 #define MAX_TAP_REPEATS 2
108 #define FLICK_AREA_THRESHOLD 22500//=150pixel * 150pixel
109 #define FLICK_AREA_TIMEOUT 700//ms
110 #define FLICK_MOVE_THRESHOLD 100//pixel
111 #define FLICK_MOVE_TIMEOUT 1000//ms
112 #define FLICK_FALSE_Y_DIFF_COUNT 7
113 #define FLICK_FALSE_X_DIFF_COUNT 5
116 typedef enum _MTSyncType
118 MTOUCH_FRAME_SYNC_END,
119 MTOUCH_FRAME_SYNC_BEGIN
122 typedef enum _EventHandleType
129 typedef enum _ErrorStatus
149 ET_Internal = 0xFF /* First byte */
152 struct _DeviceEvent {
153 unsigned char header; /**< Always ET_Internal */
154 enum EventType type; /**< One of EventType */
155 int length; /**< Length in bytes */
156 Time time; /**< Time in ms */
157 int deviceid; /**< Device to post this event for */
158 int sourceid; /**< The physical source device */
160 uint32_t button; /**< Button number (also used in pointer emulating
162 uint32_t key; /**< Key code */
164 uint32_t touchid; /**< Touch ID (client_id) */
165 int16_t root_x; /**< Pos relative to root window in integral data */
166 float root_x_frac; /**< Pos relative to root window in frac part */
167 int16_t root_y; /**< Pos relative to root window in integral part */
168 float root_y_frac; /**< Pos relative to root window in frac part */
169 uint8_t buttons[(MAX_BUTTONS + 7) / 8]; /**< Button mask */
171 uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */
172 uint8_t mode[(MAX_VALUATORS + 7) / 8];/**< Valuator mode (Abs or Rel)*/
173 double data[MAX_VALUATORS]; /**< Valuator data */
176 uint32_t base; /**< XKB base modifiers */
177 uint32_t latched; /**< XKB latched modifiers */
178 uint32_t locked; /**< XKB locked modifiers */
179 uint32_t effective;/**< XKB effective modifiers */
182 uint8_t base; /**< XKB base group */
183 uint8_t latched; /**< XKB latched group */
184 uint8_t locked; /**< XKB locked group */
185 uint8_t effective;/**< XKB effective group */
187 Window root; /**< Root window of the event */
188 int corestate; /**< Core key/button state BEFORE the event */
189 int key_repeat; /**< Internally-generated key repeat event */
190 uint32_t flags; /**< Flags to be copied into the generated event */
193 typedef struct _AnyEvent AnyEvent;
196 unsigned char header; /**< Always ET_Internal */
197 enum EventType type; /**< One of EventType */
198 int length; /**< Length in bytes */
199 Time time; /**< Time in ms */
206 union _InternalEvent {
208 unsigned char header; /**< Always ET_Internal */
209 enum EventType type; /**< One of ET_* */
210 int length; /**< Length in bytes */
211 Time time; /**< Time in ms. */
214 DeviceEvent device_event;
217 #define wUseDefault(w,field,def) ((w)->optional ? (w)->optional->field : def)
218 #define wBoundingShape(w) wUseDefault(w, boundingShape, NULL)
219 #define wInputShape(w) wUseDefault(w, inputShape, NULL)
220 #define wBorderWidth(w) ((int) (w)->borderWidth)
222 /* used as NULL-terminated list */
223 typedef struct _DevCursorNode {
226 struct _DevCursorNode* next;
227 } DevCursNodeRec, *DevCursNodePtr, *DevCursorList;
229 typedef struct _WindowOpt {
230 VisualID visual; /* default: same as parent */
231 CursorPtr cursor; /* default: window.cursorNone */
232 Colormap colormap; /* default: same as parent */
233 Mask dontPropagateMask; /* default: window.dontPropagate */
234 Mask otherEventMasks; /* default: 0 */
235 struct _OtherClients *otherClients; /* default: NULL */
236 struct _GrabRec *passiveGrabs; /* default: NULL */
237 PropertyPtr userProps; /* default: NULL */
238 unsigned long backingBitPlanes; /* default: ~0L */
239 unsigned long backingPixel; /* default: 0 */
240 RegionPtr boundingShape; /* default: NULL */
241 RegionPtr clipShape; /* default: NULL */
242 RegionPtr inputShape; /* default: NULL */
243 struct _OtherInputMasks *inputMasks; /* default: NULL */
244 DevCursorList deviceCursors; /* default: NULL */
245 } WindowOptRec, *WindowOptPtr;
247 typedef struct _Window {
248 DrawableRec drawable;
249 PrivateRec *devPrivates;
250 WindowPtr parent; /* ancestor chain */
251 WindowPtr nextSib; /* next lower sibling */
252 WindowPtr prevSib; /* next higher sibling */
253 WindowPtr firstChild; /* top-most child */
254 WindowPtr lastChild; /* bottom-most child */
255 RegionRec clipList; /* clipping rectangle for output */
256 RegionRec borderClip; /* NotClippedByChildren + border */
257 union _Validate *valdata;
259 RegionRec borderSize;
260 DDXPointRec origin; /* position relative to parent */
261 unsigned short borderWidth;
262 unsigned short deliverableEvents; /* all masks from all clients */
263 Mask eventMask; /* mask from the creating client */
266 pointer backStorage; /* null when BS disabled */
267 WindowOptPtr optional;
268 unsigned backgroundState:2; /* None, Relative, Pixel, Pixmap */
269 unsigned borderIsPixel:1;
270 unsigned cursorIsNone:1; /* else real cursor (might inherit) */
271 unsigned backingStore:2;
272 unsigned saveUnder:1;
273 unsigned DIXsaveUnder:1;
274 unsigned bitGravity:4;
275 unsigned winGravity:4;
276 unsigned overrideRedirect:1;
277 unsigned visibility:2;
279 unsigned realized:1; /* ancestors are all mapped */
280 unsigned viewable:1; /* realized && InputOutput */
281 unsigned dontPropagate:3;/* index into DontPropagateMasks */
282 unsigned forcedBS:1; /* system-supplied backingStore */
283 unsigned redirectDraw:2; /* COMPOSITE rendering redirect */
284 unsigned forcedBG:1; /* must have an opaque background */
286 unsigned rootlessUnhittable:1; /* doesn't hit-test */
290 typedef struct _IEvent {
291 InternalEvent *event;
294 } IEventRec, *IEventPtr;
303 #define PressFlagFlick 0x01//(1 << 0)
304 #define PressFlagPan 0x02//(1 << 1)
305 #define PressFlagPinchRotation 0x04//(1 << 2)
306 #define PressFlagTap 0x08//(1 << 3)
307 #define PressFlagTapNHold 0x10//(1 << 4)
308 #define PressFlagHold 0x20//(1 << 5)
310 #define FlickFilterMask 0x01//(1 << 0)
311 #define PanFilterMask 0x02//(1 << 1)
312 #define PinchRotationFilterMask 0x04//(1 << 2)
313 #define TapFilterMask 0x08//(1 << 3)
314 #define TapNHoldFilterMask 0x10//(1 << 4)
315 #define HoldFilterMask 0x20//(1 << 5)
317 #define GESTURE_FILTER_MASK_ALL 0x3f//(FlickFilterMask | PanFilterMask | PinchRotationFilterMask | TapFilterMask |TapNHoldFilterMask | HoldFilterMask)
319 #define WFlickFilterMask 0x01//(1 << 0)
320 #define WTapFilterMask 0x02//(1 << 1)
321 #define WHoldFilterMask 0x04//(1 << 2)
323 #define GESTURE_WATCH_FILTER_MASK_ALL 0x07//(WFlickFilterMask | WTapFilterMask | WHoldFilterMask)
325 typedef struct _tagTouchStatus
327 int status;//One of BTN_RELEASED, BTN_PRESSED and BTN_MOVING
336 Time ptime; //press time
337 Time mtime; //motion time
338 Time rtime; //current/previous release time
341 typedef struct _GestureDeviceRec
344 int version; /* Driver version */
345 OsTimerPtr device_setting_timer;
349 int flick_pressed_point;
352 int hwkeycode_flick_down;
353 int hwkeycode_flick_up;
354 int shutdown_keycode;
355 int flick_press_area;
356 int flick_press_area_left;
357 int flick_press_area_left_right;
358 int flick_minimum_height;
359 int activate_flick_down;//up to down
360 int activate_flick_up;//down to up
361 int activate_flick_right;//left to right
364 int singletap_threshold;
365 int doubletap_threshold;
366 double hold_area_threshold;
367 int hold_move_threshold;
368 int hold_time_threshold;
372 DeviceIntPtr hwkey_dev;
373 MTSyncType mtsync_status;
375 DeviceIntPtr power_device;
383 GestureGrabEventPtr GrabEvents;
384 Mask lastSelectedMask;
385 Window lastSelectedWin;
387 EventHandleType ehtype;
392 pixman_region16_t area;
393 pixman_region16_t finger_rects[MAX_MT_DEVICES];
400 TouchStatus fingers[MAX_MT_DEVICES];
402 int event_sum[MAX_MT_DEVICES];
403 uint32_t recognized_gesture;
404 uint32_t filter_mask;
406 DeviceIntPtr this_device;
407 DeviceIntPtr mt_devices[MAX_MT_DEVICES];
408 DeviceIntPtr master_pointer;
409 DeviceIntPtr xtest_pointer;
410 } GestureDeviceRec, *GestureDevicePtr ;