Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for window can become key #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions INPopoverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
/** Whether the popover is currently visible or not **/
@property (readonly) BOOL popoverIsVisible;

/** Whether the window can become key or not. Default value: YES **/
@property (nonatomic, assign) BOOL windowCanBecomeKey;

#pragma mark -
#pragma mark Methods

Expand Down
13 changes: 12 additions & 1 deletion INPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ - (void)_closePopoverAndResetVariables
[_popoverWindow orderOut:nil]; // Close the window
[self _callDelegateMethod:@selector(popoverDidClose:)]; // Call the delegate to inform that the popover has closed
[positionWindow removeChildWindow:_popoverWindow]; // Remove it as a child window
[positionWindow makeKeyAndOrderFront:nil];
if ( self.windowCanBecomeKey )
[positionWindow makeKeyAndOrderFront:nil];
// Clear all the ivars
[self _setArrowDirection:INPopoverArrowDirectionUndefined];
[self _setPositionView:nil];
Expand All @@ -403,4 +404,14 @@ - (void)_callDelegateMethod:(SEL)selector
}
}

- (void)setWindowCanBecomeKey:(BOOL)windowCanBecomeKey
{
_popoverWindow.canBecomeKeyWindow = windowCanBecomeKey;
}

- (BOOL)windowCanBecomeKey
{
return _popoverWindow.canBecomeKeyWindow;
}

@end
2 changes: 2 additions & 0 deletions INPopoverWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
@interface INPopoverWindow : NSWindow {
NSView *_popoverContentView;
NSWindow *_zoomWindow;
BOOL _canBecomeKeyWindow;
}

@property (nonatomic, readonly) INPopoverWindowFrame *frameView; // Equivalent to contentView
@property (nonatomic, retain) NSView *popoverContentView;
@property (nonatomic, assign) BOOL canBecomeKeyWindow;

- (void)presentWithPopoverController:(INPopoverController *)popoverController;
- (void)dismissAnimated;
Expand Down
5 changes: 4 additions & 1 deletion INPopoverWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ - (NSWindow *)_zoomWindowWithRect:(NSRect)rect;

@implementation INPopoverWindow

@synthesize canBecomeKeyWindow = _canBecomeKeyWindow;

// Borderless, transparent window
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
{
if ((self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:deferCreation])) {
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
[self setHasShadow:YES];
[self setCanBecomeKeyWindow:YES];
}
return self;
}
Expand All @@ -49,7 +52,7 @@ - (NSRect)frameRectForContentRect:(NSRect)contentRect
// Allow the popover to become the key window
- (BOOL)canBecomeKeyWindow
{
return YES;
return _canBecomeKeyWindow;
}

- (BOOL)canBecomeMainWindow
Expand Down
Loading