From: Joe Wreschnig Date: Sun, 3 Mar 2013 21:37:54 +0000 (+0100) Subject: Big rename part 3: 'target' to 'output'. X-Git-Tag: version-1.0~49 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=dcedf147ddcb6c21768cea94a2f06b93007d2a82;p=enjoyable.git Big rename part 3: 'target' to 'output'. --- diff --git a/ApplicationController.h b/ApplicationController.h index 88c9d29..a1b8742 100644 --- a/ApplicationController.h +++ b/ApplicationController.h @@ -7,7 +7,7 @@ // @class NJInputController; -@class TargetController; +@class NJOutputController; @class NJMappingsController; @interface ApplicationController : NSObject { @@ -19,7 +19,7 @@ } @property (nonatomic, strong) IBOutlet NJInputController *inputController; -@property (nonatomic, strong) IBOutlet TargetController *targetController; +@property (nonatomic, strong) IBOutlet NJOutputController *outputController; @property (nonatomic, strong) IBOutlet NJMappingsController *mappingsController; - (IBAction)toggleActivity:(id)sender; diff --git a/ApplicationController.m b/ApplicationController.m index 50f9c29..faad07a 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -10,7 +10,7 @@ #import "NJMapping.h" #import "NJMappingsController.h" #import "NJInputController.h" -#import "TargetController.h" +#import "NJOutputController.h" #import "NJEvents.h" @implementation ApplicationController { @@ -24,7 +24,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification { [drawer open]; - self.targetController.enabled = NO; + self.outputController.enabled = NO; [self.inputController setup]; [self.mappingsController load]; [NSNotificationCenter.defaultCenter @@ -92,7 +92,7 @@ keyEquivalent:keyEquiv]; } - [_targetController refreshMappings]; + [_outputController refreshMappings]; } - (void)mappingDidChange:(NSNotification *)note { diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index c2ebf64..8dd62bf 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -1134,7 +1134,7 @@ NJInputController - TargetController + NJOutputController @@ -1277,19 +1277,19 @@ - targetController + mappingsController - + - 695 + 822 - mappingsController + outputController - + - 822 + 826 @@ -1339,14 +1339,6 @@ 611 - - - targetController - - - - 712 - dockMenuBase @@ -1371,6 +1363,14 @@ 820 + + + outputController + + + + 825 + addPressed: @@ -1403,14 +1403,6 @@ 520 - - - targetController - - - - 697 - exportPressed: @@ -1427,6 +1419,14 @@ 816 + + + outputController + + + + 827 + dataSource @@ -1451,14 +1451,6 @@ 692 - - - joystickController - - - - 694 - title @@ -1555,6 +1547,14 @@ 824 + + + inputController + + + + 828 + keyDelegate @@ -2233,7 +2233,7 @@ - 824 + 828 diff --git a/Enjoyable.xcodeproj/project.pbxproj b/Enjoyable.xcodeproj/project.pbxproj index cbcf390..c633833 100644 --- a/Enjoyable.xcodeproj/project.pbxproj +++ b/Enjoyable.xcodeproj/project.pbxproj @@ -8,10 +8,10 @@ /* Begin PBXBuildFile section */ 1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; }; - 8B7E476C15C314A200C588FA /* TargetMouseBtn.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B7E476B15C314A200C588FA /* TargetMouseBtn.m */; }; - 8BD9B54315C230FF00929C5D /* TargetMouseMove.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD9B54215C230FE00929C5D /* TargetMouseMove.m */; }; - 8BEFAD9C15C46BFF00823AEC /* TargetMouseScroll.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BEFAD9B15C46BFF00823AEC /* TargetMouseScroll.m */; }; - 8BEFADA015C476DC00823AEC /* TargetToggleMouseScope.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BEFAD9F15C476DC00823AEC /* TargetToggleMouseScope.m */; }; + 8B7E476C15C314A200C588FA /* NJOutputMouseButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B7E476B15C314A200C588FA /* NJOutputMouseButton.m */; }; + 8BD9B54315C230FF00929C5D /* NJOutputMouseMove.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD9B54215C230FE00929C5D /* NJOutputMouseMove.m */; }; + 8BEFAD9C15C46BFF00823AEC /* NJOutputMouseScroll.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BEFAD9B15C46BFF00823AEC /* NJOutputMouseScroll.m */; }; + 8BEFADA015C476DC00823AEC /* NJOutputSwitchMouseMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BEFAD9F15C476DC00823AEC /* NJOutputSwitchMouseMode.m */; }; 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; @@ -21,16 +21,16 @@ D5617D1A0FAF568100928B3A /* NJInputButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D190FAF568100928B3A /* NJInputButton.m */; }; D5617D260FAF579300928B3A /* NJInputHat.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D250FAF579300928B3A /* NJInputHat.m */; }; D5617D2B0FAF579A00928B3A /* NJInputAnalog.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D2A0FAF579A00928B3A /* NJInputAnalog.m */; }; - D5617FD60FAFD06000928B3A /* Target.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD50FAFD06000928B3A /* Target.m */; }; - D5617FD90FAFD1E600928B3A /* TargetKeyboard.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD80FAFD1E600928B3A /* TargetKeyboard.m */; }; - D5617FE40FAFD7B000928B3A /* TargetController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FE30FAFD7B000928B3A /* TargetController.m */; }; + D5617FD60FAFD06000928B3A /* NJOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD50FAFD06000928B3A /* NJOutput.m */; }; + D5617FD90FAFD1E600928B3A /* NJOutputKeyPress.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD80FAFD1E600928B3A /* NJOutputKeyPress.m */; }; + D5617FE40FAFD7B000928B3A /* NJOutputController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FE30FAFD7B000928B3A /* NJOutputController.m */; }; 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 */; }; D594BF000FAE7397007A85F2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D594BEFF0FAE7397007A85F2 /* IOKit.framework */; }; D594BF830FAE9661007A85F2 /* ApplicationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BF820FAE9661007A85F2 /* ApplicationController.m */; }; - D5F809710FB093400006A4DE /* TargetConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = D5F809700FB093400006A4DE /* TargetConfig.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 */; }; EE1D7C9616E0ECCF00B000EB /* NSError+Description.m in Sources */ = {isa = PBXBuildFile; fileRef = EE1D7C9516E0ECCF00B000EB /* NSError+Description.m */; }; @@ -44,14 +44,14 @@ 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 32CA4F630368D1EE00C91783 /* Enjoyable_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enjoyable_Prefix.pch; sourceTree = ""; }; - 8B7E476A15C314A200C588FA /* TargetMouseBtn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetMouseBtn.h; sourceTree = ""; }; - 8B7E476B15C314A200C588FA /* TargetMouseBtn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetMouseBtn.m; sourceTree = ""; }; - 8BD9B54115C230FE00929C5D /* TargetMouseMove.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetMouseMove.h; sourceTree = ""; }; - 8BD9B54215C230FE00929C5D /* TargetMouseMove.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetMouseMove.m; sourceTree = ""; }; - 8BEFAD9A15C46BFF00823AEC /* TargetMouseScroll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetMouseScroll.h; sourceTree = ""; }; - 8BEFAD9B15C46BFF00823AEC /* TargetMouseScroll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetMouseScroll.m; sourceTree = ""; }; - 8BEFAD9E15C476DC00823AEC /* TargetToggleMouseScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetToggleMouseScope.h; sourceTree = ""; }; - 8BEFAD9F15C476DC00823AEC /* TargetToggleMouseScope.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetToggleMouseScope.m; sourceTree = ""; }; + 8B7E476A15C314A200C588FA /* NJOutputMouseButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputMouseButton.h; sourceTree = ""; }; + 8B7E476B15C314A200C588FA /* NJOutputMouseButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputMouseButton.m; sourceTree = ""; }; + 8BD9B54115C230FE00929C5D /* NJOutputMouseMove.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputMouseMove.h; sourceTree = ""; }; + 8BD9B54215C230FE00929C5D /* NJOutputMouseMove.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputMouseMove.m; sourceTree = ""; }; + 8BEFAD9A15C46BFF00823AEC /* NJOutputMouseScroll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputMouseScroll.h; sourceTree = ""; }; + 8BEFAD9B15C46BFF00823AEC /* NJOutputMouseScroll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputMouseScroll.m; sourceTree = ""; }; + 8BEFAD9E15C476DC00823AEC /* NJOutputSwitchMouseMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputSwitchMouseMode.h; sourceTree = ""; }; + 8BEFAD9F15C476DC00823AEC /* NJOutputSwitchMouseMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputSwitchMouseMode.m; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8D1107320486CEB800E47090 /* Enjoyable.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Enjoyable.app; sourceTree = BUILT_PRODUCTS_DIR; }; D549CA4B0FBB441B00BC8203 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = ""; }; @@ -66,12 +66,12 @@ D5617D250FAF579300928B3A /* NJInputHat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInputHat.m; sourceTree = ""; }; D5617D290FAF579A00928B3A /* NJInputAnalog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInputAnalog.h; sourceTree = ""; }; D5617D2A0FAF579A00928B3A /* NJInputAnalog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInputAnalog.m; sourceTree = ""; }; - D5617FD40FAFD06000928B3A /* Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Target.h; sourceTree = ""; }; - D5617FD50FAFD06000928B3A /* Target.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Target.m; sourceTree = ""; }; - D5617FD70FAFD1E600928B3A /* TargetKeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetKeyboard.h; sourceTree = ""; }; - D5617FD80FAFD1E600928B3A /* TargetKeyboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetKeyboard.m; sourceTree = ""; }; - D5617FE20FAFD7B000928B3A /* TargetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetController.h; sourceTree = ""; }; - D5617FE30FAFD7B000928B3A /* TargetController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetController.m; sourceTree = ""; }; + D5617FD40FAFD06000928B3A /* NJOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutput.h; sourceTree = ""; }; + D5617FD50FAFD06000928B3A /* NJOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutput.m; sourceTree = ""; }; + D5617FD70FAFD1E600928B3A /* NJOutputKeyPress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputKeyPress.h; sourceTree = ""; }; + D5617FD80FAFD1E600928B3A /* NJOutputKeyPress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputKeyPress.m; sourceTree = ""; }; + D5617FE20FAFD7B000928B3A /* NJOutputController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputController.h; sourceTree = ""; }; + D5617FE30FAFD7B000928B3A /* NJOutputController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputController.m; sourceTree = ""; }; D5617FE50FAFDB5800928B3A /* NJKeyInputField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJKeyInputField.h; sourceTree = ""; }; D5617FE60FAFDB5800928B3A /* NJKeyInputField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJKeyInputField.m; sourceTree = ""; }; D594BE840FAE6219007A85F2 /* NJDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJDevice.h; sourceTree = ""; }; @@ -83,8 +83,8 @@ D594BEFF0FAE7397007A85F2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = ""; }; D594BF810FAE9661007A85F2 /* ApplicationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationController.h; sourceTree = ""; }; D594BF820FAE9661007A85F2 /* ApplicationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ApplicationController.m; sourceTree = ""; }; - D5F8096F0FB093400006A4DE /* TargetConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetConfig.h; sourceTree = ""; }; - D5F809700FB093400006A4DE /* TargetConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetConfig.m; sourceTree = ""; }; + D5F8096F0FB093400006A4DE /* NJOutputMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJOutputMapping.h; sourceTree = ""; }; + D5F809700FB093400006A4DE /* NJOutputMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJOutputMapping.m; sourceTree = ""; }; EE1D7C9016E01E7000B000EB /* NSView+FirstResponder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSView+FirstResponder.h"; sourceTree = ""; }; EE1D7C9116E01E7000B000EB /* NSView+FirstResponder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSView+FirstResponder.m"; sourceTree = ""; }; EE1D7C9416E0ECCF00B000EB /* NSError+Description.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Description.h"; sourceTree = ""; }; @@ -127,24 +127,24 @@ D5617A350FAEB74000928B3A /* NJMappingsController.m */, D5617A370FAEBA1800928B3A /* NJMapping.h */, D5617A380FAEBA1800928B3A /* NJMapping.m */, - D5F8096F0FB093400006A4DE /* TargetConfig.h */, - D5F809700FB093400006A4DE /* TargetConfig.m */, - D5617FD40FAFD06000928B3A /* Target.h */, - D5617FD50FAFD06000928B3A /* Target.m */, - D5617FD70FAFD1E600928B3A /* TargetKeyboard.h */, - D5617FD80FAFD1E600928B3A /* TargetKeyboard.m */, - D5617FE20FAFD7B000928B3A /* TargetController.h */, - D5617FE30FAFD7B000928B3A /* TargetController.m */, + D5F8096F0FB093400006A4DE /* NJOutputMapping.h */, + D5F809700FB093400006A4DE /* NJOutputMapping.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 /* TargetMouseMove.h */, - 8BD9B54215C230FE00929C5D /* TargetMouseMove.m */, - 8B7E476A15C314A200C588FA /* TargetMouseBtn.h */, - 8B7E476B15C314A200C588FA /* TargetMouseBtn.m */, - 8BEFAD9A15C46BFF00823AEC /* TargetMouseScroll.h */, - 8BEFAD9B15C46BFF00823AEC /* TargetMouseScroll.m */, - 8BEFAD9E15C476DC00823AEC /* TargetToggleMouseScope.h */, - 8BEFAD9F15C476DC00823AEC /* TargetToggleMouseScope.m */, + 8BD9B54115C230FE00929C5D /* NJOutputMouseMove.h */, + 8BD9B54215C230FE00929C5D /* NJOutputMouseMove.m */, + 8B7E476A15C314A200C588FA /* NJOutputMouseButton.h */, + 8B7E476B15C314A200C588FA /* NJOutputMouseButton.m */, + 8BEFAD9A15C46BFF00823AEC /* NJOutputMouseScroll.h */, + 8BEFAD9B15C46BFF00823AEC /* NJOutputMouseScroll.m */, + 8BEFAD9E15C476DC00823AEC /* NJOutputSwitchMouseMode.h */, + 8BEFAD9F15C476DC00823AEC /* NJOutputSwitchMouseMode.m */, EEF86B7316E2241000674B87 /* NJInputPathElement.h */, EEF86B7416E298CD00674B87 /* NJEvents.h */, ); @@ -300,15 +300,15 @@ D5617D1A0FAF568100928B3A /* NJInputButton.m in Sources */, D5617D260FAF579300928B3A /* NJInputHat.m in Sources */, D5617D2B0FAF579A00928B3A /* NJInputAnalog.m in Sources */, - D5617FD60FAFD06000928B3A /* Target.m in Sources */, - D5617FD90FAFD1E600928B3A /* TargetKeyboard.m in Sources */, - D5617FE40FAFD7B000928B3A /* TargetController.m in Sources */, + D5617FD60FAFD06000928B3A /* NJOutput.m in Sources */, + D5617FD90FAFD1E600928B3A /* NJOutputKeyPress.m in Sources */, + D5617FE40FAFD7B000928B3A /* NJOutputController.m in Sources */, D5617FE70FAFDB5800928B3A /* NJKeyInputField.m in Sources */, - D5F809710FB093400006A4DE /* TargetConfig.m in Sources */, - 8BD9B54315C230FF00929C5D /* TargetMouseMove.m in Sources */, - 8B7E476C15C314A200C588FA /* TargetMouseBtn.m in Sources */, - 8BEFAD9C15C46BFF00823AEC /* TargetMouseScroll.m in Sources */, - 8BEFADA015C476DC00823AEC /* TargetToggleMouseScope.m in Sources */, + D5F809710FB093400006A4DE /* NJOutputMapping.m in Sources */, + 8BD9B54315C230FF00929C5D /* NJOutputMouseMove.m in Sources */, + 8B7E476C15C314A200C588FA /* NJOutputMouseButton.m in Sources */, + 8BEFAD9C15C46BFF00823AEC /* NJOutputMouseScroll.m in Sources */, + 8BEFADA015C476DC00823AEC /* NJOutputSwitchMouseMode.m in Sources */, EE1D7C9216E01E7000B000EB /* NSView+FirstResponder.m in Sources */, EE1D7C9616E0ECCF00B000EB /* NSError+Description.m in Sources */, ); diff --git a/NJInputController.h b/NJInputController.h index feea2e2..fdd0532 100644 --- a/NJInputController.h +++ b/NJInputController.h @@ -9,16 +9,16 @@ @class NJDevice; @class NJInput; @class NJMappingsController; -@class TargetController; +@class NJOutputController; @interface NJInputController : NSObject { IBOutlet NSOutlineView *outlineView; - IBOutlet TargetController *targetController; + IBOutlet NJOutputController *outputController; IBOutlet NJMappingsController *mappingsController; } - (void)setup; -- (NJDevice *)findJoystickByRef:(IOHIDDeviceRef)device; +- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device; @property (nonatomic, readonly) NJInput *selectedInput; @property (nonatomic, assign) NSPoint mouseLoc; diff --git a/NJInputController.m b/NJInputController.m index a708d82..618e99b 100644 --- a/NJInputController.m +++ b/NJInputController.m @@ -11,21 +11,21 @@ #import "NJMappingsController.h" #import "NJDevice.h" #import "NJInput.h" -#import "Target.h" -#import "TargetController.h" +#import "NJOutput.h" +#import "NJOutputController.h" #import "NJEvents.h" @implementation NJInputController { IOHIDManagerRef hidManager; NSTimer *continuousTimer; - NSMutableArray *runningTargets; - NSMutableArray *_joysticks; + NSMutableArray *runningOutputs; + NSMutableArray *_devices; } - (id)init { if ((self = [super init])) { - _joysticks = [[NSMutableArray alloc] initWithCapacity:16]; - runningTargets = [[NSMutableArray alloc] initWithCapacity:32]; + _devices = [[NSMutableArray alloc] initWithCapacity:16]; + runningOutputs = [[NSMutableArray alloc] initWithCapacity:32]; } return self; } @@ -43,9 +43,9 @@ } } -- (void)addRunningTarget:(Target *)target { - if (![runningTargets containsObject:target]) { - [runningTargets addObject:target]; +- (void)addRunningOutput:(NJOutput *)output { + if (![runningOutputs containsObject:output]) { + [runningOutputs addObject:output]; } if (!continuousTimer) { continuousTimer = [NSTimer scheduledTimerWithTimeInterval:1.f/60.f @@ -53,33 +53,33 @@ selector:@selector(updateContinuousInputs:) userInfo:nil repeats:YES]; - NSLog(@"Scheduled continuous target timer."); + NSLog(@"Scheduled continuous output timer."); } } -- (void)runTargetForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value { - NJDevice *dev = [self findJoystickByRef:device]; +- (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) { - Target *target = mappingsController.currentMapping[subInput]; - target.magnitude = mainInput.magnitude; - target.running = subInput.active; - if (target.running && target.isContinuous) - [self addRunningTarget:target]; + NJOutput *output = mappingsController.currentMapping[subInput]; + output.magnitude = mainInput.magnitude; + output.running = subInput.active; + if (output.running && output.isContinuous) + [self addRunningOutput:output]; } } -- (void)showTargetForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value { - NJDevice *dev = [self findJoystickByRef:device]; +- (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]; - [targetController focusKey]; + [outputController focusKey]; } static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) { @@ -87,9 +87,9 @@ static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDVa IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender); if (controller.translatingEvents) { - [controller runTargetForDevice:device value:value]; + [controller runOutputForDevice:device value:value]; } else if ([NSApplication sharedApplication].mainWindow.isVisible) { - [controller showTargetForDevice:device value:value]; + [controller showOutputForDevice:device value:value]; } } @@ -107,21 +107,21 @@ static int findAvailableIndex(NSArray *list, NJDevice *dev) { } } -- (void)addJoystickForDevice:(IOHIDDeviceRef)device { +- (void)addDeviceForDevice:(IOHIDDeviceRef)device { IOHIDDeviceRegisterInputValueCallback(device, input_callback, (__bridge void*)self); NJDevice *dev = [[NJDevice alloc] initWithDevice:device]; - dev.index = findAvailableIndex(_joysticks, dev); - [_joysticks addObject:dev]; + 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 addJoystickForDevice:device]; + [controller addDeviceForDevice:device]; } -- (NJDevice *)findJoystickByRef:(IOHIDDeviceRef)device { - for (NJDevice *dev in _joysticks) +- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device { + for (NJDevice *dev in _devices) if (dev.device == device) return dev; return nil; @@ -129,14 +129,14 @@ static void add_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDevi static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { NJInputController *controller = (__bridge NJInputController *)ctx; - [controller removeJoystickForDevice:device]; + [controller removeDeviceForDevice:device]; } -- (void)removeJoystickForDevice:(IOHIDDeviceRef)device { - NJDevice *match = [self findJoystickByRef:device]; +- (void)removeDeviceForDevice:(IOHIDDeviceRef)device { + NJDevice *match = [self findDeviceByRef:device]; IOHIDDeviceRegisterInputValueCallback(device, NULL, NULL); if (match) { - [_joysticks removeObject:match]; + [_devices removeObject:match]; [outlineView reloadData]; } @@ -144,15 +144,15 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD - (void)updateContinuousInputs:(NSTimer *)timer { self.mouseLoc = [NSEvent mouseLocation]; - for (Target *target in [runningTargets copy]) { - if (![target update:self]) { - [runningTargets removeObject:target]; + for (NJOutput *output in [runningOutputs copy]) { + if (![output update:self]) { + [runningOutputs removeObject:output]; } } - if (!runningTargets.count) { + if (!runningOutputs.count) { [continuousTimer invalidate]; continuousTimer = nil; - NSLog(@"Unscheduled continuous target timer."); + NSLog(@"Unscheduled continuous output timer."); } } @@ -196,7 +196,7 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id )item { - return item ? item.children.count : _joysticks.count; + return item ? item.children.count : _devices.count; } - (BOOL)outlineView:(NSOutlineView *)outlineView @@ -207,7 +207,7 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id )item { - return item ? item.children[index] : _joysticks[index]; + return item ? item.children[index] : _devices[index]; } - (id)outlineView:(NSOutlineView *)outlineView @@ -218,7 +218,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn - (void)outlineViewSelectionDidChange:(NSNotification *)notification { - [targetController loadCurrent]; + [outputController loadCurrent]; } - (void)setTranslatingEvents:(BOOL)translatingEvents { diff --git a/NJMapping.h b/NJMapping.h index a4068ff..f997fa8 100644 --- a/NJMapping.h +++ b/NJMapping.h @@ -6,7 +6,7 @@ // Copyright 2009 University of Otago. All rights reserved. // -@class Target; +@class NJOutput; @class NJInput; @interface NJMapping : NSObject @@ -15,8 +15,8 @@ @property (nonatomic, readonly) NSMutableDictionary *entries; - (id)initWithName:(NSString *)name; -- (Target *)objectForKeyedSubscript:(NJInput *)input; -- (void)setObject:(Target *)target forKeyedSubscript:(NJInput *)input; +- (NJOutput *)objectForKeyedSubscript:(NJInput *)input; +- (void)setObject:(NJOutput *)output forKeyedSubscript:(NJInput *)input; - (NSDictionary *)serialize; @end diff --git a/NJMapping.m b/NJMapping.m index a5f810c..4e7c4b2 100644 --- a/NJMapping.m +++ b/NJMapping.m @@ -19,14 +19,14 @@ return self; } -- (Target *)objectForKeyedSubscript:(NJInput *)input { +- (NJOutput *)objectForKeyedSubscript:(NJInput *)input { return input ? _entries[input.uid] : nil; } -- (void)setObject:(Target *)target forKeyedSubscript:(NJInput *)input { +- (void)setObject:(NJOutput *)output forKeyedSubscript:(NJInput *)input { if (input) { - if (target) - _entries[input.uid] = target; + if (output) + _entries[input.uid] = output; else [_entries removeObjectForKey:input.uid]; } diff --git a/NJMappingsController.h b/NJMappingsController.h index cda477f..d793714 100644 --- a/NJMappingsController.h +++ b/NJMappingsController.h @@ -7,14 +7,14 @@ // @class NJMapping; -@class TargetController; +@class NJOutputController; @interface NJMappingsController : NSObject { IBOutlet NSButton *removeButton; IBOutlet NSTableView *tableView; - IBOutlet TargetController *targetController; + IBOutlet NJOutputController *outputController; } @property (nonatomic, readonly) NJMapping *currentMapping; diff --git a/NJMappingsController.m b/NJMappingsController.m index e5b2b7d..e01cb91 100644 --- a/NJMappingsController.m +++ b/NJMappingsController.m @@ -10,8 +10,8 @@ #import "ApplicationController.h" #import "NJMapping.h" #import "NJMappingsController.h" -#import "Target.h" -#import "TargetController.h" +#import "NJOutput.h" +#import "NJOutputController.h" #import "NJEvents.h" @implementation NJMappingsController { @@ -53,7 +53,7 @@ manualMapping = mapping; _currentMapping = mapping; [removeButton setEnabled:_mappings[0] != mapping]; - [targetController loadCurrent]; + [outputController loadCurrent]; [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged object:_currentMapping]; [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[_mappings indexOfObject:mapping]] byExtendingSelection:NO]; @@ -124,7 +124,7 @@ NSArray *storedMappings = envelope[@"mappings"]; NSMutableArray* newMappings = [[NSMutableArray alloc] initWithCapacity:storedMappings.count]; - // have to do two passes in case mapping1 refers to mapping2 via a TargetMapping + // have to do two passes in case mapping1 refers to mapping2 via a NJOutputMapping for (NSDictionary *storedMapping in storedMappings) { NJMapping *mapping = [[NJMapping alloc] initWithName:storedMapping[@"name"]]; [newMappings addObject:mapping]; @@ -134,10 +134,10 @@ NSDictionary *entries = storedMappings[i][@"entries"]; NJMapping *mapping = newMappings[i]; for (id key in entries) { - Target *target = [Target targetDeserialize:entries[key] - withMappings:newMappings]; - if (target) - mapping.entries[key] = target; + NJOutput *output = [NJOutput outputDeserialize:entries[key] + withMappings:newMappings]; + if (output) + mapping.entries[key] = output; } } @@ -174,10 +174,10 @@ for (id key in entries) { NSDictionary *value = entries[key]; if ([key isKindOfClass:NSString.class]) { - Target *target = [Target targetDeserialize:value - withMappings:_mappings]; - if (target) - mapping.entries[key] = target; + NJOutput *output = [NJOutput outputDeserialize:value + withMappings:_mappings]; + if (output) + mapping.entries[key] = output; } } return mapping; @@ -236,7 +236,7 @@ [self save]; [(ApplicationController *)NSApplication.sharedApplication.delegate mappingsChanged]; [self activateMapping:mapping]; - [targetController loadCurrent]; + [outputController loadCurrent]; if (conflict && !mergeInto) { [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_mappings.count - 1] byExtendingSelection:NO]; diff --git a/NJOutput.h b/NJOutput.h new file mode 100644 index 0000000..2bfc167 --- /dev/null +++ b/NJOutput.h @@ -0,0 +1,26 @@ +// +// NJOutput.h +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +@class NJInputController; + +@interface NJOutput : NSObject + +@property (nonatomic, assign) float magnitude; +@property (nonatomic, assign) BOOL running; +@property (nonatomic, readonly) BOOL isContinuous; + +- (void)trigger; +- (void)untrigger; +- (BOOL)update:(NJInputController *)jc; + +- (NSDictionary *)serialize; ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings; ++ (NSString *)serializationCode; + +@end diff --git a/NJOutput.m b/NJOutput.m new file mode 100644 index 0000000..dd751e1 --- /dev/null +++ b/NJOutput.m @@ -0,0 +1,89 @@ +// +// NJOutput.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#import "NJOutput.h" + +#import "NJOutputKeyPress.h" +#import "NJOutputMapping.h" +#import "NJOutputMouseMove.h" +#import "NJOutputMouseButton.h" +#import "NJOutputMouseScroll.h" +#import "NJOutputSwitchMouseMode.h" + +@implementation NJOutput { + BOOL running; +} + ++ (NSString *)serializationCode { + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (NSDictionary *)serialize { + [self doesNotRecognizeSelector:_cmd]; + return nil; +} + +- (BOOL)isEqual:(id)object { + return [object isKindOfClass:NJOutput.class] + && [[self serialize] isEqual:[object serialize]]; +} + +- (NSUInteger)hash { + return [[self serialize] hash]; +} + ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + // Don't crash loading old/bad mappings (but don't load them either). + if (![serialization isKindOfClass:NSDictionary.class]) + return nil; + NSString *type = serialization[@"type"]; + for (Class cls in @[NJOutputKeyPress.class, + NJOutputMapping.class, + NJOutputMouseMove.class, + NJOutputMouseButton.class, + NJOutputMouseScroll.class, + NJOutputSwitchMouseMode.class + ]) { + if ([type isEqualToString:cls.serializationCode]) + return [cls outputDeserialize:serialization withMappings:mappings]; + } + + return nil; +} + +- (void)trigger { +} + +- (void)untrigger { +} + +- (BOOL)update:(NJInputController *)jc { + return NO; +} + +- (BOOL)isContinuous { + return NO; +} + +- (BOOL)running { + return running; +} + +- (void)setRunning:(BOOL)newRunning { + if (running != newRunning) { + running = newRunning; + if (running) + [self trigger]; + else + [self untrigger]; + } +} + + +@end diff --git a/NJOutputController.h b/NJOutputController.h new file mode 100644 index 0000000..bf590a6 --- /dev/null +++ b/NJOutputController.h @@ -0,0 +1,38 @@ +// +// NJOutputController.h +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import "NJKeyInputField.h" + +@class NJMappingsController; +@class NJInputController; +@class NJOutput; +@class NJOutputMouseMove; + +@interface NJOutputController : NSObject { + IBOutlet NJKeyInputField *keyInput; + IBOutlet NSMatrix *radioButtons; + IBOutlet NSSegmentedControl *mouseDirSelect; + IBOutlet NSSegmentedControl *mouseBtnSelect; + IBOutlet NSSegmentedControl *scrollDirSelect; + IBOutlet NSTextField *title; + IBOutlet NSPopUpButton *mappingPopup; + IBOutlet NJMappingsController *mappingsController; + IBOutlet NJInputController *inputController; +} + +@property (assign) BOOL enabled; + +- (void)loadCurrent; +- (void)refreshMappings; +- (IBAction)radioChanged:(id)sender; +- (IBAction)mdirChanged:(id)sender; +- (IBAction)mbtnChanged:(id)sender; +- (IBAction)sdirChanged:(id)sender; +- (void)focusKey; + +@end diff --git a/NJOutputController.m b/NJOutputController.m new file mode 100644 index 0000000..f05c615 --- /dev/null +++ b/NJOutputController.m @@ -0,0 +1,235 @@ +// +// NJOutputController.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#import "NJOutputController.h" + +#import "NJMappingsController.h" +#import "NJMapping.h" +#import "NJInput.h" +#import "NJInputController.h" +#import "NJKeyInputField.h" +#import "NJOutputMapping.h" +#import "NJOutputController.h" +#import "NJOutputKeyPress.h" +#import "NJOutputMouseButton.h" +#import "NJOutputMouseMove.h" +#import "NJOutputMouseScroll.h" +#import "NJOutputSwitchMouseMode.h" + +@implementation NJOutputController + +- (void)cleanUpInterface { + NSInteger row = radioButtons.selectedRow; + + if (row != 1) { + keyInput.keyCode = -1; + [keyInput resignIfFirstResponder]; + } + + if (row != 2) { + [mappingPopup selectItemAtIndex:-1]; + [mappingPopup resignIfFirstResponder]; + } else if (!mappingPopup.selectedItem) + [mappingPopup selectItemAtIndex:0]; + + if (row != 3) { + mouseDirSelect.selectedSegment = -1; + [mouseDirSelect resignIfFirstResponder]; + } else if (mouseDirSelect.selectedSegment == -1) + mouseDirSelect.selectedSegment = 0; + + if (row != 4) { + mouseBtnSelect.selectedSegment = -1; + [mouseBtnSelect resignIfFirstResponder]; + } else if (mouseBtnSelect.selectedSegment == -1) + mouseBtnSelect.selectedSegment = 0; + + if (row != 5) { + scrollDirSelect.selectedSegment = -1; + [scrollDirSelect resignIfFirstResponder]; + } else if (scrollDirSelect.selectedSegment == -1) + scrollDirSelect.selectedSegment = 0; +} + +- (IBAction)radioChanged:(NSView *)sender { + [sender.window makeFirstResponder:sender]; + if (radioButtons.selectedRow == 1) + [keyInput.window makeFirstResponder:keyInput]; + [self commit]; +} + +- (void)keyInputField:(NJKeyInputField *)keyInput didChangeKey:(CGKeyCode)keyCode { + [radioButtons selectCellAtRow:1 column:0]; + [radioButtons.window makeFirstResponder:radioButtons]; + [self commit]; +} + +- (void)keyInputFieldDidClear:(NJKeyInputField *)keyInput { + [radioButtons selectCellAtRow:0 column:0]; + [self commit]; +} + +- (void)mappingChosen:(id)sender { + [radioButtons selectCellAtRow:2 column:0]; + [mappingPopup.window makeFirstResponder:mappingPopup]; + [self commit]; +} + +- (void)mdirChanged:(NSView *)sender { + [radioButtons selectCellAtRow:3 column:0]; + [sender.window makeFirstResponder:sender]; + [self commit]; +} + +- (void)mbtnChanged:(NSView *)sender { + [radioButtons selectCellAtRow:4 column:0]; + [sender.window makeFirstResponder:sender]; + [self commit]; +} + +- (void)sdirChanged:(NSView *)sender { + [radioButtons selectCellAtRow:5 column:0]; + [sender.window makeFirstResponder:sender]; + [self commit]; +} + +- (NJOutput *)currentOutput { + return mappingsController.currentMapping[inputController.selectedInput]; +} + +- (NJOutput *)makeOutput { + switch (radioButtons.selectedRow) { + case 0: + return nil; + case 1: + if (keyInput.hasKeyCode) { + NJOutputKeyPress *k = [[NJOutputKeyPress alloc] init]; + k.vk = keyInput.keyCode; + return k; + } else { + return nil; + } + break; + case 2: { + NJOutputMapping *c = [[NJOutputMapping alloc] init]; + c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem]; + return c; + } + case 3: { + NJOutputMouseMove *mm = [[NJOutputMouseMove alloc] init]; + mm.axis = mouseDirSelect.selectedSegment; + return mm; + } + case 4: { + NJOutputMouseButton *mb = [[NJOutputMouseButton alloc] init]; + mb.button = mouseBtnSelect.selectedSegment == 0 ? kCGMouseButtonLeft : kCGMouseButtonRight; + return mb; + } + case 5: { + NJOutputMouseScroll *ms = [[NJOutputMouseScroll alloc] init]; + ms.amount = scrollDirSelect.selectedSegment ? 1 : -1; + return ms; + } + case 6: { + NJOutputSwitchMouseMode *tms = [[NJOutputSwitchMouseMode alloc] init]; + return tms; + } + default: + return nil; + } +} + +- (void)commit { + [self cleanUpInterface]; + mappingsController.currentMapping[inputController.selectedInput] = [self makeOutput]; + [mappingsController save]; +} + +- (BOOL)enabled { + return [radioButtons isEnabled]; +} + +- (void)setEnabled:(BOOL)enabled { + [radioButtons setEnabled:enabled]; + [keyInput setEnabled:enabled]; + [mappingPopup setEnabled:enabled]; + [mouseDirSelect setEnabled:enabled]; + [mouseBtnSelect setEnabled:enabled]; + [scrollDirSelect setEnabled:enabled]; +} + +- (void)loadOutput:(NJOutput *)output forInput:(NJInput *)input { + if (!input) { + self.enabled = NO; + title.stringValue = @""; + } else { + self.enabled = YES; + NSString *inpFullName = input.name; + for (id cur = input.base; cur; cur = cur.base) { + inpFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, inpFullName]; + } + title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", mappingsController.currentMapping.name, inpFullName]; + } + + if ([output isKindOfClass:NJOutputKeyPress.class]) { + [radioButtons selectCellAtRow:1 column:0]; + keyInput.keyCode = [(NJOutputKeyPress*)output vk]; + } else if ([output isKindOfClass:NJOutputMapping.class]) { + [radioButtons selectCellAtRow:2 column:0]; + NSUInteger idx = [mappingsController.mappings + indexOfObject:[(NJOutputMapping *)output mapping]]; + if (idx == NSNotFound) { + [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; + [mappingPopup selectItemAtIndex:-1]; + } else + [mappingPopup selectItemAtIndex:idx]; + } + else if ([output isKindOfClass:NJOutputMouseMove.class]) { + [radioButtons selectCellAtRow:3 column:0]; + [mouseDirSelect setSelectedSegment:[(NJOutputMouseMove *)output axis]]; + } + else if ([output isKindOfClass:NJOutputMouseButton.class]) { + [radioButtons selectCellAtRow:4 column:0]; + mouseBtnSelect.selectedSegment = [(NJOutputMouseButton *)output button] == kCGMouseButtonLeft ? 0 : 1; + } + else if ([output isKindOfClass:NJOutputMouseScroll.class]) { + [radioButtons selectCellAtRow:5 column:0]; + scrollDirSelect.selectedSegment = [(NJOutputMouseScroll *)output amount] > 0; + } + else if ([output isKindOfClass:NJOutputSwitchMouseMode.class]) { + [radioButtons selectCellAtRow:6 column:0]; + } else { + [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; + } + [self cleanUpInterface]; +} + +- (void)loadCurrent { + [self loadOutput:self.currentOutput forInput:inputController.selectedInput]; +} + +- (void)focusKey { + if (radioButtons.selectedRow <= 1) + [keyInput.window makeFirstResponder:keyInput]; + else + [keyInput resignIfFirstResponder]; +} + +- (void)refreshMappings { + NSInteger initialIndex = mappingPopup.indexOfSelectedItem; + [mappingPopup.menu removeAllItems]; + for (NJMapping *mapping in mappingsController.mappings) { + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name + action:@selector(mappingChosen:) + keyEquivalent:@""]; + item.target = self; + [mappingPopup.menu addItem:item]; + } + [mappingPopup selectItemAtIndex:initialIndex]; +} + +@end diff --git a/NJOutputKeyPress.h b/NJOutputKeyPress.h new file mode 100644 index 0000000..052b010 --- /dev/null +++ b/NJOutputKeyPress.h @@ -0,0 +1,15 @@ +// +// NJOutputKeyPress.h +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import "NJOutput.h" + +@interface NJOutputKeyPress : NJOutput + +@property (nonatomic, assign) CGKeyCode vk; + +@end diff --git a/NJOutputKeyPress.m b/NJOutputKeyPress.m new file mode 100644 index 0000000..c2000d8 --- /dev/null +++ b/NJOutputKeyPress.m @@ -0,0 +1,41 @@ +// +// NJOutputKeyPress.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#import "NJOutputKeyPress.h" + +#import "NJKeyInputField.h" + +@implementation NJOutputKeyPress + ++ (NSString *)serializationCode { + return @"key"; +} + +- (NSDictionary *)serialize { + return @{ @"type": @"key press", @"key": @(_vk) }; +} + ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + NJOutputKeyPress *output = [[NJOutputKeyPress alloc] init]; + output.vk = [serialization[@"key"] intValue]; + return output; +} + +- (void)trigger { + CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, _vk, YES); + CGEventPost(kCGHIDEventTap, keyDown); + CFRelease(keyDown); +} + +- (void)untrigger { + CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, _vk, NO); + CGEventPost(kCGHIDEventTap, keyUp); + CFRelease(keyUp); +} + +@end diff --git a/NJOutputMapping.h b/NJOutputMapping.h new file mode 100644 index 0000000..e8c3029 --- /dev/null +++ b/NJOutputMapping.h @@ -0,0 +1,17 @@ +// +// NJOutputMapping.h +// Enjoy +// +// Created by Sam McCall on 6/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import "NJOutput.h" + +@class NJMapping; + +@interface NJOutputMapping : NJOutput + +@property (nonatomic, weak) NJMapping *mapping; + +@end diff --git a/NJOutputMapping.m b/NJOutputMapping.m new file mode 100644 index 0000000..e411172 --- /dev/null +++ b/NJOutputMapping.m @@ -0,0 +1,44 @@ +// +// NJOutputMapping.m +// Enjoy +// +// Created by Sam McCall on 6/05/09. +// + +#import "NJOutputMapping.h" + +#import "ApplicationController.h" +#import "NJMapping.h" +#import "NJMappingsController.h" + +@implementation NJOutputMapping + ++ (NSString *)serializationCode { + return @"mapping"; +} + +- (NSDictionary *)serialize { + return _mapping + ? @{ @"type": @"mapping", @"name": _mapping.name } + : nil; +} + ++ (NJOutputMapping *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + NSString *name = serialization[@"name"]; + NJOutputMapping *output = [[NJOutputMapping alloc] init]; + for (NJMapping *mapping in mappings) { + if ([mapping.name isEqualToString:name]) { + output.mapping = mapping; + return output; + } + } + return nil; +} + +- (void)trigger { + ApplicationController *ctrl = NSApplication.sharedApplication.delegate; + [ctrl.mappingsController activateMapping:_mapping]; +} + +@end diff --git a/NJOutputMouseButton.h b/NJOutputMouseButton.h new file mode 100644 index 0000000..4d790e5 --- /dev/null +++ b/NJOutputMouseButton.h @@ -0,0 +1,14 @@ +// +// NJOutputMouseButton.h +// Enjoy +// +// Created by Yifeng Huang on 7/27/12. +// + +#import "NJOutput.h" + +@interface NJOutputMouseButton : NJOutput + +@property (nonatomic, assign) CGMouseButton button; + +@end diff --git a/NJOutputMouseButton.m b/NJOutputMouseButton.m new file mode 100644 index 0000000..0cc403f --- /dev/null +++ b/NJOutputMouseButton.m @@ -0,0 +1,51 @@ +// +// NJOutputMouseButton.m +// Enjoy +// +// Created by Yifeng Huang on 7/27/12. +// + +#import "NJOutputMouseButton.h" + +@implementation NJOutputMouseButton + ++ (NSString *)serializationCode { + return @"mouse button"; +} + +- (NSDictionary *)serialize { + return @{ @"type": @"mouse button", @"button": @(_button) }; +} + ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + NJOutputMouseButton *output = [[NJOutputMouseButton alloc] init]; + output.button = [serialization[@"button"] intValue]; + return output; +} + +-(void) trigger { + CGFloat height = NSScreen.mainScreen.frame.size.height; + NSPoint mouseLoc = NSEvent.mouseLocation; + CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; + CGEventRef click = CGEventCreateMouseEvent(NULL, + eventType, + CGPointMake(mouseLoc.x, height - mouseLoc.y), + _button); + CGEventPost(kCGHIDEventTap, click); + CFRelease(click); +} + +-(void) untrigger { + CGFloat height = NSScreen.mainScreen.frame.size.height; + NSPoint mouseLoc = NSEvent.mouseLocation; + CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; + CGEventRef click = CGEventCreateMouseEvent(NULL, + eventType, + CGPointMake(mouseLoc.x, height - mouseLoc.y), + _button); + CGEventPost(kCGHIDEventTap, click); + CFRelease(click); +} + +@end diff --git a/NJOutputMouseMove.h b/NJOutputMouseMove.h new file mode 100644 index 0000000..21db416 --- /dev/null +++ b/NJOutputMouseMove.h @@ -0,0 +1,14 @@ +// +// NJOutputMouseMove.h +// Enjoy +// +// Created by Yifeng Huang on 7/26/12. +// + +#import "NJOutput.h" + +@interface NJOutputMouseMove : NJOutput + +@property (nonatomic, assign) int axis; + +@end diff --git a/NJOutputMouseMove.m b/NJOutputMouseMove.m new file mode 100644 index 0000000..5e59d4e --- /dev/null +++ b/NJOutputMouseMove.m @@ -0,0 +1,85 @@ +// +// NJOutputMouseMove.m +// Enjoy +// +// Created by Yifeng Huang on 7/26/12. +// + +#import "NJOutputMouseMove.h" + +#import "NJInputController.h" + +@implementation NJOutputMouseMove { + int sign; +} + +-(BOOL) isContinuous { + return YES; +} + ++ (NSString *)serializationCode { + return @"mouse move"; +} + +- (NSDictionary *)serialize { + return @{ @"type": @"mouse move", @"axis": @(_axis) }; +} + ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init]; + output.axis = [serialization[@"axis"] intValue]; + return output; +} + +- (BOOL)update:(NJInputController *)jc { + if (fabsf(self.magnitude) < 0.01) { + sign = 0; + return NO; // dead zone + } + + // If the input crossed over High/Low, this output is done. + if (!sign) + sign = self.magnitude < 0 ? -1 : 1; + else if (sign / self.magnitude < 0) { + sign = 0; + return NO; + } + + CGFloat height = NSScreen.mainScreen.frame.size.height; + + // TODO + float speed = 4.f; + if (jc.frontWindowOnly) + speed = 12.f; + float dx = 0.f, dy = 0.f; + if (_axis == 0) + dx = self.magnitude * speed; + else + dy = self.magnitude * speed; + NSPoint mouseLoc = jc.mouseLoc; + mouseLoc.x += dx; + mouseLoc.y -= dy; + jc.mouseLoc = mouseLoc; + + CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, + CGPointMake(mouseLoc.x, height - mouseLoc.y), + 0); + CGEventSetType(move, kCGEventMouseMoved); + CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx); + CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy); + + if (jc.frontWindowOnly) { + ProcessSerialNumber psn; + GetFrontProcess(&psn); + CGEventPostToPSN(&psn, move); + } + else { + CGEventPost(kCGHIDEventTap, move); + } + + CFRelease(move); + return YES; +} + +@end diff --git a/NJOutputMouseScroll.h b/NJOutputMouseScroll.h new file mode 100644 index 0000000..6ef2cdc --- /dev/null +++ b/NJOutputMouseScroll.h @@ -0,0 +1,14 @@ +// +// NJOutputMouseScroll.h +// Enjoy +// +// Created by Yifeng Huang on 7/28/12. +// + +#import "NJOutput.h" + +@interface NJOutputMouseScroll : NJOutput + +@property (nonatomic, assign) int amount; + +@end diff --git a/NJOutputMouseScroll.m b/NJOutputMouseScroll.m new file mode 100644 index 0000000..9057125 --- /dev/null +++ b/NJOutputMouseScroll.m @@ -0,0 +1,69 @@ +// +// NJOutputMouseScroll.m +// Enjoy +// +// Created by Yifeng Huang on 7/28/12. +// + +#import "NJOutputMouseScroll.h" + +@implementation NJOutputMouseScroll { + int sign; +} + ++ (NSString *)serializationCode { + return @"mouse scroll"; +} + +- (NSDictionary *)serialize { + return @{ @"type": @"mouse scroll", @"amount": @(_amount) }; +} + ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init]; + output.amount = [serialization[@"amount"] intValue]; + return output; +} + +- (void)trigger { + if (!self.magnitude) { + CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, + kCGScrollEventUnitLine, + 1, + _amount); + CGEventPost(kCGHIDEventTap, scroll); + CFRelease(scroll); + } +} + +- (BOOL)update:(NJInputController *)jc { + if (fabsf(self.magnitude) < 0.01f) { + sign = 0; + return NO; // dead zone + } + + // If the input crossed over High/Low, this output is done. + if (!sign) + sign = self.magnitude < 0 ? -1 : 1; + else if (sign / self.magnitude < 0) { + sign = 0; + return NO; + } + + int amount = (int)(16.f * fabsf(self.magnitude) * _amount); + CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, + kCGScrollEventUnitPixel, + 1, + amount); + CGEventPost(kCGHIDEventTap, scroll); + CFRelease(scroll); + + return YES; +} + +- (BOOL)isContinuous { + return YES; +} + +@end diff --git a/NJOutputSwitchMouseMode.h b/NJOutputSwitchMouseMode.h new file mode 100644 index 0000000..790f84b --- /dev/null +++ b/NJOutputSwitchMouseMode.h @@ -0,0 +1,12 @@ +// +// NJOutputSwitchMouseMode.h +// Enjoy +// +// Created by Yifeng Huang on 7/28/12. +// + +#import "NJOutput.h" + +@interface NJOutputSwitchMouseMode : NJOutput + +@end diff --git a/NJOutputSwitchMouseMode.m b/NJOutputSwitchMouseMode.m new file mode 100644 index 0000000..3332a91 --- /dev/null +++ b/NJOutputSwitchMouseMode.m @@ -0,0 +1,35 @@ +// +// NJOutputSwitchMouseMode.m +// Enjoy +// +// Created by Yifeng Huang on 7/28/12. +// + +#import "NJOutputSwitchMouseMode.h" + +#import "ApplicationController.h" +#import "NJInputController.h" + +@implementation NJOutputSwitchMouseMode + ++ (NSString *)serializationCode { + return @"switch mouse mode"; +} + +- (NSDictionary *)serialize { + return @{ @"type": @"switch mouse mode" }; +} + ++ (NJOutput *)outputDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + return [[NJOutputSwitchMouseMode alloc] init]; +} +- (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; + jc.frontWindowOnly = !jc.frontWindowOnly; +} + +@end diff --git a/Target.h b/Target.h deleted file mode 100644 index 1a37f01..0000000 --- a/Target.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Target.h -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -@class NJInputController; - -@interface Target : NSObject - -@property (nonatomic, assign) float magnitude; -@property (nonatomic, assign) BOOL running; -@property (nonatomic, readonly) BOOL isContinuous; - -- (void)trigger; -- (void)untrigger; -- (BOOL)update:(NJInputController *)jc; - -- (NSDictionary *)serialize; -+ (Target *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings; -+ (NSString *)serializationCode; - -@end diff --git a/Target.m b/Target.m deleted file mode 100644 index 097562e..0000000 --- a/Target.m +++ /dev/null @@ -1,89 +0,0 @@ -// -// Target.m -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// - -#import "Target.h" - -#import "TargetKeyboard.h" -#import "TargetConfig.h" -#import "TargetMouseMove.h" -#import "TargetMouseBtn.h" -#import "TargetMouseScroll.h" -#import "TargetToggleMouseScope.h" - -@implementation Target { - BOOL running; -} - -+ (NSString *)serializationCode { - [self doesNotRecognizeSelector:_cmd]; - return nil; -} - -- (NSDictionary *)serialize { - [self doesNotRecognizeSelector:_cmd]; - return nil; -} - -- (BOOL)isEqual:(id)object { - return [object isKindOfClass:Target.class] - && [[self serialize] isEqual:[object serialize]]; -} - -- (NSUInteger)hash { - return [[self serialize] hash]; -} - -+ (Target *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { - // Don't crash loading old/bad mappings (but don't load them either). - if (![serialization isKindOfClass:NSDictionary.class]) - return nil; - NSString *type = serialization[@"type"]; - for (Class cls in @[TargetKeyboard.class, - TargetConfig.class, - TargetMouseMove.class, - TargetMouseBtn.class, - TargetMouseScroll.class, - TargetToggleMouseScope.class - ]) { - if ([type isEqualToString:cls.serializationCode]) - return [cls targetDeserialize:serialization withMappings:mappings]; - } - - return nil; -} - -- (void)trigger { -} - -- (void)untrigger { -} - -- (BOOL)update:(NJInputController *)jc { - return NO; -} - -- (BOOL)isContinuous { - return NO; -} - -- (BOOL)running { - return running; -} - -- (void)setRunning:(BOOL)newRunning { - if (running != newRunning) { - running = newRunning; - if (running) - [self trigger]; - else - [self untrigger]; - } -} - - -@end diff --git a/TargetConfig.h b/TargetConfig.h deleted file mode 100644 index 1018e5d..0000000 --- a/TargetConfig.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// TargetConfig.h -// Enjoy -// -// Created by Sam McCall on 6/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import "Target.h" - -@class NJMapping; - -@interface TargetConfig : Target - -@property (nonatomic, weak) NJMapping *mapping; - -@end diff --git a/TargetConfig.m b/TargetConfig.m deleted file mode 100644 index 0f892c6..0000000 --- a/TargetConfig.m +++ /dev/null @@ -1,44 +0,0 @@ -// -// TargetConfig.m -// Enjoy -// -// Created by Sam McCall on 6/05/09. -// - -#import "TargetConfig.h" - -#import "ApplicationController.h" -#import "NJMapping.h" -#import "NJMappingsController.h" - -@implementation TargetConfig - -+ (NSString *)serializationCode { - return @"mapping"; -} - -- (NSDictionary *)serialize { - return _mapping - ? @{ @"type": @"mapping", @"name": _mapping.name } - : nil; -} - -+ (TargetConfig *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { - NSString *name = serialization[@"name"]; - TargetConfig *target = [[TargetConfig alloc] init]; - for (NJMapping *mapping in mappings) { - if ([mapping.name isEqualToString:name]) { - target.mapping = mapping; - return target; - } - } - return nil; -} - -- (void)trigger { - ApplicationController *ctrl = NSApplication.sharedApplication.delegate; - [ctrl.mappingsController activateMapping:_mapping]; -} - -@end diff --git a/TargetController.h b/TargetController.h deleted file mode 100644 index da7974c..0000000 --- a/TargetController.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// TargetController.h -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import "NJKeyInputField.h" - -@class NJMappingsController; -@class NJInputController; -@class Target; -@class TargetMouseMove; - -@interface TargetController : NSObject { - IBOutlet NJKeyInputField *keyInput; - IBOutlet NSMatrix *radioButtons; - IBOutlet NSSegmentedControl *mouseDirSelect; - IBOutlet NSSegmentedControl *mouseBtnSelect; - IBOutlet NSSegmentedControl *scrollDirSelect; - IBOutlet NSTextField *title; - IBOutlet NSPopUpButton *mappingPopup; - IBOutlet NJMappingsController *mappingsController; - IBOutlet NJInputController *joystickController; -} - -@property (assign) BOOL enabled; - -- (void)loadCurrent; -- (void)refreshMappings; -- (IBAction)radioChanged:(id)sender; -- (IBAction)mdirChanged:(id)sender; -- (IBAction)mbtnChanged:(id)sender; -- (IBAction)sdirChanged:(id)sender; -- (void)focusKey; - -@end diff --git a/TargetController.m b/TargetController.m deleted file mode 100644 index 1da2c99..0000000 --- a/TargetController.m +++ /dev/null @@ -1,235 +0,0 @@ -// -// TargetController.m -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// - -#import "TargetController.h" - -#import "NJMappingsController.h" -#import "NJMapping.h" -#import "NJInput.h" -#import "NJInputController.h" -#import "NJKeyInputField.h" -#import "TargetConfig.h" -#import "TargetController.h" -#import "TargetKeyboard.h" -#import "TargetMouseBtn.h" -#import "TargetMouseMove.h" -#import "TargetMouseScroll.h" -#import "TargetToggleMouseScope.h" - -@implementation TargetController - -- (void)cleanUpInterface { - NSInteger row = radioButtons.selectedRow; - - if (row != 1) { - keyInput.keyCode = -1; - [keyInput resignIfFirstResponder]; - } - - if (row != 2) { - [mappingPopup selectItemAtIndex:-1]; - [mappingPopup resignIfFirstResponder]; - } else if (!mappingPopup.selectedItem) - [mappingPopup selectItemAtIndex:0]; - - if (row != 3) { - mouseDirSelect.selectedSegment = -1; - [mouseDirSelect resignIfFirstResponder]; - } else if (mouseDirSelect.selectedSegment == -1) - mouseDirSelect.selectedSegment = 0; - - if (row != 4) { - mouseBtnSelect.selectedSegment = -1; - [mouseBtnSelect resignIfFirstResponder]; - } else if (mouseBtnSelect.selectedSegment == -1) - mouseBtnSelect.selectedSegment = 0; - - if (row != 5) { - scrollDirSelect.selectedSegment = -1; - [scrollDirSelect resignIfFirstResponder]; - } else if (scrollDirSelect.selectedSegment == -1) - scrollDirSelect.selectedSegment = 0; -} - -- (IBAction)radioChanged:(NSView *)sender { - [sender.window makeFirstResponder:sender]; - if (radioButtons.selectedRow == 1) - [keyInput.window makeFirstResponder:keyInput]; - [self commit]; -} - -- (void)keyInputField:(NJKeyInputField *)keyInput didChangeKey:(CGKeyCode)keyCode { - [radioButtons selectCellAtRow:1 column:0]; - [radioButtons.window makeFirstResponder:radioButtons]; - [self commit]; -} - -- (void)keyInputFieldDidClear:(NJKeyInputField *)keyInput { - [radioButtons selectCellAtRow:0 column:0]; - [self commit]; -} - -- (void)mappingChosen:(id)sender { - [radioButtons selectCellAtRow:2 column:0]; - [mappingPopup.window makeFirstResponder:mappingPopup]; - [self commit]; -} - -- (void)mdirChanged:(NSView *)sender { - [radioButtons selectCellAtRow:3 column:0]; - [sender.window makeFirstResponder:sender]; - [self commit]; -} - -- (void)mbtnChanged:(NSView *)sender { - [radioButtons selectCellAtRow:4 column:0]; - [sender.window makeFirstResponder:sender]; - [self commit]; -} - -- (void)sdirChanged:(NSView *)sender { - [radioButtons selectCellAtRow:5 column:0]; - [sender.window makeFirstResponder:sender]; - [self commit]; -} - -- (Target *)currentTarget { - return mappingsController.currentMapping[joystickController.selectedInput]; -} - -- (Target *)makeTarget { - switch (radioButtons.selectedRow) { - case 0: - return nil; - case 1: - if (keyInput.hasKeyCode) { - TargetKeyboard *k = [[TargetKeyboard alloc] init]; - k.vk = keyInput.keyCode; - return k; - } else { - return nil; - } - break; - case 2: { - TargetConfig *c = [[TargetConfig alloc] init]; - c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem]; - return c; - } - case 3: { - TargetMouseMove *mm = [[TargetMouseMove alloc] init]; - mm.axis = mouseDirSelect.selectedSegment; - return mm; - } - case 4: { - TargetMouseBtn *mb = [[TargetMouseBtn alloc] init]; - mb.button = mouseBtnSelect.selectedSegment == 0 ? kCGMouseButtonLeft : kCGMouseButtonRight; - return mb; - } - case 5: { - TargetMouseScroll *ms = [[TargetMouseScroll alloc] init]; - ms.amount = scrollDirSelect.selectedSegment ? 1 : -1; - return ms; - } - case 6: { - TargetToggleMouseScope *tms = [[TargetToggleMouseScope alloc] init]; - return tms; - } - default: - return nil; - } -} - -- (void)commit { - [self cleanUpInterface]; - mappingsController.currentMapping[joystickController.selectedInput] = [self makeTarget]; - [mappingsController save]; -} - -- (BOOL)enabled { - return [radioButtons isEnabled]; -} - -- (void)setEnabled:(BOOL)enabled { - [radioButtons setEnabled:enabled]; - [keyInput setEnabled:enabled]; - [mappingPopup setEnabled:enabled]; - [mouseDirSelect setEnabled:enabled]; - [mouseBtnSelect setEnabled:enabled]; - [scrollDirSelect setEnabled:enabled]; -} - -- (void)loadTarget:(Target *)target forInput:(NJInput *)input { - if (!input) { - self.enabled = NO; - title.stringValue = @""; - } else { - self.enabled = YES; - NSString *inpFullName = input.name; - for (id cur = input.base; cur; cur = cur.base) { - inpFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, inpFullName]; - } - title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", mappingsController.currentMapping.name, inpFullName]; - } - - if ([target isKindOfClass:TargetKeyboard.class]) { - [radioButtons selectCellAtRow:1 column:0]; - keyInput.keyCode = [(TargetKeyboard*)target vk]; - } else if ([target isKindOfClass:TargetConfig.class]) { - [radioButtons selectCellAtRow:2 column:0]; - NSUInteger idx = [mappingsController.mappings - indexOfObject:[(TargetConfig *)target mapping]]; - if (idx == NSNotFound) { - [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; - [mappingPopup selectItemAtIndex:-1]; - } else - [mappingPopup selectItemAtIndex:idx]; - } - else if ([target isKindOfClass:TargetMouseMove.class]) { - [radioButtons selectCellAtRow:3 column:0]; - [mouseDirSelect setSelectedSegment:[(TargetMouseMove *)target axis]]; - } - else if ([target isKindOfClass:TargetMouseBtn.class]) { - [radioButtons selectCellAtRow:4 column:0]; - mouseBtnSelect.selectedSegment = [(TargetMouseBtn *)target button] == kCGMouseButtonLeft ? 0 : 1; - } - else if ([target isKindOfClass:TargetMouseScroll.class]) { - [radioButtons selectCellAtRow:5 column:0]; - scrollDirSelect.selectedSegment = [(TargetMouseScroll *)target amount] > 0; - } - else if ([target isKindOfClass:TargetToggleMouseScope.class]) { - [radioButtons selectCellAtRow:6 column:0]; - } else { - [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; - } - [self cleanUpInterface]; -} - -- (void)loadCurrent { - [self loadTarget:self.currentTarget forInput:joystickController.selectedInput]; -} - -- (void)focusKey { - if (radioButtons.selectedRow <= 1) - [keyInput.window makeFirstResponder:keyInput]; - else - [keyInput resignIfFirstResponder]; -} - -- (void)refreshMappings { - NSInteger initialIndex = mappingPopup.indexOfSelectedItem; - [mappingPopup.menu removeAllItems]; - for (NJMapping *mapping in mappingsController.mappings) { - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name - action:@selector(mappingChosen:) - keyEquivalent:@""]; - item.target = self; - [mappingPopup.menu addItem:item]; - } - [mappingPopup selectItemAtIndex:initialIndex]; -} - -@end diff --git a/TargetKeyboard.h b/TargetKeyboard.h deleted file mode 100644 index 551bb8d..0000000 --- a/TargetKeyboard.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// TargetKeyboard.h -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import "Target.h" - -@interface TargetKeyboard : Target - -@property (nonatomic, assign) CGKeyCode vk; - -@end diff --git a/TargetKeyboard.m b/TargetKeyboard.m deleted file mode 100644 index eaabd07..0000000 --- a/TargetKeyboard.m +++ /dev/null @@ -1,41 +0,0 @@ -// -// TargetKeyboard.m -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// - -#import "TargetKeyboard.h" - -#import "NJKeyInputField.h" - -@implementation TargetKeyboard - -+ (NSString *)serializationCode { - return @"key"; -} - -- (NSDictionary *)serialize { - return @{ @"type": @"key", @"key": @(_vk) }; -} - -+ (Target *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { - TargetKeyboard *target = [[TargetKeyboard alloc] init]; - target.vk = [serialization[@"key"] intValue]; - return target; -} - -- (void)trigger { - CGEventRef keyDown = CGEventCreateKeyboardEvent(NULL, _vk, YES); - CGEventPost(kCGHIDEventTap, keyDown); - CFRelease(keyDown); -} - -- (void)untrigger { - CGEventRef keyUp = CGEventCreateKeyboardEvent(NULL, _vk, NO); - CGEventPost(kCGHIDEventTap, keyUp); - CFRelease(keyUp); -} - -@end diff --git a/TargetMouseBtn.h b/TargetMouseBtn.h deleted file mode 100644 index 2597b2d..0000000 --- a/TargetMouseBtn.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// TargetMouseBtn.h -// Enjoy -// -// Created by Yifeng Huang on 7/27/12. -// - -#import "Target.h" - -@interface TargetMouseBtn : Target - -@property (nonatomic, assign) CGMouseButton button; - -@end diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m deleted file mode 100644 index a19b484..0000000 --- a/TargetMouseBtn.m +++ /dev/null @@ -1,51 +0,0 @@ -// -// TargetMouseBtn.m -// Enjoy -// -// Created by Yifeng Huang on 7/27/12. -// - -#import "TargetMouseBtn.h" - -@implementation TargetMouseBtn - -+ (NSString *)serializationCode { - return @"mbtn"; -} - -- (NSDictionary *)serialize { - return @{ @"type": @"mbtn", @"button": @(_button) }; -} - -+ (Target *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { - TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; - target.button = [serialization[@"button"] intValue]; - return target; -} - --(void) trigger { - CGFloat height = NSScreen.mainScreen.frame.size.height; - NSPoint mouseLoc = NSEvent.mouseLocation; - CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; - CGEventRef click = CGEventCreateMouseEvent(NULL, - eventType, - CGPointMake(mouseLoc.x, height - mouseLoc.y), - _button); - CGEventPost(kCGHIDEventTap, click); - CFRelease(click); -} - --(void) untrigger { - CGFloat height = NSScreen.mainScreen.frame.size.height; - NSPoint mouseLoc = NSEvent.mouseLocation; - CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; - CGEventRef click = CGEventCreateMouseEvent(NULL, - eventType, - CGPointMake(mouseLoc.x, height - mouseLoc.y), - _button); - CGEventPost(kCGHIDEventTap, click); - CFRelease(click); -} - -@end diff --git a/TargetMouseMove.h b/TargetMouseMove.h deleted file mode 100644 index e91b569..0000000 --- a/TargetMouseMove.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// TargetMouseMove.h -// Enjoy -// -// Created by Yifeng Huang on 7/26/12. -// - -#import "Target.h" - -@interface TargetMouseMove : Target - -@property (nonatomic, assign) int axis; - -@end diff --git a/TargetMouseMove.m b/TargetMouseMove.m deleted file mode 100644 index b1d52a0..0000000 --- a/TargetMouseMove.m +++ /dev/null @@ -1,85 +0,0 @@ -// -// TargetMouseMove.m -// Enjoy -// -// Created by Yifeng Huang on 7/26/12. -// - -#import "TargetMouseMove.h" - -#import "NJInputController.h" - -@implementation TargetMouseMove { - int sign; -} - --(BOOL) isContinuous { - return YES; -} - -+ (NSString *)serializationCode { - return @"mmove"; -} - -- (NSDictionary *)serialize { - return @{ @"type": @"mmove", @"axis": @(_axis) }; -} - -+ (Target *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { - TargetMouseMove *target = [[TargetMouseMove alloc] init]; - target.axis = [serialization[@"axis"] intValue]; - return target; -} - -- (BOOL)update:(NJInputController *)jc { - if (fabsf(self.magnitude) < 0.01) { - sign = 0; - return NO; // dead zone - } - - // If the input crossed over High/Low, this target is done. - if (!sign) - sign = self.magnitude < 0 ? -1 : 1; - else if (sign / self.magnitude < 0) { - sign = 0; - return NO; - } - - CGFloat height = NSScreen.mainScreen.frame.size.height; - - // TODO - float speed = 4.f; - if (jc.frontWindowOnly) - speed = 12.f; - float dx = 0.f, dy = 0.f; - if (_axis == 0) - dx = self.magnitude * speed; - else - dy = self.magnitude * speed; - NSPoint mouseLoc = jc.mouseLoc; - mouseLoc.x += dx; - mouseLoc.y -= dy; - jc.mouseLoc = mouseLoc; - - CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, - CGPointMake(mouseLoc.x, height - mouseLoc.y), - 0); - CGEventSetType(move, kCGEventMouseMoved); - CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx); - CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy); - - if (jc.frontWindowOnly) { - ProcessSerialNumber psn; - GetFrontProcess(&psn); - CGEventPostToPSN(&psn, move); - } - else { - CGEventPost(kCGHIDEventTap, move); - } - - CFRelease(move); - return YES; -} - -@end diff --git a/TargetMouseScroll.h b/TargetMouseScroll.h deleted file mode 100644 index d261659..0000000 --- a/TargetMouseScroll.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// TargetMouseScroll.h -// Enjoy -// -// Created by Yifeng Huang on 7/28/12. -// - -#import "Target.h" - -@interface TargetMouseScroll : Target - -@property (nonatomic, assign) int amount; - -@end diff --git a/TargetMouseScroll.m b/TargetMouseScroll.m deleted file mode 100644 index 8f87c02..0000000 --- a/TargetMouseScroll.m +++ /dev/null @@ -1,69 +0,0 @@ -// -// TargetMouseScroll.m -// Enjoy -// -// Created by Yifeng Huang on 7/28/12. -// - -#import "TargetMouseScroll.h" - -@implementation TargetMouseScroll { - int sign; -} - -+ (NSString *)serializationCode { - return @"mscroll"; -} - -- (NSDictionary *)serialize { - return @{ @"type": @"mscroll", @"amount": @(_amount) }; -} - -+ (Target *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { - TargetMouseScroll *target = [[TargetMouseScroll alloc] init]; - target.amount = [serialization[@"amount"] intValue]; - return target; -} - -- (void)trigger { - if (!self.magnitude) { - CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, - kCGScrollEventUnitLine, - 1, - _amount); - CGEventPost(kCGHIDEventTap, scroll); - CFRelease(scroll); - } -} - -- (BOOL)update:(NJInputController *)jc { - if (fabsf(self.magnitude) < 0.01f) { - sign = 0; - return NO; // dead zone - } - - // If the input crossed over High/Low, this target is done. - if (!sign) - sign = self.magnitude < 0 ? -1 : 1; - else if (sign / self.magnitude < 0) { - sign = 0; - return NO; - } - - int amount = (int)(16.f * fabsf(self.magnitude) * _amount); - CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, - kCGScrollEventUnitPixel, - 1, - amount); - CGEventPost(kCGHIDEventTap, scroll); - CFRelease(scroll); - - return YES; -} - -- (BOOL)isContinuous { - return YES; -} - -@end diff --git a/TargetToggleMouseScope.h b/TargetToggleMouseScope.h deleted file mode 100644 index a935c67..0000000 --- a/TargetToggleMouseScope.h +++ /dev/null @@ -1,12 +0,0 @@ -// -// TargetToggleMouseScope.h -// Enjoy -// -// Created by Yifeng Huang on 7/28/12. -// - -#import "Target.h" - -@interface TargetToggleMouseScope : Target - -@end diff --git a/TargetToggleMouseScope.m b/TargetToggleMouseScope.m deleted file mode 100644 index 0413b73..0000000 --- a/TargetToggleMouseScope.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// TargetToggleMouseScope.m -// Enjoy -// -// Created by Yifeng Huang on 7/28/12. -// - -#import "TargetToggleMouseScope.h" - -#import "ApplicationController.h" -#import "NJInputController.h" - -@implementation TargetToggleMouseScope - -+ (NSString *)serializationCode { - return @"mtoggle"; -} - -- (NSDictionary *)serialize { - return @{ @"type": @"mtoggle" }; -} - -+ (Target *)targetDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { - TargetToggleMouseScope *target = [[TargetToggleMouseScope alloc] init]; - return target; -} -- (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; - jc.frontWindowOnly = !jc.frontWindowOnly; -} - -@end