Permalink
Browse files

Can now switch between tap and click. Made new controller class.

  • Loading branch information...
Alex Galonsky Alex Galonsky
Alex Galonsky authored and Alex Galonsky committed Nov 9, 2009
1 parent 64fe6f2 commit c6983042d1c986fa1a73ed11e6c97f961ee1d85e
Showing with 52 additions and 82 deletions.
  1. +6 −0 MiddleClick.xcodeproj/project.pbxproj
  2. +6 −0 TrayMenu.h
  3. +35 −1 TrayMenu.m
  4. +5 −81 main.m
@@ -17,6 +17,7 @@
75A6B6AB0FEE96540071FAC0 /* mouse.png in Resources */ = {isa = PBXBuildFile; fileRef = 75A6B6AA0FEE96540071FAC0 /* mouse.png */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+ FAD94F9410A88A7800A520EC /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = FAD94F9310A88A7800A520EC /* Controller.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -38,6 +39,8 @@
75A6B6AA0FEE96540071FAC0 /* mouse.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = mouse.png; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* MiddleClick.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MiddleClick.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ FAD94F9210A88A7800A520EC /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; };
+ FAD94F9310A88A7800A520EC /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -107,6 +110,8 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
+ FAD94F9210A88A7800A520EC /* Controller.h */,
+ FAD94F9310A88A7800A520EC /* Controller.m */,
32CA4F630368D1EE00C91783 /* MiddleClick_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
);
@@ -195,6 +200,7 @@
8D11072D0486CEB800E47090 /* main.m in Sources */,
75A6B6600FEE3BE90071FAC0 /* TrayMenu.m in Sources */,
7519A949108A763300466740 /* WakeObserver.m in Sources */,
+ FAD94F9410A88A7800A520EC /* Controller.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -5,10 +5,16 @@
//
#import <Foundation/Foundation.h>
+#import "Controller.h"
@interface TrayMenu : NSObject {
@private
NSStatusItem *_statusItem;
+ Controller *myController;
+ BOOL click;
+ NSMenuItem *tapItem;
+ NSMenuItem *clickItem;
}
+- (id)initWithController:(Controller *)ctrl;
@end
View
@@ -5,16 +5,41 @@
//
#import "TrayMenu.h"
-
+#import "Controller.h"
@implementation TrayMenu
+- (id)initWithController:(Controller *)ctrl
+{
+ [super init];
+ myController = ctrl;
+ click = YES;
+ return self;
+}
+
+
- (void) openWebsite:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://clement.beffa.org/labs/projects/middleclick/"];
[[NSWorkspace sharedWorkspace] openURL:url];
//[url release];
}
+- (void)toggleClick:(id)sender
+{
+ click = !click;
+ if(click)
+ {
+ [clickItem setState:NSOnState];
+ [tapItem setState:NSOffState];
+ }
+ else {
+ [clickItem setState:NSOffState];
+ [tapItem setState:NSOnState];
+ }
+
+ [myController toggleMode];
+}
+
- (void) openFinder:(id)sender {
[[NSWorkspace sharedWorkspace] launchApplication:@"Finder"];
}
@@ -33,6 +58,15 @@ - (NSMenu *) createMenu {
action:@selector(openWebsite:)
keyEquivalent:@""];
[menuItem setTarget:self];
+
+ clickItem = [menu addItemWithTitle:@"3 Finger Click" action:@selector(toggleClick:) keyEquivalent:@""];
+ [clickItem setState:NSOnState];
+ [clickItem setTarget:self];
+
+ tapItem = [menu addItemWithTitle:@"3 Finger Tap" action:@selector(toggleClick:) keyEquivalent:@""];
+ [tapItem setState:NSOffState];
+ [tapItem setTarget:self];
+
// Add Separator
[menu addItem:[NSMenuItem separatorItem]];
View
86 main.m
@@ -12,89 +12,13 @@
#include <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import "WakeObserver.h"
+#import "Controller.h"
-typedef struct { float x,y; } mtPoint;
-typedef struct { mtPoint pos,vel; } mtReadout;
-
-typedef struct {
- int frame;
- double timestamp;
- int identifier, state, foo3, foo4;
- mtReadout normalized;
- float size;
- int zero1;
- float angle, majorAxis, minorAxis; // ellipsoid
- mtReadout mm;
- int zero2[2];
- float unk2;
-} Finger;
-
-typedef int MTDeviceRef;
-typedef int (*MTContactCallbackFunction)(int,Finger*,int,double,int);
-
-MTDeviceRef MTDeviceCreateDefault();
-void MTRegisterContactFrameCallback(MTDeviceRef, MTContactCallbackFunction);
-void MTDeviceStart(MTDeviceRef);
-CFMutableArrayRef MTDeviceCreateList(void); //returns a CFMutableArrayRef array of all multitouch devices
-
-BOOL maybeMiddleClick;
-NSDate *touchStartTime;
-float middleclickX, middleclickY;
-float middleclickX2, middleclickY2;
-MTDeviceRef dev;
-BOOL pressed = NO;
-
-int callback(int device, Finger *data, int nFingers, double timestamp, int frame) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- if(nFingers == 3)
- {
- if(!pressed)
- {
- CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)55, true );
- pressed = YES;
- }
-
- }
- else {
- if(pressed)
- {
- CGPostKeyboardEvent( (CGCharCode)0, (CGKeyCode)55, false );
- pressed = NO;
- }
- }
-
- [pool release];
- return 0;
-}
+Controller *con;
int main(int argc, char *argv[]) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [NSApplication sharedApplication];
-
-
- //Get list of all multi touch devices
- NSMutableArray* deviceList = (NSMutableArray*)MTDeviceCreateList(); //grab our device list
-
-
- //Iterate and register callbacks for multitouch devices.
- for(int i = 0; i<[deviceList count]; i++) //iterate available devices
- {
- MTRegisterContactFrameCallback((MTDeviceRef)[deviceList objectAtIndex:i], callback); //assign callback for device
- MTDeviceStart((MTDeviceRef)[deviceList objectAtIndex:i]); //start sending events
- }
-
-
- //register a callback to know when osx come back from sleep
- WakeObserver *wo = [[WakeObserver alloc] init];
- [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: wo selector: @selector(receiveWakeNote:) name: NSWorkspaceDidWakeNotification object: NULL];
-
-
- //add traymenu
- TrayMenu *menu = [[TrayMenu alloc] init];
- [NSApp setDelegate:menu];
- [NSApp run];
-
- [pool release];
+ con = [[Controller alloc] init];
+ [con start];
+
return EXIT_SUCCESS;
}

0 comments on commit c698304

Please sign in to comment.