diff --git a/easy-move-resize/EMRAppDelegate.h b/easy-move-resize/EMRAppDelegate.h index 5795dd1..87c2303 100644 --- a/easy-move-resize/EMRAppDelegate.h +++ b/easy-move-resize/EMRAppDelegate.h @@ -34,11 +34,7 @@ static const double kResizeFilterInterval = 0.04; @property (weak) IBOutlet NSMenuItem *disabledAppsMenu; @property (weak) IBOutlet NSMenuItem *lastAppMenu; -@property (weak) IBOutlet NSMenuItem *oneFourtyFourHertz; -@property (weak) IBOutlet NSMenuItem *oneTwentyHertz; -@property (weak) IBOutlet NSMenuItem *oneHundredHertz; -@property (weak) IBOutlet NSMenuItem *sixtyHertz; - @property (nonatomic) BOOL sessionActive; +@property NSTimeInterval refreshInterval; @end diff --git a/easy-move-resize/EMRAppDelegate.m b/easy-move-resize/EMRAppDelegate.m index b66ea8f..d1ded4b 100644 --- a/easy-move-resize/EMRAppDelegate.m +++ b/easy-move-resize/EMRAppDelegate.m @@ -11,6 +11,17 @@ - (id) init { if (self) { NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"userPrefs"]; preferences = [[EMRPreferences alloc] initWithUserDefaults:userDefaults]; + + // Default to 60hz, but check each connected screen for a faster refresh and use the fastest one we find + self.refreshInterval = 0.0167; + for (NSScreen *screen in [NSScreen screens]) { + if (@available(macOS 12.0, *)) { + NSTimeInterval maxRefreshInterval = [screen maximumRefreshInterval]; + if (maxRefreshInterval < self.refreshInterval) { + self.refreshInterval = maxRefreshInterval; + } + } + } } return self; } @@ -25,7 +36,7 @@ CGEventRef myCGEventCallback(CGEventTapProxy __unused proxy, CGEventType type, C CGEventType resizeModifierUp = kCGEventRightMouseUp; bool handled = NO; - double interval = [ourDelegate refreshInterval]; + double refreshInterval = [ourDelegate refreshInterval]; if (![ourDelegate sessionActive]) { return event; @@ -140,7 +151,7 @@ CGEventRef myCGEventCallback(CGEventTapProxy __unused proxy, CGEventType type, C CFTypeRef _position; // actually applying the change is expensive, so only do it every kMoveFilterInterval seconds - if (CACurrentMediaTime() - [moveResize tracking] > interval) { + if (CACurrentMediaTime() - [moveResize tracking] > refreshInterval) { _position = (CFTypeRef) (AXValueCreate(kAXValueCGPointType, (const void *) &thePoint)); AXUIElementSetAttributeValue(_clickedWindow, (__bridge CFStringRef) NSAccessibilityPositionAttribute, (CFTypeRef *) _position); if (_position != NULL) CFRelease(_position); @@ -238,7 +249,7 @@ CGEventRef myCGEventCallback(CGEventTapProxy __unused proxy, CGEventType type, C [moveResize setWndSize:wndSize]; // actually applying the change is expensive, so only do it every kResizeFilterInterval events - if (CACurrentMediaTime() - [moveResize tracking] > interval) { + if (CACurrentMediaTime() - [moveResize tracking] > refreshInterval) { // only make a call to update the position if we need to if (resizeSection.xResizeDirection == left || resizeSection.yResizeDirection == bottom) { CFTypeRef _position = (CFTypeRef)(AXValueCreate(kAXValueCGPointType, (const void *)&cTopLeft)); @@ -410,34 +421,6 @@ - (void)initMenuItems { if ([flags containsObject:FN_KEY]) { [_fnMenu setState:1]; } - - [self updateRefreshRate]; -} - -- (void)updateRefreshRate { - [[self sixtyHertz] setState:0]; - [[self oneHundredHertz] setState:0]; - [[self oneTwentyHertz] setState:0]; - [[self oneFourtyFourHertz] setState:0]; - - int refreshRate = [preferences getRefreshRate]; - if (refreshRate == 0) { - refreshRate = 60; - [preferences setRefreshRate: 60]; - } - if (refreshRate == 144) { - [[self oneFourtyFourHertz] setState: 1]; - } - if (refreshRate == 120) { - [[self oneTwentyHertz] setState: 1]; - } - if (refreshRate == 100) { - [[self oneHundredHertz] setState: 1]; - } - if (refreshRate == 60) { - [[self sixtyHertz] setState: 1]; - } - } - (IBAction)modifierToggle:(id)sender { @@ -509,13 +492,6 @@ - (IBAction)enableDisabledApp:(id)sender { [self reconstructDisabledAppsSubmenu]; } -- (IBAction)toggleRefreshRate:(id)sender { - NSMenuItem *menu = (NSMenuItem*)sender; - int refreshRate = (int)[menu tag]; - [preferences setRefreshRate:refreshRate]; - [self updateRefreshRate]; -} - - (int)modifierFlags { return keyModifierFlags; } @@ -542,10 +518,6 @@ - (BOOL)resizeOnly { return [preferences resizeOnly]; } -- (double)refreshInterval { - return [preferences refreshInterval]; -} - - (void)setMenusEnabled:(BOOL)enabled { [_altMenu setEnabled:enabled]; [_cmdMenu setEnabled:enabled]; diff --git a/easy-move-resize/EMRPreferences.h b/easy-move-resize/EMRPreferences.h index b526748..f6d01df 100644 --- a/easy-move-resize/EMRPreferences.h +++ b/easy-move-resize/EMRPreferences.h @@ -8,7 +8,6 @@ #ifndef EMRPreferences_h #define EMRPreferences_h -#define REFRESH_RATE @"RefreshRate" #define SHOULD_BRING_WINDOW_TO_FRONT @"BringToFront" #define SHOULD_MIDDLE_CLICK_RESIZE @"MiddleClickResize" #define RESIZE_ONLY @"ResizeOnly" @@ -43,15 +42,6 @@ // returns a dict of disabled apps - (NSDictionary*)getDisabledApps; -// get current refresh rate -- (int)getRefreshRate; - -// set refresh rate -- (void)setRefreshRate:(int)refreshRate; - -// get current refresh rate -- (double)refreshInterval; - // add or remove an app from the disabled apps list - (void)setDisabledForApp:(NSString*)bundleIdentifier withLocalizedName:(NSString*)localizedName disabled:(BOOL)disabled; diff --git a/easy-move-resize/EMRPreferences.m b/easy-move-resize/EMRPreferences.m index d98e537..66a1ff7 100644 --- a/easy-move-resize/EMRPreferences.m +++ b/easy-move-resize/EMRPreferences.m @@ -5,7 +5,6 @@ @implementation EMRPreferences { @private NSUserDefaults *userDefaults; - double refreshInterval; } - (id)init { @@ -100,7 +99,6 @@ - (void)setToDefaults { [userDefaults setBool:NO forKey:SHOULD_MIDDLE_CLICK_RESIZE]; [userDefaults setBool:NO forKey:RESIZE_ONLY]; [userDefaults setObject:[NSDictionary dictionary] forKey:DISABLED_APPS_DEFAULTS_KEY]; - [userDefaults setInteger:60 forKey:REFRESH_RATE]; } - (NSMutableSet*)createSetFromFlagString:(NSString*)modifierFlagString { @@ -166,17 +164,4 @@ - (void)setResizeOnly:(BOOL)resizeOnly { [userDefaults setBool:resizeOnly forKey:RESIZE_ONLY]; } -- (int)getRefreshRate { - return (int)[userDefaults integerForKey:REFRESH_RATE]; -} - -- (void)setRefreshRate:(int)refreshRate { - [userDefaults setInteger:refreshRate forKey:REFRESH_RATE]; - refreshInterval = (1.0 / refreshRate); -} - -- (double)refreshInterval { - return refreshInterval; -} - @end diff --git a/easy-move-resize/en.lproj/MainMenu.xib b/easy-move-resize/en.lproj/MainMenu.xib index 359db01..abb5964 100644 --- a/easy-move-resize/en.lproj/MainMenu.xib +++ b/easy-move-resize/en.lproj/MainMenu.xib @@ -720,31 +720,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - @@ -772,12 +747,8 @@ - - - -