| Date: Fri, 20 Jan 2012 22:31:00 -0500
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
Diffstat:
M src/cmd/devdraw/cocoa-screen.m | 191 ++-----------------------------
1 file changed, 8 insertions(+), 183 deletions(-)
--- |
| t@@ -102,8 +102,6 @@ struct
int mbuttons;
NSPoint mpos;
int mscroll;
- int undo;
- int touchevent;
int willactivate;
} in;
t@@ -134,8 +132,6 @@ static NSCursor* makecursor(Cursor*);
}
- (void)windowDidBecomeKey:(id)arg
{
- in.touchevent = 0;
-
getmousepos();
sendmouse();
}
t@@ -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
t@@ -779,57 +774,20 @@ getmouse(NSEvent *e)
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)
t@@ -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;
-
- if(usegestures == 0)
- return;
+ int p;
switch(type){
-
case NSTouchPhaseBegan:
- in.touchevent = 1;
p = NSTouchPhaseTouching;
set = [e touchesMatchingPhase:p inView:nil];
if(set.count == 3){
t@@ -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 |