Rename the application delegate, and hopefully catch the last vestiges of the old...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Sun, 3 Mar 2013 22:49:27 +0000 (23:49 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Sun, 3 Mar 2013 22:49:27 +0000 (23:49 +0100)
19 files changed:
ApplicationController.h [deleted file]
ApplicationController.m [deleted file]
English.lproj/MainMenu.xib
Enjoyable.xcodeproj/project.pbxproj
EnjoyableApplicationDelegate.h [new file with mode: 0644]
EnjoyableApplicationDelegate.m [new file with mode: 0644]
NJDeviceController.h [new file with mode: 0644]
NJDeviceController.m [new file with mode: 0644]
NJInputController.h [deleted file]
NJInputController.m [deleted file]
NJMappingsController.m
NJOutput.h
NJOutput.m
NJOutputController.h
NJOutputController.m
NJOutputMapping.m
NJOutputMouseMove.m
NJOutputMouseScroll.m
NJOutputSwitchMouseMode.m

diff --git a/ApplicationController.h b/ApplicationController.h
deleted file mode 100644 (file)
index a1b8742..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-//  ApplicationController.h
-//  Enjoy
-//
-//  Created by Sam McCall on 4/05/09.
-//  Copyright 2009 University of Otago. All rights reserved.
-//
-
-@class NJInputController;
-@class NJOutputController;
-@class NJMappingsController;
-
-@interface ApplicationController : NSObject <NSApplicationDelegate> {
-    IBOutlet NSDrawer *drawer;
-    IBOutlet NSWindow *mainWindow;
-    IBOutlet NSToolbarItem *activeButton;
-    IBOutlet NSMenuItem *activeMenuItem;
-    IBOutlet NSMenu *dockMenuBase;
-}
-
-@property (nonatomic, strong) IBOutlet NJInputController *inputController;
-@property (nonatomic, strong) IBOutlet NJOutputController *outputController;
-@property (nonatomic, strong) IBOutlet NJMappingsController *mappingsController;
-
-- (IBAction)toggleActivity:(id)sender;
-- (void)mappingsChanged;
-
-@end
diff --git a/ApplicationController.m b/ApplicationController.m
deleted file mode 100644 (file)
index faad07a..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-//
-//  ApplicationController.m
-//  Enjoy
-//
-//  Created by Sam McCall on 4/05/09.
-//
-
-#import "ApplicationController.h"
-
-#import "NJMapping.h"
-#import "NJMappingsController.h"
-#import "NJInputController.h"
-#import "NJOutputController.h"
-#import "NJEvents.h"
-
-@implementation ApplicationController {
-    BOOL active;
-}
-
-- (void)didSwitchApplication:(NSNotification *)notification {
-    NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey];
-    [self.mappingsController activateMappingForProcess:currentApp.localizedName];
-}
-
-- (void)applicationDidFinishLaunching:(NSNotification *)notification {
-    [drawer open];
-    self.outputController.enabled = NO;
-    [self.inputController setup];
-    [self.mappingsController 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)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 {
-    self.inputController.translatingEvents = !self.inputController.translatingEvents;
-}
-
-- (NSInteger)firstMappingMenuIndex {
-    for (NSInteger i = dockMenuBase.numberOfItems - 1; i >= 0; --i)
-        if ([dockMenuBase itemAtIndex:i].isSeparatorItem)
-            return i + 1;
-    return dockMenuBase.numberOfItems;
-}
-
-- (void)mappingsChanged {
-    NSInteger removeFrom = self.firstMappingMenuIndex;
-    while (dockMenuBase.numberOfItems > removeFrom)
-        [dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1];
-    int added = 0;
-    for (NJMapping *mapping in self.mappingsController.mappings) {
-        NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @"";
-        [dockMenuBase addItemWithTitle:mapping.name
-                                action:@selector(chooseMapping:)
-                         keyEquivalent:keyEquiv];
-        
-    }
-    [_outputController refreshMappings];
-}
-
-- (void)mappingDidChange:(NSNotification *)note {
-    NSInteger firstMapping = self.firstMappingMenuIndex;
-    NJMapping *current = note.object;
-    NSArray *mappings = self.mappingsController.mappings;
-    for (NSUInteger i = 0; i < mappings.count; ++i)
-        [dockMenuBase itemAtIndex:i + firstMapping].state = mappings[i] == current;
-}
-
-- (void)chooseMapping:(id)sender {
-    NSInteger idx = [dockMenuBase indexOfItem:sender] - self.firstMappingMenuIndex;
-    NJMapping *chosen = self.mappingsController.mappings[idx];
-    [_mappingsController activateMapping:chosen];
-}
-@end
index 8dd62bf..1a87bd7 100644 (file)
                                <nil key="NSDelegate"/>
                        </object>
                        <object class="NSCustomObject" id="207406104">
-                               <string key="NSClassName">ApplicationController</string>
+                               <string key="NSClassName">EnjoyableApplicationDelegate</string>
                        </object>
                        <object class="NSCustomObject" id="468285243">
                                <string key="NSClassName">NJMappingsController</string>
                        </object>
                        <object class="NSCustomObject" id="1007832501">
-                               <string key="NSClassName">NJInputController</string>
+                               <string key="NSClassName">NJDeviceController</string>
                        </object>
                        <object class="NSCustomObject" id="801536542">
                                <string key="NSClassName">NJOutputController</string>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
-                               <object class="IBPartialClassDescription">
-                                       <string key="className">ApplicationController</string>
-                                       <string key="superclassName">NSObject</string>
-                                       <object class="NSMutableDictionary" key="actions">
-                                               <string key="NS.key.0">toggleActivity:</string>
-                                               <string key="NS.object.0">id</string>
-                                       </object>
-                                       <object class="NSMutableDictionary" key="actionInfosByName">
-                                               <string key="NS.key.0">toggleActivity:</string>
-                                               <object class="IBActionInfo" key="NS.object.0">
-                                                       <string key="name">toggleActivity:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                       </object>
-                                       <dictionary class="NSMutableDictionary" key="outlets">
-                                               <string key="activeButton">NSToolbarItem</string>
-                                               <string key="activeMenuItem">NSMenuItem</string>
-                                               <string key="configsController">ConfigsController</string>
-                                               <string key="dockMenuBase">NSMenu</string>
-                                               <string key="drawer">NSDrawer</string>
-                                               <string key="jsController">JoystickController</string>
-                                               <string key="mainWindow">NSWindow</string>
-                                               <string key="targetController">TargetController</string>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
-                                               <object class="IBToOneOutletInfo" key="activeButton">
-                                                       <string key="name">activeButton</string>
-                                                       <string key="candidateClassName">NSToolbarItem</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="activeMenuItem">
-                                                       <string key="name">activeMenuItem</string>
-                                                       <string key="candidateClassName">NSMenuItem</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="configsController">
-                                                       <string key="name">configsController</string>
-                                                       <string key="candidateClassName">ConfigsController</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="dockMenuBase">
-                                                       <string key="name">dockMenuBase</string>
-                                                       <string key="candidateClassName">NSMenu</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="drawer">
-                                                       <string key="name">drawer</string>
-                                                       <string key="candidateClassName">NSDrawer</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="jsController">
-                                                       <string key="name">jsController</string>
-                                                       <string key="candidateClassName">JoystickController</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="mainWindow">
-                                                       <string key="name">mainWindow</string>
-                                                       <string key="candidateClassName">NSWindow</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="targetController">
-                                                       <string key="name">targetController</string>
-                                                       <string key="candidateClassName">TargetController</string>
-                                               </object>
-                                       </dictionary>
-                                       <object class="IBClassDescriptionSource" key="sourceIdentifier">
-                                               <string key="majorKey">IBProjectSource</string>
-                                               <string key="minorKey">./Classes/ApplicationController.h</string>
-                                       </object>
-                               </object>
-                               <object class="IBPartialClassDescription">
-                                       <string key="className">ConfigsController</string>
-                                       <string key="superclassName">NSObject</string>
-                                       <dictionary class="NSMutableDictionary" key="actions">
-                                               <string key="addPressed:">id</string>
-                                               <string key="exportPressed:">id</string>
-                                               <string key="importPressed:">id</string>
-                                               <string key="removePressed:">id</string>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="actionInfosByName">
-                                               <object class="IBActionInfo" key="addPressed:">
-                                                       <string key="name">addPressed:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                               <object class="IBActionInfo" key="exportPressed:">
-                                                       <string key="name">exportPressed:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                               <object class="IBActionInfo" key="importPressed:">
-                                                       <string key="name">importPressed:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                               <object class="IBActionInfo" key="removePressed:">
-                                                       <string key="name">removePressed:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="outlets">
-                                               <string key="removeButton">NSButton</string>
-                                               <string key="tableView">NSTableView</string>
-                                               <string key="targetController">TargetController</string>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
-                                               <object class="IBToOneOutletInfo" key="removeButton">
-                                                       <string key="name">removeButton</string>
-                                                       <string key="candidateClassName">NSButton</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="tableView">
-                                                       <string key="name">tableView</string>
-                                                       <string key="candidateClassName">NSTableView</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="targetController">
-                                                       <string key="name">targetController</string>
-                                                       <string key="candidateClassName">TargetController</string>
-                                               </object>
-                                       </dictionary>
-                                       <object class="IBClassDescriptionSource" key="sourceIdentifier">
-                                               <string key="majorKey">IBProjectSource</string>
-                                               <string key="minorKey">./Classes/ConfigsController.h</string>
-                                       </object>
-                               </object>
-                               <object class="IBPartialClassDescription">
-                                       <string key="className">JoystickController</string>
-                                       <string key="superclassName">NSObject</string>
-                                       <dictionary class="NSMutableDictionary" key="outlets">
-                                               <string key="configsController">ConfigsController</string>
-                                               <string key="outlineView">NSOutlineView</string>
-                                               <string key="targetController">TargetController</string>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
-                                               <object class="IBToOneOutletInfo" key="configsController">
-                                                       <string key="name">configsController</string>
-                                                       <string key="candidateClassName">ConfigsController</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="outlineView">
-                                                       <string key="name">outlineView</string>
-                                                       <string key="candidateClassName">NSOutlineView</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="targetController">
-                                                       <string key="name">targetController</string>
-                                                       <string key="candidateClassName">TargetController</string>
-                                               </object>
-                                       </dictionary>
-                                       <object class="IBClassDescriptionSource" key="sourceIdentifier">
-                                               <string key="majorKey">IBProjectSource</string>
-                                               <string key="minorKey">./Classes/JoystickController.h</string>
-                                       </object>
-                               </object>
                                <object class="IBPartialClassDescription">
                                        <string key="className">NJKeyInputField</string>
                                        <string key="superclassName">NSTextField</string>
                                                <string key="minorKey">./Classes/NJKeyInputField.h</string>
                                        </object>
                                </object>
-                               <object class="IBPartialClassDescription">
-                                       <string key="className">TargetController</string>
-                                       <string key="superclassName">NSObject</string>
-                                       <dictionary class="NSMutableDictionary" key="actions">
-                                               <string key="configChosen:">id</string>
-                                               <string key="mbtnChanged:">id</string>
-                                               <string key="mdirChanged:">id</string>
-                                               <string key="radioChanged:">id</string>
-                                               <string key="sdirChanged:">id</string>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="actionInfosByName">
-                                               <object class="IBActionInfo" key="configChosen:">
-                                                       <string key="name">configChosen:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                               <object class="IBActionInfo" key="mbtnChanged:">
-                                                       <string key="name">mbtnChanged:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                               <object class="IBActionInfo" key="mdirChanged:">
-                                                       <string key="name">mdirChanged:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                               <object class="IBActionInfo" key="radioChanged:">
-                                                       <string key="name">radioChanged:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                               <object class="IBActionInfo" key="sdirChanged:">
-                                                       <string key="name">sdirChanged:</string>
-                                                       <string key="candidateClassName">id</string>
-                                               </object>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="outlets">
-                                               <string key="configPopup">NSPopUpButton</string>
-                                               <string key="configsController">ConfigsController</string>
-                                               <string key="joystickController">JoystickController</string>
-                                               <string key="keyInput">NJKeyInputField</string>
-                                               <string key="mouseBtnSelect">NSSegmentedControl</string>
-                                               <string key="mouseDirSelect">NSSegmentedControl</string>
-                                               <string key="radioButtons">NSMatrix</string>
-                                               <string key="scrollDirSelect">NSSegmentedControl</string>
-                                               <string key="title">NSTextField</string>
-                                       </dictionary>
-                                       <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
-                                               <object class="IBToOneOutletInfo" key="configPopup">
-                                                       <string key="name">configPopup</string>
-                                                       <string key="candidateClassName">NSPopUpButton</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="configsController">
-                                                       <string key="name">configsController</string>
-                                                       <string key="candidateClassName">ConfigsController</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="joystickController">
-                                                       <string key="name">joystickController</string>
-                                                       <string key="candidateClassName">JoystickController</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="keyInput">
-                                                       <string key="name">keyInput</string>
-                                                       <string key="candidateClassName">NJKeyInputField</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="mouseBtnSelect">
-                                                       <string key="name">mouseBtnSelect</string>
-                                                       <string key="candidateClassName">NSSegmentedControl</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="mouseDirSelect">
-                                                       <string key="name">mouseDirSelect</string>
-                                                       <string key="candidateClassName">NSSegmentedControl</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="radioButtons">
-                                                       <string key="name">radioButtons</string>
-                                                       <string key="candidateClassName">NSMatrix</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="scrollDirSelect">
-                                                       <string key="name">scrollDirSelect</string>
-                                                       <string key="candidateClassName">NSSegmentedControl</string>
-                                               </object>
-                                               <object class="IBToOneOutletInfo" key="title">
-                                                       <string key="name">title</string>
-                                                       <string key="candidateClassName">NSTextField</string>
-                                               </object>
-                                       </dictionary>
-                                       <object class="IBClassDescriptionSource" key="sourceIdentifier">
-                                               <string key="majorKey">IBProjectSource</string>
-                                               <string key="minorKey">./Classes/TargetController.h</string>
-                                       </object>
-                               </object>
                        </array>
                </object>
                <int key="IBDocument.localizationMode">0</int>
index c633833..ccdd256 100644 (file)
@@ -27,9 +27,9 @@
                D5617FE70FAFDB5800928B3A /* NJKeyInputField.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FE60FAFDB5800928B3A /* NJKeyInputField.m */; };
                D594BE860FAE6219007A85F2 /* NJDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BE850FAE6219007A85F2 /* NJDevice.m */; };
                D594BE8A0FAE64AD007A85F2 /* NJInput.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BE890FAE64AD007A85F2 /* NJInput.m */; };
