X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=ApplicationController.m;h=1acc692151d78f548dda0c36cfbb872952338145;hp=9a2db2af3c1d31a5034f7cae19c235516b8ae03c;hb=f563321aec9e13b8479ab3b890a9179f095a8b17;hpb=f9903acac24bb4be43e370d5f3eb942510f727e1 diff --git a/ApplicationController.m b/ApplicationController.m index 9a2db2a..1acc692 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -11,6 +11,7 @@ #import "ConfigsController.h" #import "JoystickController.h" #import "TargetController.h" +#import "NJEvents.h" @implementation ApplicationController { BOOL active; @@ -26,26 +27,50 @@ self.targetController.enabled = NO; [self.jsController setup]; [self.configsController load]; + [NSNotificationCenter.defaultCenter + addObserver:self + selector:@selector(mappingDidChange:) + name:NJEventMappingChanged + object:nil]; + [NSNotificationCenter.defaultCenter + addObserver:self + selector:@selector(eventTranslationActivated:) + name:NJEventTranslationActivated + object:nil]; + [NSNotificationCenter.defaultCenter + addObserver:self + selector:@selector(eventTranslationDeactivated:) + name:NJEventTranslationDeactivated + object:nil]; +} + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + [NSUserDefaults.standardUserDefaults synchronize]; +} + +- (void)eventTranslationActivated:(NSNotification *)note { + activeButton.image = [NSImage imageNamed:@"NSStopProgressFreestandingTemplate"]; + activeMenuItem.state = [note.object translatingEvents]; [NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(didSwitchApplication:) name:NSWorkspaceDidActivateApplicationNotification object:nil]; + NSLog(@"Listening for application changes."); } -- (void)applicationWillTerminate:(NSNotification *)aNotification { - [NSUserDefaults.standardUserDefaults synchronize]; +- (void)eventTranslationDeactivated:(NSNotification *)note { + activeButton.image = [NSImage imageNamed:@"NSGoRightTemplate"]; + activeMenuItem.state = [note.object translatingEvents]; [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceDidActivateApplicationNotification object:nil]; + NSLog(@"Ignoring application changes."); } - (IBAction)toggleActivity:(id)sender { - BOOL sendRealEvents = !self.jsController.sendingRealEvents; - self.jsController.sendingRealEvents = sendRealEvents; - activeButton.image = [NSImage imageNamed:sendRealEvents ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"]; - activeMenuItem.state = sendRealEvents; + self.jsController.translatingEvents = !self.jsController.translatingEvents; } - (NSInteger)firstConfigMenuIndex { @@ -68,12 +93,11 @@ } [_targetController refreshConfigs]; - [self configChanged]; } -- (void)configChanged { +- (void)mappingDidChange:(NSNotification *)note { NSInteger firstConfig = self.firstConfigMenuIndex; - Config *current = self.configsController.currentConfig; + Config *current = note.object; NSArray *configs = self.configsController.configs; for (NSUInteger i = 0; i < configs.count; ++i) [dockMenuBase itemAtIndex:i + firstConfig].state = configs[i] == current;