From 89246f3714773efcce84eabe3ed2eb75f2c3b4f0 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 27 Sep 2017 17:43:09 -0400 Subject: [PATCH 1/2] :wrench: Allow dragging over menubar --- atom/browser/native_browser_view_mac.mm | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/atom/browser/native_browser_view_mac.mm b/atom/browser/native_browser_view_mac.mm index 39d785980afe..bd465014f981 100644 --- a/atom/browser/native_browser_view_mac.mm +++ b/atom/browser/native_browser_view_mac.mm @@ -68,13 +68,41 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask = NSPoint newOrigin; NSRect screenFrame = [[NSScreen mainScreen] frame]; + NSSize screenSize = screenFrame.size; NSRect windowFrame = [self.window frame]; + NSSize windowSize = windowFrame.size; newOrigin.x = currentLocation.x - self.initialLocation.x; newOrigin.y = currentLocation.y - self.initialLocation.y; + BOOL inMenuBar = (newOrigin.y + windowSize.height) > (screenFrame.origin.y + screenSize.height); + BOOL screenAboveMainScreen = false; + + if (inMenuBar) { + for (NSScreen *screen in [NSScreen screens]) { + NSRect currentScreenFrame = [screen frame]; + BOOL isHigher = currentScreenFrame.origin.y < screenFrame.origin.y; + + // If there's another screen that is generally above the current screen, + // we'll check if the screen is roughly on the same vertical axis. If so, + // we'll let the move pass and allow the window to go underneath the menu bar. + if (isHigher) { + NSPoint aboveLeft = NSMakePoint( + screenFrame.origin.x + screenFrame.size.height + 10, screenFrame.origin.y); + NSPoint aboveRight = NSMakePoint( + screenFrame.origin.x + screenFrame.size.height + 10, + screenFrame.origin.y + screenFrame.size.width); + + if (NSPointInRect(aboveLeft, screenFrame) || NSPointInRect(aboveRight, screenFrame)) { + screenAboveMainScreen = true; + break; + } + } + } + } + // Don't let window get dragged up under the menu bar - if ((newOrigin.y + windowFrame.size.height) > (screenFrame.origin.y + screenFrame.size.height)) { + if (inMenuBar && !screenAboveMainScreen) { newOrigin.y = screenFrame.origin.y + (screenFrame.size.height - windowFrame.size.height); } From 0cc1ebc021c28cd2148bca388af60e8dcb5d8e66 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Fri, 29 Sep 2017 14:20:34 -0400 Subject: [PATCH 2/2] :wrench: Allow dragging window to screen above menubar (for real) --- atom/browser/native_browser_view_mac.mm | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/atom/browser/native_browser_view_mac.mm b/atom/browser/native_browser_view_mac.mm index bd465014f981..17b0a1ee9006 100644 --- a/atom/browser/native_browser_view_mac.mm +++ b/atom/browser/native_browser_view_mac.mm @@ -43,6 +43,12 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask = - (void)mouseDown:(NSEvent *)event { if ([self.window respondsToSelector:@selector(performWindowDragWithEvent)]) { + // According to Google, using performWindowDragWithEvent: + // does not generate a NSWindowWillMoveNotification. Hence post one. + [[NSNotificationCenter defaultCenter] + postNotificationName:NSWindowWillMoveNotification + object:self]; + [self.window performWindowDragWithEvent:event]; return; } @@ -81,19 +87,23 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask = if (inMenuBar) { for (NSScreen *screen in [NSScreen screens]) { NSRect currentScreenFrame = [screen frame]; - BOOL isHigher = currentScreenFrame.origin.y < screenFrame.origin.y; + BOOL isHigher = currentScreenFrame.origin.y > screenFrame.origin.y; // If there's another screen that is generally above the current screen, - // we'll check if the screen is roughly on the same vertical axis. If so, - // we'll let the move pass and allow the window to go underneath the menu bar. + // we'll draw a new rectangle that is just above the current screen. If the + // "higher" screen intersects with this rectangle, we'll allow drawing above + // the menubar. if (isHigher) { - NSPoint aboveLeft = NSMakePoint( - screenFrame.origin.x + screenFrame.size.height + 10, screenFrame.origin.y); - NSPoint aboveRight = NSMakePoint( - screenFrame.origin.x + screenFrame.size.height + 10, - screenFrame.origin.y + screenFrame.size.width); + NSRect aboveScreenRect = NSMakeRect( + screenFrame.origin.x, + screenFrame.origin.y + screenFrame.size.height - 10, + screenFrame.size.width, + 200 + ); - if (NSPointInRect(aboveLeft, screenFrame) || NSPointInRect(aboveRight, screenFrame)) { + BOOL screenAboveIntersects = NSIntersectsRect(currentScreenFrame, aboveScreenRect); + + if (screenAboveIntersects) { screenAboveMainScreen = true; break; }