-               D594BEF90FAE6FF2007A85F2 /* NJInputController.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BEF80FAE6FF2007A85F2 /* NJInputController.m */; };
+               D594BEF90FAE6FF2007A85F2 /* NJDeviceController.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BEF80FAE6FF2007A85F2 /* NJDeviceController.m */; };
                D594BF000FAE7397007A85F2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D594BEFF0FAE7397007A85F2 /* IOKit.framework */; };
-               D594BF830FAE9661007A85F2 /* ApplicationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BF820FAE9661007A85F2 /* ApplicationController.m */; };
+               D594BF830FAE9661007A85F2 /* EnjoyableApplicationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BF820FAE9661007A85F2 /* EnjoyableApplicationDelegate.m */; };
                D5F809710FB093400006A4DE /* NJOutputMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = D5F809700FB093400006A4DE /* NJOutputMapping.m */; };
                D5F80A9D0FB0A2FF0006A4DE /* icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = D5617A080FAEAF8300928B3A /* icon.icns */; };
                EE1D7C9216E01E7000B000EB /* NSView+FirstResponder.m in Sources */ = {isa = PBXBuildFile; fileRef = EE1D7C9116E01E7000B000EB /* NSView+FirstResponder.m */; };
                D594BE850FAE6219007A85F2 /* NJDevice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJDevice.m; sourceTree = "<group>"; };
                D594BE880FAE64AD007A85F2 /* NJInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInput.h; sourceTree = "<group>"; };
                D594BE890FAE64AD007A85F2 /* NJInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInput.m; sourceTree = "<group>"; };
-               D594BEF70FAE6FF2007A85F2 /* NJInputController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInputController.h; sourceTree = "<group>"; };
-               D594BEF80FAE6FF2007A85F2 /* NJInputController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInputController.m; sourceTree = "<group>"; };
+               D594BEF70FAE6FF2007A85F2 /* NJDeviceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJDeviceController.h; sourceTree = "<group>"; };
+               D594BEF80FAE6FF2007A85F2 /* NJDeviceController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJDeviceController.m; sourceTree = "<group>"; };
                D594BEFF0FAE7397007A85F2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
-               D594BF810FAE9661007A85F2 /* ApplicationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationController.h; sourceTree = "<group>"; };
-               D594BF820FAE9661007A85F2 /* ApplicationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ApplicationController.m; sourceTree = "<group>"; };
+               D594BF810FAE9661007A85F2 /* EnjoyableApplicationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnjoyableApplicationDelegate.h; sourceTree = "<group>"; };
+               D594BF820FAE9661007A85F2 /* EnjoyableApplicationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EnjoyableApplicationDelegate.m; sourceTree = "<group>"; };
                D5F8096F0FB093400006A4DE /* NJOutputMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputMapping.h; sourceTree = "<group>"; };
                D5F809700FB093400006A4DE /* NJOutputMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputMapping.m; sourceTree = "<group>"; };
                EE1D7C9016E01E7000B000EB /* NSView+FirstResponder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSView+FirstResponder.h"; sourceTree = "<group>"; };
                080E96DDFE201D6D7F000001 /* Classes */ = {
                        isa = PBXGroup;
                        children = (
-                               D5617D290FAF579A00928B3A /* NJInputAnalog.h */,
-                               D5617D2A0FAF579A00928B3A /* NJInputAnalog.m */,
+                               D594BF810FAE9661007A85F2 /* EnjoyableApplicationDelegate.h */,
+                               D594BF820FAE9661007A85F2 /* EnjoyableApplicationDelegate.m */,
+                               D594BEF70FAE6FF2007A85F2 /* NJDeviceController.h */,
+                               D594BEF80FAE6FF2007A85F2 /* NJDeviceController.m */,
+                               D5617A340FAEB74000928B3A /* NJMappingsController.h */,
+                               D5617A350FAEB74000928B3A /* NJMappingsController.m */,
+                               D5617FE20FAFD7B000928B3A /* NJOutputController.h */,
+                               D5617FE30FAFD7B000928B3A /* NJOutputController.m */,
+                               D5617FE50FAFDB5800928B3A /* NJKeyInputField.h */,
+                               D5617FE60FAFDB5800928B3A /* NJKeyInputField.m */,
+                               D5617A370FAEBA1800928B3A /* NJMapping.h */,
+                               D5617A380FAEBA1800928B3A /* NJMapping.m */,
                                D594BE840FAE6219007A85F2 /* NJDevice.h */,
                                D594BE850FAE6219007A85F2 /* NJDevice.m */,
+                               EEF86B7316E2241000674B87 /* NJInputPathElement.h */,
                                D594BE880FAE64AD007A85F2 /* NJInput.h */,
                                D594BE890FAE64AD007A85F2 /* NJInput.m */,
-                               D5617D240FAF579300928B3A /* NJInputHat.h */,
-                               D5617D250FAF579300928B3A /* NJInputHat.m */,
+                               D5617D290FAF579A00928B3A /* NJInputAnalog.h */,
+                               D5617D2A0FAF579A00928B3A /* NJInputAnalog.m */,
                                D5617D180FAF568100928B3A /* NJInputButton.h */,
                                D5617D190FAF568100928B3A /* NJInputButton.m */,
-                               D594BEF70FAE6FF2007A85F2 /* NJInputController.h */,
-                               D594BEF80FAE6FF2007A85F2 /* NJInputController.m */,
-                               D594BF810FAE9661007A85F2 /* ApplicationController.h */,
-                               D594BF820FAE9661007A85F2 /* ApplicationController.m */,
-                               D5617A340FAEB74000928B3A /* NJMappingsController.h */,
-                               D5617A350FAEB74000928B3A /* NJMappingsController.m */,
-                               D5617A370FAEBA1800928B3A /* NJMapping.h */,
-                               D5617A380FAEBA1800928B3A /* NJMapping.m */,
-                               D5F8096F0FB093400006A4DE /* NJOutputMapping.h */,
-                               D5F809700FB093400006A4DE /* NJOutputMapping.m */,
+                               D5617D240FAF579300928B3A /* NJInputHat.h */,
+                               D5617D250FAF579300928B3A /* NJInputHat.m */,
                                D5617FD40FAFD06000928B3A /* NJOutput.h */,
                                D5617FD50FAFD06000928B3A /* NJOutput.m */,
                                D5617FD70FAFD1E600928B3A /* NJOutputKeyPress.h */,
                                D5617FD80FAFD1E600928B3A /* NJOutputKeyPress.m */,
-                               D5617FE20FAFD7B000928B3A /* NJOutputController.h */,
-                               D5617FE30FAFD7B000928B3A /* NJOutputController.m */,
-                               D5617FE50FAFDB5800928B3A /* NJKeyInputField.h */,
-                               D5617FE60FAFDB5800928B3A /* NJKeyInputField.m */,
-                               8BD9B54115C230FE00929C5D /* NJOutputMouseMove.h */,
-                               8BD9B54215C230FE00929C5D /* NJOutputMouseMove.m */,
+                               D5F8096F0FB093400006A4DE /* NJOutputMapping.h */,
+                               D5F809700FB093400006A4DE /* NJOutputMapping.m */,
                                8B7E476A15C314A200C588FA /* NJOutputMouseButton.h */,
                                8B7E476B15C314A200C588FA /* NJOutputMouseButton.m */,
+                               8BD9B54115C230FE00929C5D /* NJOutputMouseMove.h */,
+                               8BD9B54215C230FE00929C5D /* NJOutputMouseMove.m */,
                                8BEFAD9A15C46BFF00823AEC /* NJOutputMouseScroll.h */,
                                8BEFAD9B15C46BFF00823AEC /* NJOutputMouseScroll.m */,
                                8BEFAD9E15C476DC00823AEC /* NJOutputSwitchMouseMode.h */,
                                8BEFAD9F15C476DC00823AEC /* NJOutputSwitchMouseMode.m */,
-                               EEF86B7316E2241000674B87 /* NJInputPathElement.h */,
-                               EEF86B7416E298CD00674B87 /* NJEvents.h */,
                        );
                        name = Classes;
                        sourceTree = "<group>";
                        isa = PBXGroup;
                        children = (
                                080E96DDFE201D6D7F000001 /* Classes */,
+                               EE1D5F8B16E403D600749C36 /* Categories */,
                                29B97315FDCFA39411CA2CEA /* Other Sources */,
                                29B97317FDCFA39411CA2CEA /* Resources */,
                                29B97323FDCFA39411CA2CEA /* Frameworks */,
                29B97315FDCFA39411CA2CEA /* Other Sources */ = {
                        isa = PBXGroup;
                        children = (
-                               32CA4F630368D1EE00C91783 /* Enjoyable_Prefix.pch */,
                                29B97316FDCFA39411CA2CEA /* main.m */,
-                               EE1D7C9416E0ECCF00B000EB /* NSError+Description.h */,
-                               EE1D7C9516E0ECCF00B000EB /* NSError+Description.m */,
-                               EE1D7C9016E01E7000B000EB /* NSView+FirstResponder.h */,
-                               EE1D7C9116E01E7000B000EB /* NSView+FirstResponder.m */,
+                               EEF86B7416E298CD00674B87 /* NJEvents.h */,
+                               32CA4F630368D1EE00C91783 /* Enjoyable_Prefix.pch */,
                        );
                        name = "Other Sources";
                        sourceTree = "<group>";
                        name = Frameworks;
                        sourceTree = "<group>";
                };
+               EE1D5F8B16E403D600749C36 /* Categories */ = {
+                       isa = PBXGroup;
+                       children = (
+                               EE1D7C9416E0ECCF00B000EB /* NSError+Description.h */,
+                               EE1D7C9516E0ECCF00B000EB /* NSError+Description.m */,
+                               EE1D7C9016E01E7000B000EB /* NSView+FirstResponder.h */,
+                               EE1D7C9116E01E7000B000EB /* NSView+FirstResponder.m */,
+                       );
+                       name = Categories;
+                       sourceTree = "<group>";
+               };
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
                                8D11072D0486CEB800E47090 /* main.m in Sources */,
                                D594BE860FAE6219007A85F2 /* NJDevice.m in Sources */,
                                D594BE8A0FAE64AD007A85F2 /* NJInput.m in Sources */,
-                               D594BEF90FAE6FF2007A85F2 /* NJInputController.m in Sources */,
-                               D594BF830FAE9661007A85F2 /* ApplicationController.m in Sources */,
+                               D594BEF90FAE6FF2007A85F2 /* NJDeviceController.m in Sources */,
+                               D594BF830FAE9661007A85F2 /* EnjoyableApplicationDelegate.m in Sources */,
                                D5617A360FAEB74000928B3A /* NJMappingsController.m in Sources */,
                                D5617A390FAEBA1800928B3A /* NJMapping.m in Sources */,
                                D5617D1A0FAF568100928B3A /* NJInputButton.m in Sources */,
diff --git a/EnjoyableApplicationDelegate.h b/EnjoyableApplicationDelegate.h
new file mode 100644 (file)
index 0000000..6a198e6
--- /dev/null
@@ -0,0 +1,28 @@
+//
+//  EnjoyableApplicationDelegate.h
+//  Enjoy
+//
+//  Created by Sam McCall on 4/05/09.
+//  Copyright 2009 University of Otago. All rights reserved.
+//
+
+@class NJDeviceController;
+@class NJOutputController;
+@class NJMappingsController;
+
+@interface EnjoyableApplicationDelegate : NSObject <NSApplicationDelegate> {
+    IBOutlet NSDrawer *drawer;
+    IBOutlet NSWindow *mainWindow;
+    IBOutlet NSToolbarItem *activeButton;
+    IBOutlet NSMenuItem *activeMenuItem;
+    IBOutlet NSMenu *dockMenuBase;
+}
+
+@property (nonatomic, strong) IBOutlet NJDeviceController *inputController;
+@property (nonatomic, strong) IBOutlet NJOutputController *outputController;
+@property (nonatomic, strong) IBOutlet NJMappingsController *mappingsController;
+
+- (IBAction)toggleActivity:(id)sender;
+- (void)mappingsChanged;
+
+@end
diff --git a/EnjoyableApplicationDelegate.m b/EnjoyableApplicationDelegate.m
new file mode 100644 (file)
index 0000000..23324d3
--- /dev/null
@@ -0,0 +1,109 @@
+//
+//  EnjoyableApplicationDelegate.m
+//  Enjoy
+//
+//  Created by Sam McCall on 4/05/09.
+//
+
+#import "EnjoyableApplicationDelegate.h"
+
+#import "NJMapping.h"
+#import "NJMappingsController.h"
+#import "NJDeviceController.h"
+#import "NJOutputController.h"
+#import "NJEvents.h"
+
+@implementation EnjoyableApplicationDelegate {
+    NSInteger mappingsMenuIndex;
+}
+
+- (void)didSwitchApplication:(NSNotification *)notification {
+    NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey];
+    [self.mappingsController activateMappingForProcess:currentApp.localizedName];
+}
+
+- (void)applicationDidFinishLaunching:(NSNotification *)notification {
+    [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];
+
+    mappingsMenuIndex = dockMenuBase.numberOfItems;
+    while (![dockMenuBase itemAtIndex:mappingsMenuIndex - 1].isSeparatorItem)
+        --mappingsMenuIndex;
+    
+    [drawer open];
+    self.outputController.enabled = NO;
+    [self.inputController setup];
+    [self.mappingsController load];
+}
+
+- (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)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 {
+    self.inputController.translatingEvents = !self.inputController.translatingEvents;
+}
+
+- (void)mappingsChanged {
+    NSInteger removeFrom = mappingsMenuIndex;
+    while (dockMenuBase.numberOfItems > removeFrom)
+        [dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1];
+    int added = 0;
+    for (NJMapping *mapping in self.mappingsController.mappings) {
+        NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @"";
+        [dockMenuBase addItemWithTitle:mapping.name
+                                action:@selector(chooseMapping:)
+                         keyEquivalent:keyEquiv];
+        
+    }
+    [_outputController refreshMappings];
+}
+
+- (void)mappingDidChange:(NSNotification *)note {
+    NJMapping *current = note.object;
+    NSArray *mappings = self.mappingsController.mappings;
+    for (NSUInteger i = 0; i < mappings.count; ++i)
+        [dockMenuBase itemAtIndex:i + mappingsMenuIndex].state = mappings[i] == current;
+}
+
+- (void)chooseMapping:(id)sender {
+    NSInteger idx = [dockMenuBase indexOfItem:sender] - mappingsMenuIndex;
+    NJMapping *chosen = self.mappingsController.mappings[idx];
+    [_mappingsController activateMapping:chosen];
+}
+
+@end
diff --git a/NJDeviceController.h b/NJDeviceController.h
new file mode 100644 (file)
index 0000000..2769222
--- /dev/null
@@ -0,0 +1,28 @@
+//
+//  NJDeviceController.h
+//  Enjoy
+//
+//  Created by Sam McCall on 4/05/09.
+//  Copyright 2009 University of Otago. All rights reserved.
+//
+
+@class NJDevice;
+@class NJInput;
+@class NJMappingsController;
+@class NJOutputController;
+
+@interface NJDeviceController : NSObject <NSOutlineViewDataSource, NSOutlineViewDelegate> {
+       IBOutlet NSOutlineView *outlineView;
+       IBOutlet NJOutputController *outputController;
+       IBOutlet NJMappingsController *mappingsController;
+}
+
+- (void)setup;
+- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device;
+
+@property (nonatomic, readonly) NJInput *selectedInput;
+@property (nonatomic, assign) NSPoint mouseLoc;
+@property (nonatomic, assign) BOOL frontWindowOnly;
+@property (nonatomic, assign) BOOL translatingEvents;
+
+@end
diff --git a/NJDeviceController.m b/NJDeviceController.m
new file mode 100644 (file)
index 0000000..e68cfdb
--- /dev/null
@@ -0,0 +1,235 @@
+//
+//  NJDeviceController.m
+//  Enjoy
+//
+//  Created by Sam McCall on 4/05/09.
+//
+
+#import "NJDeviceController.h"
+
+#import "NJMapping.h"
+#import "NJMappingsController.h"
+#import "NJDevice.h"
+#import "NJInput.h"
+#import "NJOutput.h"
+#import "NJOutputController.h"
+#import "NJEvents.h"
+
+@implementation NJDeviceController {
+    IOHIDManagerRef hidManager;
+    NSTimer *continuousTimer;
+    NSMutableArray *runningOutputs;
+    NSMutableArray *_devices;
+}
+
+- (id)init {
+    if ((self = [super init])) {
+        _devices = [[NSMutableArray alloc] initWithCapacity:16];
+        runningOutputs = [[NSMutableArray alloc] initWithCapacity:32];
+    }
+    return self;
+}
+
+- (void)dealloc {
+    [continuousTimer invalidate];
+    IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone);
+    CFRelease(hidManager);
+}
+
+- (void)expandRecursive:(id <NJInputPathElement>)pathElement {
+    if (pathElement) {
+        [self expandRecursive:pathElement.base];
+        [outlineView expandItem:pathElement];
+    }
+}
+
+- (void)addRunningOutput:(NJOutput *)output {
+    if (![runningOutputs containsObject:output]) {
+        [runningOutputs addObject:output];
+    }
+    if (!continuousTimer) {
+        continuousTimer = [NSTimer scheduledTimerWithTimeInterval:1.f/60.f
+                                                           target:self
+                                                         selector:@selector(updateContinuousInputs:)
+                                                         userInfo:nil
+                                                          repeats:YES];
+        NSLog(@"Scheduled continuous output timer.");
+    }
+}
+
+- (void)runOutputForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value {
+    NJDevice *dev = [self findDeviceByRef:device];
+    NJInput *mainInput = [dev inputForEvent:value];
+    [mainInput notifyEvent:value];
+    NSArray *children = mainInput.children ? mainInput.children : mainInput ? @[mainInput] : @[];
+    for (NJInput *subInput in children) {
+        NJOutput *output = mappingsController.currentMapping[subInput];
+        output.magnitude = mainInput.magnitude;
+        output.running = subInput.active;
+        if (output.running && output.isContinuous)
+            [self addRunningOutput:output];
+    }
+}
+
+- (void)showOutputForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value {
+    NJDevice *dev = [self findDeviceByRef:device];
+    NJInput *handler = [dev handlerForEvent:value];
+    if (!handler)
+        return;
+    
+    [self expandRecursive:handler];
+    [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[outlineView rowForItem:handler]] byExtendingSelection: NO];
+    [outputController focusKey];
+}
+
+static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) {
+    NJDeviceController *controller = (__bridge NJDeviceController *)ctx;
+    IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender);
+    
+    if (controller.translatingEvents) {
+        [controller runOutputForDevice:device value:value];
+    } else if ([NSApplication sharedApplication].mainWindow.isVisible) {
+        [controller showOutputForDevice:device value:value];
+    }
+}
+
+static int findAvailableIndex(NSArray *list, NJDevice *dev) {
+    for (int index = 1; ; index++) {
+        BOOL available = YES;
+        for (NJDevice *used in list) {
+            if ([used.productName isEqualToString:dev.productName] && used.index == index) {
+                available = NO;
+                break;
+            }
+        }
+        if (available)
+            return index;
+    }
+}
+
+- (void)addDeviceForDevice:(IOHIDDeviceRef)device {
+    IOHIDDeviceRegisterInputValueCallback(device, input_callback, (__bridge void*)self);
+    NJDevice *dev = [[NJDevice alloc] initWithDevice:device];
+    dev.index = findAvailableIndex(_devices, dev);
+    [_devices addObject:dev];
+    [outlineView reloadData];
+}
+
+static void add_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) {
+    NJDeviceController *controller = (__bridge NJDeviceController *)ctx;
+    [controller addDeviceForDevice:device];
+}
+
+- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device {
+    for (NJDevice *dev in _devices)
+        if (dev.device == device)
+            return dev;
+    return nil;
+}
+
+static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) {
+    NJDeviceController *controller = (__bridge NJDeviceController *)ctx;
+    [controller removeDeviceForDevice:device];
+}
+
+- (void)removeDeviceForDevice:(IOHIDDeviceRef)device {
+    NJDevice *match = [self findDeviceByRef:device];
+    IOHIDDeviceRegisterInputValueCallback(device, NULL, NULL);
+    if (match) {
+        [_devices removeObject:match];
+        [outlineView reloadData];
+    }
+    
+}
+
+- (void)updateContinuousInputs:(NSTimer *)timer {
+    self.mouseLoc = [NSEvent mouseLocation];
+    for (NJOutput *output in [runningOutputs copy]) {
+        if (![output update:self]) {
+            [runningOutputs removeObject:output];
+        }
+    }
+    if (!runningOutputs.count) {
+        [continuousTimer invalidate];
+        continuousTimer = nil;
+        NSLog(@"Unscheduled continuous output timer.");
+    }
+}
+
+#define NSSTR(e) ((NSString *)CFSTR(e))
+
+- (void)setup {
+    hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
+    NSArray *criteria = @[ @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop),
+                              NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_Joystick) },
+                           @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop),
+                              NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_GamePad) },
+                           @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop),
+                              NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_MultiAxisController) }
+                           ];
+    IOHIDManagerSetDeviceMatchingMultiple(hidManager, (__bridge CFArrayRef)criteria);
+    
+    IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+    IOReturn ret = IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone);
+    if (ret != kIOReturnSuccess) {
+        [[NSAlert alertWithMessageText:@"Input devices are unavailable"
+                         defaultButton:nil
+                       alternateButton:nil
+                           otherButton:nil
+             informativeTextWithFormat:@"Error 0x%08x occured trying to access your devices. "
+                                       @"Input may not be correctly detected or mapped.",
+                                       ret]
+         beginSheetModalForWindow:outlineView.window
+                    modalDelegate:nil
+                   didEndSelector:nil
+                      contextInfo:nil];
+    }
+    
+    IOHIDManagerRegisterDeviceMatchingCallback(hidManager, add_callback, (__bridge void *)self);
+    IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (__bridge void *)self);
+}
+
+- (NJInput *)selectedInput {
+    id <NJInputPathElement> item = [outlineView itemAtRow:outlineView.selectedRow];
+    return (!item.children && item.base) ? item : nil;
+}
+
+- (NSInteger)outlineView:(NSOutlineView *)outlineView
+  numberOfChildrenOfItem:(id <NJInputPathElement>)item {
+    return item ? item.children.count : _devices.count;
+}
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView
+   isItemExpandable:(id <NJInputPathElement>)item {
+    return item ? [[item children] count] > 0: YES;
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView
+            child:(NSInteger)index
+           ofItem:(id <NJInputPathElement>)item {
+    return item ? item.children[index] : _devices[index];
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView
+objectValueForTableColumn:(NSTableColumn *)tableColumn
+           byItem:(id <NJInputPathElement>)item  {
+    return item ? item.name : @"root";
+}
+
+- (void)outlineViewSelectionDidChange:(NSNotification *)notification {
+    
+    [outputController loadCurrent];
+}
+
+- (void)setTranslatingEvents:(BOOL)translatingEvents {
+    if (translatingEvents != _translatingEvents) {
+        _translatingEvents = translatingEvents;
+        NSString *name = translatingEvents
+            ? NJEventTranslationActivated
+            : NJEventTranslationDeactivated;
+        [NSNotificationCenter.defaultCenter postNotificationName:name
+                                                          object:self];
+    }
+}
+
+@end
diff --git a/NJInputController.h b/NJInputController.h
deleted file mode 100644 (file)
index fdd0532..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-//  NJInputController.h
-//  Enjoy
-//
-//  Created by Sam McCall on 4/05/09.
-//  Copyright 2009 University of Otago. All rights reserved.
-//
-
-@class NJDevice;
-@class NJInput;
-@class NJMappingsController;
-@class NJOutputController;
-
-@interface NJInputController : NSObject <NSOutlineViewDataSource, NSOutlineViewDelegate> {
-       IBOutlet NSOutlineView *outlineView;
-       IBOutlet NJOutputController *outputController;
-       IBOutlet NJMappingsController *mappingsController;
-}
-
-- (void)setup;
-- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device;
-
-@property (nonatomic, readonly) NJInput *selectedInput;
-@property (nonatomic, assign) NSPoint mouseLoc;
-@property (nonatomic, assign) BOOL frontWindowOnly;
-@property (nonatomic, assign) BOOL translatingEvents;
-
-@end
diff --git a/NJInputController.m b/NJInputController.m
deleted file mode 100644 (file)
index 618e99b..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-//
-//  NJInputController.h
-//  Enjoy
-//
-//  Created by Sam McCall on 4/05/09.
-//
-
-#import "NJInputController.h"
-
-#import "NJMapping.h"
-#import "NJMappingsController.h"
-#import "NJDevice.h"
-#import "NJInput.h"
-#import "NJOutput.h"
-#import "NJOutputController.h"
-#import "NJEvents.h"
-
-@implementation NJInputController {
-    IOHIDManagerRef hidManager;
-    NSTimer *continuousTimer;
-    NSMutableArray *runningOutputs;
-    NSMutableArray *_devices;
-}
-
-- (id)init {
-    if ((self = [super init])) {
-        _devices = [[NSMutableArray alloc] initWithCapacity:16];
-        runningOutputs = [[NSMutableArray alloc] initWithCapacity:32];
-    }
-    return self;
-}
-
-- (void)dealloc {
-    [continuousTimer invalidate];
-    IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone);
-    CFRelease(hidManager);
-}
-
-- (void)expandRecursive:(id <NJInputPathElement>)pathElement {
-    if (pathElement) {
-        [self expandRecursive:pathElement.base];
-        [outlineView expandItem:pathElement];
-    }
-}
-
-- (void)addRunningOutput:(NJOutput *)output {
-    if (![runningOutputs containsObject:output]) {
-        [runningOutputs addObject:output];
-    }
-    if (!continuousTimer) {
-        continuousTimer = [NSTimer scheduledTimerWithTimeInterval:1.f/60.f
-                                                           target:self
-                                                         selector:@selector(updateContinuousInputs:)
-                                                         userInfo:nil
-                                                          repeats:YES];
-        NSLog(@"Scheduled continuous output timer.");
-    }
-}
-
-- (void)runOutputForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value {
-    NJDevice *dev = [self findDeviceByRef:device];
-    NJInput *mainInput = [dev inputForEvent:value];
-    [mainInput notifyEvent:value];
-    NSArray *children = mainInput.children ? mainInput.children : mainInput ? @[mainInput] : @[];
-    for (NJInput *subInput in children) {
-        NJOutput *output = mappingsController.currentMapping[subInput];
-        output.magnitude = mainInput.magnitude;
-        output.running = subInput.active;
-        if (output.running && output.isContinuous)
-            [self addRunningOutput:output];
-    }
-}
-
-- (void)showOutputForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value {
-    NJDevice *dev = [self findDeviceByRef:device];
-    NJInput *handler = [dev handlerForEvent:value];
-    if (!handler)
-        return;
-    
-    [self expandRecursive:handler];
-    [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[outlineView rowForItem:handler]] byExtendingSelection: NO];
-    [outputController focusKey];
-}
-
-static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) {
-    NJInputController *controller = (__bridge NJInputController *)ctx;
-    IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender);
-    
-    if (controller.translatingEvents) {
-        [controller runOutputForDevice:device value:value];
-    } else if ([NSApplication sharedApplication].mainWindow.isVisible) {
-        [controller showOutputForDevice:device value:value];
-    }
-}
-
-static int findAvailableIndex(NSArray *list, NJDevice *dev) {
-    for (int index = 1; ; index++) {
-        BOOL available = YES;
-        for (NJDevice *used in list) {
-            if ([used.productName isEqualToString:dev.productName] && used.index == index) {
-                available = NO;
-                break;
-            }
-        }
-        if (available)
-            return index;
-    }
-}
-
-- (void)addDeviceForDevice:(IOHIDDeviceRef)device {
-    IOHIDDeviceRegisterInputValueCallback(device, input_callback, (__bridge void*)self);
-    NJDevice *dev = [[NJDevice alloc] initWithDevice:device];
-    dev.index = findAvailableIndex(_devices, dev);
-    [_devices addObject:dev];
-    [outlineView reloadData];
-}
-
-static void add_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) {
-    NJInputController *controller = (__bridge NJInputController *)ctx;
-    [controller addDeviceForDevice:device];
-}
-
-- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device {
-    for (NJDevice *dev in _devices)
-        if (dev.device == device)
-            return dev;
-    return nil;
-}
-
-static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) {
-    NJInputController *controller = (__bridge NJInputController *)ctx;
-    [controller removeDeviceForDevice:device];
-}
-
-- (void)removeDeviceForDevice:(IOHIDDeviceRef)device {
-    NJDevice *match = [self findDeviceByRef:device];
-    IOHIDDeviceRegisterInputValueCallback(device, NULL, NULL);
-    if (match) {
-        [_devices removeObject:match];
-        [outlineView reloadData];
-    }
-    
-}
-
-- (void)updateContinuousInputs:(NSTimer *)timer {
-    self.mouseLoc = [NSEvent mouseLocation];
-    for (NJOutput *output in [runningOutputs copy]) {
-        if (![output update:self]) {
-            [runningOutputs removeObject:output];
-        }
-    }
-    if (!runningOutputs.count) {
-        [continuousTimer invalidate];
-        continuousTimer = nil;
-        NSLog(@"Unscheduled continuous output timer.");
-    }
-}
-
-#define NSSTR(e) ((NSString *)CFSTR(e))
-
-- (void)setup {
-    hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
-    NSArray *criteria = @[ @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop),
-                              NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_Joystick) },
-                           @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop),
-                              NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_GamePad) },
-                           @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop),
-                              NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_MultiAxisController) }
-                           ];
-    IOHIDManagerSetDeviceMatchingMultiple(hidManager, (__bridge CFArrayRef)criteria);
-    
-    IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
-    IOReturn ret = IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone);
-    if (ret != kIOReturnSuccess) {
-        [[NSAlert alertWithMessageText:@"Input devices are unavailable"
-                         defaultButton:nil
-                       alternateButton:nil
-                           otherButton:nil
-             informativeTextWithFormat:@"Error 0x%08x occured trying to access your devices. "
-                                       @"Input may not be correctly detected or mapped.",
-                                       ret]
-         beginSheetModalForWindow:outlineView.window
-                    modalDelegate:nil
-                   didEndSelector:nil
-                      contextInfo:nil];
-    }
-    
-    IOHIDManagerRegisterDeviceMatchingCallback(hidManager, add_callback, (__bridge void *)self);
-    IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (__bridge void *)self);
-}
-
-- (NJInput *)selectedInput {
-    id <NJInputPathElement> item = [outlineView itemAtRow:outlineView.selectedRow];
-    return (!item.children && item.base) ? item : nil;
-}
-
-- (NSInteger)outlineView:(NSOutlineView *)outlineView
-  numberOfChildrenOfItem:(id <NJInputPathElement>)item {
-    return item ? item.children.count : _devices.count;
-}
-
-- (BOOL)outlineView:(NSOutlineView *)outlineView
-   isItemExpandable:(id <NJInputPathElement>)item {
-    return item ? [[item children] count] > 0: YES;
-}
-
-- (id)outlineView:(NSOutlineView *)outlineView
-            child:(NSInteger)index
-           ofItem:(id <NJInputPathElement>)item {
-    return item ? item.children[index] : _devices[index];
-}
-
-- (id)outlineView:(NSOutlineView *)outlineView
-objectValueForTableColumn:(NSTableColumn *)tableColumn
-           byItem:(id <NJInputPathElement>)item  {
-    return item ? item.name : @"root";
-}
-
-- (void)outlineViewSelectionDidChange:(NSNotification *)notification {
-    
-    [outputController loadCurrent];
-}
-
-- (void)setTranslatingEvents:(BOOL)translatingEvents {
-    if (translatingEvents != _translatingEvents) {
-        _translatingEvents = translatingEvents;
-        NSString *name = translatingEvents
-            ? NJEventTranslationActivated
-            : NJEventTranslationDeactivated;
-        [NSNotificationCenter.defaultCenter postNotificationName:name
-                                                          object:self];
-    }
-}
-
-@end
index e01cb91..fe96462 100644 (file)
@@ -7,7 +7,7 @@
 
 #import "NJMappingsController.h"
 
