From fdd0d67fd3ccb54e2cc95101ad4d1d5f1ce1f432 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 9 Aug 2017 11:57:57 -0700 Subject: [PATCH] :wrench: Support older versions of macOS --- atom/browser/native_browser_view_mac.mm | 35 ++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/atom/browser/native_browser_view_mac.mm b/atom/browser/native_browser_view_mac.mm index 096b87dbb4d..5e8db8cf554 100644 --- a/atom/browser/native_browser_view_mac.mm +++ b/atom/browser/native_browser_view_mac.mm @@ -15,6 +15,9 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask = NSViewMaxXMargin | NSViewMinYMargin; @interface DragRegionView : NSView + +@property (assign) NSPoint initialLocation; + @end @implementation DragRegionView @@ -26,7 +29,37 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask = - (void)mouseDown:(NSEvent *)event { - [self.window performWindowDragWithEvent:event]; + if ([self.window respondsToSelector:@selector(performWindowDragWithEvent:)]) { + [self.window performWindowDragWithEvent:event]; + return; + } + + self.initialLocation = [event locationInWindow]; +} + +- (void)mouseDragged:(NSEvent *)theEvent +{ + if ([self.window respondsToSelector:@selector(performWindowDragWithEvent:)]) { + return; + } + + NSPoint currentLocation; + NSPoint newOrigin; + + NSRect screenFrame = [[NSScreen mainScreen] frame]; + NSRect windowFrame = [self.window frame]; + + currentLocation = [NSEvent mouseLocation]; + newOrigin.x = currentLocation.x - self.initialLocation.x; + newOrigin.y = currentLocation.y - self.initialLocation.y; + + // Don't let window get dragged up under the menu bar + if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) ){ + newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height); + } + + // Move the window to the new location + [self.window setFrameOrigin:newOrigin]; } // Debugging tips: