Skip to content

Commit

Permalink
New hotkey for toggling gaze target: Command-Control-G
Browse files Browse the repository at this point in the history
  • Loading branch information
David Pitman committed Dec 9, 2011
1 parent e51afed commit de27a8c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "DDHotKey"]
path = DDHotKey
url = git://github.com/davedelong/DDHotKey.git
1 change: 1 addition & 0 deletions DDHotKey
Submodule DDHotKey added at 8c2ee2
18 changes: 18 additions & 0 deletions og3.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
AE1D9F27148F35D9009FB298 /* gazeTarget.png in Resources */ = {isa = PBXBuildFile; fileRef = AE1D9F26148F35D9009FB298 /* gazeTarget.png */; };
AE1D9F2A149002EE009FB298 /* LCGazeTrackerWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = AE1D9F29149002EE009FB298 /* LCGazeTrackerWindowController.m */; };
AE1D9F2C14901374009FB298 /* GazeTrackerWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = AE1D9F2B14901373009FB298 /* GazeTrackerWindow.xib */; };
AE55644114927BEF0036008D /* DDHotKeyCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = AE55644014927BEF0036008D /* DDHotKeyCenter.m */; };
AE556443149280950036008D /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE556442149280950036008D /* Carbon.framework */; };
AE815AAA14863FA6009E362E /* LCCalibrationView.m in Sources */ = {isa = PBXBuildFile; fileRef = AE815A9A14863FA6009E362E /* LCCalibrationView.m */; };
AE815AAB14863FA6009E362E /* LCCalibrationWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE815A9C14863FA6009E362E /* LCCalibrationWindowController.mm */; };
AE815AAC14863FA6009E362E /* LCCalibrationLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = AE815A9E14863FA6009E362E /* LCCalibrationLayer.m */; };
Expand Down Expand Up @@ -373,6 +375,9 @@
AE1D9F28149002ED009FB298 /* LCGazeTrackerWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCGazeTrackerWindowController.h; sourceTree = "<group>"; };
AE1D9F29149002EE009FB298 /* LCGazeTrackerWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCGazeTrackerWindowController.m; sourceTree = "<group>"; };
AE1D9F2B14901373009FB298 /* GazeTrackerWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GazeTrackerWindow.xib; sourceTree = "<group>"; };
AE55643F14927BEF0036008D /* DDHotKeyCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DDHotKeyCenter.h; path = DDHotKey/DDHotKeyCenter.h; sourceTree = "<group>"; };
AE55644014927BEF0036008D /* DDHotKeyCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DDHotKeyCenter.m; path = DDHotKey/DDHotKeyCenter.m; sourceTree = "<group>"; };
AE556442149280950036008D /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
AE815A9914863FA6009E362E /* LCCalibrationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCCalibrationView.h; sourceTree = "<group>"; };
AE815A9A14863FA6009E362E /* LCCalibrationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCCalibrationView.m; sourceTree = "<group>"; };
AE815A9B14863FA6009E362E /* LCCalibrationWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCCalibrationWindowController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -400,6 +405,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
AE556443149280950036008D /* Carbon.framework in Frameworks */,
722F1CC21486B8D100276526 /* QuartzCore.framework in Frameworks */,
722F1CBC1486B19300276526 /* QTKit.framework in Frameworks */,
7212EA43147C50C700CB2A8D /* Cocoa.framework in Frameworks */,
Expand Down Expand Up @@ -468,6 +474,7 @@
7212EA33147C50C600CB2A8D = {
isa = PBXGroup;
children = (
AE556442149280950036008D /* Carbon.framework */,
7212EAC6147C516500CB2A8D /* opengazer */,
7212EA5F147C50DF00CB2A8D /* dylibs */,
7212EA48147C50C700CB2A8D /* og3 */,
Expand All @@ -488,6 +495,7 @@
7212EA41147C50C700CB2A8D /* Frameworks */ = {
isa = PBXGroup;
children = (
AE55643D14927B820036008D /* DDHotKey */,
7212EA42147C50C700CB2A8D /* Cocoa.framework */,
7212EA44147C50C700CB2A8D /* Other Frameworks */,
);
Expand Down Expand Up @@ -657,6 +665,15 @@
name = Resources;
sourceTree = "<group>";
};
AE55643D14927B820036008D /* DDHotKey */ = {
isa = PBXGroup;
children = (
AE55643F14927BEF0036008D /* DDHotKeyCenter.h */,
AE55644014927BEF0036008D /* DDHotKeyCenter.m */,
);
name = DDHotKey;
sourceTree = "<group>";
};
AE815A9414863F50009E362E /* LCGazeFoundation */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -810,6 +827,7 @@
7204E6751489649400D482B9 /* GlobalManager.mm in Sources */,
AEEAA609148C44E20049271E /* LCCalibrationCameraView.mm in Sources */,
AE1D9F2A149002EE009FB298 /* LCGazeTrackerWindowController.m in Sources */,
AE55644114927BEF0036008D /* DDHotKeyCenter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion og3/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@


// Notifications
-(void)moveGazeEstimationTarget:(NSNotification*)note;
-(void)moveCalibrationPoint:(NSNotification*)note;
-(void)calibrationStarted:(NSNotification*)note;
-(void)finishedCalibration:(NSNotification*)note;
-(void)terminationRequested:(NSNotification*)note;
-(void)calibrationStartRequested:(NSNotification*)note;

-(void)toggleGazeTarget:(NSEvent*)hotKeyEvent;

@end
31 changes: 16 additions & 15 deletions og3/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
//

#import "AppDelegate.h"
#import <Carbon/Carbon.h>

#import "CoreFoundation/CoreFoundation.h"
#import "LCCalibrationPoint.h"
#import "DDHotKeyCenter.h"

@implementation AppDelegate

Expand Down Expand Up @@ -49,10 +51,6 @@ -(void)applicationWillFinishLaunching:(NSNotification*)aNotification{
selector:@selector(calibrationStarted:)
name:kGazeTrackerCalibrationStarted
object:kGazeSenderID];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(moveGazeEstimationTarget:)
name:kGazePointNotification
object:kGazeSenderID];

[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishedCalibration:)
Expand All @@ -79,6 +77,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
if(!self.runHeadless){
[self launchCalibrationGUI];
}
[[[DDHotKeyCenter alloc] init] registerHotKeyWithKeyCode:kVK_ANSI_G
modifierFlags:(NSCommandKeyMask | NSControlKeyMask)
target:self
action:@selector(toggleGazeTarget:)
object:nil];
NSLog(@"OGC finished launching");
}

Expand Down Expand Up @@ -209,15 +212,6 @@ -(void)showCalibration{

#pragma mark - Notifications

-(void)moveGazeEstimationTarget:(NSNotification*)note{
//NSLog(@"Receive move gaze tracking Point");
LCGazePoint* point = [[LCGazePoint alloc] init];
NSDictionary* dict = (NSDictionary*)[note userInfo];
point.x = [(NSNumber*)[dict objectForKey:kGazePointXKey] floatValue];
point.y = [(NSNumber*)[dict objectForKey:kGazePointYKey] floatValue];
[gazeWindowController moveGazeTarget:point];
}

-(void)moveCalibrationPoint:(NSNotification*)note{
//NSLog(@"Receive move calibration Point");
NSPoint point = [(NSValue*)[(NSDictionary*)[note userInfo] objectForKey:@"point"] pointValue];
Expand All @@ -231,7 +225,7 @@ -(void)moveCalibrationPoint:(NSNotification*)note{
// The calibration process has started
-(void)calibrationStarted:(NSNotification*)note{
NSLog(@"Notification :: Calibration Started");
[gazeWindowController window];
[gazeWindowController show:YES];
}

// There was a request to show the calibration GUI and such
Expand All @@ -252,7 +246,7 @@ -(void) calibrationClosed:(NSNotification*)note{
NSLog(@"Notification :: Calibration UI Closed");

// Close the Gaze Target window
[[gazeWindowController window] close];
[gazeWindowController show:NO];

// Resign focus
//[[NSApplication sharedApplication] hide:self];
Expand All @@ -269,4 +263,11 @@ -(void)terminationRequested:(NSNotification*)note{
[[NSApplication sharedApplication] terminate:self];
}

-(void)toggleGazeTarget:(NSEvent*)hotKeyEvent{
NSLog(@"HotKey :: Gaze Target estimation being toggled");
if(gazeWindowController != nil){
[gazeWindowController show:!gazeWindowController.isActive];
}
}

@end
2 changes: 1 addition & 1 deletion og3/GazeTrackerWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<object class="NSWindowTemplate" id="1005">
<int key="NSWindowBacking">2</int>
<string key="NSWindowRect">{{196, 240}, {480, 270}}</string>
<int key="NSWTFlags">544739328</int>
<int key="NSWTFlags">1618481152</int>
<string key="NSWindowTitle">Window</string>
<string key="NSWindowClass">NSWindow</string>
<nil key="NSViewClass"/>
Expand Down
9 changes: 9 additions & 0 deletions og3/LCGazeTrackerWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
@interface LCGazeTrackerWindowController : NSWindowController{
CALayer* _gazeTargetLayer;
NSScreen* _screen;
BOOL _isActive;
}

@property BOOL isActive;

// Init to cover a particular screen
- (id)initWithScreen:(NSScreen*)screen;

Expand All @@ -26,4 +29,10 @@
// Move the gaze estimation target
-(void) moveGazeTarget:(LCGazePoint*) point;

// Show the gaze estimation target
-(void) show:(BOOL)show;

// Notification to move the gaze estimation target
-(void)moveGazeEstimationTarget:(NSNotification*)note;

@end
32 changes: 32 additions & 0 deletions og3/LCGazeTrackerWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

@implementation LCGazeTrackerWindowController

@synthesize isActive = _isActive;

- (id)initWithScreen:(NSScreen*)screen{
self = [super initWithWindowNibName:@"GazeTrackerWindow"];
if (self) {
_screen = screen;
_isActive = NO;
}

return self;
Expand All @@ -23,6 +26,7 @@ - (id)initWithScreen:(NSScreen*)screen{
- (void)awakeFromNib
{
[super awakeFromNib];
//NSLog(@"GazeTrackerWindowController :: awakeFromNib");
// Setup the window to float above everything else and not intercept events
[self.window setBackgroundColor:[NSColor clearColor]];
[self.window setIgnoresMouseEvents:YES];
Expand Down Expand Up @@ -65,5 +69,33 @@ -(void) moveGazeTarget:(LCGazePoint*) point{
[CATransaction commit];
}

-(void) show:(BOOL)show{
if(show != self.isActive){
self.isActive = show;
if(_isActive){
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(moveGazeEstimationTarget:)
name:kGazePointNotification
object:kGazeSenderID];
[[self window] makeKeyAndOrderFront:self];

}else{
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
[[self window] close];
}
}

}


-(void)moveGazeEstimationTarget:(NSNotification*)note{
//NSLog(@"Receive move gaze tracking Point");
LCGazePoint* point = [[LCGazePoint alloc] init];
NSDictionary* dict = (NSDictionary*)[note userInfo];
point.x = [(NSNumber*)[dict objectForKey:kGazePointXKey] floatValue];
point.y = [(NSNumber*)[dict objectForKey:kGazePointYKey] floatValue];
[self moveGazeTarget:point];
}


@end

0 comments on commit de27a8c

Please sign in to comment.