-#import "ApplicationController.h"
+#import "EnjoyableApplicationDelegate.h"
 #import "NJMapping.h"
 #import "NJMappingsController.h"
 #import "NJOutput.h"
@@ -62,7 +62,7 @@
 - (IBAction)addPressed:(id)sender {
     NJMapping *newMapping = [[NJMapping alloc] initWithName:@"Untitled"];
     [_mappings addObject:newMapping];
-    [(ApplicationController *)NSApplication.sharedApplication.delegate mappingsChanged];
+    [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
     [tableView reloadData];
     [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_mappings.count - 1] byExtendingSelection:NO];
     [tableView editColumn:0 row:_mappings.count - 1 withEvent:nil select:YES];
@@ -75,7 +75,7 @@
     
     [_mappings removeObjectAtIndex:tableView.selectedRow];
     [tableView reloadData];
-    [(ApplicationController *)NSApplication.sharedApplication.delegate mappingsChanged];
+    [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
     [self activateMapping:_mappings[0]];
     [self save];
 }
@@ -92,7 +92,7 @@
 - (void)tableView:(NSTableView *)view setObjectValue:(NSString *)obj forTableColumn:(NSTableColumn *)col row:(NSInteger)index {
     [(NJMapping *)_mappings[index] setName:obj];
     [tableView reloadData];
-    [(ApplicationController *)NSApplication.sharedApplication.delegate mappingsChanged];
+    [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
 }
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
             current = 0;
         _mappings = newMappings;
         [tableView reloadData];
-        [(ApplicationController *)NSApplication.sharedApplication.delegate mappingsChanged];
+        [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
         [self activateMapping:_mappings[current]];
     }
 }
                           }
                           
                           [self save];
