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 **************************************************************************/
36 #include <linux/input.h>
37 #include <linux/types.h>
39 #include <xf86_OSproc.h>
44 #include <xf86Xinput.h>
46 #include <xorgVersion.h>
49 #ifdef HAVE_PROPERTIES
50 #include <X11/Xatom.h>
51 #include <xserver-properties.h>
52 /* 1.6 has properties, but no labels */
53 #ifdef AXIS_LABEL_PROP
61 #include <X11/Xatom.h>
65 #include <sys/syscall.h>
68 #include <sys/types.h>
70 #include <xorg-server.h>
71 #include <xorgVersion.h>
72 #include <xf86Module.h>
73 #include <X11/Xatom.h>
78 #define MGEST XDBG_M('G','E','S','T')
80 static const void(*PalmRecognize)(int, InternalEvent*, DeviceIntPtr);
82 #define _GESTUREPALMRECOGNIZE_(function, type, ev, device) \
85 XDBG_WARNING(MGEST, "[_GESTUREPALMRECOGNIZE_] Enable GesturePalmRecognize. type=%d\n", type); \
86 function(type, ev, device); \
90 XDBG_WARNING(MGEST, "[_GESTUREPALMRECOGNIZE_] Disable GesturePalmRecognize \n"); \
93 static void printk(const char* fmt, ...) __attribute__((format(printf, 1, 0)));
94 extern char *strcasestr(const char *s, const char *find);
95 extern ScreenPtr miPointerCurrentScreen(void);
96 extern EventQueuePtr mieqGetEventQueuePtr();
98 static Bool GestureIsEventInMIEQ(int finger_index, enum EventType type);
99 static int GestureGetFingerIndexFromDevice(DeviceIntPtr device);
100 static int GestureGetDeviceIdFromFingerIndex(int finger_index);
101 static Bool GestureIsPalmEventInMIEQ(void);
102 static Bool GestureIsPalmEvent(InternalEvent *event);
103 static int GestureGetMTToolValuator(InternalEvent *ev, DeviceIntPtr device);
104 static void GestureRegisterTouchInfo(InternalEvent *ev, DeviceIntPtr device);
105 static void GestureSetToolData(InternalEvent *ev, double val_tool);
106 static void GestureCleanupTouch(int screen_num, InternalEvent *ev, DeviceIntPtr device);
107 static void GestureChangeEventToFirstFingerEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
110 static int GesturePreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags);
111 static void GestureUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags);
112 static pointer GesturePlug(pointer module, pointer options, int *errmaj, int *errmin);
113 static void GestureUnplug(pointer p);
114 static int GestureControl(DeviceIntPtr device,int what);
115 static int GestureInit(DeviceIntPtr device);
116 static void GestureFini(DeviceIntPtr device);
117 static void GestureReadInput(InputInfoPtr pInfo);
120 ErrorStatus GestureRegionsInit(void);
122 //event queue handling functions
123 ErrorStatus GestureInitEQ(void);
124 ErrorStatus GestureFiniEQ(void);
125 ErrorStatus GestureEnqueueEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
126 ErrorStatus GestureEventsFlush(void);
127 void GestureEventsDrop(void);
130 ErrorStatus GestureRegionsReinit(void);
131 void GestureEnable(int enable, Bool prop, DeviceIntPtr dev);
132 static inline void GestureEnableDisable();
133 void GestureCbEventsGrabbed(Mask *pGrabMask, GestureGrabEventPtr *pGrabEvent);
134 void GestureCbEventsSelected(Window win, Mask *pEventMask);
135 WindowPtr GestureGetEventsWindow(void);
136 static Bool GestureHasFingersEvents(int eventType);
138 //Enqueued event handlers and enabler/disabler
139 static ErrorStatus GestureEnableEventHandler(InputInfoPtr pInfo);
140 static ErrorStatus GestureDisableEventHandler(void);
141 static CARD32 GestureEventTimerHandler(OsTimerPtr timer, CARD32 time, pointer arg);
142 void GestureHandleMTSyncEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
143 void GestureHandleButtonPressEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
144 void GestureHandleButtonReleaseEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
145 void GestureHandleMotionEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
146 void GestureHandleKeyPressEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
147 void GestureHandleKeyReleaseEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device);
149 static void GestureRegisterDeviceInfo(DeviceIntPtr device);
151 //Gesture recognizer helper
152 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 21
153 static Bool PointInBorderSize(WindowPtr pWin, int x, int y);
155 static WindowPtr GestureWindowOnXY(int x, int y);
156 Bool GestureHasFingerEventMask(int eventType, int num_finger);
157 #ifdef _F_SUPPORT_BEZEL_FLICK_
158 static int get_distance(int x1, int y1, int x2, int y2);
160 static double get_angle(int x1, int y1, int x2, int y2);
162 //Gesture recognizer and handlers
163 void GestureRecognize_GroupPinchRotation(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired);
164 void GestureRecognize_GroupFlick(int type, InternalEvent *ev, DeviceIntPtr device, int idx);
165 void GestureRecognize_GroupPan(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired);
166 void GestureRecognize_GroupTap(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired);
167 void GestureRecognize_GroupTapNHold(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired);
168 void GestureRecognize_GroupHold(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired);
169 #ifdef _F_SUPPORT_BEZEL_FLICK_
170 int GestureBezelAngleRecognize(int type, int distance, double angle);
172 void GestureHandleGesture_Flick(int num_of_fingers, int distance, Time duration, int direction);
173 void GestureHandleGesture_Tap(int num_finger, int tap_repeat, int cx, int cy);
174 void GestureHandleGesture_PinchRotation(int num_of_fingers, double zoom, double angle, int distance, int cx, int cy, int kinds);
175 void GestureHandleGesture_Hold(int num_fingers, int cx, int cy, Time holdtime, int kinds);
176 void GestureHandleGesture_TapNHold(int num_fingers, int cx, int cy, Time interval, Time holdtime, int kinds);
177 void GestureHandleGesture_Pan(int num_fingers, short int dx, short int dy, int direction, int distance, Time duration, int kinds);
178 static void GestureHoldDetector(int type, InternalEvent *ev, DeviceIntPtr device);
179 void GestureRecognize(int type, InternalEvent *ev, DeviceIntPtr device);
180 ErrorStatus GestureFlushOrDrop(void);
182 static int GesturePalmGetHorizIndexWithX(int x, int type);
183 static int GesturePalmGetVertiIndexWithY(int y, int type);
184 static void GesturePalmRecognize_FlickHorizen(int type, int idx);
185 static void GesturePalmRecognize_FlickVertical(int type,int idx);
186 static int GesturePalmGetScreenInfo();
187 static int GesturePalmGetAbsAxisInfo(DeviceIntPtr dev);
188 static void GesturePalmDataUpdate(int idx, int type, InternalEvent *ev, DeviceIntPtr device);
189 static void GesturePalmUpdateAreaInfo(int type, int idx);
190 void GesturePalmRecognize(int type, InternalEvent *ev, DeviceIntPtr device);
192 //#define __PALM_GESTURE_LOG__
193 //#define __PALM_DETAIL_LOG__
194 //#define __DETAIL_DEBUG__
195 //#define __BEZEL_DEBUG__
196 //#define __DEBUG_EVENT_HANDLER__
198 #ifdef HAVE_PROPERTIES
199 //function related property handling
200 static void GestureInitProperty(DeviceIntPtr dev);
201 static int GestureSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, BOOL checkonly);
204 static Atom prop_gesture_recognizer_onoff = None;
205 static Atom prop_gesture_palm_rejection_mode = None;
207 #ifdef SUPPORT_ANR_WITH_INPUT_EVENT
208 static Atom prop_anr_in_input_event = None;
209 static Atom prop_anr_event_window = None;
210 static Window prop_anr_event_window_xid = None;
213 GestureDevicePtr g_pGesture = NULL;
214 _X_EXPORT InputDriverRec GESTURE = {
224 static XF86ModuleVersionInfo GestureVersionRec =
230 XORG_VERSION_CURRENT,
231 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR,
232 PACKAGE_VERSION_PATCHLEVEL,
239 _X_EXPORT XF86ModuleData gestureModuleData =
247 printk(const char* fmt, ...)
249 static FILE* fp = NULL;
250 static char init = 0;
255 fp = fopen("/dev/kmsg", "wt");
261 va_start(argptr, fmt);
262 vfprintf(fp, fmt, argptr);
267 #ifdef SUPPORT_ANR_WITH_INPUT_EVENT
269 _GestureFindANRWindow(DeviceIntPtr device)
272 WindowPtr anr_window=NULL;
277 root = RootWindow(device);
279 if( prop_anr_event_window == None )
280 prop_anr_event_window = MakeAtom(ANR_EVENT_WINDOW, strlen(ANR_EVENT_WINDOW), TRUE);
282 rc = dixLookupProperty (&pProp, root, prop_anr_event_window, serverClient, DixReadAccess);
283 if (rc == Success && pProp->data){
284 anr_xid = *(int*)pProp->data;
289 rc = dixLookupWindow(&anr_window, anr_xid, serverClient, DixSetPropAccess);
290 if( rc == BadWindow )
292 XDBG_ERROR(MGEST, "Can't find ANR window !!\n");
295 prop_anr_event_window_xid = anr_xid;
298 XDBG_DEBUG(MGEST, "ANR Window is %#x. Ptr is %#x\n", anr_xid, anr_window);
303 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 21
305 PointInBorderSize(WindowPtr pWin, int x, int y)
308 if (pixman_region_contains_point (&pWin->borderSize, x, y, &box))
317 GestureWindowOnXY(int x, int y)
322 DeviceIntPtr pDev = g_pGesture->master_pointer;
324 pSprite = pDev->spriteInfo->sprite;
325 pSprite->spriteTraceGood = 1; /* root window still there */
326 pWin = RootWindow(pDev)->firstChild;
329 if ((pWin->mapped) &&
330 (x >= pWin->drawable.x - wBorderWidth (pWin)) &&
331 (x < pWin->drawable.x + (int)pWin->drawable.width +
332 wBorderWidth(pWin)) &&
333 (y >= pWin->drawable.y - wBorderWidth (pWin)) &&
334 (y < pWin->drawable.y + (int)pWin->drawable.height +
336 /* When a window is shaped, a further check
337 * is made to see if the point is inside
340 && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y))
341 && (!wInputShape(pWin) ||
342 RegionContainsPoint(wInputShape(pWin),
343 x - pWin->drawable.x,
344 y - pWin->drawable.y, &box))
346 /* In rootless mode windows may be offscreen, even when
347 * they're in X's stack. (E.g. if the native window system
348 * implements some form of virtual desktop system).
350 && !pWin->rootlessUnhittable
354 if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize)
356 pSprite->spriteTraceSize += 10;
357 pSprite->spriteTrace = realloc(pSprite->spriteTrace,
358 pSprite->spriteTraceSize*sizeof(WindowPtr));
360 pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin;
361 pWin = pWin->firstChild;
364 pWin = pWin->nextSib;
366 return pSprite->spriteTrace[pSprite->spriteTraceGood-1];
370 GestureHasFingerEventMask(int eventType, int num_finger)
373 Mask eventmask = (1L << eventType);
375 if( (g_pGesture->grabMask & eventmask) &&
376 (g_pGesture->GrabEvents[eventType].pGestureGrabWinInfo[num_finger].window != None) )
378 #ifdef __DETAIL_DEBUG__
379 XDBG_DEBUG(MGEST, "TRUE !! Has grabMask\n");
380 #endif//__DETAIL_DEBUG__
384 if( g_pGesture->eventMask & eventmask )
386 #ifdef __DETAIL_DEBUG__
387 XDBG_DEBUG(MGEST, "TRUE !! Has eventMask\n");
388 #endif//__DETAIL_DEBUG__
392 #ifdef __DETAIL_DEBUG__
393 XDBG_DEBUG(MGEST, "FALSE !! eventType=%d, num_finger=%d\n", eventType, num_finger);
394 #endif//__DETAIL_DEBUG__
399 #ifdef _F_SUPPORT_BEZEL_FLICK_
401 get_distance(int _x1, int _y1, int _x2, int _y2)
409 return (int)sqrt(pow(xx, 2) + pow(yy, 2));
424 #endif//_F_SUPPORT_BEZEL_FLICK_
427 get_angle(int _x1, int _y1, int _x2, int _y2)
430 xx = fabs(_x2 - _x1);
431 yy = fabs(_y2 - _y1);
433 if (((int) xx) && ((int) yy))
440 return (RAD_360DEG - a);
451 return (RAD_180DEG + a);
455 return (RAD_180DEG - a);
461 { /* Horizontal line */
484 GestureHandleGesture_Flick(int num_of_fingers, int distance, Time duration, int direction)
487 WindowPtr target_pWin;
488 xGestureNotifyFlickEvent fev;
490 #ifdef __DETAIL_DEBUG__
491 XDBG_DEBUG(MGEST, "num_fingers=%d, distance=%d, duration=%d, direction=%d\n",
492 num_of_fingers, distance, duration, direction);
493 #endif//__DETAIL_DEBUG__
495 if(num_of_fingers == 0)
497 if(direction == FLICK_EASTWARD || direction == FLICK_WESTWARD)
498 g_pGesture->recognized_palm |= PalmFlickHorizFilterMask;
499 if(direction == FLICK_NORTHWARD || direction == FLICK_SOUTHWARD)
500 g_pGesture->recognized_palm |= PalmFlickVertiFilterMask;
502 #ifdef _F_SUPPORT_BEZEL_FLICK_
503 else if(num_of_fingers == 1)
505 g_pGesture->bezel_recognized_mask |= BezelFlickFilterMask;
509 g_pGesture->recognized_gesture |= FlickFilterMask;
511 memset(&fev, 0, sizeof(xGestureNotifyFlickEvent));
512 fev.type = GestureNotifyFlick;
513 fev.kind = GestureDone;
514 fev.num_finger = num_of_fingers;
515 fev.distance = distance;
516 fev.duration = duration;
517 fev.direction = direction;
519 if(g_pGesture->GrabEvents)
521 target_win = g_pGesture->GrabEvents[GestureNotifyFlick].pGestureGrabWinInfo[num_of_fingers].window;
522 target_pWin = g_pGesture->GrabEvents[GestureNotifyFlick].pGestureGrabWinInfo[num_of_fingers].pWin;
530 if( g_pGesture->grabMask && (target_win != None) )
532 fev.window = target_win;
536 fev.window = g_pGesture->gestureWin;
539 #ifdef __DETAIL_DEBUG__
540 XDBG_DEBUG(MGEST, "fev.window=0x%x, g_pGesture->grabMask=0x%x\n", fev.window, g_pGesture->grabMask);
541 #endif//__DETAIL_DEBUG__
543 GestureSendEvent(target_pWin, GestureNotifyFlick, GestureFlickMask, (xGestureCommonEvent *)&fev);
547 GestureHandleGesture_Tap(int num_finger, int tap_repeat, int cx, int cy)
550 WindowPtr target_pWin;
551 xGestureNotifyTapEvent tev;
553 //skip non-tap events and single finger tap
554 if( !tap_repeat || num_finger <= 1 )
557 #ifdef __DETAIL_DEBUG__
558 XDBG_DEBUG(MGEST, "num_finger=%d, tap_repeat=%d, cx=%d, cy=%d\n",
559 num_finger, tap_repeat, cx, cy);
560 #endif//__DETAIL_DEBUG__
562 g_pGesture->recognized_gesture |= TapFilterMask;
563 memset(&tev, 0, sizeof(xGestureNotifyTapEvent));
564 tev.type = GestureNotifyTap;
565 tev.kind = GestureDone;
566 tev.num_finger = num_finger;
567 tev.tap_repeat = tap_repeat;
572 if(g_pGesture->GrabEvents)
574 target_win = g_pGesture->GrabEvents[GestureNotifyTap].pGestureGrabWinInfo[num_finger].window;
575 target_pWin = g_pGesture->GrabEvents[GestureNotifyTap].pGestureGrabWinInfo[num_finger].pWin;
583 if( g_pGesture->grabMask && (target_win != None) )
585 tev.window = target_win;
589 tev.window = g_pGesture->gestureWin;
592 #ifdef __DETAIL_DEBUG__
593 XDBG_DEBUG(MGEST, "tev.window=0x%x, g_pGesture->grabMask=0x%x\n", tev.window, g_pGesture->grabMask);
594 #endif//__DETAIL_DEBUG__
596 GestureSendEvent(target_pWin, GestureNotifyTap, GestureTapMask, (xGestureCommonEvent *)&tev);
599 void GestureHandleGesture_PinchRotation(int num_of_fingers, double zoom, double angle, int distance, int cx, int cy, int kinds)
602 WindowPtr target_pWin;
603 xGestureNotifyPinchRotationEvent prev;
605 #ifdef __DETAIL_DEBUG__
606 XDBG_DEBUG(MGEST, "num_fingers=%d, zoom=%.2f, angle=%.2f(deg=%.2f), distance=%d, cx=%d, cy=%d\n",
607 num_of_fingers, zoom, angle, rad2degree(angle), distance, cx, cy);
608 #endif//__DETAIL_DEBUG__
610 g_pGesture->recognized_gesture |= PinchRotationFilterMask;
611 memset(&prev, 0, sizeof(xGestureNotifyPinchRotationEvent));
612 prev.type = GestureNotifyPinchRotation;
614 prev.num_finger = num_of_fingers;
615 prev.zoom = XDoubleToFixed(zoom);
616 prev.angle = XDoubleToFixed(angle);
617 prev.distance = distance;
621 if(g_pGesture->GrabEvents)
623 target_win = g_pGesture->GrabEvents[GestureNotifyPinchRotation].pGestureGrabWinInfo[num_of_fingers].window;
624 target_pWin = g_pGesture->GrabEvents[GestureNotifyPinchRotation].pGestureGrabWinInfo[num_of_fingers].pWin;
632 if( g_pGesture->grabMask && (target_win != None) )
634 prev.window = target_win;
638 prev.window = g_pGesture->gestureWin;
641 #ifdef __DETAIL_DEBUG__
642 XDBG_DEBUG(MGEST, "prev.window=0x%x, g_pGesture->grabMask=0x%x\n", (unsigned int)prev.window, (unsigned int)g_pGesture->grabMask);
643 #endif//__DETAIL_DEBUG__
645 GestureSendEvent(target_pWin, GestureNotifyPinchRotation, GesturePinchRotationMask, (xGestureCommonEvent *)&prev);
648 void GestureHandleGesture_Hold(int num_fingers, int cx, int cy, Time holdtime, int kinds)
651 WindowPtr target_pWin;
652 xGestureNotifyHoldEvent hev;
654 #ifdef __DETAIL_DEBUG__
655 XDBG_DEBUG(MGEST, "num_fingers=%d, cx=%d, cy=%d, holdtime=%d, kinds=%d\n",
656 num_fingers, cx, cy, holdtime, kinds);
657 #endif//__DETAIL_DEBUG__
660 g_pGesture->hold_detected = TRUE;
662 g_pGesture->recognized_gesture |= HoldFilterMask;
663 memset(&hev, 0, sizeof(xGestureNotifyHoldEvent));
664 hev.type = GestureNotifyHold;
666 hev.num_finger = num_fingers;
667 hev.holdtime = holdtime;
671 if(g_pGesture->GrabEvents)
673 target_win = g_pGesture->GrabEvents[GestureNotifyHold].pGestureGrabWinInfo[num_fingers].window;
674 target_pWin = g_pGesture->GrabEvents[GestureNotifyHold].pGestureGrabWinInfo[num_fingers].pWin;
682 if( g_pGesture->grabMask && (target_win != None) )
684 hev.window = target_win;
688 hev.window = g_pGesture->gestureWin;
691 #ifdef __DETAIL_DEBUG__
692 XDBG_DEBUG(MGEST, "hev.window=0x%x, g_pGesture->grabMask=0x%x\n", hev.window, g_pGesture->grabMask);
693 #endif//__DETAIL_DEBUG__
695 GestureSendEvent(target_pWin, GestureNotifyHold, GestureHoldMask, (xGestureCommonEvent *)&hev);
698 void GestureHandleGesture_TapNHold(int num_fingers, int cx, int cy, Time interval, Time holdtime, int kinds)
701 WindowPtr target_pWin;
702 xGestureNotifyTapNHoldEvent thev;
704 #ifdef __DETAIL_DEBUG__
705 XDBG_DEBUG(MGEST, "num_fingers=%d, cx=%d, cy=%d, interval=%d, holdtime=%d, kinds=%d\n",
706 num_fingers, cx, cy, interval, holdtime, kinds);
707 #endif//__DETAIL_DEBUG__
709 g_pGesture->recognized_gesture |= TapNHoldFilterMask;
710 memset(&thev, 0, sizeof(xGestureNotifyTapNHoldEvent));
711 thev.type = GestureNotifyTapNHold;
713 thev.num_finger = num_fingers;
714 thev.holdtime = holdtime;
717 thev.interval = interval;
719 if(g_pGesture->GrabEvents)
721 target_win = g_pGesture->GrabEvents[GestureNotifyTapNHold].pGestureGrabWinInfo[num_fingers].window;
722 target_pWin = g_pGesture->GrabEvents[GestureNotifyTapNHold].pGestureGrabWinInfo[num_fingers].pWin;
730 if( g_pGesture->grabMask && (target_win != None) )
732 thev.window = target_win;
736 thev.window = g_pGesture->gestureWin;
739 #ifdef __DETAIL_DEBUG__
740 XDBG_DEBUG(MGEST, "thev.window=0x%x, g_pGesture->grabMask=0x%x\n", thev.window, g_pGesture->grabMask);
741 #endif//__DETAIL_DEBUG__
743 GestureSendEvent(target_pWin, GestureNotifyTapNHold, GestureTapNHoldMask, (xGestureCommonEvent *)&thev);
746 void GestureHandleGesture_Pan(int num_fingers, short int dx, short int dy, int direction, int distance, Time duration, int kinds)
749 WindowPtr target_pWin;
750 xGestureNotifyPanEvent pev;
752 #ifdef __DETAIL_DEBUG__
753 XDBG_DEBUG(MGEST, "num_fingers=%d, dx=%d, dy=%d, direction=%d, distance=%d, duration=%d, kinds=%d\n",
754 num_fingers, dx, dy, direction, distance, duration, kinds);
755 #endif//__DETAIL_DEBUG__
757 g_pGesture->recognized_gesture |= PanFilterMask;
758 memset(&pev, 0, sizeof(xGestureNotifyPanEvent));
759 pev.type = GestureNotifyPan;
761 pev.num_finger = num_fingers;
762 pev.direction = direction;
763 pev.distance = distance;
764 pev.duration = duration;
768 if(g_pGesture->GrabEvents)
770 target_win = g_pGesture->GrabEvents[GestureNotifyPan].pGestureGrabWinInfo[num_fingers].window;
771 target_pWin = g_pGesture->GrabEvents[GestureNotifyPan].pGestureGrabWinInfo[num_fingers].pWin;
779 if( g_pGesture->grabMask && (target_win != None) )
781 pev.window = target_win;
785 pev.window = g_pGesture->gestureWin;
788 #ifdef __DETAIL_DEBUG__
789 XDBG_DEBUG(MGEST, "pev.window=0x%x, g_pGesture->grabMask=0x%x\n", pev.window, g_pGesture->grabMask);
790 #endif//__DETAIL_DEBUG__
792 GestureSendEvent(target_pWin, GestureNotifyPan, GesturePanMask, (xGestureCommonEvent *)&pev);
795 static void GestureHoldDetector(int type, InternalEvent *ev, DeviceIntPtr device)
799 pixman_region16_t tarea1;
800 static int num_pressed = 0;
801 unsigned int hold_area_size;
802 PalmMiscInfoPtr pPalmMisc = &g_pGesture->palm_misc;
804 if(!g_pGesture->hold_detector_activate)
806 #ifdef __HOLD_DETECTOR_DEBUG__
807 XDBG_DEBUG(MGEST, "g_pGesture->hold_detector_activate=0\n");
808 #endif//__HOLD_DETECTOR_DEBUG__
812 if(!g_pGesture->has_hold_grabmask)
814 Mask eventmask = (1L << GestureNotifyHold);
816 if( (g_pGesture->grabMask & eventmask) &&
817 (g_pGesture->GrabEvents[GestureNotifyHold].pGestureGrabWinInfo[0].window != None) )
819 g_pGesture->has_hold_grabmask = 1;
821 //Initialize a set of variables
823 memset(&g_pGesture->cts, 0, sizeof(g_pGesture->cts));
824 pixman_region_init(&g_pGesture->chold_area);
825 #ifdef __HOLD_DETECTOR_DEBUG__
826 XDBG_DEBUG(MGEST, "[%d] Initialize...\n", __LINE__);
827 #endif//__HOLD_DETECTOR_DEBUG__
831 //reset local hold_grab_mask variable
832 g_pGesture->has_hold_grabmask = 0;
834 g_pGesture->hold_detector_activate = 0;
835 #ifdef __HOLD_DETECTOR_DEBUG__
836 XDBG_DEBUG(MGEST, "has_hold_grabmask=0 and g_pGesture->hold_detector_activate=0\n");
837 #endif//__HOLD_DETECTOR_DEBUG__
842 if( IGNORE_EVENTS == g_pGesture->ehtype ||
843 device->id < g_pGesture->first_fingerid )
845 #ifdef __HOLD_DETECTOR_DEBUG__
846 XDBG_DEBUG(MGEST, "Return (IGNORE_EVENTS or device->id:%d < first_fingerid:%d)\n", device->id, g_pGesture->first_fingerid);
847 #endif//__HOLD_DETECTOR_DEBUG__
851 for( i = 0 ; i < g_pGesture->num_mt_devices ; i++ )
853 if( device->id == g_pGesture->mt_devices[i]->id )
859 if( (idx < 0) || ((MAX_MT_DEVICES-1) < idx )) return;
864 g_pGesture->cts[idx].status = BTN_PRESSED;
865 g_pGesture->cts[idx].cx = ev->device_event.root_x;
866 g_pGesture->cts[idx].cy = ev->device_event.root_y;
869 if(num_pressed < 3) break;
871 if( num_pressed > g_pGesture->num_mt_devices )
872 num_pressed = g_pGesture->num_mt_devices;
874 pixman_region_init(&tarea1);
875 pixman_region_init(&g_pGesture->chold_area);
876 pixman_region_init_rect(&tarea1, g_pGesture->cts[0].cx, g_pGesture->cts[0].cy, g_pGesture->cts[0].cx+1, g_pGesture->cts[0].cy+1);
878 tarea1.extents.x1 = g_pGesture->cts[0].cx;
879 tarea1.extents.x2 = g_pGesture->cts[0].cx+1;
880 tarea1.extents.y1 = g_pGesture->cts[0].cy;
881 tarea1.extents.y2 = g_pGesture->cts[0].cy+1;
883 pixman_region_union(&g_pGesture->chold_area, &tarea1, &tarea1);
885 for( i = 1 ; i < num_pressed ; i++ )
887 pixman_region_init_rect(&tarea1, g_pGesture->cts[i].cx, g_pGesture->cts[i].cy, g_pGesture->cts[i].cx + 1, g_pGesture->cts[i].cy + 1);
889 tarea1.extents.x1 = g_pGesture->cts[i].cx;
890 tarea1.extents.x2 = g_pGesture->cts[i].cx + 1;
891 tarea1.extents.y1 = g_pGesture->cts[i].cy;
892 tarea1.extents.y2 = g_pGesture->cts[i].cy + 1;
894 pixman_region_union(&g_pGesture->chold_area, &g_pGesture->chold_area, &tarea1);
899 if(BTN_RELEASED == g_pGesture->cts[idx].status)
902 g_pGesture->cts[idx].status = BTN_MOVING;
903 g_pGesture->cts[idx].cx = ev->device_event.root_x;
904 g_pGesture->cts[idx].cy = ev->device_event.root_y;
906 if(num_pressed < 3) break;
908 pixman_region_init(&tarea1);
909 pixman_region_init(&g_pGesture->chold_area);
910 pixman_region_init_rect(&tarea1, g_pGesture->cts[0].cx, g_pGesture->cts[0].cy, g_pGesture->cts[0].cx+1, g_pGesture->cts[0].cy+1);
912 tarea1.extents.x1 = g_pGesture->cts[0].cx;
913 tarea1.extents.x2 = g_pGesture->cts[0].cx+1;
914 tarea1.extents.y1 = g_pGesture->cts[0].cy;
915 tarea1.extents.y2 = g_pGesture->cts[0].cy+1;
917 pixman_region_union(&g_pGesture->chold_area, &tarea1, &tarea1);
919 for( i = 1 ; i < num_pressed ; i++ )
921 pixman_region_init_rect(&tarea1, g_pGesture->cts[i].cx, g_pGesture->cts[i].cy, g_pGesture->cts[i].cx + 1, g_pGesture->cts[i].cy + 1);
923 tarea1.extents.x1 = g_pGesture->cts[i].cx;
924 tarea1.extents.x2 = g_pGesture->cts[i].cx + 1;
925 tarea1.extents.y1 = g_pGesture->cts[i].cy;
926 tarea1.extents.y2 = g_pGesture->cts[i].cy + 1;
928 pixman_region_union(&g_pGesture->chold_area, &g_pGesture->chold_area, &tarea1);
932 case ET_ButtonRelease:
933 g_pGesture->cts[idx].status = BTN_RELEASED;
934 g_pGesture->cts[idx].cx = ev->device_event.root_x;
935 g_pGesture->cts[idx].cy = ev->device_event.root_y;
940 pixman_region_init(&g_pGesture->chold_area);
947 hold_area_size = AREA_SIZE(&g_pGesture->chold_area.extents);
949 #ifdef __HOLD_DETECTOR_DEBUG__
950 XDBG_DEBUG(MGEST, "hold_area_size=%d, pPalmMisc->half_scrn_area_size=%d\n", hold_area_size, pPalmMisc->half_scrn_area_size);
951 #endif//__HOLD_DETECTOR_DEBUG__
953 if(pPalmMisc->half_scrn_area_size <= hold_area_size)
955 GestureHandleGesture_Hold(0, AREA_CENTER_X(&g_pGesture->chold_area.extents), AREA_CENTER_Y(&g_pGesture->chold_area.extents), PALM_HOLD_TIME_THRESHOLD, GestureBegin);
956 GestureHandleGesture_Hold(0, AREA_CENTER_X(&g_pGesture->chold_area.extents), AREA_CENTER_Y(&g_pGesture->chold_area.extents), PALM_HOLD_TIME_THRESHOLD, GestureEnd);
958 g_pGesture->hold_detector_activate = 0;
959 g_pGesture->has_hold_grabmask = 0;
965 GestureRecognize_GroupPinchRotation(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired)
969 static int num_pressed = 0;
970 static int state = GestureEnd;
971 static int event_type = GestureNotifyPinchRotation;
972 static OsTimerPtr pinchrotation_event_timer = NULL;
974 static pixman_region16_t base_area;
975 static pixman_region16_t cur_area;
977 static double base_distance = 0.0f;
978 static double base_angle = 0.0f;
980 static double prev_distance = 0.0f;
981 static double prev_angle = 0.0f;
983 static double cur_distance = 0.0f;
984 static double cur_angle = 0.0f;
986 double diff_distance = 0.0f;
987 double diff_angle = 0.0f;
989 static int has_event_mask = 0;
991 static Time base_time = 0;
994 if(g_pGesture->recognized_palm || g_pGesture->enqueue_fulled == 1 || g_pGesture->hold_detected
995 #ifdef _F_SUPPORT_BEZEL_FLICK_
996 || g_pGesture->bezel_recognized_mask)
1000 goto cleanup_pinchrotation;
1004 if( state == GestureEnd )
1006 current_time = GetTimeInMillis();
1007 if( (current_time - base_time) >= g_pGesture->pinchrotation_time_threshold )
1009 #ifdef __DETAIL_DEBUG__
1010 XDBG_DEBUG(MGEST, "[Timer] You must move farther than dist threshold(=%.2f) or angle threshold(=%2f) within time threshold(=%d) !\n", g_pGesture->pinchrotation_dist_threshold, g_pGesture->pinchrotation_angle_threshold, g_pGesture->pinchrotation_time_threshold);
1011 #endif//__DETAIL_DEBUG__
1012 goto cleanup_pinchrotation;
1021 case ET_ButtonPress:
1022 g_pGesture->fingers[idx].flags |= PressFlagPinchRotation;
1024 if( g_pGesture->num_pressed < 2 )
1027 if( g_pGesture->num_pressed < num_pressed && state != GestureEnd )
1029 #ifdef __DETAIL_DEBUG__
1030 XDBG_DEBUG(MGEST, "[P][cleanup] num_finger changed !(state: %d) num_pressed=%d, g_pGesture->num_pressed=%d\n", state, num_pressed, g_pGesture->num_pressed);
1031 #endif//__DETAIL_DEBUG__
1032 goto cleanup_pinchrotation;
1035 if( base_distance == 0.0f && g_pGesture->num_pressed == 2 )
1037 #ifdef __DETAIL_DEBUG__
1038 XDBG_DEBUG(MGEST, "[First Time !!!] num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1039 #endif//__DETAIL_DEBUG__
1041 base_time = GetTimeInMillis();
1042 pixman_region_init(&base_area);
1043 pixman_region_union(&base_area, &g_pGesture->finger_rects[0], &g_pGesture->finger_rects[1]);
1045 prev_distance = base_distance = AREA_DIAG_LEN(&base_area.extents);
1047 #ifdef __DETAIL_DEBUG__
1048 XDBG_DEBUG(MGEST, "[P] x1=%d, x2=%d, y1=%d, y2=%d\n", g_pGesture->fingers[0].px, g_pGesture->fingers[1].px,
1049 g_pGesture->fingers[0].py, g_pGesture->fingers[1].py);
1050 #endif//__DETAIL_DEBUG__
1052 prev_angle = base_angle = get_angle(g_pGesture->fingers[0].px, g_pGesture->fingers[0].py, g_pGesture->fingers[1].px, g_pGesture->fingers[1].py);
1053 #ifdef __DETAIL_DEBUG__
1054 XDBG_DEBUG(MGEST, "[P] base_angle=%.2f(deg=%.2f)\n", base_angle, rad2degree(base_angle));
1055 #endif//__DETAIL_DEBUG__
1056 event_type = GestureNotifyPinchRotation;
1057 pinchrotation_event_timer = TimerSet(pinchrotation_event_timer, 0, g_pGesture->pinchrotation_time_threshold, GestureEventTimerHandler, (int *)&event_type);
1059 num_pressed = g_pGesture->num_pressed;
1061 #ifdef __DETAIL_DEBUG__
1062 XDBG_DEBUG(MGEST, "[P][num_pressed=%d] AREA_SIZE(base_area.extents)=%d\n", num_pressed, AREA_SIZE(&base_area.extents));
1063 XDBG_DEBUG(MGEST, "[P][num_pressed=%d] base_distance=%.2f, base_angle=%.2f(deg=%.2f)\n", num_pressed, base_distance, base_angle, rad2degree(base_angle));
1064 #endif//__DETAIL_DEBUG__
1068 if( !(g_pGesture->fingers[idx].flags & PressFlagPinchRotation) )
1071 if( (num_pressed != g_pGesture->num_pressed) && (state != GestureEnd) )
1073 #ifdef __DETAIL_DEBUG__
1074 XDBG_DEBUG(MGEST, "[M][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1075 #endif//__DETAIL_DEBUG__
1076 goto cleanup_pinchrotation;
1079 if( num_pressed < 2 )
1082 if( g_pGesture->fingers[0].mx && g_pGesture->fingers[0].my && g_pGesture->fingers[1].mx && g_pGesture->fingers[1].my )
1084 pixman_region_init(&cur_area);
1085 pixman_region_union(&cur_area, &g_pGesture->finger_rects[0], &g_pGesture->finger_rects[1]);
1087 cur_distance = AREA_DIAG_LEN(&cur_area.extents);
1089 #ifdef __DETAIL_DEBUG__
1090 XDBG_DEBUG(MGEST, "[M] x1=%d, x2=%d, y1=%d, y2=%d\n", g_pGesture->fingers[0].mx, g_pGesture->fingers[1].mx,
1091 g_pGesture->fingers[0].my, g_pGesture->fingers[1].my);
1092 #endif//__DETAIL_DEBUG__
1094 cur_angle = get_angle(g_pGesture->fingers[0].mx, g_pGesture->fingers[0].my, g_pGesture->fingers[1].mx, g_pGesture->fingers[1].my);
1095 #ifdef __DETAIL_DEBUG__
1096 XDBG_DEBUG(MGEST, "[M] cur_angle=%.2f(deg=%.2f)\n", cur_angle, rad2degree(cur_angle));
1097 #endif//__DETAIL_DEBUG__
1099 diff_distance = prev_distance - cur_distance;
1100 diff_angle = prev_angle - cur_angle;
1102 cx = AREA_CENTER_X(&cur_area.extents);
1103 cy = AREA_CENTER_Y(&cur_area.extents);
1105 #ifdef __DETAIL_DEBUG__
1106 XDBG_DEBUG(MGEST, "[M][state=%d] cx=%d, cy=%d\n", state, cx, cy);
1107 #endif//__DETAIL_DEBUG__
1109 #ifdef __DETAIL_DEBUG__
1110 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] prev_distance=%.2f, cur_distance=%.2f, diff=%.2f\n", num_pressed, prev_distance, cur_distance, diff_distance);
1111 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] prev_angle=%.2f(deg=%.2f), cur_angle=%.2f(deg=%.2f), diff=%.2f(deg=%.2f)\n", num_pressed, prev_angle, rad2degree(prev_angle), cur_angle, rad2degree(cur_angle), diff_angle, rad2degree(diff_angle));
1112 #endif//__DETAIL_DEBUG__
1117 if( (ABS(diff_distance) >= g_pGesture->pinchrotation_dist_threshold) || (ABS(diff_angle) >= g_pGesture->pinchrotation_angle_threshold) )
1119 #ifdef __DETAIL_DEBUG__
1120 if( ABS(diff_distance) >= g_pGesture->pinchrotation_dist_threshold )
1121 XDBG_DEBUG(MGEST, "[M] zoom changed !\n");
1123 if( ABS(diff_angle) >= g_pGesture->pinchrotation_angle_threshold )
1124 XDBG_DEBUG(MGEST, "[M] angle changed !\n");
1125 #endif//__DETAIL_DEBUG__
1127 TimerCancel(pinchrotation_event_timer);
1128 state = GestureBegin;
1129 goto gesture_begin_handle;
1134 gesture_begin_handle:
1135 #ifdef __DETAIL_DEBUG__
1136 XDBG_DEBUG(MGEST, "PINCHROTATION Begin !cx=%d, cy=%d, state=%d\n", cx, cy, state);
1137 #endif//__DETAIL_DEBUG__
1138 if( GestureHasFingerEventMask(GestureNotifyPinchRotation, num_pressed) )
1140 GestureHandleGesture_PinchRotation(num_pressed, cur_distance / base_distance, (cur_angle > base_angle) ? (cur_angle-base_angle) : (RAD_360DEG + cur_angle - base_angle), cur_distance, cx, cy, GestureBegin);
1141 prev_distance = cur_distance;
1142 prev_angle = cur_angle;
1143 state = GestureUpdate;
1149 goto cleanup_pinchrotation;
1154 //if( ABS(diff_distance) < g_pGesture->pinchrotation_dist_threshold && ABS(diff_angle) < g_pGesture->pinchrotation_angle_threshold )
1157 #ifdef __DETAIL_DEBUG__
1158 if( ABS(diff_distance) >= g_pGesture->pinchrotation_dist_threshold )
1159 XDBG_DEBUG(MGEST, "[M] zoom changed !\n");
1161 if( ABS(diff_angle) >= g_pGesture->pinchrotation_angle_threshold )
1162 XDBG_DEBUG(MGEST, "[M] angle changed !\n");
1163 #endif//__DETAIL_DEBUG__
1165 #ifdef __DETAIL_DEBUG__
1166 XDBG_DEBUG(MGEST, "PINCHROTATION Update ! cx=%d, cy=%d, state=%d\n", cx, cy, state);
1167 #endif//__DETAIL_DEBUG__
1168 GestureHandleGesture_PinchRotation(num_pressed, cur_distance / base_distance, (cur_angle > base_angle) ? (cur_angle-base_angle) : (RAD_360DEG + cur_angle - base_angle), cur_distance, cx, cy, GestureUpdate);
1169 prev_distance = cur_distance;
1170 prev_angle = cur_angle;
1180 case ET_ButtonRelease:
1181 if( state != GestureEnd && num_pressed >= 2)
1183 #ifdef __DETAIL_DEBUG__
1184 XDBG_DEBUG(MGEST, "[R][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1185 #endif//__DETAIL_DEBUG__
1186 goto cleanup_pinchrotation;
1189 if( g_pGesture->num_pressed )
1192 goto cleanup_pinchrotation;
1198 cleanup_pinchrotation:
1199 g_pGesture->filter_mask |= PinchRotationFilterMask;
1200 if( has_event_mask && (state == GestureBegin || state == GestureUpdate) )
1203 #ifdef __DETAIL_DEBUG__
1204 XDBG_DEBUG(MGEST, "PINCHROTATION End ! cx=%d, cy=%d, state=%d\n", cx, cy, state);
1205 #endif//__DETAIL_DEBUG__
1206 GestureHandleGesture_PinchRotation(num_pressed, cur_distance / base_distance, (cur_angle > base_angle) ? (cur_angle-base_angle) : (RAD_360DEG + cur_angle - base_angle), cur_distance, cx, cy, GestureEnd);
1208 else if(g_pGesture->num_pressed > 1)
1210 if(!(g_pGesture->filter_mask & PanFilterMask))
1212 pixman_region_init(&base_area);
1213 pixman_region_union(&base_area, &g_pGesture->finger_rects[0], &g_pGesture->finger_rects[1]);
1215 prev_distance = base_distance = AREA_DIAG_LEN(&base_area.extents);
1216 prev_angle = base_angle = get_angle(g_pGesture->fingers[0].px, g_pGesture->fingers[0].py, g_pGesture->fingers[1].px, g_pGesture->fingers[1].py);
1218 g_pGesture->filter_mask &= ~PinchRotationFilterMask;
1222 g_pGesture->recognized_gesture &= ~PinchRotationFilterMask;
1225 if( g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL )
1227 #ifdef __DETAIL_DEBUG__
1228 XDBG_DEBUG(MGEST, "[cleanup] GestureFlushOrDrop() !\n");
1229 #endif//__DETAIL_DEBUG__
1231 if( ERROR_INVALPTR == GestureFlushOrDrop() )
1233 GestureControl(g_pGesture->this_device, DEVICE_OFF);
1237 prev_distance = base_distance = 0.0f;
1238 prev_angle = base_angle = 0.0f;
1239 has_event_mask = num_pressed = 0;
1242 TimerCancel(pinchrotation_event_timer);
1247 GestureRecognize_GroupFlick(int type, InternalEvent *ev, DeviceIntPtr device, int idx)
1249 static int num_pressed = 0;
1250 static int mbits = 0;
1251 static int base_area_size = 0;
1252 static Time base_time = 0;
1253 static int base_x, base_y;
1257 int distance, direction;
1261 if(g_pGesture->recognized_palm || g_pGesture->enqueue_fulled == 1 || g_pGesture->hold_detected
1262 #ifdef _F_SUPPORT_BEZEL_FLICK_
1263 || g_pGesture->bezel_recognized_mask)
1271 case ET_ButtonPress:
1272 g_pGesture->fingers[idx].flags |= PressFlagFlick;
1273 if( g_pGesture->num_pressed < 2 )
1276 if( !base_area_size || g_pGesture->num_pressed > num_pressed )
1278 base_area_size = AREA_SIZE(&g_pGesture->area.extents);
1279 base_x = g_pGesture->area.extents.x1;
1280 base_y = g_pGesture->area.extents.y1;
1281 base_time = GetTimeInMillis();
1283 num_pressed = g_pGesture->num_pressed;
1285 #ifdef __DETAIL_DEBUG__
1286 XDBG_DEBUG(MGEST, "[P]][num_pressed=%d] AREA_SIZE(area.extents)=%d\n", num_pressed, base_area_size);
1287 #endif//__DETAIL_DEBUG__
1291 if( !(g_pGesture->fingers[idx].flags & PressFlagFlick ) )
1294 #ifdef __DETAIL_DEBUG__
1295 if( num_pressed > g_pGesture->num_pressed )
1297 XDBG_DEBUG(MGEST, "[M][cleanup] num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1298 //goto cleanup_flick;
1300 #endif//__DETAIL_DEBUG__
1302 if( num_pressed < 2 )
1305 mbits |= (1 << idx);
1306 if( mbits == (pow(2, num_pressed)-1) )
1308 area_size = AREA_SIZE(&g_pGesture->area.extents);
1309 #ifdef __DETAIL_DEBUG__
1310 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] AREA_SIZE(area.extents)=%d\n", num_pressed, area_size);
1311 #endif//__DETAIL_DEBUG__
1312 if( ABS(base_area_size - area_size) >= FLICK_AREA_THRESHOLD )
1314 #ifdef __DETAIL_DEBUG__
1315 XDBG_DEBUG(MGEST, "[M] diff between Area size(=%d) and base area size(=%d) is bigger than threshold(=%d)!\n", area_size, base_area_size, FLICK_AREA_THRESHOLD);
1316 #endif//__DETAIL_DEBUG__
1320 current_time = GetTimeInMillis();
1321 if( (current_time - base_time) >= FLICK_AREA_TIMEOUT )
1323 #ifdef __DETAIL_DEBUG__
1324 XDBG_DEBUG(MGEST, "[M] diff between current time(=%d) and base time(=%d) is bigger than threashold(=%d) !\n", current_time, base_time, FLICK_AREA_TIMEOUT);
1325 #endif//__DETAIL_DEBUG__
1332 case ET_ButtonRelease:
1333 if( g_pGesture->num_pressed )
1336 duration = GetTimeInMillis() - base_time;
1337 distx = g_pGesture->area.extents.x1 - base_x;
1338 disty = g_pGesture->area.extents.y1 - base_y;
1340 #ifdef __DETAIL_DEBUG__
1341 XDBG_DEBUG(MGEST, "duration=%d, distx=%d, disty=%d\n", duration, distx, disty);
1342 #endif//__DETAIL_DEBUG__
1344 if( duration <= 0 || duration >= FLICK_AREA_TIMEOUT )
1347 if( ABS(distx) >= FLICK_MOVE_THRESHOLD )
1349 direction = (distx > 0) ? FLICK_EASTWARD : FLICK_WESTWARD;
1350 distance = ABS(distx);
1353 else if( ABS(disty) >= FLICK_MOVE_THRESHOLD )
1355 direction = (disty > 0) ? FLICK_SOUTHWARD : FLICK_NORTHWARD;
1356 distance = ABS(disty);
1363 if( GestureHasFingerEventMask(GestureNotifyFlick, num_pressed) )
1364 GestureHandleGesture_Flick(num_pressed, distance, duration, direction);
1365 goto cleanup_flick_recognized;
1373 g_pGesture->recognized_gesture &= ~FlickFilterMask;
1375 cleanup_flick_recognized:
1377 g_pGesture->filter_mask |= FlickFilterMask;
1386 GestureRecognize_GroupPan(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired)
1388 static int num_pressed = 0;
1389 static int mbits = 0;
1390 static int base_area_size = 0;
1391 static Time base_time = 0;
1392 static pixman_box16_t base_box_ext;
1400 static Time prev_time = 0;
1401 Time current_time = 0;
1405 static int time_checked = 0;
1406 static int state = GestureEnd;
1408 static OsTimerPtr pan_event_timer = NULL;
1409 static int event_type = GestureNotifyPan;
1411 if(g_pGesture->recognized_palm || g_pGesture->enqueue_fulled == 1 || g_pGesture->hold_detected
1412 #ifdef _F_SUPPORT_BEZEL_FLICK_
1413 || g_pGesture->bezel_recognized_mask)
1423 current_time = GetTimeInMillis();
1424 if( (current_time - base_time) >= PAN_TIME_THRESHOLD )
1426 if( (!cx && !cy) || INBOX(&base_box_ext, cx, cy) )
1428 #ifdef __DETAIL_DEBUG__
1429 XDBG_DEBUG(MGEST, "[Timer] You must move farther than move threshold(=%d) within time threshold(=%d) !\n", PAN_MOVE_THRESHOLD*2, PAN_TIME_THRESHOLD);
1430 #endif//__DETAIL_DEBUG__
1441 case ET_ButtonPress:
1442 g_pGesture->fingers[idx].flags |= PressFlagPan;
1444 if( g_pGesture->num_pressed < 2 )
1447 if( !base_area_size || g_pGesture->num_pressed > num_pressed )
1449 if( state != GestureEnd )
1451 #ifdef __DETAIL_DEBUG__
1452 XDBG_DEBUG(MGEST, "[P][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1453 #endif//__DETAIL_DEBUG__
1456 base_area_size = AREA_SIZE(&g_pGesture->area.extents);
1457 prev_cx = base_cx = AREA_CENTER_X(&g_pGesture->area.extents);
1458 prev_cy = base_cy = AREA_CENTER_Y(&g_pGesture->area.extents);
1459 prev_time = base_time = GetTimeInMillis();
1460 base_box_ext.x1 = base_cx-PAN_MOVE_THRESHOLD;
1461 base_box_ext.y1 = base_cy-PAN_MOVE_THRESHOLD;
1462 base_box_ext.x2 = base_cx+PAN_MOVE_THRESHOLD;
1463 base_box_ext.y2 = base_cy+PAN_MOVE_THRESHOLD;
1464 event_type = GestureNotifyPan;
1465 pan_event_timer = TimerSet(pan_event_timer, 0, PAN_TIME_THRESHOLD, GestureEventTimerHandler, (int *)&event_type);
1467 num_pressed = g_pGesture->num_pressed;
1469 #ifdef __DETAIL_DEBUG__
1470 XDBG_DEBUG(MGEST, "[P][num_pressed=%d] AREA_SIZE(area.extents)=%d, base_cx=%d, base_cy=%d\n", num_pressed, base_area_size, base_cx, base_cy);
1471 #endif//__DETAIL_DEBUG__
1475 if( !(g_pGesture->fingers[idx].flags & PressFlagPan ) )
1478 if( num_pressed != g_pGesture->num_pressed )
1480 if( state != GestureEnd )
1482 #ifdef __DETAIL_DEBUG__
1483 XDBG_DEBUG(MGEST, "[M][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1484 #endif//__DETAIL_DEBUG__
1489 if( num_pressed < 2 )
1492 mbits |= (1 << idx);
1493 if( mbits == (pow(2, num_pressed)-1) )
1495 area_size = AREA_SIZE(&g_pGesture->area.extents);
1496 #ifdef __DETAIL_DEBUG__
1497 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] area_size=%d, base_area_size=%d, diff=%d\n", num_pressed, area_size, base_area_size, ABS(base_area_size - area_size));
1498 #endif//__DETAIL_DEBUG__
1500 if( (state != GestureUpdate) && (ABS(base_area_size - area_size) >= PAN_AREA_THRESHOLD) )
1502 #ifdef __DETAIL_DEBUG__
1503 XDBG_DEBUG(MGEST, "[M] diff between area size(=%d) and base area size(=%d) is bigger than threshold(=%d)!\n", area_size, base_area_size, PAN_AREA_THRESHOLD);
1504 #endif//__DETAIL_DEBUG__
1508 cx = AREA_CENTER_X(&g_pGesture->area.extents);
1509 cy = AREA_CENTER_Y(&g_pGesture->area.extents);
1510 #ifdef __DETAIL_DEBUG__
1511 XDBG_DEBUG(MGEST, "[M] cx=%d, prev_cx=%d, diff=%d\n", cx, prev_cx, ABS(cx-prev_cx));
1512 XDBG_DEBUG(MGEST, "[M] cy=%d, prev_cy=%d, diff=%d\n", cy, prev_cy, ABS(cy-prev_cy));
1513 #endif//__DETAIL_DEBUG__
1515 if( state <= GestureBegin )
1517 if( !INBOX(&base_box_ext, cx, cy) )
1519 TimerCancel(pan_event_timer);
1520 pan_event_timer = NULL;
1522 if( GestureHasFingerEventMask(GestureNotifyPan, num_pressed) )
1524 GestureHandleGesture_Pan(num_pressed, prev_cx, prev_cy, direction, distance, current_time-prev_time, GestureBegin);
1525 state = GestureUpdate;
1536 //if( ABS(dx) >= PAN_UPDATE_MOVE_THRESHOLD || ABS(dy) >= PAN_UPDATE_MOVE_THRESHOLD )
1538 #ifdef __DETAIL_DEBUG__
1539 XDBG_DEBUG(MGEST, "PAN Update !dx=%d, dy=%d, state=%d\n", dx, dy, state);
1540 #endif//__DETAIL_DEBUG__
1542 GestureHandleGesture_Pan(num_pressed, dx, dy, direction, distance, current_time-prev_time, GestureUpdate);
1552 case ET_ButtonRelease:
1553 if( state != GestureEnd && num_pressed >= 2)
1555 #ifdef __DETAIL_DEBUG__
1556 XDBG_DEBUG(MGEST, "[R][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1557 #endif//__DETAIL_DEBUG__
1561 if( g_pGesture->num_pressed )
1571 g_pGesture->filter_mask |= PanFilterMask;
1572 if( state == GestureBegin || state == GestureUpdate )
1575 if( GestureHasFingerEventMask(GestureNotifyPan, num_pressed) )
1577 GestureHandleGesture_Pan(num_pressed, (short int)(cx-prev_cx), (short int)(cy-prev_cy), direction, distance, GetTimeInMillis()-prev_time, GestureEnd);
1580 else if(g_pGesture->num_pressed > 1)
1582 if(!(g_pGesture->filter_mask & PinchRotationFilterMask))
1584 base_area_size = AREA_SIZE(&g_pGesture->area.extents);
1585 prev_cx = base_cx = AREA_CENTER_X(&g_pGesture->area.extents);
1586 prev_cy = base_cy = AREA_CENTER_Y(&g_pGesture->area.extents);
1587 prev_time = base_time = GetTimeInMillis();
1588 base_box_ext.x1 = base_cx-PAN_MOVE_THRESHOLD;
1589 base_box_ext.y1 = base_cy-PAN_MOVE_THRESHOLD;
1590 base_box_ext.x2 = base_cx+PAN_MOVE_THRESHOLD;
1591 base_box_ext.y2 = base_cy+PAN_MOVE_THRESHOLD;
1592 g_pGesture->filter_mask &= ~PanFilterMask;
1595 g_pGesture->recognized_gesture &= ~PanFilterMask;
1606 base_box_ext.x1 = base_box_ext.x2 = base_box_ext.y1 = base_box_ext.y2 = 0;
1607 if( pan_event_timer )
1609 TimerCancel(pan_event_timer);
1610 pan_event_timer = NULL;
1616 GestureRecognize_GroupTap(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired)
1618 static int num_pressed = 0;
1619 static int base_area_size = 0;
1621 static Time base_time = 0;
1626 static int state = GestureEnd;
1627 static int mbits = 0;
1630 static pixman_box16_t base_box_ext;
1632 static int tap_repeat = 0;
1633 static int prev_num_pressed = 0;
1635 static OsTimerPtr tap_event_timer = NULL;
1636 static int event_type = GestureNotifyTap;
1638 if(g_pGesture->recognized_palm || g_pGesture->enqueue_fulled == 1 || g_pGesture->hold_detected
1639 #ifdef _F_SUPPORT_BEZEL_FLICK_
1640 || g_pGesture->bezel_recognized_mask)
1648 #ifdef __DETAIL_DEBUG__
1649 XDBG_DEBUG(MGEST, "[Timer] state=%d\n", state);
1650 #endif//__DETAIL_DEBUG__
1654 case GestureBegin://first tap initiation check
1657 #ifdef __DETAIL_DEBUG__
1658 XDBG_DEBUG(MGEST, "[Timer][state=1] Tap time expired !(num_pressed=%d, tap_repeat=%d)\n", num_pressed, tap_repeat);
1659 #endif//__DETAIL_DEBUG__
1666 if( tap_repeat <= 1 )
1668 #ifdef __DETAIL_DEBUG__
1669 XDBG_DEBUG(MGEST, "[Timer][state=2] %d finger SINGLE TAP !(ignored)\n", prev_num_pressed);
1670 #endif//__DETAIL_DEBUG__
1675 #ifdef __DETAIL_DEBUG__
1676 XDBG_DEBUG(MGEST, "[Timer][state=2] tap_repeat=%d, num_pressed=%d\n", tap_repeat, num_pressed);
1677 #endif//__DETAIL_DEBUG__
1678 if( GestureHasFingerEventMask(GestureNotifyTap, prev_num_pressed) )
1680 if(prev_num_pressed == 2 && tap_repeat == 2)
1682 g_pGesture->zoom_enabled = (g_pGesture->zoom_enabled + 1)%2;
1683 if(g_pGesture->zoom_enabled == 1)
1685 g_pGesture->recognized_gesture |= TapFilterMask;
1688 GestureHandleGesture_Tap(prev_num_pressed, tap_repeat, base_cx, base_cy);
1699 case ET_ButtonPress:
1700 g_pGesture->fingers[idx].flags |= PressFlagTap;
1702 if( g_pGesture->num_pressed < 2 )
1705 if( !prev_num_pressed && (!base_area_size || g_pGesture->num_pressed > num_pressed) )
1707 base_area_size = AREA_SIZE(&g_pGesture->area.extents);
1708 base_cx = AREA_CENTER_X(&g_pGesture->area.extents);
1709 base_cy = AREA_CENTER_Y(&g_pGesture->area.extents);
1710 base_time = GetTimeInMillis();
1711 base_box_ext.x1 = base_cx-TAP_MOVE_THRESHOLD;
1712 base_box_ext.y1 = base_cy-TAP_MOVE_THRESHOLD;
1713 base_box_ext.x2 = base_cx+TAP_MOVE_THRESHOLD;
1714 base_box_ext.y2 = base_cy+TAP_MOVE_THRESHOLD;
1715 state = GestureBegin;
1716 TimerCancel(tap_event_timer);
1717 tap_event_timer = TimerSet(tap_event_timer, 0, g_pGesture->singletap_threshold, GestureEventTimerHandler, (int *)&event_type);
1720 num_pressed = g_pGesture->num_pressed;
1722 #ifdef __DETAIL_DEBUG__
1723 XDBG_DEBUG(MGEST, "[P][num_pressed=%d] AREA_SIZE(area.extents)=%d, base_cx=%d, base_cy=%d, base_time=%d, current_time=%d\n", num_pressed, base_area_size, base_cx, base_cy, base_time, GetTimeInMillis());
1724 #endif//__DETAIL_DEBUG__
1728 if( !(g_pGesture->fingers[idx].flags & PressFlagTap ) )
1731 if( num_pressed < 2 )
1734 #ifdef __DETAIL_DEBUG__
1735 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] g_pGesture->num_pressed: %d\n", num_pressed, g_pGesture->num_pressed);
1736 #endif//__DETAIL_DEBUG__
1738 if( num_pressed != g_pGesture->num_pressed )
1740 #ifdef __DETAIL_DEBUG__
1741 XDBG_DEBUG(MGEST, "[M][cleanup] num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1742 #endif//__DETAIL_DEBUG__
1747 mbits |= (1 << idx);
1748 if( mbits == (pow(2, num_pressed)-1) )
1750 area_size = AREA_SIZE(&g_pGesture->area.extents);
1751 cx = AREA_CENTER_X(&g_pGesture->area.extents);
1752 cy = AREA_CENTER_Y(&g_pGesture->area.extents);
1753 #ifdef __DETAIL_DEBUG__
1754 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] area_size=%d, base_area_size=%d, diff=%d\n", num_pressed, area_size, base_area_size, ABS(base_area_size - area_size));
1755 XDBG_DEBUG(MGEST, "[M] cx=%d, base_cx=%d, diff=%d\n", cx, base_cx, ABS(cx-base_cx));
1756 XDBG_DEBUG(MGEST, "[M] cy=%d, base_cy=%d, diff=%d\n", cy, base_cy, ABS(cy-base_cy));
1757 #endif//__DETAIL_DEBUG__
1759 if( ABS(base_area_size-area_size) >= TAP_AREA_THRESHOLD )
1761 #ifdef __DETAIL_DEBUG__
1762 XDBG_DEBUG(MGEST, "[M] diff between area size(=%d) and base area size(=%d) is bigger than threshold(=%d)!\n", area_size, base_area_size, ABS(base_area_size-area_size));
1763 #endif//__DETAIL_DEBUG__
1767 if( !INBOX(&base_box_ext, cx, cy) )
1769 #ifdef __DETAIL_DEBUG__
1770 XDBG_DEBUG(MGEST, "[M] current center coordinates is not in base coordinates box !\n");
1771 #endif//__DETAIL_DEBUG__
1777 case ET_ButtonRelease:
1778 if( g_pGesture->num_pressed )
1785 prev_num_pressed = num_pressed;
1789 g_pGesture->tap_repeated = tap_repeat;
1791 #ifdef __DETAIL_DEBUG__
1792 XDBG_DEBUG(MGEST, "[R] tap_repeat=%d, num_pressed=%d, prev_num_pressed=%d\n", tap_repeat, num_pressed, prev_num_pressed);
1793 #endif//__DETAIL_DEBUG__
1795 if( num_pressed != prev_num_pressed || !GestureHasFingerEventMask(GestureNotifyTap, num_pressed) )
1797 #ifdef __DETAIL_DEBUG__
1798 XDBG_DEBUG(MGEST, "[R] num_pressed(=%d) != prev_num_pressed(=%d) OR %d finger tap event was not grabbed/selected !\n",
1799 num_pressed, prev_num_pressed, num_pressed);
1800 #endif//__DETAIL_DEBUG__
1804 if( tap_repeat < MAX_TAP_REPEATS )
1806 state = GestureUpdate;
1807 TimerCancel(tap_event_timer);
1808 tap_event_timer = TimerSet(tap_event_timer, 0, g_pGesture->doubletap_threshold, GestureEventTimerHandler, (int *)&event_type);
1813 #ifdef __DETAIL_DEBUG__
1814 XDBG_DEBUG(MGEST, "[R] %d finger %s\n", num_pressed, (tap_repeat==2) ? "DBL_TAP" : "TRIPLE_TAP");
1815 #endif//__DETAIL_DEBUG__
1817 if( GestureHasFingerEventMask(GestureNotifyTap, num_pressed) )
1818 GestureHandleGesture_Tap(num_pressed, tap_repeat, base_cx, base_cy);
1820 if( tap_repeat >= MAX_TAP_REPEATS )
1825 prev_num_pressed = num_pressed;
1834 if( GestureEnd == state )
1835 g_pGesture->recognized_gesture &= ~TapFilterMask;
1836 g_pGesture->filter_mask |= TapFilterMask;
1838 if( g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL )
1840 #ifdef __DETAIL_DEBUG__
1841 XDBG_DEBUG(MGEST, "[cleanup] GestureFlushOrDrop() !\n");
1842 #endif//__DETAIL_DEBUG__
1844 if( ERROR_INVALPTR == GestureFlushOrDrop() )
1846 GestureControl(g_pGesture->this_device, DEVICE_OFF);
1852 g_pGesture->tap_repeated = 0;
1853 prev_num_pressed = 0;
1857 TimerCancel(tap_event_timer);
1862 GestureRecognize_GroupTapNHold(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired)
1864 static int num_pressed = 0;
1865 static int base_area_size = 0;
1866 static Time base_time = 0;
1870 static pixman_box16_t base_box_ext;
1872 static int mbits = 0;
1874 static int tap_repeat = 0;
1875 static int prev_num_pressed = 0;
1877 static OsTimerPtr tapnhold_event_timer = NULL;
1878 static int event_type = GestureNotifyTapNHold;
1879 static int state = GestureEnd;
1884 if(g_pGesture->recognized_palm || g_pGesture->enqueue_fulled == 1 || g_pGesture->hold_detected
1885 #ifdef _F_SUPPORT_BEZEL_FLICK_
1886 || g_pGesture->bezel_recognized_mask)
1890 goto cleanup_tapnhold;
1894 if( (state == GestureEnd) && num_pressed )
1896 #ifdef __DETAIL_DEBUG__
1897 XDBG_DEBUG(MGEST, "[Timer][state=%d] Tap time expired !(num_pressed=%d, tap_repeat=%d)\n", GestureEnd, tap_repeat, num_pressed, tap_repeat);
1898 #endif//__DETAIL_DEBUG__
1900 goto cleanup_tapnhold;
1903 if( state == GestureDone )
1905 #ifdef __DETAIL_DEBUG__
1906 XDBG_DEBUG(MGEST, "[Timer][state=%d] Interval between Tap and Hold is too long !\n");
1907 #endif//__DETAIL_DEBUG__
1908 goto cleanup_tapnhold;
1911 #ifdef __DETAIL_DEBUG__
1915 XDBG_DEBUG(MGEST, "[Timer] TapNHold Begin !\n");
1919 XDBG_DEBUG(MGEST, "[Timer] TapNHold Update !\n");
1922 #endif//__DETAIL_DEBUG__
1924 if( GestureHasFingerEventMask(GestureNotifyTapNHold, prev_num_pressed) )
1926 GestureHandleGesture_TapNHold(prev_num_pressed, base_cx, base_cy, interval, holdtime, state);
1927 tapnhold_event_timer = TimerSet(tapnhold_event_timer, 0, TAPNHOLD_HOLD_TIME_THRESHOLD, GestureEventTimerHandler, (int *)&event_type);
1931 #ifdef __DETAIL_DEBUG__
1932 XDBG_DEBUG(MGEST, "[Timer] %d finger TapNHold event was not grabbed/selected !\n", prev_num_pressed);
1933 #endif//__DETAIL_DEBUG__
1934 goto cleanup_tapnhold;
1937 if( state <= GestureBegin )
1944 case ET_ButtonPress:
1945 g_pGesture->fingers[idx].flags |= PressFlagTapNHold;
1947 if( g_pGesture->num_pressed < 2 )
1950 //if( !prev_num_pressed && (!base_area_size || g_pGesture->num_pressed > num_pressed) )
1951 if( !base_area_size || g_pGesture->num_pressed > num_pressed )
1954 if( state == GestureUpdate )
1956 #ifdef __DETAIL_DEBUG__
1957 XDBG_DEBUG(MGEST, "[P][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
1958 #endif//__DETAIL_DEBUG__
1959 goto cleanup_tapnhold;
1962 if( state == GestureDone )
1963 state = GestureBegin;
1965 base_area_size = AREA_SIZE(&g_pGesture->area.extents);
1966 base_cx = AREA_CENTER_X(&g_pGesture->area.extents);
1967 base_cy = AREA_CENTER_Y(&g_pGesture->area.extents);
1968 base_time = GetTimeInMillis();
1969 base_box_ext.x1 = base_cx-TAPNHOLD_MOVE_THRESHOLD;
1970 base_box_ext.y1 = base_cy-TAPNHOLD_MOVE_THRESHOLD;
1971 base_box_ext.x2 = base_cx+TAPNHOLD_MOVE_THRESHOLD;
1972 base_box_ext.y2 = base_cy+TAPNHOLD_MOVE_THRESHOLD;
1973 if( state == GestureEnd )
1974 tapnhold_event_timer = TimerSet(tapnhold_event_timer, 0, TAPNHOLD_TAP_TIME_THRESHOLD, GestureEventTimerHandler, (int *)&event_type);
1977 TimerCancel(tapnhold_event_timer);
1978 tapnhold_event_timer = TimerSet(tapnhold_event_timer, 0, TAPNHOLD_HOLD_TIME_THRESHOLD, GestureEventTimerHandler, (int *)&event_type);
1980 #ifdef __DETAIL_DEBUG__
1981 XDBG_DEBUG(MGEST, "[P] Create Timer !(state=%d)\n", state);
1982 #endif//__DETAIL_DEBUG__
1985 num_pressed = g_pGesture->num_pressed;
1987 #ifdef __DETAIL_DEBUG__
1988 XDBG_DEBUG(MGEST, "[P][num_pressed=%d] AREA_SIZE(area.extents)=%d, base_cx=%d, base_cy=%d, base_time=%d\n", num_pressed, base_area_size, base_cx, base_cy, base_time);
1989 #endif//__DETAIL_DEBUG__
1993 if( !(g_pGesture->fingers[idx].flags & PressFlagTapNHold ) )
1996 if( num_pressed < 2 )
1999 if( num_pressed != g_pGesture->num_pressed )
2001 if( state != GestureEnd )
2003 #ifdef __DETAIL_DEBUG__
2004 XDBG_DEBUG(MGEST, "[M][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2005 #endif//__DETAIL_DEBUG__
2006 goto cleanup_tapnhold;
2008 #ifdef __DETAIL_DEBUG__
2009 XDBG_DEBUG(MGEST, "[M][cleanup] num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2010 #endif//__DETAIL_DEBUG__
2011 //goto cleanup_tapnhold;
2014 mbits |= (1 << idx);
2015 if( mbits == (pow(2, num_pressed)-1) )
2017 area_size = AREA_SIZE(&g_pGesture->area.extents);
2018 cx = AREA_CENTER_X(&g_pGesture->area.extents);
2019 cy = AREA_CENTER_Y(&g_pGesture->area.extents);
2020 #ifdef __DETAIL_DEBUG__
2021 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] area_size=%d, base_area_size=%d, diff=%d\n", num_pressed, area_size, base_area_size, ABS(base_area_size - area_size));
2022 XDBG_DEBUG(MGEST, "[M] cx=%d, base_cx=%d, diff=%d\n", cx, base_cx, ABS(cx-base_cx));
2023 XDBG_DEBUG(MGEST, "[M] cy=%d, base_cy=%d, diff=%d\n", cy, base_cy, ABS(cy-base_cy));
2024 #endif//__DETAIL_DEBUG__
2026 if( ABS(base_area_size-area_size) >= TAPNHOLD_AREA_THRESHOLD )
2028 #ifdef __DETAIL_DEBUG__
2029 XDBG_DEBUG(MGEST, "[M] diff between area size(=%d) and base area size(=%d) is bigger than threshold(=%d)!\n", area_size, base_area_size, ABS(base_area_size-area_size));
2030 #endif//__DETAIL_DEBUG__
2031 goto cleanup_tapnhold;
2034 if( !INBOX(&base_box_ext, cx, cy) )
2036 #ifdef __DETAIL_DEBUG__
2037 XDBG_DEBUG(MGEST, "[M] current center coordinates is not in base coordinates box !\n");
2038 #endif//__DETAIL_DEBUG__
2039 goto cleanup_tapnhold;
2044 case ET_ButtonRelease:
2045 if( state != GestureEnd && num_pressed >= 2)
2047 #ifdef __DETAIL_DEBUG__
2048 XDBG_DEBUG(MGEST, "[R][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2049 #endif//__DETAIL_DEBUG__
2050 goto cleanup_tapnhold;
2053 if( g_pGesture->num_pressed )
2058 prev_num_pressed = num_pressed;
2063 #ifdef __DETAIL_DEBUG__
2064 XDBG_DEBUG(MGEST, "[R] tap_repeat=%d, num_pressed=%d, prev_num_pressed=%d\n", tap_repeat, num_pressed, prev_num_pressed);
2065 #endif//__DETAIL_DEBUG__
2067 if( num_pressed != prev_num_pressed || !GestureHasFingerEventMask(GestureNotifyTapNHold, num_pressed) )
2069 #ifdef __DETAIL_DEBUG__
2070 XDBG_DEBUG(MGEST, "[R] num_pressed(=%d) != prev_num_pressed(=%d) OR %d finger tap event was not grabbed/selected !\n",
2071 num_pressed, prev_num_pressed, num_pressed);
2072 #endif//__DETAIL_DEBUG__
2073 goto cleanup_tapnhold;
2076 if( tap_repeat > 1 )
2078 #ifdef __DETAIL_DEBUG__
2079 XDBG_DEBUG(MGEST, "[R] Tap events(tap_repeat=%d) were put twice or more !(ignored)\n", tap_repeat);
2080 #endif//__DETAIL_DEBUG__
2081 goto cleanup_tapnhold;
2084 prev_num_pressed = num_pressed;
2086 state = GestureDone;
2088 TimerCancel(tapnhold_event_timer);
2089 tapnhold_event_timer = TimerSet(tapnhold_event_timer, 0, TAPNHOLD_INTV_TIME_THRESHOLD, GestureEventTimerHandler, (int *)&event_type);
2091 #ifdef __DETAIL_DEBUG__
2092 XDBG_DEBUG(MGEST, "[R][Last] state=%d, tap_repeat=%d, num_pressed=%d, prev_num_pressed=%d\n", state, tap_repeat, num_pressed, prev_num_pressed);
2093 #endif//__DETAIL_DEBUG__
2101 if( state == GestureUpdate )
2104 if( GestureHasFingerEventMask(GestureNotifyTapNHold, prev_num_pressed) )
2106 GestureHandleGesture_TapNHold(prev_num_pressed, base_cx, base_cy, interval, holdtime, state);
2111 g_pGesture->recognized_gesture &= ~TapNHoldFilterMask;
2114 g_pGesture->filter_mask |= TapNHoldFilterMask;
2115 if( g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL )
2117 #ifdef __DETAIL_DEBUG__
2118 XDBG_DEBUG(MGEST, "[cleanup] GestureFlushOrDrop() !\n");
2119 #endif//__DETAIL_DEBUG__
2121 if( ERROR_INVALPTR == GestureFlushOrDrop() )
2123 GestureControl(g_pGesture->this_device, DEVICE_OFF);
2127 TimerCancel(tapnhold_event_timer);
2130 prev_num_pressed = 0;
2138 void GestureRecognize_GroupHold(int type, InternalEvent *ev, DeviceIntPtr device, int idx, int timer_expired)
2140 static int num_pressed = 0;
2141 static int base_area_size = 0;
2142 static Time base_time = 0;
2146 static pixman_box16_t base_box_ext;
2148 static int state = GestureEnd;
2150 static OsTimerPtr hold_event_timer = NULL;
2151 static int event_type = GestureNotifyHold;
2153 if(g_pGesture->recognized_palm || g_pGesture->enqueue_fulled == 1 || g_pGesture->hold_detected
2154 #ifdef _F_SUPPORT_BEZEL_FLICK_
2155 || g_pGesture->bezel_recognized_mask)
2163 if( state <= GestureBegin )
2166 #ifdef __DETAIL_DEBUG__
2170 XDBG_DEBUG(MGEST, "HOLD Begin !\n");
2174 XDBG_DEBUG(MGEST, "HOLD Update !\n");
2177 #endif//__DETAIL_DEBUG__
2179 if( GestureHasFingerEventMask(GestureNotifyHold, num_pressed) )
2181 GestureHandleGesture_Hold(num_pressed, base_cx, base_cy, GetTimeInMillis()-base_time, state);
2182 hold_event_timer = TimerSet(hold_event_timer, 0, HOLD_TIME_THRESHOLD, GestureEventTimerHandler, (int *)&event_type);
2189 case ET_ButtonPress:
2190 g_pGesture->fingers[idx].flags |= PressFlagHold;
2192 if( g_pGesture->num_pressed < 2 )
2195 if( !base_area_size || g_pGesture->num_pressed > num_pressed )
2197 if( state != GestureEnd )
2199 #ifdef __DETAIL_DEBUG__
2200 XDBG_DEBUG(MGEST, "[P][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2201 #endif//__DETAIL_DEBUG__
2205 base_area_size = AREA_SIZE(&g_pGesture->area.extents);
2206 base_cx = AREA_CENTER_X(&g_pGesture->area.extents);
2207 base_cy = AREA_CENTER_Y(&g_pGesture->area.extents);
2208 base_time = GetTimeInMillis();
2209 base_box_ext.x1 = base_cx-HOLD_MOVE_THRESHOLD;
2210 base_box_ext.y1 = base_cy-HOLD_MOVE_THRESHOLD;
2211 base_box_ext.x2 = base_cx+HOLD_MOVE_THRESHOLD;
2212 base_box_ext.y2 = base_cy+HOLD_MOVE_THRESHOLD;
2213 event_type = GestureNotifyHold;
2214 hold_event_timer = TimerSet(hold_event_timer, 0, HOLD_TIME_THRESHOLD, GestureEventTimerHandler, (int *)&event_type);
2216 num_pressed = g_pGesture->num_pressed;
2218 #ifdef __DETAIL_DEBUG__
2219 XDBG_DEBUG(MGEST, "[P]][num_pressed=%d] AREA_SIZE(area.extents)=%d, base_cx=%d, base_cy=%d\n", num_pressed, base_area_size, base_cx, base_cy);
2220 #endif//__DETAIL_DEBUG__
2224 if( !(g_pGesture->fingers[idx].flags & PressFlagHold ) )
2227 if( num_pressed < 2 )
2230 if( num_pressed != g_pGesture->num_pressed )
2232 if( state != GestureEnd )
2234 #ifdef __DETAIL_DEBUG__
2235 XDBG_DEBUG(MGEST, "[M][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2236 #endif//__DETAIL_DEBUG__
2239 #ifdef __DETAIL_DEBUG__
2240 XDBG_DEBUG(MGEST, "[M][cleanup] num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2241 #endif//__DETAIL_DEBUG__
2242 //goto cleanup_hold;
2245 area_size = AREA_SIZE(&g_pGesture->area.extents);
2246 cx = AREA_CENTER_X(&g_pGesture->area.extents);
2247 cy = AREA_CENTER_Y(&g_pGesture->area.extents);
2248 #ifdef __DETAIL_DEBUG__
2249 XDBG_DEBUG(MGEST, "[M][num_pressed=%d] area_size=%d, base_area_size=%d, diff=%d\n", num_pressed, area_size, base_area_size, ABS(base_area_size - area_size));
2250 XDBG_DEBUG(MGEST, "[M] cx=%d, base_cx=%d, diff=%d\n", cx, base_cx, ABS(cx-base_cx));
2251 XDBG_DEBUG(MGEST, "[M] cy=%d, base_cy=%d, diff=%d\n", cy, base_cy, ABS(cy-base_cy));
2252 #endif//__DETAIL_DEBUG__
2254 if( ABS(base_area_size-area_size) >= HOLD_AREA_THRESHOLD )
2256 #ifdef __DETAIL_DEBUG__
2257 XDBG_DEBUG(MGEST, "[M] diff between area size(=%d) and base area size(=%d) is bigger than threshold(=%d)!\n", area_size, base_area_size, ABS(base_area_size-area_size));
2258 #endif//__DETAIL_DEBUG__
2262 if( !INBOX(&base_box_ext, cx, cy) )
2264 #ifdef __DETAIL_DEBUG__
2265 XDBG_DEBUG(MGEST, "[M] current center coordinates is not in base coordinates box !\n");
2266 #endif//__DETAIL_DEBUG__
2271 case ET_ButtonRelease:
2272 if( state != GestureEnd && num_pressed >= 2)
2274 #ifdef __DETAIL_DEBUG__
2275 XDBG_DEBUG(MGEST, "[R][cleanup] num_finger changed ! num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2276 #endif//__DETAIL_DEBUG__
2280 //XDBG_DEBUG(MGEST, "[R] num_pressed=%d, g_pGesture->num_pressed=%d\n", num_pressed, g_pGesture->num_pressed);
2281 if( g_pGesture->num_pressed )
2292 if( state == GestureBegin || state == GestureUpdate )
2295 if( GestureHasFingerEventMask(GestureNotifyHold, num_pressed) )
2297 GestureHandleGesture_Hold(num_pressed, base_cx, base_cy, GetTimeInMillis()-base_time, state);
2302 g_pGesture->recognized_gesture &= ~HoldFilterMask;
2305 g_pGesture->filter_mask |= HoldFilterMask;
2309 base_cx = base_cy = 0;
2311 base_box_ext.x1 = base_box_ext.x2 = base_box_ext.y1 = base_box_ext.y2 = 0;
2312 TimerCancel(hold_event_timer);
2316 #ifdef _F_SUPPORT_BEZEL_FLICK_
2318 GestureBezelAngleRecognize(int type, int distance, double angle)
2320 if (distance < g_pGesture->bezel.flick_distance)
2322 #ifdef __BEZEL_DEBUG__
2323 XDBG_DEBUG(MGEST, "distance(%d) < flick_distance(%d)\n", distance, g_pGesture->bezel.flick_distance);
2324 #endif//__BEZEL_DEBUG__
2329 case BEZEL_TOP_LEFT:
2331 case BEZEL_TOP_RIGHT:
2333 case BEZEL_BOTTOM_LEFT:
2334 if( (g_pGesture->bezel.min_rad< angle) && (angle < g_pGesture->bezel.max_rad) )
2336 #ifdef __BEZEL_DEBUG__
2337 XDBG_DEBUG(MGEST, "bottom_left bezel success....\n");
2338 #endif//__BEZEL_DEBUG__
2343 #ifdef __BEZEL_DEBUG__
2344 XDBG_DEBUG(MGEST, "bottom_left bezel failed....\n");
2345 #endif//__BEZEL_DEBUG__
2348 case BEZEL_BOTTOM_RIGHT:
2349 if( (g_pGesture->bezel.min_180_rad< angle) && (angle < g_pGesture->bezel.max_180_rad))
2351 #ifdef __BEZEL_DEBUG__
2352 XDBG_DEBUG(MGEST, "bottom_right bezel success...\n");
2353 #endif//__BEZEL_DEBUG__
2358 #ifdef __BEZEL_DEBUG__
2359 XDBG_DEBUG(MGEST, "bottom_right bezel failed....\n");
2360 #endif//__BEZEL_DEBUG__
2371 GestureEnableDisable()
2373 if((g_pGesture->grabMask) || (g_pGesture->lastSelectedWin != None))
2375 GestureEnable(1, FALSE, g_pGesture->this_device);
2379 GestureEnable(0, FALSE, g_pGesture->this_device);
2384 GestureCbEventsGrabbed(Mask *pGrabMask, GestureGrabEventPtr *pGrabEvent)
2386 g_pGesture->grabMask = *pGrabMask;
2387 g_pGesture->GrabEvents = (GestureGrabEventPtr)pGrabEvent;
2388 GestureEnableDisable();
2392 GestureCbEventsSelected(Window win, Mask *pEventMask)
2394 g_pGesture->lastSelectedWin = win;
2395 g_pGesture->lastSelectedMask = (pEventMask) ? *pEventMask : 0;
2396 GestureEnableDisable();
2400 GestureGetEventsWindow(void)
2405 pWin = GestureWindowOnXY(g_pGesture->fingers[0].px, g_pGesture->fingers[0].py);
2409 #ifdef __DETAIL_DEBUG__
2410 XDBG_DEBUG(MGEST, "pWin->drawable.id=0x%x\n", pWin->drawable.id);
2411 #endif//__DETAIL_DEBUG__
2412 g_pGesture->gestureWin = pWin->drawable.id;
2416 #ifdef __DETAIL_DEBUG__
2417 XDBG_DEBUG(MGEST, "GestureWindowOnXY returns NULL !\n");
2418 #endif//__DETAIL_DEBUG__
2421 if(g_pGesture->gestureWin == g_pGesture->lastSelectedWin)
2423 g_pGesture->eventMask = g_pGesture->lastSelectedMask;
2424 goto nonempty_eventmask;
2427 //check selected event(s)
2428 if( !GestureHasSelectedEvents(pWin, &g_pGesture->eventMask) )
2430 g_pGesture->eventMask = 0;
2434 g_pGesture->lastSelectedWin = g_pGesture->gestureWin;
2435 g_pGesture->lastSelectedMask = g_pGesture->eventMask;
2438 if( !g_pGesture->eventMask && !g_pGesture->grabMask)
2440 #ifdef __DETAIL_DEBUG__
2441 XDBG_DEBUG(MGEST, "No grabbed events or no events were selected for window(0x%x) !\n", pWin->drawable.id);
2442 #endif//__DETAIL_DEBUG__
2448 #ifdef __DETAIL_DEBUG__
2449 XDBG_DEBUG(MGEST, "g_pGesture->eventMask=0x%x\n", g_pGesture->eventMask);
2450 #endif//__DETAIL_DEBUG__
2452 mask = (GESTURE_FILTER_MASK_ALL & ~(g_pGesture->grabMask | g_pGesture->eventMask));
2454 #ifdef __DETAIL_DEBUG__
2455 #ifdef _F_SUPPORT_BEZEL_FLICK_
2456 XDBG_DEBUG(MGEST, "g_pGesture->filter_mask=0x%x, mask=0x%x, palm_filter_mask=0x%x bezel_filter_mask=0x%x\n", g_pGesture->filter_mask, mask, g_pGesture->palm_filter_mask, g_pGesture->bezel_filter_mask);
2458 XDBG_DEBUG(MGEST, "g_pGesture->filter_mask=0x%x, mask=0x%x, palm_filter_mask=0x%x\n", g_pGesture->filter_mask, mask, g_pGesture->palm_filter_mask);
2460 #endif//__DETAIL_DEBUG__
2461 g_pGesture->palm_filter_mask = 0;
2462 if(mask & FlickFilterMask)
2464 g_pGesture->palm_filter_mask |= PalmFlickHorizFilterMask;
2465 g_pGesture->palm_filter_mask |= PalmFlickVertiFilterMask;
2466 #ifdef _F_SUPPORT_BEZEL_FLICK_
2467 g_pGesture->bezel_filter_mask |= BezelFlickFilterMask;
2470 if(!(mask & FlickFilterMask))
2472 #ifdef _F_SUPPORT_BEZEL_FLICK_
2473 if(!(g_pGesture->GrabEvents[GestureNotifyFlick].pGestureGrabWinInfo[1].window))
2475 g_pGesture->bezel_filter_mask |= BezelFlickFilterMask;
2479 if(!(g_pGesture->GrabEvents[GestureNotifyFlick].pGestureGrabWinInfo[0].window))
2481 g_pGesture->palm_filter_mask |= PalmFlickHorizFilterMask;
2482 g_pGesture->palm_filter_mask |= PalmFlickVertiFilterMask;
2485 if(!g_pGesture->palm.palmflag)
2487 if(!GestureHasFingersEvents(HoldFilterMask))
2488 mask |= HoldFilterMask;
2489 if(!GestureHasFingersEvents(FlickFilterMask))
2490 mask |= FlickFilterMask;
2491 g_pGesture->filter_mask = mask;
2493 #ifdef __DETAIL_DEBUG__
2494 #ifdef _F_SUPPORT_BEZEL_FLICK_
2495 XDBG_DEBUG(MGEST, "g_pGesture->filter_mask=0x%x, palm_filter_mask: 0x%x, bezel_filter_mask=0x%x\n", g_pGesture->filter_mask, g_pGesture->palm_filter_mask, g_pGesture->bezel_filter_mask);
2497 XDBG_DEBUG(MGEST, "g_pGesture->filter_mask=0x%x, palm_filter_mask: 0x%x\n", g_pGesture->filter_mask, g_pGesture->palm_filter_mask);
2499 #endif//__DETAIL_DEBUG__
2505 GestureHasFingersEvents(int eventType)
2508 Mask eventmask = (1L << eventType);
2509 for(i=2; i<MAX_MT_DEVICES; i++)
2511 if( (g_pGesture->grabMask & eventmask) &&
2512 (g_pGesture->GrabEvents[eventType].pGestureGrabWinInfo[i].window != None) )
2514 #ifdef __DETAIL_DEBUG__
2515 XDBG_DEBUG(MGEST, "TRUE !! Has grabMask\n");
2516 #endif//__DETAIL_DEBUG__
2524 GestureEventTimerHandler(OsTimerPtr timer, CARD32 time, pointer arg)
2526 int event_type = *(int *)arg;
2528 switch( event_type )
2530 case GestureNotifyHold:
2531 #ifdef __DETAIL_DEBUG__
2532 XDBG_DEBUG(MGEST, "GestureNotifyHold (event_type = %d)\n", event_type);
2533 #endif//__DETAIL_DEBUG__
2534 GestureRecognize_GroupHold(event_type, NULL, NULL, 0, 1);
2537 case GestureNotifyPan:
2538 #ifdef __DETAIL_DEBUG__
2539 XDBG_DEBUG(MGEST, "GestureNotifyPan (event_type = %d)\n", event_type);
2540 #endif//__DETAIL_DEBUG__
2541 GestureRecognize_GroupPan(event_type, NULL, NULL, 0, 1);
2544 case GestureNotifyTap:
2545 #ifdef __DETAIL_DEBUG__
2546 XDBG_DEBUG(MGEST, "GestureNotifyTap (event_type = %d)\n", event_type);
2547 #endif//__DETAIL_DEBUG__
2548 GestureRecognize_GroupTap(event_type, NULL, NULL, 0, 1);
2551 case GestureNotifyTapNHold:
2552 #ifdef __DETAIL_DEBUG__
2553 XDBG_DEBUG(MGEST, "GestureNotifyTapNHold (event_type = %d)\n", event_type);
2554 #endif//__DETAIL_DEBUG__
2555 GestureRecognize_GroupTapNHold(event_type, NULL, NULL, 0, 1);
2558 case GestureNotifyPinchRotation:
2559 #ifdef __DETAIL_DEBUG__
2560 XDBG_DEBUG(MGEST, "GestureNotifyPinchRotation (event_type = %d)\n", event_type);
2561 #endif//__DETAIL_DEBUG__
2562 GestureRecognize_GroupPinchRotation(event_type, NULL, NULL, 0, 1);
2566 #ifdef __DETAIL_DEBUG__
2567 XDBG_DEBUG(MGEST, "unknown event_type (=%d)\n", event_type);
2568 #endif//__DETAIL_DEBUG__
2570 XDBG_INFO(MGEST, "timer=%x\n", (unsigned int)timer);
2576 #ifdef _F_SUPPORT_BEZEL_FLICK_
2578 GestureBezelSingleFingerTimerHandler(OsTimerPtr timer, CARD32 time, pointer arg)
2580 BezelFlickStatusPtr pBezel = &g_pGesture->bezel;
2582 if( pBezel->is_active != BEZEL_NONE )
2584 pBezel->is_active = BEZEL_END;
2585 #ifdef __BEZEL_DEBUG__
2586 XDBG_DEBUG(MGEST, "end\n");
2587 #endif//__BEZEL_DEBUG__
2594 GestureSingleFingerTimerHandler(OsTimerPtr timer, CARD32 time, pointer arg)
2596 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
2597 g_pGesture->recognized_gesture = 0;
2599 if( ERROR_INVALPTR == GestureFlushOrDrop() )
2601 GestureControl(g_pGesture->this_device, DEVICE_OFF);
2604 #ifdef __DETAIL_DEBUG__
2605 XDBG_DEBUG(MGEST, "expired !\n");
2606 #endif//__DETAIL_DEBUG__
2612 GesturePalmSingleFingerTimerHandler(OsTimerPtr timer, CARD32 time, pointer arg)
2614 PalmStatusPtr pPalm = &g_pGesture->palm;
2615 if(pPalm->palmflag || (pPalm->biggest_tmajor >= PALM_FLICK_FINGER_MIN_TOUCH_MAJOR))
2617 pPalm->single_timer_expired = 0;
2621 pPalm->single_timer_expired = 1;
2622 #ifdef __PALM_DETAIL_LOG__
2623 XDBG_DEBUG(MGEST, "palm expired !\n");
2624 #endif//__DETAIL_DEBUG__
2630 GesturePalmGetHorizIndexWithX(int x, int type)
2634 static int pressed_idx = -1;
2635 PalmMiscInfoPtr pPalmMisc = &g_pGesture->palm_misc;
2637 for(i = 0 ; i < PALM_HORIZ_ARRAY_COUNT ; i++)
2639 #ifdef __PALM_DETAIL_LOG__
2640 XDBG_DEBUG(MGEST, "pPalmMisc->horiz_coord[%d]=%d, x=%d\n", i, pPalmMisc->horiz_coord[i], x);
2641 #endif//__PALM_DETAIL_LOG__
2642 if(x <= pPalmMisc->horiz_coord[i])
2644 #ifdef __PALM_DETAIL_LOG__
2645 XDBG_DEBUG(MGEST, "index=%d\n", i);
2646 #endif//__PALM_DETAIL_LOG__
2651 #ifdef __PALM_DETAIL_LOG__
2652 XDBG_DEBUG(MGEST, "Error ! Failed to get horiz coordinate index !\n");
2653 #endif//__PALM_DETAIL_LOG__
2658 if(type == ET_ButtonPress)
2660 pressed_idx = ret_idx;
2662 else if(type == ET_ButtonRelease)
2664 if((pressed_idx <= 1) && (ret_idx >= (PALM_HORIZ_ARRAY_COUNT-2)))
2666 #ifdef __PALM_DETAIL_LOG__
2667 XDBG_DEBUG(MGEST, "[R] Valid !\n");
2670 #endif//__PALM_DETAIL_LOG__
2672 else if((pressed_idx >= (PALM_HORIZ_ARRAY_COUNT-2)) && (ret_idx <= 1))
2674 #ifdef __PALM_DETAIL_LOG__
2675 XDBG_DEBUG(MGEST, "[R] Valid !\n");
2678 #endif//__PALM_DETAIL_LOG__
2682 #ifdef __PALM_DETAIL_LOG__
2683 XDBG_DEBUG(MGEST, "[R] Invalid !(pressed_idx=%d, released_idx=%d\n", pressed_idx, ret_idx);
2684 #endif//__PALM_DETAIL_LOG__
2693 GesturePalmGetVertiIndexWithY(int y, int type)
2697 static int pressed_idx = -1;
2698 PalmMiscInfoPtr pPalmMisc = &g_pGesture->palm_misc;
2700 for(i = 0 ; i < PALM_VERTI_ARRAY_COUNT ; i++)
2702 #ifdef __PALM_DETAIL_LOG__
2703 XDBG_DEBUG(MGEST, "pPalmMisc->verti_coord[%d]=%d, x=%d\n", i, pPalmMisc->verti_coord[i], y);
2704 #endif//__PALM_DETAIL_LOG__
2705 if(y <= pPalmMisc->verti_coord[i])
2707 #ifdef __PALM_DETAIL_LOG__
2708 XDBG_DEBUG(MGEST, "index=%d\n", i);
2709 #endif//__PALM_DETAIL_LOG__
2714 #ifdef __PALM_DETAIL_LOG__
2715 XDBG_DEBUG(MGEST, "Error ! Failed to get verti coordinate index !\n");
2716 #endif//__PALM_DETAIL_LOG__
2721 if(type == ET_ButtonPress)
2723 if((ret_idx <= 1) || (ret_idx >=(PALM_VERTI_ARRAY_COUNT-2)))
2725 #ifdef __PALM_DETAIL_LOG__
2726 XDBG_DEBUG(MGEST, "[P] Valid !\n");
2727 #endif//__PALM_DETAIL_LOG__
2728 pressed_idx = ret_idx;
2732 #ifdef __PALM_DETAIL_LOG__
2733 XDBG_DEBUG(MGEST, "[P] Invalid !(pressed_idx(=%d) must be between 0 and 1 or between 3 and 4\n", pressed_idx);
2734 #endif//__PALM_DETAIL_LOG__
2739 else if(type == ET_ButtonRelease)
2741 if((pressed_idx <= 1) && (ret_idx >= (PALM_VERTI_ARRAY_COUNT-2)))
2743 #ifdef __PALM_DETAIL_LOG__
2744 XDBG_DEBUG(MGEST, "[R] Valid !\n");
2747 #endif//__PALM_DETAIL_LOG__
2749 else if((pressed_idx >= (PALM_VERTI_ARRAY_COUNT-2)) && (ret_idx <= 1))
2751 #ifdef __PALM_DETAIL_LOG__
2752 XDBG_DEBUG(MGEST, "[R] Valid !\n");
2755 #endif//__PALM_DETAIL_LOG__
2759 #ifdef __PALM_DETAIL_LOG__
2760 XDBG_DEBUG(MGEST, "[R] Invalid !(pressed_idx=%d, released_idx=%d\n", pressed_idx, ret_idx);
2761 #endif//__PALM_DETAIL_LOG__
2770 GesturePalmRecognize_FlickHorizen(int type, int idx)
2772 static int curTouched = 0;
2773 static int num_pressed = 0;
2774 static int base_width_size = 0;
2775 static Time base_time = 0;
2777 static pixman_box16_t base_box_ext;
2778 #ifdef __PALM_GESTURE_LOG__
2783 static int prev_line_idx;
2784 static int horiz_line[PALM_HORIZ_ARRAY_COUNT];
2787 int distx=0, disty=0;
2788 int distance, direction;
2791 static int is_flicking = 1;
2792 //static int is_surface = 0;
2793 static int pass_count = 0;
2794 static int base_cx=0, base_cy=0;
2795 static int release_flag = 0;
2797 PalmStatusPtr pPalm = &g_pGesture->palm;
2798 #ifdef __PALM_GESTURE_LOG__
2799 XDBG_DEBUG(MGEST, "recognized_palm= 0x%x, palm_filter_mask= 0x%x\n", g_pGesture->recognized_palm, g_pGesture->palm_filter_mask);
2800 XDBG_DEBUG(MGEST, "num_pressed: %d, cur_touched: %d palmflag: %d\n", num_pressed, pPalm->cur_touched, pPalm->palmflag);
2801 XDBG_DEBUG(MGEST, "idx: %d, cx: %d, cy: %d, type: %d, touch_status: %d\n", idx, pPalm->cx, pPalm->cy, type, pPalm->pti[idx].touch_status);
2807 if(g_pGesture->enqueue_fulled == 1)
2809 #ifdef __PALM_GESTURE_LOG__
2810 XDBG_DEBUG(MGEST, "EQ Event is full.... palm recognize drop..\n");
2815 if(pPalm->single_timer_expired)
2817 #ifdef __PALM_GESTURE_LOG__
2818 XDBG_DEBUG(MGEST, "No flick single finger...expired\n");
2823 if(g_pGesture->recognized_gesture || g_pGesture->hold_detected ||
2824 (g_pGesture->recognized_palm && !(g_pGesture->recognized_palm & PalmFlickHorizFilterMask)) || (g_pGesture->palm_filter_mask & PalmFlickHorizFilterMask)
2825 #ifdef _F_SUPPORT_BEZEL_FLICK_
2826 || g_pGesture->bezel_recognized_mask)
2831 #ifdef __PALM_GESTURE_LOG__
2832 XDBG_DEBUG(MGEST, "zoom_enabled: %d\n", g_pGesture->zoom_enabled);
2833 XDBG_DEBUG(MGEST, "type(%d) recognized_palm= 0x%x, palm_filter_mask= 0x%x\n", type, g_pGesture->recognized_palm, g_pGesture->palm_filter_mask);
2834 XDBG_DEBUG(MGEST, "type(%d) recognized_gesture= 0x%x, filter_mask= 0x%x\n", type, g_pGesture->recognized_gesture, g_pGesture->filter_mask);
2840 case ET_ButtonPress:
2843 if(!base_width_size || pPalm->cur_touched > curTouched)
2847 base_time = GetTimeInMillis();
2848 base_x = AREA_CENTER_X(&pPalm->area.extents);
2849 line_idx = GesturePalmGetHorizIndexWithX(base_x, type);
2850 #ifdef __PALM_GESTURE_LOG__
2851 XDBG_DEBUG(MGEST, "[P] cx: %d, cy: %d, x1: %d, x2: %d, y1: %d, y2: %d, line_idx: %d\n", pPalm->cx, pPalm->cy, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2, line_idx);
2855 #ifdef __PALM_GESTURE_LOG__
2856 XDBG_DEBUG(MGEST, "[P] No line_idx is invalid.. base_x: %d, line_idx: %d\n", base_x, line_idx);
2861 horiz_line[line_idx]++;
2863 prev_line_idx = line_idx;
2865 #ifdef __PALM_GESTURE_LOG__
2866 XDBG_DEBUG(MGEST, "[P] Base_width=%d, base_x=%d, line_idx=%d\n", base_width_size, base_x, line_idx);
2870 base_width_size = AREA_WIDTH(&pPalm->area.extents);
2871 if(base_width_size > PALM_FLICK_HORIZ_MAX_BASE_WIDTH)
2873 #ifdef __PALM_GESTURE_LOG__
2874 XDBG_DEBUG(MGEST, "[P] No flickBase_width=%d > %d: MAX_WIDTH\n", base_width_size, PALM_FLICK_HORIZ_MAX_BASE_WIDTH);
2878 #ifdef __PALM_GESTURE_LOG__
2879 XDBG_DEBUG(MGEST, "[P] Base_width=%d, cur_touched=%d\n", base_width_size, pPalm->cur_touched);
2881 if(pPalm->max_touched == 1)
2883 base_cx = AREA_CENTER_X(&pPalm->area.extents);
2884 base_cy = AREA_CENTER_Y(&pPalm->area.extents);
2885 base_box_ext.x1 = base_cx-HOLD_MOVE_THRESHOLD;
2886 base_box_ext.y1 = base_cy-HOLD_MOVE_THRESHOLD;
2887 base_box_ext.x2 = base_cx+HOLD_MOVE_THRESHOLD;
2888 base_box_ext.y2 = base_cy+HOLD_MOVE_THRESHOLD;
2891 curTouched = pPalm->cur_touched;
2896 if(!num_pressed || !is_flicking)
2898 #ifdef __PALM_GESTURE_LOG__
2899 XDBG_DEBUG(MGEST, "[M] num_pressed: %d, is_flicking: %d\n", num_pressed, is_flicking);
2904 distx = AREA_CENTER_X(&pPalm->area.extents);
2905 disty = AREA_CENTER_Y(&pPalm->area.extents);
2906 line_idx = GesturePalmGetHorizIndexWithX(distx, type);
2907 #ifdef __PALM_GESTURE_LOG__
2908 for(i=0; i<PALM_HORIZ_ARRAY_COUNT; i++)
2910 XDBG_DEBUG(MGEST, "M] %d: %d\n", i, horiz_line[i]);
2912 XDBG_DEBUG(MGEST, "[M] distx: %d, line_idx: %d, prev_line_idx: %d! pass_count: %d\n", distx, line_idx, prev_line_idx, pass_count);
2917 #ifdef __PALM_GESTURE_LOG__
2918 XDBG_DEBUG(MGEST, "[M] No line_idx is invalid.. base_x: %d, line_idx: %d\n", base_x, line_idx);
2923 if(pPalm->max_touched == 1)
2925 if(ABS(disty - base_cy) > PALM_FLICK_HORIZ_MAX_MOVE_Y)
2927 #ifdef __PALM_GESTURE_LOG__
2928 XDBG_DEBUG(MGEST, "[M] No flick ! (move too long toward y coordination %d(%d - %d) > %d\n", ABS(disty - base_cy), disty, base_cy, PALM_FLICK_HORIZ_MAX_MOVE_Y);
2934 if(prev_line_idx != line_idx)
2936 horiz_line[line_idx]++;
2937 if(horiz_line[line_idx] > 2)
2939 #ifdef __PALM_GESTURE_LOG__
2940 XDBG_DEBUG(MGEST, "[M] No flick ! horiz_line[%d]: %d > 2\n", line_idx, horiz_line[line_idx]);
2948 #ifdef __PALM_GESTURE_LOG__
2949 XDBG_DEBUG(MGEST, "[M] No flick !(visit same place twice !)\n");
2954 if((prev_line_idx != line_idx) && horiz_line[line_idx] && !release_flag)
2956 #ifdef __PALM_GESTURE_LOG__
2957 XDBG_DEBUG(MGEST, "[M] No flick !(visit same place twice !)\n");
2962 prev_line_idx = line_idx;
2964 width_size = AREA_WIDTH(&pPalm->area.extents);
2965 #ifdef __PALM_GESTURE_LOG__
2966 XDBG_DEBUG(MGEST, "[M] Base_width=%d, Current_width=%d, diff=%d\n", base_width_size, width_size, ABS(width_size - base_width_size));
2968 duration = GetTimeInMillis() - base_time;
2969 #ifdef __PALM_GESTURE_LOG__
2970 XDBG_DEBUG(MGEST, "[M] duration =%d !\n", duration);
2972 if(((!pPalm->palmflag) && (pPalm->biggest_tmajor < PALM_FLICK_TOUCH_MAJOR-20) && (pPalm->biggest_wmajor < PALM_FLICK_TOUCH_MAJOR-20)) &&
2973 (duration >= PALM_FLICK_INITIAL_TIMEOUT))
2975 #ifdef __PALM_GESTURE_LOG__
2976 XDBG_DEBUG(MGEST, "[M] No flick !(initial flick timeout : duration=%d)\n", duration);
2980 if( (duration >= PALM_FLICK_INITIAL_TIMEOUT) && (INBOX(&base_box_ext, distx, disty)) )
2982 #ifdef __PALM_GESTURE_LOG__
2983 XDBG_DEBUG(MGEST, "[M] No flick !(move too short !in duration: %d)\n", duration);
2987 if( (duration >= PALM_FLICK_FALSE_TIMEOUT) && (pPalm->biggest_tmajor < PALM_FLICK_TOUCH_MAJOR) && (pPalm->biggest_wmajor < PALM_FLICK_TOUCH_MAJOR))
2989 #ifdef __PALM_GESTURE_LOG__
2990 XDBG_DEBUG(MGEST, "[M] No flick !(press touch major(%.f) width major (%.f) < (%.f) is little in duration(%d))\n", pPalm->biggest_tmajor, pPalm->biggest_wmajor, PALM_FLICK_TOUCH_MAJOR, duration);
2995 if(duration >= PALM_FLICK_DETECT_TIMEOUT)
2997 #ifdef __PALM_GESTURE_LOG__
2998 XDBG_DEBUG(MGEST, "[M] No flick !(flick detection timeout : duration=%d)\n", duration);
3004 case ET_ButtonRelease:
3006 if(--num_pressed < 0)
3008 base_width_size = AREA_WIDTH(&pPalm->area.extents);
3012 if((!pPalm->palmflag) && (pPalm->biggest_tmajor < 100) && (pPalm->bigger_wmajor < 100))
3014 #ifdef __PALM_GESTURE_LOG__
3015 XDBG_DEBUG(MGEST, "[R] No flick (No palm comming and all finger release))\n");
3023 duration = GetTimeInMillis() - base_time;
3024 distx = AREA_CENTER_X(&pPalm->area.extents);
3025 line_idx = GesturePalmGetHorizIndexWithX(distx, type);
3029 #ifdef __PALM_GESTURE_LOG__
3030 XDBG_DEBUG(MGEST, "[R] No flick (distx: %d, line_idx: %d))\n", distx, line_idx);
3034 #ifdef __PALM_GESTURE_LOG__
3035 XDBG_DEBUG(MGEST, "[R] duration=%d, distx=%d\n", duration, distx);
3037 if(duration >= PALM_FLICK_DETECT_TIMEOUT)
3039 #ifdef __PALM_GESTURE_LOG__
3040 XDBG_DEBUG(MGEST, "[R] No flick !(flick detection timeout : duration=%d)\n", duration);
3044 if(pass_count < PALM_HORIZ_ARRAY_COUNT - 1)
3046 #ifdef __PALM_GESTURE_LOG__
3047 XDBG_DEBUG(MGEST, "[R] No flick !(flick distance is short!\n");
3051 if((pPalm->biggest_tmajor < PALM_FLICK_TOUCH_MAJOR) && (pPalm->biggest_wmajor < PALM_FLICK_TOUCH_MAJOR))
3053 #ifdef __PALM_GESTURE_LOG__
3054 XDBG_DEBUG(MGEST, "[R] No flick !(touch major(%.f) width major(%.f) < %d) is small...)\n", pPalm->biggest_tmajor, pPalm->biggest_wmajor, PALM_FLICK_TOUCH_MAJOR);
3059 direction = (line_idx <= 1) ? FLICK_EASTWARD : FLICK_WESTWARD;
3060 distance = ABS(distx - base_x);
3061 #ifdef __PALM_GESTURE_LOG__
3062 XDBG_DEBUG(MGEST, "[R] Palm Flick !!!, direction=%d, distance=%d\n", direction, distance);
3064 if( GestureHasFingerEventMask(GestureNotifyFlick, 0) )
3065 GestureHandleGesture_Flick(0, distance, duration, direction);
3074 g_pGesture->recognized_palm &= ~PalmFlickHorizFilterMask;
3075 g_pGesture->palm_filter_mask |= PalmFlickHorizFilterMask;
3076 #ifdef __PALM_GESTURE_LOG__
3077 XDBG_DEBUG(MGEST, "[Failed] recognized_palm= 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->recognized_palm, g_pGesture->palm_filter_mask);
3085 base_width_size = 0;
3092 base_cx = base_cy = 0;
3093 base_box_ext.x1 = base_box_ext.x2 = base_box_ext.y1 = base_box_ext.y2 = 0;
3094 memset(&horiz_line, 0L, PALM_HORIZ_ARRAY_COUNT * sizeof(int));
3095 #ifdef __PALM_GESTURE_LOG__
3096 XDBG_DEBUG(MGEST, "[cleanup_flick] base_width_size=%d, curTouched=%d\n", base_width_size, curTouched);
3102 GesturePalmRecognize_FlickVertical(int type,int idx)
3104 static int curTouched = 0;
3105 static int num_pressed = 0;
3106 static int base_height_size = 0;
3107 static Time base_time = 0;
3109 static int base_cx, base_cy;
3110 static int pass_count = 0;
3111 static int release_flag = 0;
3112 static pixman_box16_t base_box_ext;
3115 static int prev_line_idx;
3116 static int verti_line[PALM_VERTI_ARRAY_COUNT];
3121 int distance, direction;
3124 static int is_flicking = 1;
3125 static int false_base_height_size = 0;
3127 PalmStatusPtr pPalm = &g_pGesture->palm;
3128 #ifdef __PALM_GESTURE_LOG__
3129 XDBG_DEBUG(MGEST, "recognized_palm= 0x%x, palm_filter_mask= 0x%x\n", g_pGesture->recognized_palm, g_pGesture->palm_filter_mask);
3130 XDBG_DEBUG(MGEST, "num_pressed: %d, cur_touched: %d, palm_flag: %d, single_timer_expired: %d\n", num_pressed, pPalm->cur_touched, pPalm->palmflag, pPalm->single_timer_expired);
3136 if(g_pGesture->enqueue_fulled == 1)
3138 #ifdef __PALM_GESTURE_LOG__
3139 XDBG_DEBUG(MGEST, "EQ Event is full.... No palm recognize drop..\n");
3144 if(g_pGesture->recognized_gesture || g_pGesture->hold_detected ||
3145 (g_pGesture->recognized_palm && !(g_pGesture->recognized_palm & PalmFlickVertiFilterMask)) || (g_pGesture->palm_filter_mask & PalmFlickVertiFilterMask)
3146 #ifdef _F_SUPPORT_BEZEL_FLICK_
3147 || g_pGesture->bezel_recognized_mask)
3152 #ifdef __PALM_GESTURE_LOG__
3153 XDBG_DEBUG(MGEST, "zoom_enabled: %d\n", g_pGesture->zoom_enabled);
3154 XDBG_DEBUG(MGEST, "type(%d) recognized_palm= 0x%x, palm_filter_mask= 0x%x\n", type, g_pGesture->recognized_palm, g_pGesture->palm_filter_mask);
3155 XDBG_DEBUG(MGEST, "type(%d) recognized_gesture= 0x%x, filter_mask= 0x%x\n", type, g_pGesture->recognized_gesture, g_pGesture->filter_mask);
3160 if(pPalm->single_timer_expired)
3162 #ifdef __PALM_GESTURE_LOG__
3163 XDBG_DEBUG(MGEST, "No flick single finger...expired\n");
3170 case ET_ButtonPress:
3173 if(!base_height_size || pPalm->cur_touched > curTouched)
3177 base_time = GetTimeInMillis();
3178 base_y = AREA_CENTER_Y(&pPalm->area.extents);
3179 line_idx = GesturePalmGetVertiIndexWithY(base_y, type);
3181 #ifdef __PALM_GESTURE_LOG__
3182 XDBG_DEBUG(MGEST, "[P] Base_height=%d, base_y=%d, line_idx=%d\n", base_height_size, base_y, line_idx);
3186 #ifdef __PALM_GESTURE_LOG__
3187 XDBG_DEBUG(MGEST, "[P] No Base_height=%d, base_y=%d, line_idx=%d\n", base_height_size, base_y, line_idx);
3192 verti_line[line_idx] = 1;
3194 prev_line_idx = line_idx;
3196 #ifdef __PALM_GESTURE_LOG__
3197 XDBG_DEBUG(MGEST, "[P] Base_height=%d, base_y=%d, line_idx=%d\n", base_height_size, base_y, line_idx);
3201 base_height_size = AREA_HEIGHT(&pPalm->area.extents);
3202 #ifdef __PALM_GESTURE_LOG__
3203 XDBG_DEBUG(MGEST, "[P] Base_height=%d, cur_touched=%d\n", base_height_size, pPalm->cur_touched);
3205 if(base_height_size > PALM_FLICK_VERTI_MAX_BASE_WIDTH)
3207 #ifdef __PALM_GESTURE_LOG__
3208 XDBG_DEBUG(MGEST, "[P] No flickBase_width=%d > MAX_WIDTH\n", base_height_size, PALM_FLICK_VERTI_MAX_BASE_WIDTH);
3212 false_base_height_size = 0;
3213 if(pPalm->max_touched == 1)
3215 base_cx = AREA_CENTER_X(&pPalm->area.extents);
3216 base_cy = AREA_CENTER_Y(&pPalm->area.extents);
3217 base_box_ext.x1 = base_cx-HOLD_MOVE_THRESHOLD;
3218 base_box_ext.y1 = base_cy-HOLD_MOVE_THRESHOLD;
3219 base_box_ext.x2 = base_cx+HOLD_MOVE_THRESHOLD;
3220 base_box_ext.y2 = base_cy+HOLD_MOVE_THRESHOLD;
3224 curTouched = pPalm->cur_touched;
3229 if(!num_pressed|| !is_flicking)
3232 distx = AREA_CENTER_X(&pPalm->area.extents);
3233 disty = AREA_CENTER_Y(&pPalm->area.extents);
3234 line_idx = GesturePalmGetVertiIndexWithY(disty, type);
3235 #ifdef __PALM_GESTURE_LOG__
3236 XDBG_DEBUG(MGEST, "[M] line_idx: %d\n", line_idx);
3241 #ifdef __PALM_GESTURE_LOG__
3242 XDBG_DEBUG(MGEST, "[M] No line_idx: %d\n", line_idx);
3246 if((prev_line_idx != line_idx) && verti_line[line_idx] && !release_flag)
3248 #ifdef __PALM_GESTURE_LOG__
3249 XDBG_DEBUG(MGEST, "[M] No flick !(visit same place twice !)\n");
3254 if(pPalm->max_touched == 1)
3256 if(ABS(AREA_CENTER_X(&pPalm->area.extents) - base_cx) > PALM_FLICK_VERTI_MAX_MOVE_X)
3258 #ifdef __PALM_GESTURE_LOG__
3259 XDBG_DEBUG(MGEST, "[M] No flick ! (move too long toward x coordination %d(%d - %d) > PALM_FLICK_VERTI_MAX_MOVE_X\n", ABS(AREA_CENTER_X(&pPalm->area.extents) - base_cx), AREA_CENTER_X(&pPalm->area.extents) , base_cx, PALM_FLICK_VERTI_MAX_MOVE_X);
3265 verti_line[line_idx] = 1;
3266 if(prev_line_idx != line_idx)
3268 prev_line_idx = line_idx;
3270 height_size = AREA_HEIGHT(&pPalm->area.extents);
3271 #ifdef __PALM_GESTURE_LOG__
3272 XDBG_DEBUG(MGEST, "[M] Base_height=%d, Current_height=%d, diff=%d\n", base_height_size, height_size, ABS(height_size - base_height_size));
3275 duration = GetTimeInMillis() - base_time;
3276 #ifdef __PALM_GESTURE_LOG__
3277 XDBG_DEBUG(MGEST, "[M] duration =%d !\n", duration);
3280 if(!pPalm->palmflag && (pPalm->biggest_tmajor < PALM_FLICK_TOUCH_MAJOR-20) && (pPalm->biggest_wmajor < PALM_FLICK_TOUCH_MAJOR-20)
3281 && (duration >= PALM_FLICK_INITIAL_TIMEOUT))
3283 #ifdef __PALM_GESTURE_LOG__
3284 XDBG_DEBUG(MGEST, "[M] No flick !(initial flick timeout : duration=%d)\n", duration);
3288 if( (duration >= PALM_FLICK_INITIAL_TIMEOUT) && (INBOX(&base_box_ext, distx, disty)) )
3290 #ifdef __PALM_GESTURE_LOG__
3291 XDBG_DEBUG(MGEST, "[M] No flick !(move too short !in duration: %d)\n", duration);
3296 if(duration >= PALM_FLICK_DETECT_TIMEOUT)
3298 #ifdef __PALM_GESTURE_LOG__
3299 XDBG_DEBUG(MGEST, "[M] No flick !(flick detection timeout : duration=%d)\n", duration);
3305 case ET_ButtonRelease:
3308 if(--num_pressed < 0)
3313 if(!pPalm->palmflag && (pPalm->biggest_tmajor < 100) && (pPalm->bigger_wmajor < 100))
3315 #ifdef __PALM_GESTURE_LOG__
3316 XDBG_DEBUG(MGEST, "[R] No flick (No palm comming and all finger release))\n");
3324 duration = GetTimeInMillis() - base_time;
3325 disty = AREA_CENTER_Y(&pPalm->area.extents);
3326 line_idx = GesturePalmGetVertiIndexWithY(disty, type);
3327 #ifdef __PALM_GESTURE_LOG__
3328 XDBG_DEBUG(MGEST, "[R] line_idx: %d\n", line_idx);
3333 #ifdef __PALM_GESTURE_LOG__
3334 XDBG_DEBUG(MGEST, "[R] No line_idx: %d\n", line_idx);
3338 #ifdef __PALM_GESTURE_LOG__
3339 XDBG_DEBUG(MGEST, "[R] duration=%d, disty=%d\n", duration, disty);
3342 if(duration >= PALM_FLICK_DETECT_TIMEOUT)
3344 #ifdef __PALM_GESTURE_LOG__
3345 XDBG_DEBUG(MGEST, "[R] No flick !(flick detection timeout : duration=%d)\n", duration);
3349 if(pass_count < PALM_VERTI_ARRAY_COUNT -1)
3351 #ifdef __PALM_GESTURE_LOG__
3352 XDBG_DEBUG(MGEST, "[R] No flick !(flick distance is short!)\n");
3356 if(pPalm->biggest_tmajor < PALM_FLICK_TOUCH_MAJOR && pPalm->biggest_wmajor < PALM_FLICK_TOUCH_MAJOR)
3358 #ifdef __PALM_GESTURE_LOG__
3359 XDBG_DEBUG(MGEST, "[R] No flick !(flick touch major(%.f) width major(%.f) < %d) is small!)\n", pPalm->biggest_tmajor, pPalm->biggest_wmajor, PALM_FLICK_TOUCH_MAJOR);
3363 direction = (line_idx <= 1) ? FLICK_SOUTHWARD : FLICK_NORTHWARD;
3364 distance = ABS(disty - base_y);
3366 #ifdef __PALM_GESTURE_LOG__
3367 XDBG_DEBUG(MGEST, "[R] Palm Flick !!!, direction=%d, distance=%d\n", direction, distance);
3370 if( GestureHasFingerEventMask(GestureNotifyFlick, 0) )
3371 GestureHandleGesture_Flick(0, distance, duration, direction);
3380 g_pGesture->recognized_palm &= ~PalmFlickVertiFilterMask;
3381 g_pGesture->palm_filter_mask |= PalmFlickVertiFilterMask;
3382 #ifdef __PALM_GESTURE_LOG__
3383 XDBG_DEBUG(MGEST, "[Fail] recognized_palm= 0x%x, palm_filter_mask= 0x%x\n", g_pGesture->recognized_palm, g_pGesture->palm_filter_mask);
3391 base_height_size = 0;
3395 false_base_height_size = 0;
3398 base_cx = base_cy = 0;
3399 base_box_ext.x1 = base_box_ext.x2 = base_box_ext.y1 = base_box_ext.y2 = 0;
3400 memset(&verti_line, 0L, PALM_VERTI_ARRAY_COUNT * sizeof(int));
3401 #ifdef __PALM_GESTURE_LOG__
3402 XDBG_DEBUG(MGEST, "[cleanup_flick] base_height_size=%d, curTouched=%d\n", base_height_size, curTouched);
3410 GesturePalmGetScreenInfo()
3413 pixman_region16_t tarea;
3414 PalmMiscInfoPtr pPalmMisc = &g_pGesture->palm_misc;
3415 ScreenPtr pScreen = miPointerCurrentScreen();
3419 #ifdef __PALM_DETAIL_LOG__
3420 XDBG_DEBUG(MGEST, "Failed to get screen information !\n");
3422 pPalmMisc->scrn_width = pPalmMisc->scrn_height = 0;
3426 pPalmMisc->scrn_width = pScreen->width;
3427 pPalmMisc->scrn_height = pScreen->height;
3428 pixman_region_init(&tarea);
3429 pixman_region_init_rect(&tarea, 0, 0, pPalmMisc->scrn_width, pPalmMisc->scrn_height);
3430 pPalmMisc->half_scrn_area_size = AREA_SIZE(&tarea.extents);
3431 pPalmMisc->half_scrn_area_size = (unsigned int)((double)pPalmMisc->half_scrn_area_size / 2.4f);
3432 #ifdef __HOLD_DETECTOR_DEBUG__
3433 XDBG_DEBUG(MGEST, "pPalmMisc->half_scrn_area_size = %d\n", pPalmMisc->half_scrn_area_size);
3434 #endif//__HOLD_DETECTOR_DEBUG__
3436 for(i = 0 ; i < PALM_HORIZ_ARRAY_COUNT ; i++)
3438 pPalmMisc->horiz_coord[i] = pPalmMisc->scrn_width * ((i+1)/(double)PALM_HORIZ_ARRAY_COUNT);
3439 #ifdef __PALM_DETAIL_LOG__
3440 XDBG_DEBUG(MGEST, "pPalmMisc->horiz_coord[%d]=%d, pPalmMisc->scrn_width=%d\n", i, pPalmMisc->horiz_coord[i], pPalmMisc->scrn_width);
3443 for(i = 0 ; i < PALM_VERTI_ARRAY_COUNT ; i++)
3445 pPalmMisc->verti_coord[i] = pPalmMisc->scrn_height * ((i+1)/(double)PALM_VERTI_ARRAY_COUNT);
3446 #ifdef __PALM_DETAIL_LOG__
3447 XDBG_DEBUG(MGEST, "pPalmMisc->verti_coord[%d]=%d, pPalmMisc->scrn_height=%d\n", i, pPalmMisc->verti_coord[i], pPalmMisc->scrn_height);
3455 GesturePalmGetAbsAxisInfo(DeviceIntPtr dev)
3459 PalmStatusPtr pPalm;
3472 Atom atom_tracking_id;
3476 g_pGesture->wmajor_idx = -1;
3477 g_pGesture->tmajor_idx = -1;
3478 g_pGesture->tminor_idx = -1;
3479 g_pGesture->tangle_idx = -1;
3480 g_pGesture->tpalm_idx = -1;
3481 g_pGesture->mt_px_idx = -1;
3482 g_pGesture->mt_py_idx = -1;
3483 g_pGesture->mt_tool_idx = -1;
3485 memset(&g_pGesture->palm, 0, sizeof(PalmStatus));
3487 if (!dev || !dev->valuator)
3490 numAxes = dev->valuator->numAxes;
3491 atom_mt_px = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_X);
3492 atom_mt_py = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_Y);
3493 atom_wmajor = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_WIDTH_MAJOR);
3494 atom_tmajor = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_TOUCH_MAJOR);
3495 atom_tminor = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_TOUCH_MINOR);
3496 atom_tangle = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_ANGLE);
3497 atom_tpalm = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_PALM);
3499 atom_px = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
3500 atom_py = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
3501 atom_mt_slot = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_SLOT);
3502 atom_tracking_id = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_TRACKING_ID);
3503 atom_distance = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_DISTANCE);
3504 atom_mt_tool = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_TOOL_TYPE);
3506 if (!numAxes || !atom_mt_px || !atom_mt_py || !atom_tmajor || !atom_tminor || !atom_tangle || !atom_tpalm)
3508 XDBG_WARNING(MGEST, "one or more axes is/are not supported!\n");
3513 XDBG_WARNING(MGEST, "multitouch various type was not supported\n");
3516 for( i = 0 ; i < numAxes ; i++ )
3518 AxisInfoPtr axes = &dev->valuator->axes[i];
3520 if (!axes || (axes->mode != Absolute))
3523 if ( axes->label == atom_mt_px )
3525 g_pGesture->mt_px_idx = i;
3528 else if ( axes->label == atom_mt_py )
3530 g_pGesture->mt_py_idx = i;
3533 else if ( axes->label == atom_wmajor )
3535 g_pGesture->wmajor_idx = i;
3538 else if ( axes->label == atom_tmajor )
3540 g_pGesture->tmajor_idx = i;
3543 else if ( axes->label == atom_tminor )
3545 g_pGesture->tminor_idx = i;
3548 else if ( axes->label == atom_tangle )
3550 g_pGesture->tangle_idx = i;
3553 else if ( axes->label == atom_tpalm )
3555 g_pGesture->tpalm_idx = i;
3558 else if ( atom_mt_tool && axes->label == atom_mt_tool )
3560 g_pGesture->mt_tool_idx = i;
3567 XDBG_WARNING(MGEST, "Various multitouch devices are not supported !\n");
3570 XDBG_WARNING(MGEST, "Axes for palm recognization are not supported !\n");
3575 pPalm = &g_pGesture->palm;
3576 pixman_region_init(&pPalm->area);
3578 for( i = 0 ; i < MAX_MT_DEVICES ; i++ )
3580 pixman_region_init_rect (&pPalm->finger_rects[i], 0, 0, FINGER_WIDTH_2T, FINGER_HEIGHT_2T);
3583 g_pGesture->palm_misc.enabled = 1;
3584 XDBG_INFO(MGEST, "Axes for palm recognization are supported !\n");
3588 g_pGesture->palm_misc.enabled = 0;
3589 XDBG_INFO(MGEST, "Palm recognization is not supported !\n");
3594 GesturePalmDataUpdate(int idx, int type, InternalEvent *ev, DeviceIntPtr device)
3596 int wmajor_idx = g_pGesture->wmajor_idx;
3597 int tmajor_idx = g_pGesture->tmajor_idx;
3598 int tminor_idx = g_pGesture->tminor_idx;
3599 int tangle_idx = g_pGesture->tangle_idx;
3600 int tpalm_idx = g_pGesture->tpalm_idx;
3601 int px_idx = g_pGesture->mt_px_idx;
3602 int py_idx= g_pGesture->mt_py_idx;
3604 double width_major = 0.0f;
3605 double touch_major = 0.0f;
3606 double touch_minor = 0.0f;
3607 double touch_angle = 0.0f;
3608 double touch_palm = 0.0f;
3609 double max_width = -1.0f;
3613 double meanX = 0.0f;
3614 double meanY = 0.0f;
3615 double tmpXp = 0.0f;
3616 double tmpYp = 0.0f;
3618 PalmStatusPtr pPalm = &g_pGesture->palm;
3619 DeviceEvent *de = &ev->device_event;
3623 if (!de || !de->valuators.data)
3625 XDBG_WARNING(MGEST, "de or de->valuators.data are NULL !\n");
3629 if ((wmajor_idx < 0) || (tmajor_idx < 0) || (tminor_idx < 0) || (tangle_idx < 0) || (tpalm_idx < 0) || (px_idx < 0) || (py_idx < 0))
3631 XDBG_WARNING(MGEST, "One or more of axes are not supported !\n");
3635 width_major = de->valuators.data[wmajor_idx];
3636 touch_major = de->valuators.data[tmajor_idx];
3637 touch_minor = de->valuators.data[tminor_idx];
3638 touch_angle = de->valuators.data[tangle_idx];
3639 touch_palm = de->valuators.data[tpalm_idx];
3640 if( !(g_pGesture->palm.palmflag) && pPalm->max_palm >= PALM_FLICK_MIN_PALM)
3642 g_pGesture->palm.palmflag = 1;
3643 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
3646 #ifdef __PALM_DETAIL_LOG__
3647 XDBG_DEBUG(MGEST, "[idx:%d, devid:%d, type:%d] width_major=%.f, touch_major=%.f, touch_minor=%.f, touch_palm=%.f \n", idx, de->deviceid, type, width_major, touch_major, touch_minor, touch_palm);
3648 XDBG_DEBUG(MGEST, "[%d]: touch_status: %d, x: %d, y: %d (cur_touched: %d);\n", idx, pPalm->pti[idx].touch_status, pPalm->pti[idx].x, pPalm->pti[idx].y, pPalm->cur_touched);
3653 case ET_ButtonPress:
3654 if (!pPalm->pti[idx].touch_status)
3656 pPalm->cur_touched++;
3657 pPalm->pti[idx].touch_status = 1;
3660 pPalm->pti[idx].x = de->root_x;
3661 pPalm->pti[idx].y = de->root_y;
3662 #ifdef __PALM_DETAIL_LOG__
3663 XDBG_DEBUG(MGEST, "[idx:%d(devid:%d)][PRESS] x=%d, y=%d, wmajor=%.f, tmajor=%.f, tminor=%.f, tangle=%.f, tpalm=%.f\n", idx, device->id, pPalm->pti[idx].x, pPalm->pti[idx].y, pPalm->pti[idx].wmajor, pPalm->pti[idx].tmajor, pPalm->pti[idx].tminor, pPalm->pti[idx].tangle, pPalm->pti[idx].tpalm);
3667 case ET_ButtonRelease:
3668 if (pPalm->pti[idx].touch_status)
3670 --pPalm->cur_touched;
3671 if (pPalm->cur_touched < 0)
3672 pPalm->cur_touched = 0;
3675 pPalm->pti[idx].touch_status = 2;
3677 pPalm->pti[idx].x = de->root_x;
3678 pPalm->pti[idx].y = de->root_y;
3680 pPalm->pti[idx].tangle = 0.0f;
3681 pPalm->pti[idx].wmajor = 0.0f;
3682 pPalm->pti[idx].tmajor = 0.0f;
3683 pPalm->pti[idx].tminor = 0.0f;
3684 pPalm->pti[idx].tpalm = 0.0f;
3685 #ifdef __PALM_DETAIL_LOG__
3686 XDBG_DEBUG(MGEST, "[idx:%d(devid:%d)][RELEASE] x=%d, y=%d, wmajor=%.f, tmajor=%.f, tminor=%.f, tangle=%.f, tpalm=%.f\n", idx, device->id, pPalm->pti[idx].x, pPalm->pti[idx].y, pPalm->pti[idx].wmajor, pPalm->pti[idx].tmajor, pPalm->pti[idx].tminor, pPalm->pti[idx].tangle, pPalm->pti[idx].tpalm);
3691 pPalm->pti[idx].x = de->root_x;
3692 pPalm->pti[idx].y = de->root_y;
3694 pPalm->pti[idx].tmajor = touch_major;
3695 pPalm->pti[idx].tangle = touch_angle;
3696 pPalm->pti[idx].wmajor = width_major;
3697 pPalm->pti[idx].tminor = touch_minor;
3698 pPalm->pti[idx].tpalm = touch_palm;
3700 if (!pPalm->pti[idx].touch_status || (pPalm->pti[idx].tmajor == 0))
3702 #ifdef __PALM_DETAIL_LOG__
3703 XDBG_DEBUG(MGEST, "[idx:%d(devid:%d)][MOVE] x=%d, y=%d, wmajor=%.f, tmajor=%.f, tminor=%.f, tangle=%.f, tpalm=%.f\n", idx, device->id, pPalm->pti[idx].x, pPalm->pti[idx].y, pPalm->pti[idx].wmajor, pPalm->pti[idx].tmajor, pPalm->pti[idx].tminor, pPalm->pti[idx].tangle, pPalm->pti[idx].tpalm);
3708 pPalm->sum_size = 0.0f;
3709 pPalm->max_wmajor = -1.0f;
3710 pPalm->max_tmajor = -1.0f;
3711 pPalm->max_tminor = -1.0f;
3712 pPalm->max_size_idx = -1;
3713 pPalm->max_palm = -1.0f;
3716 for( count = 0, i = 0 ; i < g_pGesture->num_mt_devices ; i++ )
3718 if (!pPalm->pti[i].touch_status)
3720 if(pPalm->pti[i].touch_status == 2)
3721 pPalm->pti[i].touch_status =0;
3723 meanX += pPalm->pti[i].x;
3724 meanY += pPalm->pti[i].y;
3725 pPalm->sum_size += pPalm->pti[i].wmajor;
3726 if(max_width < pPalm->pti[i].wmajor)
3728 pPalm->max_size_idx = i;
3730 if (pPalm->max_wmajor < pPalm->pti[i].wmajor)
3732 pPalm->max_wmajor = pPalm->pti[i].wmajor;
3734 if(pPalm->max_tmajor < pPalm->pti[i].tmajor)
3735 pPalm->max_tmajor = pPalm->pti[i].tmajor;
3736 if(pPalm->max_tminor < pPalm->pti[i].tminor)
3737 pPalm->max_tminor = pPalm->pti[i].tminor;
3738 if(pPalm->max_palm < pPalm->pti[i].tpalm)
3740 pPalm->max_palm = (int)pPalm->pti[i].tpalm;
3741 #ifdef __PALM_DETAIL_LOG__
3742 XDBG_DEBUG(MGEST, "max_palm=%d pPalm->pti[%d].tpalm: %.f\n", pPalm->max_palm, i, pPalm->pti[i].tpalm);
3747 if (pPalm->max_size_idx < 0)
3749 #ifdef __PALM_DETAIL_LOG__
3750 XDBG_DEBUG(MGEST, "Failed to get sum_size !\n");
3754 pPalm->dispersionX = 0.0f;
3755 pPalm->deviationX = 0.0f;
3756 pPalm->dispersionY= 0.0f;
3757 pPalm->deviationY = 0.0f;
3758 pPalm->max_eccen = 0.0f;
3759 pPalm->max_angle = 0.0f;
3768 for( i = 0 ; i < g_pGesture->num_mt_devices ; i++ )
3770 if (!pPalm->pti[i].touch_status)
3773 tmpXp += (pPalm->pti[i].x - meanX)*(pPalm->pti[i].x - meanX);
3774 tmpYp += (pPalm->pti[i].y - meanY)*(pPalm->pti[i].y - meanY);
3777 pPalm->dispersionX = tmpXp / count;
3778 pPalm->deviationX = sqrt(pPalm->dispersionX);
3779 pPalm->dispersionY = tmpYp / count;
3780 pPalm->deviationY = sqrt(pPalm->dispersionY);
3781 #ifdef __PALM_DETAIL_LOG__
3782 XDBG_DEBUG(MGEST, "meanX=%.f, meanY=%.f, count=%d, tmpXp=%.f, tmpYp=%.f\n", meanX, meanY, count, tmpXp, tmpYp);
3785 pPalm->max_eccen = pPalm->max_tmajor/ pPalm->max_tminor;
3786 pPalm->max_angle = pPalm->pti[pPalm->max_size_idx].tangle;
3790 TimerCancel(pPalm->palm_single_finger_timer);
3791 pPalm->single_timer_expired = 0;
3793 if(pPalm->biggest_tmajor < pPalm->max_tmajor)
3794 pPalm->biggest_tmajor = pPalm->max_tmajor;
3795 if(pPalm->biggest_wmajor < pPalm->max_wmajor)
3796 pPalm->biggest_wmajor = pPalm->max_wmajor;
3797 if(pPalm->bigger_wmajor < pPalm->max_wmajor)
3798 pPalm->bigger_wmajor = pPalm->max_wmajor;
3799 #ifdef __PALM_DETAIL_LOG__
3800 XDBG_DEBUG(MGEST, "[maxidx:%d] cur_touched=%d, palmflag=%d, sum_size=%.f, max_wmajor=%.f, max_eccen=%.1f, max_angle=%.f\n", pPalm->max_size_idx, pPalm->cur_touched, pPalm->palmflag, pPalm->sum_size, pPalm->max_wmajor, pPalm->max_eccen, pPalm->max_angle);
3801 XDBG_DEBUG(MGEST, "sum_size=%.f, max_tmajor=%.f, dispersionX=%.f, deviationX=%.f, dispersionY=%.f, deviationY=%.f\n", pPalm->sum_size, pPalm->max_tmajor, pPalm->dispersionX, pPalm->deviationX, pPalm->dispersionY, pPalm->deviationY);
3802 XDBG_DEBUG(MGEST, "max_palm=%d\n", pPalm->max_palm);
3807 GesturePalmUpdateAreaInfo(int type, int idx)
3810 PalmStatusPtr pPalm = &g_pGesture->palm;
3814 case ET_ButtonPress:
3815 pPalm->finger_rects[idx].extents.x1 = pPalm->pti[idx].x - FINGER_WIDTH;
3816 pPalm->finger_rects[idx].extents.x2 = pPalm->pti[idx].x + FINGER_WIDTH;
3817 pPalm->finger_rects[idx].extents.y1 = pPalm->pti[idx].y - FINGER_HEIGHT;
3818 pPalm->finger_rects[idx].extents.y2 = pPalm->pti[idx].y + FINGER_HEIGHT;
3819 #ifdef __PALM_DETAIL_LOG__
3820 XDBG_DEBUG(MGEST, "[P] [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", idx, pPalm->finger_rects[idx].extents.x1, pPalm->finger_rects[idx].extents.x2, pPalm->finger_rects[idx].extents.y1, pPalm->finger_rects[idx].extents.y2);
3821 XDBG_DEBUG(MGEST, "[P] area [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", idx, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2);
3822 #endif// __PALM_DETAIL_LOG__
3824 if(pPalm->cur_touched == 1)
3826 pixman_region_union(&pPalm->area, &pPalm->finger_rects[idx], &pPalm->finger_rects[idx]);
3827 #ifdef __PALM_DETAIL_LOG__
3828 XDBG_DEBUG(MGEST, "[P] cur:1 [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", idx, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2);
3829 #endif//__PALM_DETAIL_LOG__
3833 pixman_region_union(&pPalm->area, &pPalm->finger_rects[idx], &pPalm->finger_rects[idx]);
3834 for(i = 0 ; i < g_pGesture->num_mt_devices ; i++)
3836 if(!pPalm->pti[i].touch_status)
3839 pixman_region_union(&pPalm->area, &pPalm->area, &pPalm->finger_rects[i]);
3840 #ifdef __PALM_DETAIL_LOG__
3841 XDBG_DEBUG(MGEST, "[P] cur:else [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", i, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2);
3842 #endif//__PALM_DETAIL_LOG__
3847 case ET_ButtonRelease:
3851 if (!pPalm->pti[idx].touch_status || (pPalm->pti[idx].tmajor == 0))
3853 pPalm->finger_rects[idx].extents.x1 = pPalm->pti[idx].x - FINGER_WIDTH;
3854 pPalm->finger_rects[idx].extents.x2 = pPalm->pti[idx].x + FINGER_WIDTH;
3855 pPalm->finger_rects[idx].extents.y1 = pPalm->pti[idx].y - FINGER_HEIGHT;
3856 pPalm->finger_rects[idx].extents.y2 = pPalm->pti[idx].y + FINGER_HEIGHT;
3857 #ifdef __PALM_DETAIL_LOG__
3858 XDBG_DEBUG(MGEST, "[M] [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", idx, pPalm->finger_rects[idx].extents.x1, pPalm->finger_rects[idx].extents.x2, pPalm->finger_rects[idx].extents.y1, pPalm->finger_rects[idx].extents.y2);
3859 XDBG_DEBUG(MGEST, "[M] area [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", idx, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2);
3860 #endif//__PALM_DETAIL_LOG__
3861 if(pPalm->cur_touched == 1)
3863 pixman_region_union(&pPalm->area, &pPalm->finger_rects[idx], &pPalm->finger_rects[idx]);
3864 #ifdef __PALM_DETAIL_LOG__
3865 XDBG_DEBUG(MGEST, "[M] cur:1 [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", idx, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2);
3866 #endif//__PALM_DETAIL_LOG__
3870 pixman_region_union(&pPalm->area, &pPalm->finger_rects[idx], &pPalm->finger_rects[idx]);
3871 #ifdef __PALM_DETAIL_LOG__
3872 XDBG_DEBUG(MGEST, "[M] cur:else:first [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", idx, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2);
3873 #endif//__PALM_DETAIL_LOG__
3875 for(i = 0 ; i < g_pGesture->num_mt_devices ; i++)
3877 if(!pPalm->pti[i].touch_status)
3879 pixman_region_union(&pPalm->area, &pPalm->area, &pPalm->finger_rects[i]);
3880 #ifdef __PALM_DETAIL_LOG__
3881 XDBG_DEBUG(MGEST, "[M] cur:else [%d]: x1: %d, x2: %d, y1: %d, y2: %d\n", i, pPalm->area.extents.x1, pPalm->area.extents.x2, pPalm->area.extents.y1, pPalm->area.extents.y2);
3882 #endif//__PALM_DETAIL_LOG__
3890 GesturePalmRecognize(int type, InternalEvent *ev, DeviceIntPtr device)
3894 PalmStatusPtr pPalm = &g_pGesture->palm;
3895 static int calc_touched = 0;
3896 static int event_sum_palm_first_finger = 0, event_sum_palm_second_finger=0;
3898 if( device->id < g_pGesture->first_fingerid )
3901 idx = GestureGetFingerIndexFromDevice(device);
3905 #ifdef __DETAIL_DEBUG__
3906 XDBG_DEBUG(MGEST, "[g_pGesture->num_pressed=%d]\n", g_pGesture->num_pressed);
3907 #endif//__DETAIL_DEBUG__
3908 if(!g_pGesture->pTempPalmWin)
3910 g_pGesture->pTempPalmWin = GestureGetEventsWindow();
3911 if(!g_pGesture->pTempPalmWin || g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL)
3913 #ifdef __PALM_DETAIL_LOG__
3914 XDBG_DEBUG(MGEST, "No events are grabbed/selected !\n");
3915 #endif//__PALM_DETAIL_LOG__
3916 g_pGesture->no_palm_events = TRUE;
3917 if (g_pGesture->palm_rejection_mode == 0)
3919 g_pGesture->palm_filter_mask = GESTURE_PALM_FILTER_MASK_ALL;
3924 g_pGesture->palm_filter_mask = 0;
3928 GesturePalmDataUpdate(idx, type, ev, device);
3929 GesturePalmUpdateAreaInfo(type, idx);
3930 #ifdef __PALM_DETAIL_LOG__
3931 XDBG_DEBUG(MGEST, "[idx: %d: %d](%d, %d)max_tmajor: %lf, palmflag: %d, max_wmajor: %lf\n", idx, type, pPalm->pti[idx].x, pPalm->pti[idx].y, pPalm->max_tmajor, pPalm->palmflag, pPalm->max_wmajor);
3932 XDBG_DEBUG(MGEST, "bigger_wmajor: %lf, biggest_tmajor: %lf, biggest_wmajor: %lf\n", pPalm->bigger_wmajor, pPalm->biggest_tmajor, pPalm->biggest_wmajor);
3933 XDBG_DEBUG(MGEST, "area: %d, deviationX: %lf, deviationY: %lf, dispersionX: %lf, dispersion: %lf\n", pPalm->area, pPalm->deviationX, pPalm->deviationY, pPalm->dispersionX, pPalm->dispersionY);
3937 case ET_ButtonPress:
3939 event_sum_palm_first_finger = BTN_PRESSED;
3941 event_sum_palm_second_finger = BTN_PRESSED;
3942 pPalm->max_touched++;
3944 if( g_pGesture->num_pressed == 1 )
3946 pPalm->palm_single_finger_timer = TimerSet(pPalm->palm_single_finger_timer, 0, 50, GesturePalmSingleFingerTimerHandler, NULL);
3948 else if(g_pGesture->num_pressed > 1)
3950 TimerCancel(pPalm->palm_single_finger_timer);
3954 if(pPalm->cur_touched == 0 || pPalm->pti[idx].touch_status != 1)
3958 if((pPalm->cur_touched == 1 && idx == 0 && event_sum_palm_first_finger == BTN_PRESSED) ||
3959 (pPalm->cur_touched == 2 && idx == 1 && event_sum_palm_second_finger == BTN_PRESSED))
3963 event_sum_palm_first_finger = BTN_MOVING;
3964 #ifdef __PALM_DETAIL_LOG__
3965 XDBG_DEBUG(MGEST, "First move detected!\n");
3966 #endif//__PALM_DETAIL_LOG__
3970 event_sum_palm_second_finger = BTN_MOVING;
3971 #ifdef __PALM_DETAIL_LOG__
3972 XDBG_DEBUG(MGEST, "Second finger First move detected!\n");
3973 #endif//__PALM_DETAIL_LOG__
3975 if (pPalm->palmflag < 1 && pPalm->biggest_tmajor < g_pGesture->palm_min_touch_major && pPalm->biggest_wmajor < g_pGesture->palm_min_width_major)
3977 #ifdef __PALM_DETAIL_LOG__
3978 XDBG_DEBUG(MGEST, "No palm coming.\n");
3979 #endif//__PALM_DETAIL_LOG__
3981 exist = GestureIsPalmEventInMIEQ();
3982 #ifdef __PALM_DETAIL_LOG__
3983 XDBG_DEBUG(MGEST, "palm event exist: %d\n", exist);
3984 #endif//__PALM_DETAIL_LOG__
3988 pPalm->palmflag = 1;
3989 g_pGesture->palm_detected = TRUE;
3994 * The following is the bezel condition for palm
3995 * -- palm touch area can be smaller than that of non-bezel regions, so the threshold value is reduced.
3997 if(!(g_pGesture->palm_filter_mask & PalmFlickHorizFilterMask) &&
3998 (pPalm->cx >= g_pGesture->screen_width - g_pGesture->palm_bezel || pPalm->cx < g_pGesture->palm_bezel) &&
3999 (pPalm->biggest_tmajor >= g_pGesture->palm_min_touch_major_bezel || pPalm->biggest_wmajor >= g_pGesture->palm_min_width_major_bezel))
4001 g_pGesture->palm_detected = TRUE;
4004 if(!(g_pGesture->palm_filter_mask & PalmFlickVertiFilterMask) &&
4005 (pPalm->cy >= g_pGesture->screen_height - g_pGesture->palm_bezel || pPalm->cy < g_pGesture->palm_bezel) &&
4006 (pPalm->biggest_tmajor >= g_pGesture->palm_min_touch_major_bezel || pPalm->biggest_wmajor >= g_pGesture->palm_min_width_major_bezel))
4008 g_pGesture->palm_detected = TRUE;
4012 if (g_pGesture->palm_rejection_mode == 1 && g_pGesture->no_palm_events == TRUE)
4013 g_pGesture->palm_filter_mask = GESTURE_PALM_FILTER_MASK_ALL;
4014 g_pGesture->recognized_palm = 0;
4015 if(!(g_pGesture->palm_filter_mask & PalmFlickHorizFilterMask))
4017 GesturePalmRecognize_FlickHorizen(type, -1);
4019 if(!(g_pGesture->palm_filter_mask & PalmFlickVertiFilterMask))
4021 GesturePalmRecognize_FlickVertical(type, -1);
4023 if (g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL)
4029 g_pGesture->palm_detected = TRUE;
4033 if(calc_touched == pPalm->cur_touched)
4038 case ET_ButtonRelease:
4040 event_sum_palm_first_finger = BTN_RELEASED;
4042 event_sum_palm_second_finger = BTN_RELEASED;
4049 if( g_pGesture->palm_rejection_mode == 1 && g_pGesture->palm_detected == TRUE && g_pGesture->no_palm_events == TRUE)
4051 g_pGesture->recognized_palm = 0;
4052 g_pGesture->palm_filter_mask = GESTURE_PALM_FILTER_MASK_ALL;
4056 if( GestureHasFingerEventMask(GestureNotifyFlick, 0) )
4058 if(!(g_pGesture->palm_filter_mask & PalmFlickHorizFilterMask))
4060 GesturePalmRecognize_FlickHorizen(type, idx);
4062 if(!(g_pGesture->palm_filter_mask & PalmFlickVertiFilterMask))
4064 GesturePalmRecognize_FlickVertical(type, idx);
4068 if(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL)
4070 pixman_region_init(&pPalm->area);
4072 for( i = 0 ; i < MAX_MT_DEVICES ; i++ )
4074 pixman_region_init_rect (&pPalm->finger_rects[i], 0, 0, FINGER_WIDTH_2T, FINGER_HEIGHT_2T);
4076 pPalm->palmflag = 0;
4081 case ET_ButtonPress:
4084 case ET_ButtonRelease:
4085 if(( g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL ) && ( pPalm->cur_touched == 0))
4092 #ifdef __PALM_DETAIL_LOG__
4093 XDBG_DEBUG(MGEST, "recognized_palm: 0x%x, palm_filter_mask: 0x%x, ehtype: %d\n", g_pGesture->recognized_palm, g_pGesture->palm_filter_mask, g_pGesture->ehtype);
4094 #endif//__PALM_DETAIL_LOG__
4095 if( g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL )
4097 if( !g_pGesture->recognized_palm )
4101 if( g_pGesture->recognized_palm )
4103 if( g_pGesture->ehtype == KEEP_EVENTS )
4104 GestureEventsDrop();
4105 g_pGesture->ehtype = IGNORE_EVENTS;
4112 #ifdef __PALM_DETAIL_LOG__
4113 XDBG_DEBUG(MGEST, "GestureFlushOrDrop() !\n");
4114 #endif//__PALM_DETAIL_LOG__
4115 if( ERROR_INVALPTR == GestureFlushOrDrop() )
4117 GestureControl(g_pGesture->this_device, DEVICE_OFF);
4122 #ifdef _F_SUPPORT_BEZEL_FLICK_
4124 GestureBezelRecognize(int type, InternalEvent *ev, DeviceIntPtr device)
4126 static OsTimerPtr bezel_finger_timer = NULL;
4128 BezelFlickStatusPtr pBezel = &g_pGesture->bezel;
4132 static Time base_time = 0;
4135 static int px=-1, py=-1;
4136 static int mx=-1, my=-1;
4137 static int rx=-1, ry=-1;
4138 static int event_count=0;
4140 if(g_pGesture->enqueue_fulled == 1)
4142 #ifdef __BEZEL_DEBUG__
4143 XDBG_DEBUG(MGEST, "EQ Event is full.... palm recognize drop..\n");
4144 #endif//__BEZEL_DEBUG__
4148 if( (PROPAGATE_EVENTS == g_pGesture->ehtype) || (device->id != g_pGesture->first_fingerid) )
4151 for( i = 0 ; i < g_pGesture->num_mt_devices ; i++ )
4153 if( device->id == g_pGesture->mt_devices[i]->id )
4159 #ifdef __BEZEL_DEBUG__
4160 XDBG_DEBUG(MGEST, "[type: %d][g_pGesture->num_pressed=%d, x,y(%d, %d) ]\n", type, g_pGesture->num_pressed, ev->device_event.root_x, ev->device_event.root_x);
4161 XDBG_DEBUG(MGEST, "[filter_mask: 0x%x, bezel_filter_mask: 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->filter_mask, g_pGesture->bezel_filter_mask, g_pGesture->palm_filter_mask);
4162 #endif//__BEZEL_DEBUG__
4166 if(g_pGesture->recognized_gesture || g_pGesture->recognized_palm)
4168 if(g_pGesture->num_pressed > 1)
4170 #ifdef __BEZEL_DEBUG__
4171 XDBG_DEBUG(MGEST, "Not single finger g_pGesture->num_pressed: %d\n", g_pGesture->num_pressed);
4172 #endif//__BEZEL_DEBUG__
4175 if(pBezel->is_active == BEZEL_END)
4177 #ifdef __BEZEL_DEBUG__
4178 XDBG_DEBUG(MGEST, "Bezel state is END pBezel->is_active: %d\n", pBezel->is_active);
4179 XDBG_DEBUG(MGEST, "[filter_mask: 0x%x, bezel_filter_mask: 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->filter_mask, g_pGesture->bezel_filter_mask, g_pGesture->palm_filter_mask);
4180 #endif//__BEZEL_DEBUG__
4186 case ET_ButtonPress:
4187 base_time = GetTimeInMillis();
4188 px = ev->device_event.root_x;
4189 py = ev->device_event.root_y;
4190 #ifdef __BEZEL_DEBUG__
4191 XDBG_DEBUG(MGEST, "[P] pBezel->is_active: %d, g_pGesture->num_pressed: %d, idx: %d\n", pBezel->is_active, g_pGesture->num_pressed, idx);
4192 XDBG_DEBUG(MGEST, "[P] g_pGesture->fingers[%d].p: (%d, %d)\n", idx, px,py);
4193 #endif//__BEZEL_DEBUG__
4194 if( (pBezel->is_active == BEZEL_ON) && ((g_pGesture->num_pressed == 1) && (idx == 0)) )
4196 if( ( px < pBezel->top_left.width) && ( py < pBezel->top_left.height) )
4198 #ifdef __BEZEL_DEBUG__
4199 XDBG_DEBUG(MGEST, "[P] top_left\n");
4200 #endif//__BEZEL_DEBUG__
4201 pBezel->is_active = BEZEL_START;
4202 pBezel->bezelStatus = BEZEL_TOP_LEFT;
4204 else if( (px > (720 - pBezel->top_right.width)) && ( py < pBezel->top_right.height) )
4206 #ifdef __BEZEL_DEBUG__
4207 XDBG_DEBUG(MGEST, "[P] top_right\n");
4208 #endif//__BEZEL_DEBUG__
4209 pBezel->is_active = BEZEL_START;
4210 pBezel->bezelStatus = BEZEL_TOP_RIGHT;
4212 else if( (px < pBezel->bottom_left.width) && ( py > (1280 - pBezel->bottom_left.height)) )
4214 #ifdef __BEZEL_DEBUG__
4215 XDBG_DEBUG(MGEST, "[P] bottom_left\n");
4216 #endif//__BEZEL_DEBUG__
4217 pBezel->is_active = BEZEL_START;
4218 pBezel->bezelStatus = BEZEL_BOTTOM_LEFT;
4220 else if( (px > (720 - pBezel->bottom_right.width)) && ( py > (1280 - pBezel->bottom_right.height)) )
4222 #ifdef __BEZEL_DEBUG__
4223 XDBG_DEBUG(MGEST, "[P] bottom_right\n");
4224 #endif//__BEZEL_DEBUG__
4225 pBezel->is_active = BEZEL_START;
4226 pBezel->bezelStatus = BEZEL_BOTTOM_RIGHT;
4230 #ifdef __BEZEL_DEBUG__
4231 XDBG_DEBUG(MGEST, "[P] None\n");
4232 #endif//__BEZEL_DEBUG__
4233 pBezel->bezelStatus = NO_BEZEL;
4237 if(pBezel->is_active == BEZEL_START)
4239 bezel_finger_timer = TimerSet(bezel_finger_timer, 0, 500, GestureBezelSingleFingerTimerHandler, NULL);
4243 TimerCancel(bezel_finger_timer);
4249 mx = ev->device_event.root_x;
4250 my = ev->device_event.root_y;
4252 if( (g_pGesture->bezel.bezel_angle_moving_check) && (event_count >= 10))
4254 angle = get_angle(px, py, mx, my);
4256 if(!GestureBezelAngleRecognize(pBezel->bezelStatus, pBezel->flick_distance, angle))
4258 #ifdef __BEZEL_DEBUG__
4259 XDBG_DEBUG(MGEST, "[M] moving limit!\n");
4260 #endif//__BEZEL_DEBUG__
4261 TimerCancel(bezel_finger_timer);
4266 case ET_ButtonRelease:
4267 rx = ev->device_event.root_x;
4268 ry = ev->device_event.root_y;
4269 if( (g_pGesture->num_pressed == 0) && (g_pGesture->inc_num_pressed == 1) && (pBezel->is_active == BEZEL_START) )
4271 angle = get_angle(px, py, rx, ry);
4272 distance = get_distance(px, py, rx, ry);
4273 Time duration = GetTimeInMillis() - base_time;
4274 #ifdef __BEZEL_DEBUG__
4275 XDBG_DEBUG(MGEST, "[R] bezelStatus: %d, distance: %d, angle: %lf\n", pBezel->bezelStatus, distance, angle);
4276 #endif//__BEZEL_DEBUG__
4277 int res = GestureBezelAngleRecognize(pBezel->bezelStatus, distance, angle);
4280 #ifdef __BEZEL_DEBUG__
4281 XDBG_DEBUG(MGEST, "[R] Bezel Success\n");
4282 #endif//__BEZEL_DEBUG__
4283 pBezel->is_active = BEZEL_DONE;
4284 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
4285 g_pGesture->palm_filter_mask = GESTURE_PALM_FILTER_MASK_ALL;
4286 TimerCancel(bezel_finger_timer);
4288 if( (0.0 < angle) && (angle < RAD_90DEG))
4289 direction = FLICK_NORTHEASTWARD;
4290 else if(angle < RAD_180DEG)
4291 direction = FLICK_NORTHWESTWARD;
4293 if( GestureHasFingerEventMask(GestureNotifyFlick, 1) )
4294 GestureHandleGesture_Flick(1, distance, duration, direction);
4297 #ifdef __BEZEL_DEBUG__
4298 XDBG_DEBUG(MGEST, "[R] Bezel failed\n");
4299 #endif//__BEZEL_DEBUG__
4306 #ifdef __BEZEL_DEBUG__
4307 XDBG_DEBUG(MGEST, "[F] Bezel failed\n");
4308 #endif//__BEZEL_DEBUG__
4309 pBezel->is_active = BEZEL_END;
4310 g_pGesture->bezel_filter_mask |= BezelFlickFilterMask;
4314 #ifdef __BEZEL_DEBUG__
4315 XDBG_DEBUG(MGEST, "[F] Bezel cleanup\n");
4316 #endif//__BEZEL_DEBUG__
4317 TimerCancel(bezel_finger_timer);
4318 if( ERROR_INVALPTR == GestureFlushOrDrop() )
4320 GestureControl(g_pGesture->this_device, DEVICE_OFF);
4322 bezel_finger_timer = NULL;
4324 px=py=mx=my=rx=ry=-1;
4329 static EventQueuePtr
4330 GestureGetMIEQ(void)
4332 if (*checkForInput[0] == *checkForInput[1])
4334 #ifdef __DETAIL_DEBUG__
4335 XDBG_DEBUG(MGEST, "mieq is empty !\n");
4336 #endif//__DETAIL_DEBUG__
4340 EventQueuePtr mieqEQPtr = NULL;
4341 mieqEQPtr = mieqGetEventQueuePtr();
4345 #ifdef __DETAIL_DEBUG__
4346 XDBG_DEBUG(MGEST, "mieqEQPtr is NULL !\n");
4347 #endif//__DETAIL_DEBUG__
4352 int num = mieqNumEnqueued(mieqEQPtr);
4353 #ifdef __DETAIL_DEBUG__
4354 XDBG_DEBUG(MGEST, " num of event in mieq = %d\n", num);
4355 #endif//__DETAIL_DEBUG__
4363 GestureIsEventInMIEQ(int finger_index, enum EventType type)
4365 EventQueuePtr mieqEQPtr = NULL;
4366 mieqEQPtr = GestureGetMIEQ();
4369 #ifdef __DETAIL_DEBUG__
4370 XDBG_DEBUG(MGEST, "failed to get mieq\n");
4371 #endif//__DETAIL_DEBUG__
4375 int deviceid = GestureGetDeviceIdFromFingerIndex(finger_index);
4378 XDBG_ERROR(MGEST, "Failed to get deviceid from finger index !\n");
4383 static InternalEvent event;
4384 HWEventQueueType head, tail;
4385 head = mieqEQPtr->head;
4386 tail = mieqEQPtr->tail;
4388 while (head != tail)
4390 e = &mieqEQPtr->events[head];
4395 if (e->pDev && (deviceid == e->pDev->id) && (event.any.type == type))
4401 head = (head + 1) % mieqEQPtr->nevents;
4408 GestureIsPalmEventInMIEQ(void)
4410 EventQueuePtr mieqEQPtr = NULL;
4411 mieqEQPtr = GestureGetMIEQ();
4414 #ifdef __PALM_DETAIL_LOG__
4415 XDBG_DEBUG(MGEST, "failed to get mieq\n");
4416 #endif//__PALM_DETAIL_LOG__
4421 static InternalEvent event;
4422 HWEventQueueType head, tail;
4423 head = mieqEQPtr->head;
4424 tail = mieqEQPtr->tail;
4426 while (head != tail)
4428 e = &mieqEQPtr->events[head];
4433 if (GestureIsPalmEvent(&event))
4439 head = (head + 1) % mieqEQPtr->nevents;
4446 GestureIsPalmEvent(InternalEvent *event)
4448 int wmajor_idx = g_pGesture->wmajor_idx;
4449 int tmajor_idx = g_pGesture->tmajor_idx;
4450 int tpalm_idx = g_pGesture->tpalm_idx;
4452 double width_major = 0.0f;
4453 double touch_major = 0.0f;
4454 double touch_palm = 0.0f;
4456 if (event->any.type != ET_ButtonPress && event->any.type != ET_Motion && event->any.type != ET_ButtonRelease)
4459 DeviceEvent *de = &event->device_event;
4461 if (!de || !de->valuators.data)
4463 XDBG_WARNING(MGEST, "de or de->valuators.data are NULL !\n");
4467 if ((wmajor_idx < 0) || (tmajor_idx < 0) || (tpalm_idx < 0))
4469 XDBG_WARNING(MGEST, "One or more of axes are not supported !\n");
4473 width_major = de->valuators.data[wmajor_idx];
4474 touch_major = de->valuators.data[tmajor_idx];
4475 touch_palm = de->valuators.data[tpalm_idx];
4476 #ifdef __PALM_DETAIL_LOG__
4477 XDBG_DEBUG(MGEST, "width_major: %.f, touch_major: %.f, touch_palm: %.f\n", width_major, touch_major, touch_palm);
4478 #endif//__PALM_DETAIL_LOG__
4480 if (touch_palm >= 1 || touch_major >= g_pGesture->palm_min_touch_major || width_major >= g_pGesture->palm_min_width_major)
4486 GestureGetFingerIndexFromDevice(DeviceIntPtr device)
4490 for( i = 0 ; i < g_pGesture->num_mt_devices ; i++ )
4492 if( device->id == g_pGesture->mt_devices[i]->id )
4502 GestureGetDeviceIdFromFingerIndex(int finger_index)
4504 if (g_pGesture->num_mt_devices <= finger_index)
4507 return g_pGesture->mt_devices[finger_index]->id;
4512 GestureRecognize(int type, InternalEvent *ev, DeviceIntPtr device)
4515 static OsTimerPtr single_finger_timer = NULL;
4518 if( PROPAGATE_EVENTS == g_pGesture->ehtype ||
4519 device->id < g_pGesture->first_fingerid )
4522 idx = GestureGetFingerIndexFromDevice(device);
4526 #ifdef __DETAIL_DEBUG__
4527 XDBG_DEBUG(MGEST, "[type: %d][g_pGesture->num_pressed=%d, x,y(%d, %d) ]\n", type, g_pGesture->num_pressed, ev->device_event.root_x, ev->device_event.root_x);
4528 XDBG_DEBUG(MGEST, "[inc_num_pressed: %d]\n", g_pGesture->inc_num_pressed);
4529 #ifdef _F_SUPPORT_BEZEL_FLICK_
4530 XDBG_DEBUG(MGEST, "[filter_mask: 0x%x, bezel_filter_mask: 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->filter_mask, g_pGesture->bezel_filter_mask, g_pGesture->palm_filter_mask);
4531 XDBG_DEBUG(MGEST, "[recognized_gesture: 0x%x, bezel_recognize_mask: 0x%x, recognized_palm: 0x%x\n", g_pGesture->recognized_gesture, g_pGesture->bezel_recognized_mask, g_pGesture->recognized_palm);
4533 XDBG_DEBUG(MGEST, "[filter_mask: 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->filter_mask, g_pGesture->palm_filter_mask);
4534 XDBG_DEBUG(MGEST, "[recognized_gesture: 0x%x, recognized_palm: 0x%x\n", g_pGesture->recognized_gesture, g_pGesture->recognized_palm);
4536 #endif//__DETAIL_DEBUG__
4541 case ET_ButtonPress:
4543 g_pGesture->event_sum[0] = BTN_PRESSED;
4544 g_pGesture->fingers[idx].ptime = ev->any.time;
4545 g_pGesture->fingers[idx].px = ev->device_event.root_x;
4546 g_pGesture->fingers[idx].py = ev->device_event.root_y;
4548 if( g_pGesture->num_pressed == 1 )
4550 single_finger_timer = TimerSet(single_finger_timer, 0, g_pGesture->tap_repeated ? 80 : g_pGesture->singlefinger_threshold, GestureSingleFingerTimerHandler, NULL);
4554 TimerCancel(single_finger_timer);
4557 if( g_pGesture->num_pressed > g_pGesture->num_mt_devices )
4558 g_pGesture->num_pressed = g_pGesture->num_mt_devices;
4560 if( !g_pGesture->pTempWin || g_pGesture->num_pressed != g_pGesture->inc_num_pressed )
4562 g_pGesture->pTempWin = GestureGetEventsWindow();
4564 if( NULL == g_pGesture->pTempWin || g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL)
4566 #ifdef __DETAIL_DEBUG__
4567 XDBG_DEBUG(MGEST, "[g_pGesture->num_pressed=%d] No events were selected !\n", g_pGesture->num_pressed);
4568 #endif//__DETAIL_DEBUG__
4569 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
4574 g_pGesture->inc_num_pressed = g_pGesture->num_pressed;
4576 g_pGesture->finger_rects[idx].extents.x1 = ev->device_event.root_x - FINGER_WIDTH;
4577 g_pGesture->finger_rects[idx].extents.x2 = ev->device_event.root_x + FINGER_WIDTH;
4578 g_pGesture->finger_rects[idx].extents.y1 = ev->device_event.root_y - FINGER_HEIGHT;
4579 g_pGesture->finger_rects[idx].extents.y2 = ev->device_event.root_y + FINGER_HEIGHT;
4581 pixman_region_union(&g_pGesture->area, &g_pGesture->finger_rects[0], &g_pGesture->finger_rects[0]);
4582 for( i = 1 ; i < g_pGesture->inc_num_pressed ; i++ )
4584 pixman_region_union(&g_pGesture->area, &g_pGesture->area, &g_pGesture->finger_rects[i]);
4586 #ifdef __DETAIL_DEBUG__
4587 XDBG_DEBUG(MGEST, "[M][g_pGesture->inc_num_pressed=%d] AREA_SIZE(area)=%d\n", g_pGesture->inc_num_pressed, AREA_SIZE(&g_pGesture->area.extents));
4588 #endif//__DETAIL_DEBUG__
4593 if( !g_pGesture->fingers[idx].ptime )
4596 g_pGesture->fingers[idx].mx = ev->device_event.root_x;
4597 g_pGesture->fingers[idx].my = ev->device_event.root_y;
4599 if( (g_pGesture->inc_num_pressed < 2) && (idx == 0))
4601 g_pGesture->event_sum[0] += BTN_MOVING;
4602 #ifdef __DETAIL_DEBUG__
4603 XDBG_DEBUG(MGEST, "no seconds finger comming\n");
4604 #endif//__DETAIL_DEBUG__
4605 if(!g_pGesture->tap_repeated)
4607 if(g_pGesture->event_sum[0] >= 3)
4609 #ifdef __DETAIL_DEBUG__
4610 XDBG_DEBUG(MGEST, "single finger!\n");
4611 #endif//__DETAIL_DEBUG__
4613 exist = GestureIsEventInMIEQ(1, ET_ButtonPress);
4614 #ifdef __DETAIL_DEBUG__
4615 XDBG_DEBUG(MGEST, "two finger touch in queue, exist: %d\n", exist);
4616 #endif//__DETAIL_DEBUG__
4618 g_pGesture->event_sum[0] -= BTN_MOVING;
4621 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
4628 if(ABS(g_pGesture->fingers[idx].mx - g_pGesture->fingers[idx].px) > FINGER_WIDTH
4629 || ABS(g_pGesture->fingers[idx].my - g_pGesture->fingers[idx].py) > FINGER_HEIGHT)
4631 #ifdef __DETAIL_DEBUG__
4632 XDBG_DEBUG(MGEST, "tap repeat Moving Limit Exceeded.\n");
4633 #endif//__DETAIL_DEBUG__
4634 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
4637 else if(g_pGesture->event_sum[0] >= 15)
4639 #ifdef __DETAIL_DEBUG__
4640 XDBG_DEBUG(MGEST, "tap repeat Moving Limit Exceeded.\n");
4641 #endif//__DETAIL_DEBUG__
4643 exist = GestureIsEventInMIEQ(1, ET_ButtonPress);
4644 #ifdef __DETAIL_DEBUG__
4645 XDBG_DEBUG(MGEST, "two finger touch in queue, exist: %d\n", exist);
4646 #endif//__DETAIL_DEBUG__
4648 g_pGesture->event_sum[0] -= BTN_MOVING;
4651 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
4658 g_pGesture->finger_rects[idx].extents.x1 = ev->device_event.root_x - FINGER_WIDTH;
4659 g_pGesture->finger_rects[idx].extents.x2 = ev->device_event.root_x + FINGER_WIDTH;
4660 g_pGesture->finger_rects[idx].extents.y1 = ev->device_event.root_y - FINGER_HEIGHT;
4661 g_pGesture->finger_rects[idx].extents.y2 = ev->device_event.root_y + FINGER_HEIGHT;
4663 pixman_region_union(&g_pGesture->area, &g_pGesture->finger_rects[0], &g_pGesture->finger_rects[0]);
4664 for( i = 1 ; i < g_pGesture->inc_num_pressed ; i++ )
4666 pixman_region_union(&g_pGesture->area, &g_pGesture->area, &g_pGesture->finger_rects[i]);
4668 #ifdef __DETAIL_DEBUG__
4669 XDBG_DEBUG(MGEST, "[M][g_pGesture->inc_num_pressed=%d] AREA_SIZE(area)=%d\n", g_pGesture->inc_num_pressed, AREA_SIZE(&g_pGesture->area.extents));
4670 #endif//__DETAIL_DEBUG__
4673 case ET_ButtonRelease:
4674 g_pGesture->fingers[idx].rtime = ev->any.time;
4675 g_pGesture->fingers[idx].rx = ev->device_event.root_x;
4676 g_pGesture->fingers[idx].ry = ev->device_event.root_y;
4678 if( g_pGesture->num_pressed <= 0 )
4680 #ifdef __DETAIL_DEBUG__
4681 XDBG_DEBUG(MGEST, "All fingers were released !\n");
4682 #endif//__DETAIL_DEBUG__
4683 if( g_pGesture->inc_num_pressed == 1 )
4689 if( g_pGesture->filter_mask != GESTURE_FILTER_MASK_ALL )
4691 if( !(g_pGesture->filter_mask & FlickFilterMask) )
4693 GestureRecognize_GroupFlick(type, ev, device, idx);
4695 if( !(g_pGesture->filter_mask & PanFilterMask) )
4697 GestureRecognize_GroupPan(type, ev, device, idx, 0);
4699 if( !(g_pGesture->filter_mask & PinchRotationFilterMask) )
4701 GestureRecognize_GroupPinchRotation(type, ev, device, idx, 0);
4703 if( !(g_pGesture->filter_mask & TapFilterMask) )
4705 GestureRecognize_GroupTap(type, ev, device, idx, 0);
4707 if( !(g_pGesture->filter_mask & TapNHoldFilterMask) )
4709 GestureRecognize_GroupTapNHold(type, ev, device, idx, 0);
4711 if( !(g_pGesture->filter_mask & HoldFilterMask) )
4713 GestureRecognize_GroupHold(type, ev, device, idx, 0);
4717 #ifdef __DETAIL_DEBUG__
4718 #ifdef _F_SUPPORT_BEZEL_FLICK_
4719 XDBG_DEBUG(MGEST, "[filter_mask: 0x%x, bezel_filter_mask: 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->filter_mask, g_pGesture->bezel_filter_mask, g_pGesture->palm_filter_mask);
4720 XDBG_DEBUG(MGEST, "[recognized_gesture: 0x%x, bezel_recognize_mask: 0x%x, recognized_palm: 0x%x\n", g_pGesture->recognized_gesture, g_pGesture->bezel_recognized_mask, g_pGesture->recognized_palm);
4722 XDBG_DEBUG(MGEST, "[filter_mask: 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->filter_mask, g_pGesture->palm_filter_mask);
4723 XDBG_DEBUG(MGEST, "[recognized_gesture: 0x%x, recognized_palm: 0x%x\n", g_pGesture->recognized_gesture, g_pGesture->recognized_palm);
4725 #endif//__DETAIL_DEBUG__
4727 if( g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL )
4729 if( !g_pGesture->recognized_gesture )
4731 else if( !g_pGesture->num_pressed )
4735 if( g_pGesture->recognized_gesture )
4737 if( g_pGesture->ehtype == KEEP_EVENTS )
4738 GestureEventsDrop();
4739 g_pGesture->ehtype = IGNORE_EVENTS;
4745 TimerCancel(single_finger_timer);
4746 #ifdef __DETAIL_DEBUG__
4747 XDBG_DEBUG(MGEST, "GestureFlushOrDrop() !\n");
4748 #endif//__DETAIL_DEBUG__
4749 if( ERROR_INVALPTR == GestureFlushOrDrop() )
4751 GestureControl(g_pGesture->this_device, DEVICE_OFF);
4756 ErrorStatus GestureFlushOrDrop(void)
4758 ErrorStatus err = ERROR_NONE;
4759 PalmStatusPtr pPalm = &g_pGesture->palm;
4761 #ifdef __DETAIL_DEBUG__
4762 XDBG_DEBUG(MGEST, "recognized_gesture: 0x%x, filter_mask: 0x%x\n", g_pGesture->recognized_gesture, g_pGesture->filter_mask);
4763 XDBG_DEBUG(MGEST, "recognized_palm: 0x%x, palm_filter_mask: 0x%x\n", g_pGesture->recognized_palm, g_pGesture->palm_filter_mask);
4764 #ifdef _F_SUPPORT_BEZEL_FLICK_
4765 XDBG_DEBUG(MGEST, "bezel_recognized_mask: 0x%x, bezel_filter_mask: 0x%x\n", g_pGesture->bezel_recognized_mask, g_pGesture->bezel_filter_mask);
4767 #endif//__DETAIL_DEBUG__
4769 if(g_pGesture->recognized_gesture || g_pGesture->recognized_palm
4770 #ifdef _F_SUPPORT_BEZEL_FLICK_
4771 || g_pGesture->bezel_recognized_mask)
4776 g_pGesture->ehtype = IGNORE_EVENTS;
4777 GestureEventsDrop();
4778 if(g_pGesture->recognized_palm)
4779 err = GestureRegionsReinit();
4780 //memset(pPalm->pti, 0, sizeof(pPalm->pti[MAX_MT_DEVICES]));
4781 for(i=0; i<MAX_MT_DEVICES; i++)
4783 pPalm->pti[i].touch_status = 0;
4784 pPalm->pti[i].tangle = 0.0f;
4785 pPalm->pti[i].wmajor = 0.0f;
4786 pPalm->pti[i].tmajor = 0.0f;
4787 pPalm->pti[i].tminor = 0.0f;
4788 pPalm->pti[i].tpalm = 0.0f;
4790 if( ERROR_NONE != err )
4793 else if((g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL) && (g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL)
4794 #ifdef _F_SUPPORT_BEZEL_FLICK_
4795 && (g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
4800 g_pGesture->ehtype = PROPAGATE_EVENTS;
4801 if (g_pGesture->palm_rejection_mode == 1 && g_pGesture->palm_detected == TRUE)
4803 GestureEventsDrop();
4807 err = GestureEventsFlush();
4808 if( ERROR_NONE != err )
4811 err = GestureRegionsReinit();
4812 for(i=0; i<MAX_MT_DEVICES; i++)
4814 pPalm->pti[i].touch_status = 0;
4815 pPalm->pti[i].tangle = 0.0f;
4816 pPalm->pti[i].wmajor = 0.0f;
4817 pPalm->pti[i].tmajor = 0.0f;
4818 pPalm->pti[i].tminor = 0.0f;
4819 pPalm->pti[i].tpalm = 0.0f;
4821 if( ERROR_NONE != err )
4824 g_pGesture->pTempWin = NULL;
4825 g_pGesture->inc_num_pressed = 0;
4826 g_pGesture->event_sum[0] = 0;
4833 GestureHandleMTSyncEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
4836 PalmStatusPtr pPalm = &g_pGesture->palm;
4837 #ifdef _F_SUPPORT_BEZEL_FLICK_
4838 BezelFlickStatusPtr pBezel = &g_pGesture->bezel;
4840 #ifdef __DEBUG_EVENT_HANDLER__
4841 XDBG_DEBUG(MGEST, "(%d:%d) time:%d cur:%d\n",
4842 ev->any_event.deviceid, ev->any_event.sync, (int)ev->any.time, (int)GetTimeInMillis());
4843 #endif//__DEBUG_EVENT_HANDLER__
4845 if( MTOUCH_FRAME_SYNC_BEGIN == ev->any_event.sync )
4847 #ifdef __DEBUG_EVENT_HANDLER__
4848 XDBG_DEBUG(MGEST, "SYNC_BEGIN\n");
4849 #endif//__DEBUG_EVENT_HANDLER
4850 g_pGesture->mtsync_status = MTOUCH_FRAME_SYNC_BEGIN;
4852 if(g_pGesture->is_active)
4854 g_pGesture->ehtype = KEEP_EVENTS;
4855 g_pGesture->filter_mask = 0;
4856 g_pGesture->recognized_gesture = 0;
4857 g_pGesture->num_pressed = 0;
4858 g_pGesture->palm_filter_mask = 0;
4859 g_pGesture->recognized_palm= 0;
4860 g_pGesture->hold_detector_activate = 1;
4861 g_pGesture->has_hold_grabmask = 0;
4862 pPalm->palmflag = 0;
4863 pPalm->single_timer_expired = 0;
4864 pPalm->biggest_tmajor = 0;
4865 pPalm->biggest_wmajor = 0;
4866 pPalm->bigger_wmajor = 0;
4867 g_pGesture->enqueue_fulled = 0;
4868 #ifdef _F_SUPPORT_BEZEL_FLICK_
4869 pBezel->is_active = BEZEL_ON;
4870 g_pGesture->bezel_filter_mask = 0;
4871 g_pGesture->bezel_recognized_mask = 0;
4873 for( i=0 ; i < g_pGesture->num_mt_devices ; i++ )
4874 g_pGesture->fingers[i].ptime = 0;
4876 g_pGesture->stylusInfo.stylus_id = 0;
4877 g_pGesture->stylusInfo.pen_detected = FALSE;
4878 g_pGesture->no_palm_events = FALSE;
4879 g_pGesture->stylusInfo.fake_events = FALSE;
4880 g_pGesture->palm_detected = FALSE;
4882 else if( MTOUCH_FRAME_SYNC_END == ev->any_event.sync )
4884 #ifdef __DEBUG_EVENT_HANDLER__
4885 XDBG_DEBUG(MGEST, "SYNC_END\n");
4886 #endif//__DEBUG_EVENT_HANDLER
4887 g_pGesture->mtsync_status = MTOUCH_FRAME_SYNC_END;
4889 if(g_pGesture->is_active)
4891 g_pGesture->ehtype = PROPAGATE_EVENTS;
4892 g_pGesture->palm_filter_mask = GESTURE_PALM_FILTER_MASK_ALL;
4893 pPalm->cur_touched = 0;
4894 pPalm->palmflag = 0;
4895 pPalm->max_palm = 0;
4896 g_pGesture->pTempPalmWin = NULL;
4897 if(pPalm->palm_single_finger_timer)
4898 TimerCancel(pPalm->palm_single_finger_timer);
4899 g_pGesture->pTempWin = NULL;
4900 g_pGesture->inc_num_pressed = g_pGesture->num_pressed = 0;
4901 g_pGesture->event_sum[0] = 0;
4902 pPalm->max_touched = 0;
4903 g_pGesture->hold_detected = FALSE;
4904 #ifdef _F_SUPPORT_BEZEL_FLICK_
4905 pBezel->is_active = BEZEL_END;
4906 g_pGesture->bezel_filter_mask = BezelFlickFilterMask;
4909 for(i=0; i<MAX_MT_DEVICES; i++)
4911 g_pGesture->stylusInfo.t_status[i].status = BTN_RELEASED;
4917 GestureGetMTToolValuator(InternalEvent *ev, DeviceIntPtr device)
4919 int mt_tool_idx = g_pGesture->mt_tool_idx;
4920 double mt_tool = 0.0f;
4922 DeviceEvent *de = &ev->device_event;
4924 if (!de || !de->valuators.data)
4926 XDBG_WARNING(MGEST, "de or de->valuators.data are NULL !\n");
4930 if (mt_tool_idx < 0)
4932 XDBG_WARNING(MGEST, "One or more of axes are not supported !\n");
4936 if (ev->any.type == ET_ButtonPress || ev->any.type == ET_ButtonRelease)
4938 if (device->id == g_pGesture->master_pointer->id && g_pGesture->stylusInfo.stylus_id == g_pGesture->first_fingerid)
4939 de->valuators.data[mt_tool_idx] = 1;
4941 if (g_pGesture->stylusInfo.stylus_id == device->id)
4942 de->valuators.data[mt_tool_idx] = 1;
4945 mt_tool = de->valuators.data[mt_tool_idx];
4947 return (int)mt_tool;
4951 GestureRegisterTouchInfo(InternalEvent *ev, DeviceIntPtr device)
4955 idx = GestureGetFingerIndexFromDevice(device);
4958 if (device->id != g_pGesture->master_pointer->id)
4959 XDBG_WARNING(MGEST, "Failed to get correct idx(%d) device->id: %d, master_pointer: %d\n", idx, device->id, g_pGesture->master_pointer->id);
4962 switch(ev->any.type)
4964 case ET_ButtonPress:
4965 g_pGesture->stylusInfo.t_status[idx].status = BTN_PRESSED;
4968 if (g_pGesture->stylusInfo.t_status[idx].status == BTN_PRESSED)
4969 g_pGesture->stylusInfo.t_status[idx].status = BTN_MOVING;
4971 case ET_ButtonRelease:
4972 g_pGesture->stylusInfo.t_status[idx].status = BTN_RELEASED;
4975 XDBG_WARNING(MGEST, "unhandled event type(%d)\n", ev->any.type);
4978 g_pGesture->stylusInfo.t_status[idx].cx = ev->device_event.root_x;
4979 g_pGesture->stylusInfo.t_status[idx].cy = ev->device_event.root_y;
4983 GestureSetToolData(InternalEvent *ev, double val_tool)
4985 int mt_tool_idx = g_pGesture->mt_tool_idx;
4986 double mt_tool = 0.0f;
4988 DeviceEvent *de = &ev->device_event;
4990 if (!de || !de->valuators.data)
4992 XDBG_WARNING(MGEST, "de or de->valuators.data are NULL !\n");
4996 if (mt_tool_idx < 0)
4998 XDBG_WARNING(MGEST, "One or more of axes are not supported !\n");
5001 de->valuators.data[mt_tool_idx] = val_tool;
5005 GestureCleanupTouch(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5009 if (g_pGesture->stylusInfo.stylus_id == 0 && g_pGesture->stylusInfo.pen_detected == FALSE)
5010 g_pGesture->stylusInfo.stylus_id = device->id;
5012 if (g_pGesture->ehtype == KEEP_EVENTS)
5014 GestureEventsDrop();
5015 g_pGesture->ehtype = PROPAGATE_EVENTS;
5017 else if (g_pGesture->stylusInfo.pen_detected == FALSE && g_pGesture->ehtype == PROPAGATE_EVENTS)
5019 g_pGesture->stylusInfo.pen_detected = TRUE;
5020 g_pGesture->stylusInfo.fake_events = TRUE;
5021 for(i=0; i<MAX_MT_DEVICES; i++)
5023 if (g_pGesture->stylusInfo.t_status[i].status == BTN_PRESSED || g_pGesture->stylusInfo.t_status[i].status == BTN_MOVING)
5025 InternalEvent release_ev;
5026 memcpy(&release_ev, ev, sizeof(InternalEvent));
5027 release_ev.any.time = ev->any.time;
5028 release_ev.any.type = ET_ButtonRelease;
5030 release_ev.device_event.detail.button = 1;
5031 release_ev.device_event.type = ET_ButtonRelease;
5032 release_ev.device_event.root_x = g_pGesture->stylusInfo.t_status[i].cx;
5033 release_ev.device_event.root_y = g_pGesture->stylusInfo.t_status[i].cy;
5034 release_ev.device_event.deviceid = g_pGesture->mt_devices[i]->id;
5035 g_pGesture->stylusInfo.t_status[i].status = BTN_RELEASED;
5036 GestureSetToolData(&release_ev, (double)0);
5038 GestureHandleButtonReleaseEvent(screen_num, &release_ev, g_pGesture->mt_devices[i]);
5039 if (g_pGesture->mt_devices[i]->id == g_pGesture->first_fingerid)
5041 InternalEvent release_mev;
5042 memcpy(&release_mev, ev, sizeof(InternalEvent));
5043 release_mev.any.time = ev->any.time;
5044 release_mev.any.type = ET_ButtonRelease;
5046 release_mev.device_event.detail.button = 1;
5047 release_mev.device_event.type = ET_ButtonRelease;
5048 release_mev.device_event.root_x = g_pGesture->stylusInfo.t_status[i].cx;
5049 release_mev.device_event.root_y = g_pGesture->stylusInfo.t_status[i].cy;
5050 release_mev.device_event.deviceid = g_pGesture->master_pointer->id;
5051 GestureSetToolData(&release_mev, (double)0);
5053 GestureHandleButtonReleaseEvent(screen_num, &release_mev, g_pGesture->master_pointer);
5057 g_pGesture->stylusInfo.fake_events = FALSE;
5059 g_pGesture->stylusInfo.pen_detected = TRUE;
5060 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
5061 g_pGesture->recognized_gesture = 0;
5062 g_pGesture->palm_filter_mask = GESTURE_PALM_FILTER_MASK_ALL;
5063 g_pGesture->recognized_palm = 0;
5067 GestureChangeEventToFirstFingerEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5069 InternalEvent master_ev;
5070 ev->device_event.deviceid = g_pGesture->first_fingerid;
5072 switch(ev->any.type)
5074 case ET_ButtonPress:
5075 if(!(device->id < g_pGesture->first_fingerid))
5076 g_pGesture->num_pressed++;
5078 case ET_ButtonRelease:
5079 if(!(device->id < g_pGesture->first_fingerid))
5080 g_pGesture->num_pressed--;
5085 memcpy(&master_ev, ev, sizeof(InternalEvent));
5086 g_pGesture->mt_devices[0]->public.processInputProc(ev, g_pGesture->mt_devices[0]);
5088 master_ev.device_event.deviceid = g_pGesture->master_pointer->id;
5089 g_pGesture->master_pointer->public.processInputProc(&master_ev, g_pGesture->master_pointer);
5093 GestureHandleButtonPressEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5095 #ifdef __DEBUG_EVENT_HANDLER__
5096 XDBG_DEBUG(MGEST, "mode: %d devid=%d time:%d cur: %d (%d, %d)\n",
5097 g_pGesture->ehtype, device->id, ev->any.time, GetTimeInMillis(), ev->device_event.root_x, ev->device_event.root_y);
5098 #endif//__DEBUG_EVENT_HANDLER__
5100 if (g_pGesture->stylus_able)
5102 int isStylus = GestureGetMTToolValuator(ev, device);
5104 #ifdef __DEBUG_EVENT_HANDLER__
5105 XDBG_DEBUG(MGEST, "isSytlus: %d, pen_detected: %d, stylus_id: %d\n", isStylus, g_pGesture->stylusInfo.pen_detected, g_pGesture->stylusInfo.stylus_id);
5106 #endif//__DEBUG_EVENT_HANDLER__
5108 if (g_pGesture->stylusInfo.pen_detected == FALSE)
5112 GestureRegisterTouchInfo(ev, device);
5116 GestureCleanupTouch(screen_num, ev, device);
5119 if (g_pGesture->stylusInfo.pen_detected == TRUE)
5121 if (!isStylus || (device->id != g_pGesture->stylusInfo.stylus_id ))
5123 if (!(g_pGesture->stylusInfo.stylus_id == g_pGesture->first_fingerid && device->id == g_pGesture->master_pointer->id))
5128 else if (device->id != g_pGesture->first_fingerid)
5130 GestureChangeEventToFirstFingerEvent(screen_num, ev, device);
5136 switch( g_pGesture->ehtype )
5139 if( ERROR_INVALPTR == GestureEnqueueEvent(screen_num, ev, device) )
5141 GestureControl(g_pGesture->this_device, DEVICE_OFF);
5144 if( g_pGesture->num_mt_devices )
5146 if(!(device->id < g_pGesture->first_fingerid))
5147 g_pGesture->num_pressed++;
5148 #ifdef _F_SUPPORT_BEZEL_FLICK_
5149 if(!(g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
5150 GestureBezelRecognize(ET_ButtonPress, ev, device);
5152 if(!(g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL))
5153 GestureRecognize(ET_ButtonPress, ev, device);
5154 if(!(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL))
5157 _GESTUREPALMRECOGNIZE_(PalmRecognize, ET_ButtonPress, ev, device)
5159 g_pGesture->ehtype = PROPAGATE_EVENTS;
5163 device->public.processInputProc(ev, device);
5164 GestureHoldDetector(ET_ButtonPress, ev, device);
5167 case PROPAGATE_EVENTS:
5168 if(!(device->id < g_pGesture->first_fingerid))
5169 g_pGesture->num_pressed++;
5170 if (g_pGesture->palm_rejection_mode == 1 && g_pGesture->stylusInfo.pen_detected == TRUE)
5172 device->public.processInputProc(ev, device);
5174 else if (!(g_pGesture->palm_rejection_mode == 1 && g_pGesture->palm_detected == TRUE))
5176 device->public.processInputProc(ev, device);
5178 GestureHoldDetector(ET_ButtonPress, ev, device);
5182 if(!(device->id < g_pGesture->first_fingerid))
5183 g_pGesture->num_pressed++;
5184 #ifdef _F_SUPPORT_BEZEL_FLICK_
5185 if(!(g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
5186 GestureBezelRecognize(ET_ButtonPress, ev, device);
5188 if(!(g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL))
5189 GestureRecognize(ET_ButtonPress, ev, device);
5190 if(!(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL))
5193 _GESTUREPALMRECOGNIZE_(PalmRecognize, ET_ButtonPress, ev, device);
5203 GestureHandleMotionEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5205 #ifdef __DEBUG_EVENT_HANDLER__
5206 XDBG_DEBUG(MGEST, "mode: %d devid=%d time:%d cur: %d (%d, %d)\n",
5207 g_pGesture->ehtype, device->id, ev->any.time, GetTimeInMillis(), ev->device_event.root_x, ev->device_event.root_y);
5208 #endif//__DEBUG_EVENT_HANDLER__
5210 if (g_pGesture->stylus_able)
5212 int isStylus = GestureGetMTToolValuator(ev, device);
5214 #ifdef __DEBUG_EVENT_HANDLER__
5215 XDBG_DEBUG(MGEST, "isSytlus: %d, pen_detected: %d, stylus_id: %d\n", isStylus, g_pGesture->stylusInfo.pen_detected, g_pGesture->stylusInfo.stylus_id);
5216 #endif//__DEBUG_EVENT_HANDLER__
5218 if (g_pGesture->stylusInfo.pen_detected == FALSE)
5222 GestureRegisterTouchInfo(ev, device);
5226 GestureCleanupTouch(screen_num, ev, device);
5229 if (g_pGesture->stylusInfo.pen_detected == TRUE)
5231 if (!isStylus || (device->id != g_pGesture->stylusInfo.stylus_id ))
5233 if (!(g_pGesture->stylusInfo.stylus_id == g_pGesture->first_fingerid && device->id == g_pGesture->master_pointer->id))
5238 else if (device->id != g_pGesture->first_fingerid)
5240 GestureChangeEventToFirstFingerEvent(screen_num, ev, device);
5246 switch( g_pGesture->ehtype )
5249 if( ERROR_INVALPTR == GestureEnqueueEvent(screen_num, ev, device) )
5251 GestureControl(g_pGesture->this_device, DEVICE_OFF);
5254 if( g_pGesture->num_mt_devices )
5256 #ifdef _F_SUPPORT_BEZEL_FLICK_
5257 if(!(g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
5258 GestureBezelRecognize(ET_Motion, ev, device);
5260 if(!(g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL))
5261 GestureRecognize(ET_Motion, ev, device);
5262 if(!(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL))
5265 _GESTUREPALMRECOGNIZE_(PalmRecognize, ET_Motion, ev, device)
5267 g_pGesture->ehtype = PROPAGATE_EVENTS;
5271 device->public.processInputProc(ev, device);
5272 GestureHoldDetector(ET_Motion, ev, device);
5275 case PROPAGATE_EVENTS:
5276 if (g_pGesture->palm_rejection_mode == 1 && g_pGesture->stylusInfo.pen_detected == TRUE)
5278 device->public.processInputProc(ev, device);
5280 else if (!(g_pGesture->palm_rejection_mode == 1 && g_pGesture->palm_detected == TRUE))
5282 device->public.processInputProc(ev, device);
5284 GestureHoldDetector(ET_Motion, ev, device);
5288 #ifdef _F_SUPPORT_BEZEL_FLICK_
5289 if(!(g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
5290 GestureBezelRecognize(ET_Motion, ev, device);
5292 if(!(g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL))
5293 GestureRecognize(ET_Motion, ev, device);
5294 if(!(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL))
5297 _GESTUREPALMRECOGNIZE_(PalmRecognize, ET_Motion, ev, device);
5308 GestureHandleButtonReleaseEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5310 #ifdef __DEBUG_EVENT_HANDLER__
5311 XDBG_DEBUG(MGEST, "mode: %d devid=%d time:%d cur: %d (%d, %d)\n",
5312 g_pGesture->ehtype, device->id, ev->any.time, GetTimeInMillis(), ev->device_event.root_x, ev->device_event.root_y);
5313 #endif//__DEBUG_EVENT_HANDLER__
5315 if (g_pGesture->stylus_able)
5317 int isStylus = GestureGetMTToolValuator(ev, device);
5319 #ifdef __DEBUG_EVENT_HANDLER__
5320 XDBG_DEBUG(MGEST, "isSytlus: %d, pen_detected: %d, stylus_id: %d\n", isStylus, g_pGesture->stylusInfo.pen_detected, g_pGesture->stylusInfo.stylus_id);
5321 #endif//__DEBUG_EVENT_HANDLER__
5323 if (g_pGesture->stylusInfo.pen_detected == FALSE)
5327 GestureRegisterTouchInfo(ev, device);
5331 GestureCleanupTouch(screen_num, ev, device);
5334 if (g_pGesture->stylusInfo.pen_detected == TRUE)
5336 if (g_pGesture->stylusInfo.fake_events == TRUE)
5340 if (!isStylus || (device->id != g_pGesture->stylusInfo.stylus_id ))
5342 if (!(g_pGesture->stylusInfo.stylus_id == g_pGesture->first_fingerid && device->id == g_pGesture->master_pointer->id))
5347 else if (device->id != g_pGesture->first_fingerid)
5349 GestureChangeEventToFirstFingerEvent(screen_num, ev, device);
5355 switch( g_pGesture->ehtype )
5358 if( ERROR_INVALPTR == GestureEnqueueEvent(screen_num, ev, device) )
5360 GestureControl(g_pGesture->this_device, DEVICE_OFF);
5363 if( g_pGesture->num_mt_devices )
5365 if(!(device->id < g_pGesture->first_fingerid))
5366 g_pGesture->num_pressed--;
5367 #ifdef _F_SUPPORT_BEZEL_FLICK_
5368 if(!(g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
5369 GestureBezelRecognize(ET_ButtonRelease, ev, device);
5371 if(!(g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL))
5372 GestureRecognize(ET_ButtonRelease, ev, device);
5373 if(!(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL))
5376 _GESTUREPALMRECOGNIZE_(PalmRecognize, ET_ButtonRelease, ev, device)
5378 g_pGesture->num_mt_devices = PROPAGATE_EVENTS;
5382 device->public.processInputProc(ev, device);
5383 GestureHoldDetector(ET_ButtonRelease, ev, device);
5386 case PROPAGATE_EVENTS:
5387 #ifdef SUPPORT_ANR_WITH_INPUT_EVENT
5388 if( IsMaster(device) && ev->any.type == ET_ButtonRelease )
5390 if( g_pGesture->anr_window == NULL )
5392 g_pGesture->anr_window = _GestureFindANRWindow(device);
5396 // Send event to the e17 process.
5397 current_time = GetTimeInMillis();
5398 if( g_pGesture->anr_window != NULL )
5400 // Check anr_window validation.
5401 if( dixLookupWindow(&g_pGesture->anr_window, prop_anr_event_window_xid, serverClient, DixSetPropAccess) != BadWindow )
5403 if( serverClient->devPrivates != NULL )
5404 dixChangeWindowProperty (serverClient, g_pGesture->anr_window, prop_anr_in_input_event,
5405 XA_CARDINAL, 32, PropModeReplace, 1, ¤t_time, TRUE);
5409 prop_anr_event_window_xid = 0;
5410 g_pGesture->anr_window = NULL;
5412 XDBG_DEBUG(MGEST, "Release TOUCH!! devid=%d time:%d cur: %d\n", device->id, ev->any.time, GetTimeInMillis());
5416 if(!(device->id < g_pGesture->first_fingerid))
5417 g_pGesture->num_pressed--;
5418 if (g_pGesture->palm_rejection_mode == 1 && g_pGesture->stylusInfo.pen_detected == TRUE)
5420 device->public.processInputProc(ev, device);
5422 else if (!(g_pGesture->palm_rejection_mode == 1 && g_pGesture->palm_detected == TRUE))
5424 device->public.processInputProc(ev, device);
5426 GestureHoldDetector(ET_ButtonRelease, ev, device);
5430 if(!(device->id < g_pGesture->first_fingerid))
5431 g_pGesture->num_pressed--;
5432 #ifdef _F_SUPPORT_BEZEL_FLICK_
5433 if(!(g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
5434 GestureBezelRecognize(ET_ButtonRelease, ev, device);
5436 if(!(g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL))
5437 GestureRecognize(ET_ButtonRelease, ev, device);
5438 if(!(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL))
5441 _GESTUREPALMRECOGNIZE_(PalmRecognize, ET_ButtonRelease, ev, device);
5451 GestureHandleKeyPressEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5453 #ifdef __DEBUG_EVENT_HANDLER__
5454 XDBG_DEBUG(MGEST, "devid=%d time:%d cur:%d\n", device->id, ev->any.time, GetTimeInMillis());
5455 #endif//__DEBUG_EVENT_HANDLER__
5456 static int find_dev_false_count = 0;
5458 if(DPMSPowerLevel == DPMSModeOff)
5460 XDBG_INFO(MGEST, "LCD status : Off\n");
5464 for(i = 0 ; i < NUM_PASSKEYS ; i++)
5466 if(0 == g_pGesture->pass_keycodes[i])
5469 if(g_pGesture->pass_keycodes[i] == ev->device_event.detail.key)
5471 XDBG_SECURE(MGEST, "Pass KeyPress (devid:%d, keycode:%d) during LCD Off!\n", device->id, ev->device_event.detail.key);
5472 goto handle_keypress;
5476 XDBG_SECURE(MGEST, "Ignore KeyPress (devid:%d, keycode:%d) during LCD Off!\n", device->id, ev->device_event.detail.key);
5482 if (g_pGesture->touchkey_id <= 0 && find_dev_false_count < 10)
5485 find_dev_false_count++;
5487 for( dev = inputInfo.keyboard ; dev; dev = dev->next )
5489 if(strcasestr(dev->name, "touchkey"))
5491 g_pGesture->touchkey_id = dev->id;
5492 find_dev_false_count = 0;
5498 if((g_pGesture->mtsync_status != MTOUCH_FRAME_SYNC_END) && (device->id == g_pGesture->touchkey_id))
5500 if(ev->device_event.detail.key == 177)
5501 XDBG_INFO(MGEST, "Ignore TouchKey KEY_MENU (devid:%d)\n", device->id);
5502 else if (ev->device_event.detail.key == 166)
5503 XDBG_INFO(MGEST, "Ignore TouchKey KEY_BACK (devid:%d)\n", device->id);
5505 XDBG_SECURE(MGEST, "Ignore TouchKey KeyPress (devid:%d, keycode:%d)\n", device->id, ev->device_event.detail.key);
5509 device->public.processInputProc(ev, device);
5513 GestureHandleKeyReleaseEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5515 if (g_pGesture->pass_keycodes[3] == ev->device_event.detail.key)
5517 XDBG_SECURE(MGEST, "TIME = %d, keycode = %d\n", ev->any.time, ev->device_event.detail.key);
5519 device->public.processInputProc(ev, device);
5523 GestureEnableEventHandler(InputInfoPtr pInfo)
5526 GestureDevicePtr pGesture = pInfo->private;
5528 res = GestureInstallResourceStateHooks();
5532 XDBG_ERROR(MGEST, "Failed on GestureInstallResourceStateHooks() !\n");
5533 return ERROR_ABNORMAL;
5536 res = GestureSetMaxNumberOfFingers((int)MAX_MT_DEVICES);
5540 XDBG_ERROR(MGEST, "Failed on GestureSetMaxNumberOfFingers(%d) !\n", (int)MAX_MT_DEVICES);
5544 res = GestureRegisterCallbacks(GestureCbEventsGrabbed, GestureCbEventsSelected);
5548 XDBG_ERROR(MGEST, "Failed to register callbacks for GestureEventsGrabbed(), GestureEventsSelected() !\n");
5555 GestureUninstallResourceStateHooks();
5556 GestureUnsetMaxNumberOfFingers();
5558 return ERROR_ABNORMAL;
5562 GestureDisableEventHandler(void)
5564 ErrorStatus err = ERROR_NONE;
5566 mieqSetHandler(ET_KeyPress, NULL);
5567 mieqSetHandler(ET_KeyRelease, NULL);
5568 mieqSetHandler(ET_ButtonPress, NULL);
5569 mieqSetHandler(ET_ButtonRelease, NULL);
5570 mieqSetHandler(ET_Motion, NULL);
5571 mieqSetHandler(ET_MTSync, NULL);
5573 err = GestureFiniEQ();
5575 if( ERROR_INVALPTR == err )
5577 XDBG_ERROR(MGEST, "EQ is invalid or was freed already !\n");
5580 GestureRegisterCallbacks(NULL, NULL);
5581 GestureUninstallResourceStateHooks();
5587 GestureRegisterDeviceInfo(DeviceIntPtr device)
5589 InputInfoPtr pInfo = device->public.devicePrivate;
5590 GestureDevicePtr pGesture = pInfo->private;
5592 ScreenPtr pScreen = miPointerCurrentScreen();
5593 int width = 0, height = 0;
5597 XDBG_INFO(MGEST, "Get devices information\n");
5599 for (i=0; i<MAX_MT_DEVICES; i++)
5601 pGesture->mt_devices[i] = NULL;
5604 for( dev = inputInfo.pointer ; dev; dev = dev->next )
5606 if(IsMaster(dev) && IsPointerDevice(dev))
5608 pGesture->master_pointer = dev;
5609 XDBG_INFO(MGEST, "[id:%d] Master Pointer=%s\n", dev->id, pGesture->master_pointer->name);
5613 if(IsXTestDevice(dev, NULL) && IsPointerDevice(dev))
5615 pGesture->xtest_pointer = dev;
5616 XDBG_INFO(MGEST, "[id:%d] XTest Pointer=%s\n", dev->id, pGesture->xtest_pointer->name);
5620 if(IsPointerDevice(dev))
5622 if( idx >= MAX_MT_DEVICES )
5624 XDBG_WARNING(MGEST, "Number of mt device is over MAX_MT_DEVICES(%d) !\n",
5628 if (strcasestr(dev->name, "Touchscreen"))
5630 pGesture->mt_devices[idx] = dev;
5631 XDBG_INFO(MGEST, "[id:%d] MT device[%d] name=%s\n", dev->id, idx, pGesture->mt_devices[idx]->name);
5632 ErrorF("[id:%d] MT device[%d] name=%s\n", dev->id, idx, pGesture->mt_devices[idx]->name);
5633 GesturePalmGetAbsAxisInfo(dev);
5639 if( !pGesture->master_pointer || !pGesture->xtest_pointer )
5641 XDBG_ERROR(MGEST, "Failed to get info of master pointer or XTest pointer !\n");
5642 pGesture->num_mt_devices = 0;
5647 pGesture->num_mt_devices = idx;
5649 if( !pGesture->num_mt_devices )
5651 XDBG_ERROR(MGEST, "Failed to mt device information !\n");
5652 pGesture->num_mt_devices = 0;
5653 pGesture->first_fingerid = -1;
5657 pGesture->first_fingerid = pGesture->mt_devices[0]->id;
5658 memset(pGesture->fingers, 0, sizeof(TouchStatus)*pGesture->num_mt_devices);
5660 pGesture->pRootWin = RootWindow(pGesture->master_pointer);
5662 if(g_pGesture->palm_misc.enabled)
5663 GesturePalmGetScreenInfo();
5665 g_pGesture->pTempWin = NULL;
5666 g_pGesture->pTempPalmWin = NULL;
5667 g_pGesture->inc_num_pressed = 0;
5669 if( ERROR_NONE != GestureRegionsInit() || ERROR_NONE != GestureInitEQ() )
5676 pGesture->screen_width = pScreen->width;
5677 pGesture->screen_height = pScreen->height;
5678 XDBG_ERROR(MGEST, "screen_width = %d, screen_height = %d\n", pGesture->screen_width, pGesture->screen_height);
5682 XDBG_ERROR(MGEST, "Fail to get current screen size\n");
5685 mieqSetHandler(ET_KeyPress, GestureHandleKeyPressEvent);
5686 mieqSetHandler(ET_KeyRelease, GestureHandleKeyReleaseEvent);
5687 mieqSetHandler(ET_ButtonPress, GestureHandleButtonPressEvent);
5688 mieqSetHandler(ET_ButtonRelease, GestureHandleButtonReleaseEvent);
5689 mieqSetHandler(ET_Motion, GestureHandleMotionEvent);
5690 mieqSetHandler(ET_MTSync, GestureHandleMTSyncEvent);
5696 GestureUninstallResourceStateHooks();
5697 GestureUnsetMaxNumberOfFingers();
5701 IsXTestDevice(DeviceIntPtr dev, DeviceIntPtr master)
5707 return (dev->xtest_master_id == master->id);
5709 return (dev->xtest_master_id != 0);
5713 GestureEnable(int enable, Bool prop, DeviceIntPtr dev)
5715 if((!enable) && (g_pGesture->is_active))
5717 g_pGesture->is_active = 0;
5718 XDBG_INFO(MGEST, "Disabled !\n");
5720 else if((enable) && (!g_pGesture->is_active))
5722 g_pGesture->is_active = 1;
5723 XDBG_INFO(MGEST, "Enabled !\n");
5727 XIChangeDeviceProperty(dev, prop_gesture_recognizer_onoff, XA_INTEGER, 32, PropModeReplace, 1, &g_pGesture->is_active, FALSE);
5731 GestureRegionsInit(void)
5734 PalmStatusPtr pPalm = &g_pGesture->palm;
5737 return ERROR_INVALPTR;
5739 pixman_region_init(&g_pGesture->area);
5740 pixman_region_init(&pPalm->area);
5742 for( i = 0 ; i < MAX_MT_DEVICES ; i++ )
5744 pixman_region_init_rect (&g_pGesture->finger_rects[i], 0, 0, FINGER_WIDTH_2T, FINGER_HEIGHT_2T);
5745 pixman_region_init_rect (&pPalm->finger_rects[i], 0, 0, FINGER_WIDTH_2T, FINGER_HEIGHT_2T);
5752 GestureRegionsReinit(void)
5754 PalmStatusPtr pPalm = &g_pGesture->palm;
5758 XDBG_ERROR(MGEST, "Invalid pointer access !\n");
5759 return ERROR_INVALPTR;
5762 pixman_region_init(&g_pGesture->area);
5763 pixman_region_init(&pPalm->area);
5765 for( i = 0 ; i < MAX_MT_DEVICES ; i++ )
5767 pixman_region_init_rect (&pPalm->finger_rects[i], 0, 0, FINGER_WIDTH_2T, FINGER_HEIGHT_2T);
5779 tmpEQ = (IEventRec *)calloc(GESTURE_EQ_SIZE, sizeof(IEventRec));
5783 XDBG_ERROR(MGEST, "Failed to allocate memory for EQ !\n");
5784 return ERROR_ALLOCFAIL;
5787 for( i = 0 ; i < GESTURE_EQ_SIZE ; i++ )
5789 tmpEQ[i].event = (InternalEvent *)malloc(sizeof(InternalEvent));
5790 if( !tmpEQ[i].event )
5792 XDBG_ERROR(MGEST, "Failed to allocation memory for each event buffer in EQ !\n");
5794 while(i >= 0 && tmpEQ[i].event)
5796 free(tmpEQ[i].event);
5797 tmpEQ[i].event = NULL;
5801 return ERROR_ALLOCFAIL;
5805 g_pGesture->EQ = tmpEQ;
5806 g_pGesture->headEQ = g_pGesture->tailEQ = 0;
5816 if( !g_pGesture || !g_pGesture->EQ )
5817 return ERROR_INVALPTR;
5819 for( i = 0 ; i < GESTURE_EQ_SIZE ; i++ )
5821 if( g_pGesture->EQ[i].event )
5823 free(g_pGesture->EQ[i].event);
5824 g_pGesture->EQ[i].event = NULL;
5828 free(g_pGesture->EQ);
5829 g_pGesture->EQ = NULL;
5835 GestureEnqueueEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
5839 if( !g_pGesture || !g_pGesture->EQ )
5841 XDBG_ERROR(MGEST, "Invalid pointer access !\n");
5842 return ERROR_INVALPTR;
5845 tail = g_pGesture->tailEQ;
5847 if( tail >= GESTURE_EQ_SIZE )
5849 XDBG_WARNING(MGEST, "Gesture EQ is full !\n");
5850 printk("[X11][GestureEnqueueEvent] Gesture EQ is full...Force Gesture Flush !\n");
5851 g_pGesture->enqueue_fulled = 1;
5852 if(!(g_pGesture->filter_mask == GESTURE_FILTER_MASK_ALL))
5854 if( !(g_pGesture->filter_mask & FlickFilterMask) )
5856 GestureRecognize_GroupFlick(ev->any.type, ev, device, 0);
5858 if( !(g_pGesture->filter_mask & PanFilterMask) )
5860 GestureRecognize_GroupPan(ev->any.type, ev, device, 0, 0);
5862 if( !(g_pGesture->filter_mask & PinchRotationFilterMask) )
5864 GestureRecognize_GroupPinchRotation(ev->any.type, ev, device, 0, 0);
5866 if( !(g_pGesture->filter_mask & TapFilterMask) )
5868 GestureRecognize_GroupTap(ev->any.type, ev, device, 0, 0);
5870 if( !(g_pGesture->filter_mask & TapNHoldFilterMask) )
5872 GestureRecognize_GroupTapNHold(ev->any.type, ev, device, 0, 0);
5874 if( !(g_pGesture->filter_mask & HoldFilterMask) )
5876 GestureRecognize_GroupHold(ev->any.type, ev, device, 0, 0);
5879 if(!(g_pGesture->palm_filter_mask == GESTURE_PALM_FILTER_MASK_ALL))
5881 if(!(g_pGesture->palm_filter_mask & PalmFlickHorizFilterMask))
5883 GesturePalmRecognize_FlickHorizen(ev->any.type, 0);
5885 if(!(g_pGesture->palm_filter_mask & PalmFlickHorizFilterMask))
5887 GesturePalmRecognize_FlickVertical(ev->any.type, 0);
5890 #ifdef _F_SUPPORT_BEZEL_FLICK_
5891 if(!(g_pGesture->bezel_filter_mask == BezelFlickFilterMask))
5893 GestureBezelRecognize(ev->any.type, ev, device);
5896 g_pGesture->filter_mask = GESTURE_FILTER_MASK_ALL;
5897 g_pGesture->palm_filter_mask = GESTURE_PALM_FILTER_MASK_ALL;
5898 #ifdef _F_SUPPORT_BEZEL_FLICK_
5899 g_pGesture->bezel_filter_mask = BezelFlickFilterMask;
5900 g_pGesture->bezel_recognized_mask = 0;
5902 g_pGesture->recognized_gesture = 0;
5903 g_pGesture->recognized_palm = 0;
5904 if( ERROR_INVALPTR == GestureFlushOrDrop() )
5906 GestureControl(g_pGesture->this_device, DEVICE_OFF);
5908 return ERROR_EQFULL;
5911 #ifdef __DETAIL_DEBUG__
5912 switch( ev->any.type )
5914 case ET_ButtonPress:
5915 XDBG_DEBUG(MGEST, "ET_ButtonPress (id:%d)\n", device->id);
5918 case ET_ButtonRelease:
5919 XDBG_DEBUG(MGEST, "ET_ButtonRelease (id:%d)\n", device->id);
5923 XDBG_DEBUG(MGEST, "ET_Motion (id:%d)\n", device->id);
5926 #endif//__DETAIL_DEBUG__
5928 g_pGesture->EQ[tail].device = device;
5929 g_pGesture->EQ[tail].screen_num = screen_num;
5930 memcpy(g_pGesture->EQ[tail].event, ev, sizeof(InternalEvent));//need to be optimized
5931 g_pGesture->tailEQ++;
5937 GestureEventsFlush(void)
5940 DeviceIntPtr device;
5942 if( !g_pGesture->EQ )
5944 XDBG_ERROR(MGEST, "Invalid pointer access !\n");
5945 return ERROR_INVALPTR;
5948 #ifdef __DETAIL_DEBUG__
5949 XDBG_DEBUG(MGEST, "\n");
5950 #endif//__DETAIL_DEBUG__
5952 for( i = g_pGesture->headEQ ; i < g_pGesture->tailEQ ; i++)
5954 device = g_pGesture->EQ[i].device;
5955 #ifdef __DETAIL_DEBUG__
5956 if(g_pGesture->EQ[i].event->any.type != ET_Motion)
5957 XDBG_DEBUG(MGEST, "[%d] type: %d\n", device->id, g_pGesture->EQ[i].event->any.type);
5958 #endif//__DETAIL_DEBUG__
5960 for(j = 0 ; j < MAX_MT_DEVICES+1 ; j++)
5962 if(g_pGesture->palm.qti[j].devid == device->id)
5964 #ifdef __DETAIL_DEBUG__
5965 if(g_pGesture->EQ[i].event->any.type != ET_Motion)
5966 XDBG_DEBUG(MGEST, "[%d] type: %d(pressed: %d) time: %d\n", device->id, g_pGesture->EQ[i].event->any.type, g_pGesture->palm.qti[j].pressed, GetTimeInMillis());
5967 #endif//__DETAIL_DEBUG__
5968 if( (g_pGesture->palm.qti[j].pressed == 0) && (g_pGesture->EQ[i].event->any.type == ET_ButtonRelease) )
5970 XDBG_WARNING(MGEST, "Enqueued event..ButtonRelease with no ButtonPress !(devid: %d)\n", device->id);
5971 g_pGesture->EQ[i].event->any.type = ET_ButtonPress;
5972 device->public.processInputProc(g_pGesture->EQ[i].event, device);
5973 g_pGesture->EQ[i].event->any.type = ET_ButtonRelease;
5974 g_pGesture->palm.qti[j].pressed = 0;
5976 else if(g_pGesture->EQ[i].event->any.type == ET_ButtonPress)
5978 g_pGesture->palm.qti[j].pressed = 1;
5980 else if( (g_pGesture->palm.qti[j].pressed == 1) && (g_pGesture->EQ[i].event->any.type == ET_ButtonRelease))
5982 g_pGesture->palm.qti[j].pressed = 0;
5986 else if(g_pGesture->palm.qti[j].devid == 0)
5988 g_pGesture->palm.qti[j].devid = device->id;
5992 #ifdef __DETAIL_DEBUG__
5993 if(g_pGesture->EQ[i].event->any.type != ET_Motion)
5994 XDBG_DEBUG(MGEST, "!!! [%d] type: %d\n", device->id, g_pGesture->EQ[i].event->any.type);
5996 device->public.processInputProc(g_pGesture->EQ[i].event, device);
5998 memset(g_pGesture->palm.qti, 0, sizeof(g_pGesture->palm.qti[MAX_MT_DEVICES+1]));
6000 for( i = 0 ; i < MAX_MT_DEVICES ; i++ )
6001 g_pGesture->event_sum[i] = 0;
6003 g_pGesture->headEQ = g_pGesture->tailEQ = 0;//Free EQ
6010 GestureEventsDrop(void)
6012 #ifdef __DETAIL_DEBUG__
6013 XDBG_DEBUG(MGEST, "\n");
6014 #endif//__DETAIL_DEBUG__
6016 g_pGesture->headEQ = g_pGesture->tailEQ = 0;//Free EQ
6019 #ifdef HAVE_PROPERTIES
6021 GestureInitProperty(DeviceIntPtr dev)
6025 #ifdef SUPPORT_ANR_WITH_INPUT_EVENT
6026 prop_anr_in_input_event = MakeAtom(CHECK_APPLICATION_NOT_RESPONSE_IN_INPUT_EVENT, strlen(CHECK_APPLICATION_NOT_RESPONSE_IN_INPUT_EVENT), TRUE);
6027 prop_anr_event_window = MakeAtom(ANR_EVENT_WINDOW, strlen(ANR_EVENT_WINDOW), TRUE);
6030 prop_gesture_recognizer_onoff = MakeAtom(GESTURE_RECOGNIZER_ONOFF, strlen(GESTURE_RECOGNIZER_ONOFF), TRUE);
6031 rc = XIChangeDeviceProperty(dev, prop_gesture_recognizer_onoff, XA_INTEGER, 32, PropModeReplace, 1, &g_pGesture->is_active, FALSE);
6036 XISetDevicePropertyDeletable(dev, prop_gesture_recognizer_onoff, FALSE);
6038 prop_gesture_palm_rejection_mode = MakeAtom(GESTURE_PALM_REJECTION_MODE, strlen(GESTURE_PALM_REJECTION_MODE), TRUE);
6039 rc = XIChangeDeviceProperty(dev, prop_gesture_palm_rejection_mode, XA_INTEGER, 8, PropModeReplace, 1, &g_pGesture->palm_rejection_mode, FALSE);
6044 XISetDevicePropertyDeletable(dev, prop_gesture_palm_rejection_mode, FALSE);
6048 GestureSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
6051 if( prop_gesture_recognizer_onoff == atom )
6054 if( val->format != 32 || val->type != XA_INTEGER || val->size != 1 )
6059 data = *((int *)val->data);
6060 GestureEnable(data, TRUE, dev);
6063 else if( prop_gesture_palm_rejection_mode == atom)
6066 if( val->format != 8 || val->type != XA_INTEGER || val->size != 1 )
6072 data = *((BOOL*)val->data);
6076 g_pGesture->palm_rejection_mode = (int)data;
6078 fd = open("/sys/class/sec/tsp/cmd", O_WRONLY);
6081 XDBG_ERROR(MGEST, "failed to open tsp node(%d)\n", fd);
6085 sprintf(buf, "stylus_enable,%d", !!(g_pGesture->palm_rejection_mode));
6086 XDBG_DEBUG(MGEST, "stylus_changed: %d!\n", !!(g_pGesture->palm_rejection_mode));
6088 ret = write(fd, buf, strlen(buf));
6091 XDBG_WARNING(MGEST, "failed to stylus_changed: %d\n", !!(g_pGesture->palm_rejection_mode));
6096 fd_result = open("/sys/class/sec/tsp/cmd_result", O_RDONLY);
6099 XDBG_ERROR(MGEST, "failed to open tsp node(%d)\n", fd_result);
6103 memset(buf, 0L, sizeof(buf));
6105 ret = read(fd_result, buf, sizeof(buf));
6108 XDBG_WARNING(MGEST, "failed to read cmd_result\n");
6112 ErrorF("stylus mode result: %s\n", buf);
6120 #endif//HAVE_PROPERTIES
6123 GestureInit(DeviceIntPtr device)
6125 #ifdef HAVE_PROPERTIES
6126 GestureInitProperty(device);
6127 XIRegisterPropertyHandler(device, GestureSetProperty, NULL, NULL);
6134 GestureFini(DeviceIntPtr device)
6136 XIRegisterPropertyHandler(device, NULL, NULL, NULL);
6140 GesturePlug(pointer module, pointer options, int *errmaj, int *errmin)
6142 xf86AddInputDriver(&GESTURE, module, 0);
6147 GestureUnplug(pointer p)
6152 GesturePreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
6155 GestureDevicePtr pGesture;
6156 #ifdef _F_SUPPORT_BEZEL_FLICK_
6157 BezelFlickStatusPtr pBezel;
6160 pGesture = calloc(1, sizeof(GestureDeviceRec));
6163 pInfo->private = NULL;
6164 //xf86DeleteInput(pInfo, 0);
6168 g_pGesture = pGesture;
6169 pInfo->private = pGesture;
6171 pInfo->read_input = GestureReadInput; /* new data avl */
6172 pInfo->switch_mode = NULL; /* toggle absolute/relative mode */
6173 pInfo->device_control = GestureControl; /* enable/disable dev */
6174 /* process driver specific options */
6175 pGesture->device = xf86SetStrOption(pInfo->options, "Device", "/dev/null");
6176 pGesture->is_active = xf86SetIntOption(pInfo->options, "Activate", 0);
6177 pGesture->stylus_able = xf86SetIntOption(pInfo->options, "Stylus", 0);
6178 pGesture->support_palm = xf86SetIntOption(pInfo->options, "SupportPalm", 0);
6180 if (pGesture->support_palm)
6182 PalmRecognize = GesturePalmRecognize;
6183 XDBG_DEBUG(MGEST, "Palm Support !!\n");
6187 PalmRecognize = NULL;
6188 XDBG_DEBUG(MGEST, "No Palm Support !!\n");
6195 memset(&pGesture->pass_keycodes, 0, sizeof(pGesture->pass_keycodes));
6197 for(i = 0 ; i < NUM_PASSKEYS ; i++)
6199 snprintf(tmp, sizeof(tmp), "PassKey%d", i+1);
6200 pGesture->pass_keycodes[i] = xf86SetIntOption(pInfo->options, tmp, 0);
6201 XDBG_SECURE(MGEST, "pass_keycode[%d]=%d\n", i, pGesture->pass_keycodes[i]);
6205 pGesture->gestureWin = None;
6207 #ifdef _F_SUPPORT_BEZEL_FLICK_
6208 pBezel = &pGesture->bezel;
6209 pBezel->is_active = xf86SetIntOption(pInfo->options, "Bezel_Activate", 0);
6210 pBezel->top_left.width = xf86SetIntOption(pInfo->options, "Bezel_Top_Left_Width", 0);
6211 pBezel->top_left.height = xf86SetIntOption(pInfo->options, "Bezel_Top_Left_Height", 0);
6212 pBezel->top_right.width = xf86SetIntOption(pInfo->options, "Bezel_Top_Right_Width", 0);
6213 pBezel->top_right.height = xf86SetIntOption(pInfo->options, "Bezel_Top_Right_Height", 0);
6214 pBezel->bottom_left.width = xf86SetIntOption(pInfo->options, "Bezel_Bottom_Left_Width", 0);
6215 pBezel->bottom_left.height = xf86SetIntOption(pInfo->options, "Bezel_Bottom_Left_Height", 0);
6216 pBezel->bottom_right.width = xf86SetIntOption(pInfo->options, "Bezel_Bottom_Right_Width", 0);
6217 pBezel->bottom_right.height = xf86SetIntOption(pInfo->options, "Bezel_Bottom_Right_Height", 0);
6218 pBezel->flick_distance = xf86SetIntOption(pInfo->options, "Bezel_Flick_Distance", 0);
6219 pBezel->bezel_angle_ratio = xf86SetIntOption(pInfo->options, "Bezel_Flick_Angle_Ratio", 0);
6220 pBezel->bezel_angle_moving_check = xf86SetIntOption(pInfo->options, "Bezel_Flick_Angle_Moving_Check", 0);
6221 #ifdef __BEZEL_DEBUG__
6222 XDBG_DEBUG(MGEST, "[BEZEL] top_left.width: %d, top_left.height: %d\n", pBezel->top_left.width, pBezel->top_left.height);
6223 XDBG_DEBUG(MGEST, "[BEZEL] top_right.width: %d, top_right.height: %d\n", pBezel->top_right.width, pBezel->top_right.height);
6224 XDBG_DEBUG(MGEST, "[BEZEL] bottom_left.width: %d, bottom_left.height: %d\n", pBezel->bottom_left.width, pBezel->bottom_left.height);
6225 XDBG_DEBUG(MGEST, "[BEZEL] bottom_right.width: %d, bottom_right.height: %d\n", pBezel->bottom_right.width, pBezel->bottom_right.height);
6226 XDBG_DEBUG(MGEST, "[BEZEL] flick_distance: %d, bezel_angle_ratio: %d, bezel_angle_moving_check: %d\n", pBezel->flick_distance, pBezel->bezel_angle_ratio, pBezel->bezel_angle_moving_check);
6227 #endif//__BEZEL_DEBUG__
6230 pGesture->pinchrotation_time_threshold = xf86SetIntOption(pInfo->options, "PinchRotationTimeThresHold", PINCHROTATION_TIME_THRESHOLD);
6231 pGesture->pinchrotation_dist_threshold = xf86SetRealOption(pInfo->options, "PinchRotationDistThresHold", PINCHROTATION_DIST_THRESHOLD);
6232 pGesture->pinchrotation_angle_threshold = xf86SetRealOption(pInfo->options, "PinchRotationAngleThresHold", PINCHROTATION_ANGLE_THRESHOLD);
6233 pGesture->singlefinger_threshold = xf86SetIntOption(pInfo->options, "SingleFingerThresHold", SGL_FINGER_TIME_THRESHOLD);
6234 pGesture->singletap_threshold = xf86SetIntOption(pInfo->options, "SingleTapThresHold", SGL_TAP_TIME_THRESHOLD);
6235 pGesture->doubletap_threshold = xf86SetIntOption(pInfo->options, "DoubleTapThresHold", DBL_TAP_TIME_THRESHOLD);
6237 pGesture->palm_min_touch_major = xf86SetIntOption(pInfo->options, "PalmMinTouchMajor", PALM_MIN_TOUCH_MAJOR);
6238 pGesture->palm_min_width_major = xf86SetIntOption(pInfo->options, "PalmMinWidthMajor", PALM_MIN_WIDTH_MAJOR);
6239 pGesture->palm_min_touch_major_bezel = xf86SetIntOption(pInfo->options, "PalmMinTouchMajorBezel", PALM_MIN_TOUCH_MAJOR_BEZEL);
6240 pGesture->palm_min_width_major_bezel = xf86SetIntOption(pInfo->options, "PalmMinWidthMajorBezel", PALM_MIN_WIDTH_MAJOR_BEZEL);
6241 pGesture->palm_bezel = xf86SetIntOption(pInfo->options, "PalmBezel", PALM_BEZEL);
6243 if (pGesture->is_active)
6244 pGesture->ehtype = KEEP_EVENTS;
6246 pGesture->ehtype = PROPAGATE_EVENTS;
6247 #ifdef _F_SUPPORT_BEZEL_FLICK_
6248 if(pBezel->bezel_angle_ratio > 0)
6250 pBezel->min_rad = (RAD_90DEG / pBezel->bezel_angle_ratio);
6251 pBezel->max_rad = ((RAD_90DEG / pBezel->bezel_angle_ratio) * (pBezel->bezel_angle_ratio-1));
6252 pBezel->min_180_rad = (RAD_90DEG + pBezel->min_rad);
6253 pBezel->max_180_rad = (RAD_90DEG + pBezel->max_rad);
6257 pBezel->min_rad = MIN_RAD;
6258 pBezel->max_rad = MAX_RAD;
6259 pBezel->min_180_rad = RAD_180DEG_MIN;
6260 pBezel->max_180_rad = RAD_180DEG_MAX;
6263 pGesture->lastSelectedWin = None;
6264 pGesture->touchkey_id = 0;
6265 pGesture->mtsync_status = MTOUCH_FRAME_SYNC_END;
6266 g_pGesture->grabMask = g_pGesture->eventMask = 0;
6268 xf86Msg(X_INFO, "%s: Using device %s.\n", pInfo->name, pGesture->device);
6270 /* process generic options */
6271 xf86CollectInputOptions(pInfo, NULL);
6272 xf86ProcessCommonOptions(pInfo, pInfo->options);
6276 g_pGesture->tap_repeated = 0;
6278 g_pGesture->palm.palmflag = 0;
6279 g_pGesture->palm.palm_single_finger_timer = NULL;
6280 g_pGesture->enqueue_fulled = 0;
6281 g_pGesture->zoom_enabled = 0;
6282 memset(g_pGesture->palm.qti, 0, sizeof(g_pGesture->palm.qti[MAX_MT_DEVICES+1]));
6284 g_pGesture->palm_rejection_mode = 0;
6285 g_pGesture->palm_detected = FALSE;
6287 memset(g_pGesture->stylusInfo.t_status, 0, sizeof(g_pGesture->stylusInfo.t_status[MAX_MT_DEVICES]));
6288 g_pGesture->stylusInfo.stylus_id = 0;
6289 g_pGesture->stylusInfo.pen_detected = FALSE;
6300 GestureUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
6302 GestureDevicePtr pGesture = pInfo->private;
6304 g_pGesture = pGesture = NULL;
6305 pInfo->private = NULL;
6307 xf86DeleteInput(pInfo, 0);
6311 GestureControl(DeviceIntPtr device, int what)
6313 InputInfoPtr pInfo = device->public.devicePrivate;
6314 GestureDevicePtr pGesture = pInfo->private;
6319 GestureInit(device);
6322 /* Switch device on. Establish socket, start event delivery. */
6324 xf86Msg(X_INFO, "%s: On.\n", pInfo->name);
6326 if (device->public.on)
6329 device->public.on = TRUE;
6330 pGesture->this_device = device;
6331 pGesture->num_mt_devices = 0;
6332 if( ERROR_ABNORMAL == GestureEnableEventHandler(pInfo) )
6338 GestureDisableEventHandler();
6339 GestureFini(device);
6340 pGesture->this_device = NULL;
6341 xf86Msg(X_INFO, "%s: Off.\n", pInfo->name);
6343 if (!device->public.on)
6347 device->public.on = FALSE;
6351 /* free what we have to free */
6354 GestureRegisterDeviceInfo(device);
6361 GestureReadInput(InputInfoPtr pInfo)