From 55be9482b4fb304dd93f8e5ab807eb029bb435be Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Thu, 11 Feb 2021 20:20:01 +0000 Subject: [PATCH] Reimplement slider scale logic in prefs controller, where i belongs --- AppDelegate.m | 2 +- MouseTap.m | 10 ++++------ PrefsWindow.xib | 6 +++--- PrefsWindowController.h | 1 + PrefsWindowController.m | 26 ++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/AppDelegate.m b/AppDelegate.m index c11228b..d7799fd 100644 --- a/AppDelegate.m +++ b/AppDelegate.m @@ -134,7 +134,7 @@ + (void)initialize PrefsReverseVertical: @(YES), PrefsReverseTrackpad: @(YES), PrefsReverseMouse: @(YES), - PrefsDiscreteScrollStepSize: @(0.2), + PrefsDiscreteScrollStepSize: @(3), LoggerMaxEntries: @(50000), PrefsBetaUpdates: @([self appIsBetaBuild]), }]; diff --git a/MouseTap.m b/MouseTap.m index ff0f4dd..7fdbe57 100644 --- a/MouseTap.m +++ b/MouseTap.m @@ -45,12 +45,10 @@ static uint64_t _nanoseconds(void) static NSInteger _stepsize(void) { - double setting=[[NSUserDefaults standardUserDefaults] doubleForKey:PrefsDiscreteScrollStepSize]; - if (setting<0.03) return 0; - if (setting<0.1) return 1; - const NSInteger result=lround(pow(2.5,(setting+0.1)*3.6)); - NSLog(@"setting %@, step %@", @(setting), @(result)); - return result; + const NSInteger setting=[[NSUserDefaults standardUserDefaults] integerForKey:PrefsDiscreteScrollStepSize]; + if (setting<0) return 0; + if (setting>100) return 100; + return setting; } static CGEventRef _callback(CGEventTapProxy proxy, diff --git a/PrefsWindow.xib b/PrefsWindow.xib index abb8fda..c37c242 100644 --- a/PrefsWindow.xib +++ b/PrefsWindow.xib @@ -19,7 +19,7 @@ - + @@ -191,7 +191,7 @@ - + @@ -444,7 +444,7 @@ - + diff --git a/PrefsWindowController.h b/PrefsWindowController.h index 53aa566..5c6f011 100644 --- a/PrefsWindowController.h +++ b/PrefsWindowController.h @@ -8,6 +8,7 @@ @interface PrefsWindowController : NSWindowController @property (readonly) AppDelegate *appDelegate; +@property NSNumber *stepSizeSliderValue; @property (weak) IBOutlet NSView *scrollingSettings; @property (weak) IBOutlet NSView *appSettings; diff --git a/PrefsWindowController.m b/PrefsWindowController.m index 3cf41f8..327cf6a 100644 --- a/PrefsWindowController.m +++ b/PrefsWindowController.m @@ -18,6 +18,8 @@ static void *_contextRefresh=&_contextRefresh; +static void *_contextPrefsStepSize=&_contextPrefsStepSize; + @interface PrefsWindowController () @property NSTabView *tabView; @@ -28,6 +30,26 @@ @interface PrefsWindowController () @implementation PrefsWindowController +static const double _offset=0.1; +static const double _exponent=1.8; +static const double _multiplier=25.0; + +- (NSNumber *)stepSizeSliderValue +{ + const NSInteger stepSize=[[NSUserDefaults standardUserDefaults] integerForKey:PrefsDiscreteScrollStepSize]; + const double result=pow(stepSize/_multiplier,1.0/_exponent); + NSLog(@"read pref %@ from %@", @(result), @(stepSize)); + return @(result-_offset); +} + +- (void)setStepSizeSliderValue:(NSNumber *)stepSizeSliderValue +{ + const double sliderValue=[stepSizeSliderValue doubleValue]+_offset; + const NSInteger result=lround(pow(sliderValue,_exponent)*_multiplier); + NSLog(@"set pref %@ from %@", @(result), @(sliderValue)); + [[NSUserDefaults standardUserDefaults] setInteger:result forKey:PrefsDiscreteScrollStepSize]; +} + // animate window frame to draw user's attention - (void)callAttention { @@ -115,6 +137,7 @@ - (void)windowDidLoad [self.appDelegate.permissionsManager addObserver:self forKeyPath:@"accessibilityEnabled" options:0 context:_contextRefresh]; [self.appDelegate.permissionsManager addObserver:self forKeyPath:@"inputMonitoringEnabled" options:0 context:_contextRefresh]; + [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:[@"values." stringByAppendingString:PrefsDiscreteScrollStepSize] options:NSKeyValueObservingOptionNew context:_contextPrefsStepSize]; // select the initial pane [self.tabView selectTabViewItemWithIdentifier:startingIdentifier]; @@ -127,6 +150,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N if (context==_contextRefresh) { NSLog(@"refresh observe"); } + else if (context==_contextPrefsStepSize) { + NSLog(@"stepsize observe"); + } } - (void)showWindow:(id)sender