-                          [(ApplicationController *)NSApplication.sharedApplication.delegate mappingsChanged];
+                          [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
                           [self activateMapping:mapping];
                           [outputController loadCurrent];
                           
index 2bfc167..b82c4e7 100644 (file)
@@ -6,7 +6,7 @@
 //  Copyright 2009 University of Otago. All rights reserved.
 //
 
-@class NJInputController;
+@class NJDeviceController;
 
 @interface NJOutput : NSObject
 
@@ -16,7 +16,7 @@
 
 - (void)trigger;
 - (void)untrigger;
-- (BOOL)update:(NJInputController *)jc;
+- (BOOL)update:(NJDeviceController *)jc;
 
 - (NSDictionary *)serialize;
 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
index dd751e1..ab29ed8 100644 (file)
@@ -63,7 +63,7 @@
 - (void)untrigger {
 }
 
-- (BOOL)update:(NJInputController *)jc {
+- (BOOL)update:(NJDeviceController *)jc {
     return NO;
 }
 
index bf590a6..5b9a749 100644 (file)
@@ -9,7 +9,7 @@
 #import "NJKeyInputField.h"
 
 @class NJMappingsController;
-@class NJInputController;
+@class NJDeviceController;
 @class NJOutput;
 @class NJOutputMouseMove;
 
@@ -22,7 +22,7 @@
     IBOutlet NSTextField *title;
     IBOutlet NSPopUpButton *mappingPopup;
     IBOutlet NJMappingsController *mappingsController;
-    IBOutlet NJInputController *inputController;
+    IBOutlet NJDeviceController *inputController;
 }
 
 @property (assign) BOOL enabled;
index f05c615..6725125 100644 (file)
@@ -10,7 +10,7 @@
 #import "NJMappingsController.h"
 #import "NJMapping.h"
 #import "NJInput.h"
-#import "NJInputController.h"
+#import "NJDeviceController.h"
 #import "NJKeyInputField.h"
 #import "NJOutputMapping.h"
 #import "NJOutputController.h"
index e411172..5cd5d9f 100644 (file)
@@ -7,7 +7,7 @@
 
 #import "NJOutputMapping.h"
 
-#import "ApplicationController.h"
+#import "EnjoyableApplicationDelegate.h"
 #import "NJMapping.h"
 #import "NJMappingsController.h"
 
@@ -37,7 +37,7 @@
 }
 
 - (void)trigger {
-    ApplicationController *ctrl = NSApplication.sharedApplication.delegate;
+    EnjoyableApplicationDelegate *ctrl = NSApplication.sharedApplication.delegate;
     [ctrl.mappingsController activateMapping:_mapping];
 }
 
