From b0c72adbe165eb077299d0313da053961b2814b6 Mon Sep 17 00:00:00 2001 From: Daniel Pham Date: Thu, 26 May 2016 17:43:38 -0400 Subject: [PATCH] :apple: Fix context menus only showing on primary monitor. --- atom/browser/api/atom_api_menu_mac.mm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_menu_mac.mm b/atom/browser/api/atom_api_menu_mac.mm index 117e8c0df7ed..3b91dac62a7f 100644 --- a/atom/browser/api/atom_api_menu_mac.mm +++ b/atom/browser/api/atom_api_menu_mac.mm @@ -52,15 +52,18 @@ void MenuMac::PopupAt(Window* window, int x, int y, int positioning_item) { // If no preferred item is specified, try to show all of the menu items. if (!positioning_item) { CGFloat windowBottom = CGRectGetMinY([view window].frame); - CGFloat distaceFromBottom = windowBottom + position.y - [menu size].height; - if (distaceFromBottom < 0) - position.y = position.y - distaceFromBottom + 4; + CGFloat lowestMenuPoint = windowBottom + position.y - [menu size].height; + CGFloat screenBottom = CGRectGetMinY([view window].screen.frame); + CGFloat distanceFromBottom = lowestMenuPoint - screenBottom; + if (distanceFromBottom < 0) + position.y = position.y - distanceFromBottom + 4; } // Place the menu left of cursor if it is overflowing off right of screen. CGFloat windowLeft = CGRectGetMinX([view window].frame); - CGFloat rightmostPoint = windowLeft + position.x + [menu size].width; - if (rightmostPoint > [[NSScreen mainScreen] visibleFrame].size.width) + CGFloat rightmostMenuPoint = windowLeft + position.x + [menu size].width; + CGFloat screenRight = CGRectGetMaxX([view window].screen.frame); + if (rightmostMenuPoint > screenRight) position.x = position.x - [menu size].width; // Show the menu.