- (IBAction)toggleActivity:(id)sender;
- (void)configsChanged;
-- (void)configChanged;
@end
#import "ConfigsController.h"
#import "JoystickController.h"
#import "TargetController.h"
+#import "NJEvents.h"
@implementation ApplicationController {
BOOL active;
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 {
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 {
}
[_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;
#import "ConfigsController.h"
#import "Target.h"
#import "TargetController.h"
+#import "NJEvents.h"
@implementation ConfigsController {
NSMutableArray *_configs;
- (void)activateConfigForProcess:(NSString *)processName {
Config *oldConfig = manualConfig;
- [self activateConfig:self[processName]];
+ Config *newConfig = self[processName];
+ if (!newConfig)
+ newConfig = oldConfig;
+ if (newConfig != _currentConfig)
+ [self activateConfig:newConfig];
manualConfig = oldConfig;
}
- (void)activateConfig:(Config *)config {
if (!config)
config = manualConfig;
- if (_currentConfig == config)
- return;
+ NSLog(@"Switching to mapping %@.", config.name);
manualConfig = config;
_currentConfig = config;
[removeButton setEnabled:_configs[0] != config];
[targetController loadCurrent];
- [(ApplicationController *)NSApplication.sharedApplication.delegate configChanged];
+ [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged
+ object:_currentConfig];
[tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[_configs indexOfObject:config]] byExtendingSelection:NO];
}
[tableView reloadData];
[tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_configs.count - 1] byExtendingSelection:NO];
[tableView editColumn:0 row:_configs.count - 1 withEvent:nil select:YES];
+ [self activateConfig:newConfig];
}
- (IBAction)removePressed:(id)sender {
}
- (void)save {
- NSLog(@"Saving defaults.");
+ NSLog(@"Saving mappings to defaults.");
[NSUserDefaults.standardUserDefaults setObject:[self dumpAll] forKey:@"configurations"];
}
EE1D7C9416E0ECCF00B000EB /* NSError+Description.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Description.h"; sourceTree = "<group>"; };
EE1D7C9516E0ECCF00B000EB /* NSError+Description.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Description.m"; sourceTree = "<group>"; };
EEF86B7316E2241000674B87 /* NJActionPathElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NJActionPathElement.h; sourceTree = "<group>"; };
+ EEF86B7416E298CD00674B87 /* NJEvents.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NJEvents.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8BEFAD9E15C476DC00823AEC /* TargetToggleMouseScope.h */,
8BEFAD9F15C476DC00823AEC /* TargetToggleMouseScope.m */,
EEF86B7316E2241000674B87 /* NJActionPathElement.h */,
+ EEF86B7416E298CD00674B87 /* NJEvents.h */,
);
name = Classes;
sourceTree = "<group>";
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_RECEIVER_WEAK = NO;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = NO;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_WARN_PEDANTIC = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_SIGN_COMPARE = YES;
- GCC_WARN_STRICT_SELECTOR_MATCH = YES;
+ GCC_WARN_STRICT_SELECTOR_MATCH = NO;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_RECEIVER_WEAK = NO;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = NO;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
GCC_WARN_PEDANTIC = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_SIGN_COMPARE = YES;
- GCC_WARN_STRICT_SELECTOR_MATCH = YES;
+ GCC_WARN_STRICT_SELECTOR_MATCH = NO;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
--- /dev/null
+//
+// NJEvents.h
+// Enjoyable
+//
+// Created by Joe Wreschnig on 3/2/13.
+//
+//
+
+#define NJEventMappingChanged @"NJEventMappingChanged"