Skip to content

Commit

Permalink
Reimplement slider scale logic in prefs controller, where i belongs
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotmoon committed Feb 11, 2021
1 parent a852088 commit 55be948
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ + (void)initialize
PrefsReverseVertical: @(YES),
PrefsReverseTrackpad: @(YES),
PrefsReverseMouse: @(YES),
PrefsDiscreteScrollStepSize: @(0.2),
PrefsDiscreteScrollStepSize: @(3),
LoggerMaxEntries: @(50000),
PrefsBetaUpdates: @([self appIsBetaBuild]),
}];
Expand Down
10 changes: 4 additions & 6 deletions MouseTap.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions PrefsWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="VQJ-Ng-zSD" customClass="SUUpdater"/>
<userDefaultsController representsSharedInstance="YES" id="9eJ-Lx-koC"/>
<view misplaced="YES" id="Ly3-tV-h1E" userLabel="Scrolling Settings">
<view id="Ly3-tV-h1E" userLabel="Scrolling Settings">
<rect key="frame" x="0.0" y="0.0" width="456" height="424"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
Expand Down Expand Up @@ -191,7 +191,7 @@
<sliderCell key="cell" state="on" alignment="left" identifier="Ste[p Size Slider" maxValue="1" tickMarkPosition="below" sliderType="linear" id="Rqw-fS-BNI"/>
<connections>
<binding destination="-2" name="enabled" keyPath="appDelegate.enabled" id="iAE-TA-dkZ"/>
<binding destination="9eJ-Lx-koC" name="value" keyPath="values.DiscreteScrollStepSize" id="tea-Dq-Ee1"/>
<binding destination="-2" name="value" keyPath="self.stepSizeSliderValue" id="DLo-7W-cST"/>
</connections>
</slider>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="h0x-10-5sx">
Expand Down Expand Up @@ -444,7 +444,7 @@
<constraint firstAttribute="trailing" secondItem="7x2-oY-UOa" secondAttribute="trailing" constant="20" symbolic="YES" id="Gsh-qp-liQ"/>
<constraint firstItem="7x2-oY-UOa" firstAttribute="leading" secondItem="Ly3-tV-h1E" secondAttribute="leading" constant="20" symbolic="YES" id="SeS-8o-hYF"/>
</constraints>
<point key="canvasLocation" x="-2077" y="-3407"/>
<point key="canvasLocation" x="-2058" y="-3500"/>
</view>
<view id="95B-NO-Ezk" userLabel="App Settings">
<rect key="frame" x="0.0" y="0.0" width="462" height="212"/>
Expand Down
1 change: 1 addition & 0 deletions PrefsWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@interface PrefsWindowController : NSWindowController <NSTabViewDelegate, NSToolbarDelegate, NSWindowDelegate>

@property (readonly) AppDelegate *appDelegate;
@property NSNumber *stepSizeSliderValue;

@property (weak) IBOutlet NSView *scrollingSettings;
@property (weak) IBOutlet NSView *appSettings;
Expand Down
26 changes: 26 additions & 0 deletions PrefsWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@


static void *_contextRefresh=&_contextRefresh;
static void *_contextPrefsStepSize=&_contextPrefsStepSize;


@interface PrefsWindowController ()
@property NSTabView *tabView;
Expand All @@ -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
{
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand Down

0 comments on commit 55be948

Please sign in to comment.