From 48186896d41ccb345e4678c53ab1480059c12d3d Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 6 Mar 2013 12:41:25 +0100 Subject: [PATCH] Improved analog support for scrolling, and allow speed adjustments. --- English.lproj/MainMenu.xib | 132 ++++++++++++++++++++++++++++++------- NJOutputController.h | 2 + NJOutputController.m | 34 ++++++++-- NJOutputMouseScroll.h | 3 +- NJOutputMouseScroll.m | 38 +++++------ 5 files changed, 158 insertions(+), 51 deletions(-) diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index bd4f12a..9cce48b 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -507,7 +507,7 @@ {200, 298} - + YES NO YES @@ -637,7 +637,7 @@ {202, 300} - + 150034 @@ -658,6 +658,31 @@ 256 + + + 268 + {{228, 52}, {140, 12}} + + + _NS:9 + YES + + -2080374784 + 262144 + + _NS:9 + + 30 + 0.0 + 15 + 0.0 + 0 + 1 + NO + NO + + NO + 268 @@ -687,7 +712,7 @@ 265 - {{226, 132}, {179, 15}} + {{227, 132}, {178, 15}} @@ -722,7 +747,7 @@ 0 - 42 + 41 ↓ 0 @@ -734,35 +759,43 @@ 265 - {{226, 55}, {180, 24}} + {{227, 64}, {178, 15}} - + _NS:9 YES 67108864 - 0 - - LucidaGrande - 13 - 16 - + 262144 + _NS:9 - 87 - Up + 68 + ↑ + Scroll up continuously YES 0 - 86 - Down + 67 + ↓ + Scroll down continuously 1 0 + + ⤒ + Scroll up one step + 0 + + + ⤓ + Scroll down one step + 0 + 1 @@ -780,7 +813,11 @@ 67108864 0 - + + LucidaGrande + 13 + 16 + _NS:9 @@ -1086,7 +1123,7 @@ {198, 198} - + YES NO YES @@ -1178,7 +1215,7 @@ {{0, 20}, {200, 200}} - + 150034 @@ -1194,7 +1231,6 @@ {{66, -1}, {134, 23}} - _NS:22 YES @@ -1698,6 +1734,22 @@ 886 + + + scrollSpeedChanged: + + + + 890 + + + + scrollSpeedSlider + + + + 891 + keyDelegate @@ -2112,6 +2164,7 @@ + Output Editor Pane @@ -2420,6 +2473,19 @@ + + 887 + + + + + + + + 888 + + + @@ -2508,11 +2574,11 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2565,13 +2631,23 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Mouse scroll speed + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - 886 + 891 @@ -2748,6 +2824,7 @@ id id id + id id @@ -2767,6 +2844,10 @@ radioChanged: id + + scrollSpeedChanged: + id + sdirChanged: id @@ -2782,6 +2863,7 @@ NSSlider NSMatrix NSSegmentedControl + NSSlider NSTextField @@ -2821,6 +2903,10 @@ scrollDirSelect NSSegmentedControl + + scrollSpeedSlider + NSSlider + title NSTextField diff --git a/NJOutputController.h b/NJOutputController.h index de8b417..f8052e7 100644 --- a/NJOutputController.h +++ b/NJOutputController.h @@ -20,6 +20,7 @@ IBOutlet NSSlider *mouseSpeedSlider; IBOutlet NSSegmentedControl *mouseBtnSelect; IBOutlet NSSegmentedControl *scrollDirSelect; + IBOutlet NSSlider *scrollSpeedSlider; IBOutlet NSTextField *title; IBOutlet NSPopUpButton *mappingPopup; IBOutlet NJMappingsController *mappingsController; @@ -34,6 +35,7 @@ - (IBAction)mbtnChanged:(id)sender; - (IBAction)sdirChanged:(id)sender; - (IBAction)mouseSpeedChanged:(id)sender; +- (IBAction)scrollSpeedChanged:(id)sender; - (void)focusKey; diff --git a/NJOutputController.m b/NJOutputController.m index e60a83e..f3eca24 100644 --- a/NJOutputController.m +++ b/NJOutputController.m @@ -71,9 +71,19 @@ if (row != 5) { scrollDirSelect.selectedSegment = -1; + scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue; [scrollDirSelect resignIfFirstResponder]; - } else if (scrollDirSelect.selectedSegment == -1) - scrollDirSelect.selectedSegment = 0; + } else { + if (scrollDirSelect.selectedSegment == -1) + scrollDirSelect.selectedSegment = 0; + if (scrollDirSelect.selectedSegment < 2 + && !scrollSpeedSlider.floatValue) + scrollSpeedSlider.floatValue = 15.f; + else if (scrollDirSelect.selectedSegment >= 2 + && scrollSpeedSlider.floatValue) + scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue; + } + } - (IBAction)radioChanged:(NSView *)sender { @@ -124,6 +134,16 @@ [self commit]; } +- (void)scrollSpeedChanged:(NSSlider *)sender { + [radioButtons selectCellAtRow:5 column:0]; + [sender.window makeFirstResponder:sender]; + if (!sender.floatValue && scrollDirSelect.selectedSegment < 2) + scrollDirSelect.selectedSegment += 2; + else if (sender.floatValue && scrollDirSelect.selectedSegment >= 2) + scrollDirSelect.selectedSegment -= 2; + [self commit]; +} + - (NJOutput *)currentOutput { return mappingsController.currentMapping[inputController.selectedInput]; } @@ -159,7 +179,10 @@ } case 5: { NJOutputMouseScroll *ms = [[NJOutputMouseScroll alloc] init]; - ms.amount = scrollDirSelect.selectedSegment ? 1 : -1; + ms.direction = (scrollDirSelect.selectedSegment & 1) ? 1 : -1; + ms.speed = scrollDirSelect.selectedSegment < 2 + ? scrollSpeedSlider.floatValue + : 0.f; return ms; } case 6: { @@ -225,7 +248,10 @@ } else if ([output isKindOfClass:NJOutputMouseScroll.class]) { [radioButtons selectCellAtRow:5 column:0]; - scrollDirSelect.selectedSegment = [(NJOutputMouseScroll *)output amount] > 0; + int direction = [(NJOutputMouseScroll *)output direction]; + float speed = [(NJOutputMouseScroll *)output speed]; + scrollDirSelect.selectedSegment = (direction > 0) + !speed * 2; + scrollSpeedSlider.floatValue = speed; } else if ([output isKindOfClass:NJOutputSwitchMouseMode.class]) { [radioButtons selectCellAtRow:6 column:0]; diff --git a/NJOutputMouseScroll.h b/NJOutputMouseScroll.h index 6ef2cdc..dd0444a 100644 --- a/NJOutputMouseScroll.h +++ b/NJOutputMouseScroll.h @@ -9,6 +9,7 @@ @interface NJOutputMouseScroll : NJOutput -@property (nonatomic, assign) int amount; +@property (nonatomic, assign) int direction; +@property (nonatomic, assign) float speed; @end diff --git a/NJOutputMouseScroll.m b/NJOutputMouseScroll.m index 4aa614d..7bbf4f8 100644 --- a/NJOutputMouseScroll.m +++ b/NJOutputMouseScroll.m @@ -7,51 +7,47 @@ #import "NJOutputMouseScroll.h" -@implementation NJOutputMouseScroll { - int sign; -} +@implementation NJOutputMouseScroll + (NSString *)serializationCode { return @"mouse scroll"; } - (NSDictionary *)serialize { - return @{ @"type": self.class.serializationCode, @"amount": @(_amount) }; + return @{ @"type": self.class.serializationCode, + @"direction": @(_direction), + @"speed": @(_speed) + }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization withMappings:(NSArray *)mappings { NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init]; - output.amount = [serialization[@"amount"] intValue]; + output.direction = [serialization[@"direction"] intValue]; + output.speed = [serialization[@"direction"] floatValue]; return output; } +- (BOOL)isContinuous { + return !!self.speed; +} + - (void)trigger { - if (!self.magnitude) { + if (!self.speed) { CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, 1, - _amount); + _direction); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); } } - (BOOL)update:(NJDeviceController *)jc { - if (fabsf(self.magnitude) < 0.01f) { - sign = 0; + if (self.magnitude < 0.05f) 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); + int amount = (int)(_speed * self.magnitude * _direction); CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, @@ -62,8 +58,4 @@ return YES; } -- (BOOL)isContinuous { - return YES; -} - @end -- 2.30.2