X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=ApplicationController.m;h=531d1f469a54aa57c31869ffc23587a10330610f;hp=9a2db2af3c1d31a5034f7cae19c235516b8ae03c;hb=f41f770d67370cbd71002515d81c0842b50cb04b;hpb=0238d141f06420e1a73eccd14ca73a7e29ad2a69 diff --git a/ApplicationController.m b/ApplicationController.m index 9a2db2a..531d1f4 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,19 +27,15 @@ self.targetController.enabled = NO; [self.jsController setup]; [self.configsController load]; - [NSWorkspace.sharedWorkspace.notificationCenter - addObserver:self - selector:@selector(didSwitchApplication:) - name:NSWorkspaceDidActivateApplicationNotification - object:nil]; + [NSNotificationCenter.defaultCenter + addObserver:self + selector:@selector(mappingDidChange:) + name:NJEventMappingChanged + object:nil]; } - (void)applicationWillTerminate:(NSNotification *)aNotification { [NSUserDefaults.standardUserDefaults synchronize]; - [NSWorkspace.sharedWorkspace.notificationCenter - removeObserver:self - name:NSWorkspaceDidActivateApplicationNotification - object:nil]; } - (IBAction)toggleActivity:(id)sender { @@ -46,6 +43,22 @@ self.jsController.sendingRealEvents = sendRealEvents; activeButton.image = [NSImage imageNamed:sendRealEvents ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"]; activeMenuItem.state = sendRealEvents; + + if (sendRealEvents) { + [NSWorkspace.sharedWorkspace.notificationCenter + addObserver:self + selector:@selector(didSwitchApplication:) + name:NSWorkspaceDidActivateApplicationNotification + object:nil]; + NSLog(@"Listening for application changes."); + } else { + [NSWorkspace.sharedWorkspace.notificationCenter + removeObserver:self + name:NSWorkspaceDidActivateApplicationNotification + object:nil]; + NSLog(@"Ignoring application changes."); + } + } - (NSInteger)firstConfigMenuIndex { @@ -68,12 +81,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;