Skip to content

Commit

Permalink
Handle screen parameter changes in full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
b4winckler committed Jul 26, 2011
1 parent d01ee9a commit 7f8ed17
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/MacVim/MMFullscreenWindow.h
Expand Up @@ -42,4 +42,5 @@
- (BOOL)canBecomeKeyWindow;
- (BOOL)canBecomeMainWindow;

- (void)applicationDidChangeScreenParameters:(NSNotification *)notification;
@end
60 changes: 27 additions & 33 deletions src/MacVim/MMFullscreenWindow.m
Expand Up @@ -50,7 +50,6 @@ - (BOOL)isOnPrimaryScreen;
- (void)windowDidBecomeMain:(NSNotification *)notification;
- (void)windowDidResignMain:(NSNotification *)notification;
- (void)windowDidMove:(NSNotification *)notification;
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification;
- (void)resizeVimView;
@end

Expand Down Expand Up @@ -103,11 +102,6 @@ - (MMFullscreenWindow *)initWithWindow:(NSWindow *)t view:(MMVimView *)v
name:NSWindowDidMoveNotification
object:self];

[nc addObserver:self
selector:@selector(applicationDidChangeScreenParameters:)
name:NSApplicationDidChangeScreenParametersNotification
object:NSApp];

// NOTE: Vim needs to process mouse moved events, so enable them here.
[self setAcceptsMouseMovedEvents:YES];

Expand Down Expand Up @@ -334,6 +328,33 @@ - (BOOL)canBecomeMainWindow
return YES;
}

- (void)applicationDidChangeScreenParameters:(NSNotification *)notification
{
if (state != InFullScreen)
return;

// This notification is sent when screen resolution may have changed (e.g.
// due to a monitor being unplugged or the resolution being changed
// manually) but it also seems to get called when the Dock is
// hidden/displayed.
ASLogDebug(@"Screen unplugged / resolution changed");

NSScreen *screen = [target screen];
if (!screen) {
// Paranoia: if window we originally used for full screen is gone, try
// screen window is on now, and failing that (not sure this can happen)
// use main screen.
screen = [self screen];
if (!screen)
screen = [NSScreen mainScreen];
}

// Ensure the full screen window is still covering the entire screen and
// then resize view according to 'fuopt'.
[self setFrame:[screen frame] display:NO];
[self resizeVimView];
}

- (void)centerView
{
NSRect outer = [self frame], inner = [view frame];
Expand Down Expand Up @@ -429,33 +450,6 @@ - (void)windowDidMove:(NSNotification *)notification
[self resizeVimView];
}

- (void)applicationDidChangeScreenParameters:(NSNotification *)notification
{
if (state != InFullScreen)
return;

// This notification is sent when screen resolution may have changed (e.g.
// due to a monitor being unplugged or the resolution being changed
// manually) but it also seems to get called when the Dock is
// hidden/displayed.
ASLogDebug(@"Screen unplugged / resolution changed");

NSScreen *screen = [target screen];
if (!screen) {
// Paranoia: if window we originally used for full screen is gone, try
// screen window is on now, and failing that (not sure this can happen)
// use main screen.
screen = [self screen];
if (!screen)
screen = [NSScreen mainScreen];
}

// Ensure the full screen window is still covering the entire screen and
// then resize view according to 'fuopt'.
[self setFrame:[screen frame] display:NO];
[self resizeVimView];
}

- (void)resizeVimView
{
// Resize vim view according to options
Expand Down
25 changes: 24 additions & 1 deletion src/MacVim/MMWindowController.m
Expand Up @@ -89,6 +89,7 @@ - (void)hideTablineSeparator:(BOOL)hide;
- (void)doFindNext:(BOOL)next;
- (void)updateToolbar;
- (void)maximizeWindow:(int)options;
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification;
@end


Expand Down Expand Up @@ -193,6 +194,12 @@ - (id)initWithVimController:(MMVimController *)controller
[win setAnimationBehavior:NSWindowAnimationBehaviorDocumentWindow];
#endif

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationDidChangeScreenParameters:)
name:NSApplicationDidChangeScreenParametersNotification
object:NSApp];

return self;
}

Expand Down Expand Up @@ -244,6 +251,8 @@ - (void)cleanup
// NOTE: Must set this before possibly leaving full screen.
setupDone = NO;

[[NSNotificationCenter defaultCenter] removeObserver:self];

if (fullscreenEnabled) {
// If we are closed while still in fullscreen, end fullscreen mode,
// release ourselves (because this won't happen in MMWindowController)
Expand Down Expand Up @@ -1439,6 +1448,9 @@ - (void)maximizeWindow:(int)options
NSSize size = [[NSScreen mainScreen] frame].size;
[vimView constrainRows:&maxRows columns:&maxColumns toSize:size];

ASLogDebug(@"max: %dx%d curr: %dx%d",
maxRows, maxColumns, currRows, currColumns);

// Compute current fu size
int fuRows = currRows, fuColumns = currColumns;
if (options & FUOPT_MAXVERT)
Expand Down Expand Up @@ -1473,6 +1485,17 @@ - (void)maximizeWindow:(int)options
}
}

@end // MMWindowController (Private)
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification
{
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
if (fullscreenEnabled) {
ASLogInfo(@"Re-maximizing full screen window...");
[self maximizeWindow:fullscreenOptions];
}
#endif
if (fullscreenWindow)
[fullscreenWindow applicationDidChangeScreenParameters:notification];
}

@end // MMWindowController (Private)

0 comments on commit 7f8ed17

Please sign in to comment.