diff --git a/SFBPopover.h b/SFBPopover.h index 2360064..178ca70 100644 --- a/SFBPopover.h +++ b/SFBPopover.h @@ -70,6 +70,7 @@ typedef NS_ENUM(NSUInteger, SFBPopoverPosition) { // Show the popover- prefer these to showWindow: - (void) displayPopoverInWindow:(nonnull NSWindow *)window atPoint:(NSPoint)point; - (void) displayPopoverInWindow:(nonnull NSWindow *)window atPoint:(NSPoint)point chooseBestLocation:(BOOL)chooseBestLocation; +- (void) displayPopoverInWindow:(NSWindow *)window atPoint:(NSPoint)point chooseBestLocation:(BOOL)chooseBestLocation makeKey:(BOOL)makeKey; // ======================================== // Move the popover to a new attachment point (should be currently displayed) diff --git a/SFBPopover.m b/SFBPopover.m index e826284..31f7ebe 100644 --- a/SFBPopover.m +++ b/SFBPopover.m @@ -226,39 +226,46 @@ - (SFBPopoverPosition) bestPositionInWindow:(NSWindow *)window atPoint:(NSPoint) - (void) displayPopoverInWindow:(NSWindow *)window atPoint:(NSPoint)point { - [self displayPopoverInWindow:window atPoint:point chooseBestLocation:NO]; + [self displayPopoverInWindow:window atPoint:point chooseBestLocation:NO makeKey:YES]; } - (void) displayPopoverInWindow:(NSWindow *)window atPoint:(NSPoint)point chooseBestLocation:(BOOL)chooseBestLocation { - if([_popoverWindow isVisible]) - return; - - if(chooseBestLocation) - [_popoverWindow setPopoverPosition:[self bestPositionInWindow:window atPoint:point]]; - - NSPoint attachmentPoint = [[_popoverWindow popoverWindowFrame] attachmentPoint]; - NSPoint pointOnScreen = point; - if(window) { - NSRect rect = { .origin = point, .size = NSZeroSize }; - NSRect rectOnScreen = [window convertRectToScreen:rect]; - pointOnScreen = rectOnScreen.origin; - } - - pointOnScreen.x -= attachmentPoint.x; - pointOnScreen.y -= attachmentPoint.y; - - [_popoverWindow setFrameOrigin:pointOnScreen]; - - if(self.animates) - [_popoverWindow setAlphaValue:0]; - - [window addChildWindow:_popoverWindow ordered:NSWindowAbove]; - - [_popoverWindow makeKeyAndOrderFront:nil]; - - if(self.animates) - [[_popoverWindow animator] setAlphaValue:1]; + [self displayPopoverInWindow:window atPoint:point chooseBestLocation:chooseBestLocation makeKey:YES]; +} + +- (void) displayPopoverInWindow:(NSWindow *)window atPoint:(NSPoint)point chooseBestLocation:(BOOL)chooseBestLocation makeKey:(BOOL)makeKey +{ + if([_popoverWindow isVisible]) + return; + + if(chooseBestLocation) + [_popoverWindow setPopoverPosition:[self bestPositionInWindow:window atPoint:point]]; + + NSPoint attachmentPoint = [[_popoverWindow popoverWindowFrame] attachmentPoint]; + NSPoint pointOnScreen = point; + if(window) { + NSRect rect = { .origin = point, .size = NSZeroSize }; + NSRect rectOnScreen = [window convertRectToScreen:rect]; + pointOnScreen = rectOnScreen.origin; + } + + pointOnScreen.x -= attachmentPoint.x; + pointOnScreen.y -= attachmentPoint.y; + + [_popoverWindow setFrameOrigin:pointOnScreen]; + + if(self.animates) + [_popoverWindow setAlphaValue:0]; + + [window addChildWindow:_popoverWindow ordered:NSWindowAbove]; + + if (makeKey) { + [_popoverWindow makeKeyAndOrderFront:nil]; + } + + if(self.animates) + [[_popoverWindow animator] setAlphaValue:1]; } - (void) movePopoverToPoint:(NSPoint)point