commit f4792e43aef14341bb40f32e8583bd4731e1dcb4 from: David Jeannot via: Russ Cox date: Sat Jan 21 03:31:00 2012 UTC devdraw: enable gestures on OS X Remove swipe gestures. Keep only 2-finger pinching and 3-finger tapping. R=rsc CC=plan9port.codebot http://codereview.appspot.com/5498094 commit - 5d434a3ff3426bfdc1a98da2543b1345a475ba67 commit + f4792e43aef14341bb40f32e8583bd4731e1dcb4 blob - 0f37d715d7fc17f06e76c069f403ef167810634b blob + 97ddd80cbfdef90676b1cf6f8b2b7be6fb62d9b1 --- src/cmd/devdraw/cocoa-screen.m +++ src/cmd/devdraw/cocoa-screen.m @@ -102,8 +102,6 @@ struct int mbuttons; NSPoint mpos; int mscroll; - int undo; - int touchevent; int willactivate; } in; @@ -134,8 +132,6 @@ static NSCursor* makecursor(Cursor*); } - (void)windowDidBecomeKey:(id)arg { - in.touchevent = 0; - getmousepos(); sendmouse(); } @@ -506,7 +502,6 @@ static void updatecursor(void); - (void)keyDown:(NSEvent*)e{ getkeyboard(e);} - (void)flagsChanged:(NSEvent*)e{ getkeyboard(e);} -- (void)swipeWithEvent:(NSEvent*)e{ getgesture(e);} - (void)magnifyWithEvent:(NSEvent*)e{ getgesture(e);} - (void)touchesBeganWithEvent:(NSEvent*)e @@ -777,59 +772,22 @@ getmouse(NSEvent *e) panic("getmouse: unexpected event type"); } sendmouse(); -} - -#define Minpinch 0.050 - -enum -{ - Left = -1, - Right = +1, - Up = +2, - Down = -2, -}; - -static int -getdir(int dx, int dy) -{ - return dx + 2*dy; } -static void interpretswipe(int); +#define Minpinch 0.02 static void getgesture(NSEvent *e) { - static float sum; - int dir; - - if(usegestures == 0) - return; - switch([e type]){ - case NSEventTypeMagnify: - sum += [e magnification]; - if(fabs(sum) > Minpinch){ + if(fabs([e magnification]) > Minpinch) togglefs(); - sum = 0; - } break; - - case NSEventTypeSwipe: - dir = getdir(-[e deltaX], [e deltaY]); - - if(in.touchevent) - if(dir==Up || dir==Down) - break; - interpretswipe(dir); - break; } } static void sendclick(int); -static void sendchord(int, int); -static void sendcmd(int); static uint msec(void) @@ -837,43 +795,16 @@ msec(void) return nsec()/1000000; } -#define Inch 72 -#define Cm Inch/2.54 - -#define Mindelta 0.0*Cm -#define Xminswipe 0.5*Cm -#define Yminswipe 0.1*Cm - -enum -{ - Finger = 1, - Msec = 1, - - Maxtap = 400*Msec, - Maxtouch = 3*Finger, -}; - static void gettouch(NSEvent *e, int type) { - static NSPoint delta; - static NSTouch *toucha[Maxtouch]; - static NSTouch *touchb[Maxtouch]; - static int done, ntouch, odir, tapping; + static int tapping; static uint taptime; - NSArray *a; - NSPoint d; NSSet *set; - NSSize s; - int dir, i, p; + int p; - if(usegestures == 0) - return; - switch(type){ - case NSTouchPhaseBegan: - in.touchevent = 1; p = NSTouchPhaseTouching; set = [e touchesMatchingPhase:p inView:nil]; if(set.count == 3){ @@ -882,80 +813,19 @@ gettouch(NSEvent *e, int type) }else if(set.count > 3) tapping = 0; - return; + break; case NSTouchPhaseMoved: - p = NSTouchPhaseMoved; - set = [e touchesMatchingPhase:p inView:nil]; - a = [set allObjects]; - if(set.count > Maxtouch) - return; - if(ntouch==0){ - ntouch = set.count; - for(i=0; iMindelta || fabs(d.y)>Mindelta){ - tapping = 0; - if(ntouch != 3){ - done = 1; - goto Return; - } - delta = NSMakePoint(delta.x+d.x, delta.y+d.y); - d = NSMakePoint(fabs(delta.x), fabs(delta.y)); - if(d.x>Xminswipe || d.y>Yminswipe){ - if(d.x > d.y) - dir = delta.x>0? Right : Left; - else - dir = delta.y>0? Up : Down; - if(dir != odir){ -// if(ntouch == 3) - if(dir==Up || dir==Down) - interpretswipe(dir); - odir = dir; - } - goto Return; - } - for(i=0; i