index 5e59d4e..3346fb2 100644 (file)
@@ -7,7 +7,7 @@
 
 #import "NJOutputMouseMove.h"
 
-#import "NJInputController.h"
+#import "NJDeviceController.h"
 
 @implementation NJOutputMouseMove {
     int sign;
@@ -32,7 +32,7 @@
        return output;
 }
 
-- (BOOL)update:(NJInputController *)jc {
+- (BOOL)update:(NJDeviceController *)jc {
     if (fabsf(self.magnitude) < 0.01) {
         sign = 0;
         return NO; // dead zone
index 9057125..2f6d2d6 100644 (file)
@@ -37,7 +37,7 @@
     }
 }
 
-- (BOOL)update:(NJInputController *)jc {
+- (BOOL)update:(NJDeviceController *)jc {
     if (fabsf(self.magnitude) < 0.01f) {
         sign = 0;
         return NO; // dead zone
index 3332a91..1750869 100644 (file)
@@ -7,8 +7,8 @@
 
 #import "NJOutputSwitchMouseMode.h"
 
-#import "ApplicationController.h"
-#import "NJInputController.h"
+#import "EnjoyableApplicationDelegate.h"
+#import "NJDeviceController.h"
 
 @implementation NJOutputSwitchMouseMode
 
@@ -27,8 +27,8 @@
 - (void)trigger {
     // FIXME: It's hacky to get at the controller this way, but it's
     // also hacky to pass it. Shouldn't need to do either.
-    ApplicationController *ac = NSApplication.sharedApplication.delegate;
-    NJInputController *jc = ac.inputController;
+    EnjoyableApplicationDelegate *ac = NSApplication.sharedApplication.delegate;
+    NJDeviceController *jc = ac.inputController;
     jc.frontWindowOnly = !jc.frontWindowOnly;
 }