From f7562b2a920b62602af4447b9f5f4a42c5732f18 Mon Sep 17 00:00:00 2001 From: joshaber Date: Thu, 19 Jun 2014 15:59:37 -0400 Subject: [PATCH 1/3] Separate these out to make it clearer. --- Rebel/RBLPopover.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Rebel/RBLPopover.m b/Rebel/RBLPopover.m index 8a99a5d..ab3692c 100644 --- a/Rebel/RBLPopover.m +++ b/Rebel/RBLPopover.m @@ -330,7 +330,8 @@ static CGFloat RBLRectsGetMedianY(CGRect r1, CGRect r2) { if (strongSelf.behavior == RBLPopoverBehaviorTransient) { shouldClose = !mouseInPopoverWindow; } else { - shouldClose = strongSelf.popoverWindow.parentWindow.isKeyWindow && NSPointInRect(NSEvent.mouseLocation, strongSelf.popoverWindow.parentWindow.frame) && !mouseInPopoverWindow; + BOOL inParentWindow = NSPointInRect(NSEvent.mouseLocation, strongSelf.popoverWindow.parentWindow.frame); + shouldClose = strongSelf.popoverWindow.parentWindow.isKeyWindow && inParentWindow && !mouseInPopoverWindow; } if (shouldClose) [strongSelf close]; From f455ccc094a65b55bfe00d1e6303acfea5de01f3 Mon Sep 17 00:00:00 2001 From: joshaber Date: Thu, 19 Jun 2014 15:59:53 -0400 Subject: [PATCH 2/3] Find the topmost parent window. --- Rebel/RBLPopover.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Rebel/RBLPopover.m b/Rebel/RBLPopover.m index ab3692c..16b8112 100644 --- a/Rebel/RBLPopover.m +++ b/Rebel/RBLPopover.m @@ -385,8 +385,12 @@ static CGFloat RBLRectsGetMedianY(CGRect r1, CGRect r2) { closeButton.target = self; closeButton.action = @selector(performClose:); [self.popoverWindow.contentView addSubview:closeButton]; - - [positioningView.window addChildWindow:self.popoverWindow ordered:NSWindowAbove]; + + NSWindow *topmostParentWindow = positioningView.window; + while (topmostParentWindow.parentWindow != nil) { + topmostParentWindow = topmostParentWindow.parentWindow; + } + [topmostParentWindow addChildWindow:self.popoverWindow ordered:NSWindowAbove]; [self.popoverWindow makeKeyAndOrderFront:self]; void (^postDisplayBlock)(void) = ^{ From 78da958e870e00ac8c8543635ece39729fa09da5 Mon Sep 17 00:00:00 2001 From: joshaber Date: Thu, 19 Jun 2014 16:00:07 -0400 Subject: [PATCH 3/3] Close popovers when our fullscreen status changes. --- Rebel/RBLPopover.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Rebel/RBLPopover.m b/Rebel/RBLPopover.m index 16b8112..287d5db 100644 --- a/Rebel/RBLPopover.m +++ b/Rebel/RBLPopover.m @@ -390,6 +390,12 @@ static CGFloat RBLRectsGetMedianY(CGRect r1, CGRect r2) { while (topmostParentWindow.parentWindow != nil) { topmostParentWindow = topmostParentWindow.parentWindow; } + + if (self.behavior != RBLPopoverBehaviorApplicationDefined) { + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(fullScreenChanged:) name:NSWindowWillEnterFullScreenNotification object:topmostParentWindow]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(fullScreenChanged:) name:NSWindowWillExitFullScreenNotification object:topmostParentWindow]; + } + [topmostParentWindow addChildWindow:self.popoverWindow ordered:NSWindowAbove]; [self.popoverWindow makeKeyAndOrderFront:self]; @@ -448,12 +454,23 @@ static CGFloat RBLRectsGetMedianY(CGRect r1, CGRect r2) { self.transientEventMonitors = nil; [NSNotificationCenter.defaultCenter removeObserver:self name:NSApplicationDidResignActiveNotification object:NSApp]; [NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowDidResignKeyNotification object:nil]; + [NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowWillEnterFullScreenNotification object:nil]; + [NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowWillExitFullScreenNotification object:nil]; } - (void)appResignedActive:(NSNotification *)notification { if (self.behavior == RBLPopoverBehaviorTransient) [self close]; } +- (void)fullScreenChanged:(NSNotification *)notification { + // Turn off animations. We want the close to be instantaneous since the + // parent window's going to be animating too. + BOOL shouldAnimate = self.animates; + self.animates = NO; + [self close]; + self.animates = shouldAnimate; +} + @end //***************************************************************************