mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-07 15:37:14 +02:00
Ensure window stays maximized in full-screen
For example, if the tabline or a scrollbar is hidden then the window will resize so that it stays maximized (in full-screen). (A side-effect is that ":set co=.." does nothing in full-screen if 'fuopt' includes "maxhorz".)
This commit is contained in:
@@ -94,7 +94,7 @@
|
||||
- (void)hideTablineSeparator:(BOOL)hide;
|
||||
- (void)doFindNext:(BOOL)next;
|
||||
- (void)updateToolbar;
|
||||
- (void)maximizeWindow:(int)options;
|
||||
- (BOOL)maximizeWindow:(int)options;
|
||||
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification;
|
||||
- (void)enterNativeFullScreen;
|
||||
@end
|
||||
@@ -527,39 +527,53 @@
|
||||
if (windowPresented && shouldResizeVimView) {
|
||||
shouldResizeVimView = NO;
|
||||
|
||||
NSSize originalSize = [vimView frame].size;
|
||||
NSSize contentSize = [vimView desiredSize];
|
||||
contentSize = [self constrainContentSizeToScreenSize:contentSize];
|
||||
int rows = 0, cols = 0;
|
||||
contentSize = [vimView constrainRows:&rows columns:&cols
|
||||
toSize:contentSize];
|
||||
[vimView setFrameSize:contentSize];
|
||||
// Make sure full-screen window stays maximized (e.g. when scrollbar or
|
||||
// tabline is hidden) according to 'fuopt'.
|
||||
BOOL didMaximize = NO;
|
||||
if (fullScreenEnabled &&
|
||||
(fullScreenOptions & (FUOPT_MAXVERT|FUOPT_MAXHORZ)) != 0)
|
||||
didMaximize = [self maximizeWindow:fullScreenOptions];
|
||||
|
||||
if (fullScreenWindow) {
|
||||
// NOTE! Don't mark the full-screen content view as needing an
|
||||
// update unless absolutely necessary since when it is updated the
|
||||
// entire screen is cleared. This may cause some parts of the Vim
|
||||
// view to be cleared but not redrawn since Vim does not realize
|
||||
// that we've erased part of the view.
|
||||
if (!NSEqualSizes(originalSize, contentSize)) {
|
||||
[[fullScreenWindow contentView] setNeedsDisplay:YES];
|
||||
[fullScreenWindow centerView];
|
||||
}
|
||||
} else {
|
||||
[self resizeWindowToFitContentSize:contentSize
|
||||
keepOnScreen:keepOnScreen];
|
||||
// Resize Vim view and window, but don't do this now if the window was
|
||||
// just reszied because this would make the window "jump" unpleasantly.
|
||||
// Instead wait for Vim to respond to the resize message and do the
|
||||
// resizing then.
|
||||
// TODO: What if the resize message fails to make it back?
|
||||
if (!didMaximize) {
|
||||
NSSize originalSize = [vimView frame].size;
|
||||
NSSize contentSize = [vimView desiredSize];
|
||||
contentSize = [self constrainContentSizeToScreenSize:contentSize];
|
||||
int rows = 0, cols = 0;
|
||||
contentSize = [vimView constrainRows:&rows columns:&cols
|
||||
toSize:contentSize];
|
||||
[vimView setFrameSize:contentSize];
|
||||
|
||||
if (!fullScreenEnabled && windowAutosaveKey && rows > 0 &&
|
||||
cols > 0) {
|
||||
// Autosave rows and columns now that they should have been
|
||||
// constrained to fit on screen. We only do this for the
|
||||
// window which also autosaves window position and we avoid
|
||||
// autosaving when in full-screen since the rows usually won't
|
||||
// fit when in windowed mode.
|
||||
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
||||
[ud setInteger:rows forKey:MMAutosaveRowsKey];
|
||||
[ud setInteger:cols forKey:MMAutosaveColumnsKey];
|
||||
[ud synchronize];
|
||||
if (fullScreenWindow) {
|
||||
// NOTE! Don't mark the full-screen content view as needing an
|
||||
// update unless absolutely necessary since when it is updated
|
||||
// the entire screen is cleared. This may cause some parts of
|
||||
// the Vim view to be cleared but not redrawn since Vim does
|
||||
// not realize that we've erased part of the view.
|
||||
if (!NSEqualSizes(originalSize, contentSize)) {
|
||||
[[fullScreenWindow contentView] setNeedsDisplay:YES];
|
||||
[fullScreenWindow centerView];
|
||||
}
|
||||
} else {
|
||||
[self resizeWindowToFitContentSize:contentSize
|
||||
keepOnScreen:keepOnScreen];
|
||||
|
||||
if (!fullScreenEnabled && windowAutosaveKey && rows > 0 &&
|
||||
cols > 0) {
|
||||
// Autosave rows and columns now that they should have been
|
||||
// constrained to fit on screen. We only do this for the
|
||||
// window which also autosaves window position and we avoid
|
||||
// autosaving when in full-screen since the rows usually
|
||||
// won't fit when in windowed mode.
|
||||
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
||||
[ud setInteger:rows forKey:MMAutosaveRowsKey];
|
||||
[ud setInteger:cols forKey:MMAutosaveColumnsKey];
|
||||
[ud synchronize];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,9 +715,9 @@
|
||||
if (![NSWindow instancesRespondToSelector:@selector(toggleFullScreen:)])
|
||||
useNativeFullScreen = NO;
|
||||
|
||||
fullScreenOptions = fuoptions;
|
||||
if (useNativeFullScreen) {
|
||||
// Enter native full-screen mode. Only supported on Mac OS X 10.7+.
|
||||
fullScreenOptions = fuoptions;
|
||||
if (windowPresented) {
|
||||
[self enterNativeFullScreen];
|
||||
} else {
|
||||
@@ -1300,6 +1314,7 @@
|
||||
round(0.5*(screenFrame.size.width - newFrame.size.width));
|
||||
}
|
||||
|
||||
ASLogDebug(@"Set window frame: %@", NSStringFromRect(newFrame));
|
||||
[decoratedWindow setFrame:newFrame display:YES];
|
||||
|
||||
NSPoint oldTopLeft = { frame.origin.x, NSMaxY(frame) };
|
||||
@@ -1469,7 +1484,7 @@
|
||||
updateToolbarFlag = 0;
|
||||
}
|
||||
|
||||
- (void)maximizeWindow:(int)options
|
||||
- (BOOL)maximizeWindow:(int)options
|
||||
{
|
||||
int currRows, currColumns;
|
||||
[[vimView textView] getMaxRows:&currRows columns:&currColumns];
|
||||
@@ -1480,7 +1495,7 @@
|
||||
NSSize size = [[NSScreen mainScreen] frame].size;
|
||||
[vimView constrainRows:&maxRows columns:&maxColumns toSize:size];
|
||||
|
||||
ASLogDebug(@"max: %dx%d curr: %dx%d",
|
||||
ASLogDebug(@"Window dimensions max: %dx%d current: %dx%d",
|
||||
maxRows, maxColumns, currRows, currColumns);
|
||||
|
||||
// Compute current fu size
|
||||
@@ -1511,10 +1526,17 @@
|
||||
}
|
||||
NSParameterAssert(data != nil && msgid != 0);
|
||||
|
||||
ASLogDebug(@"%s: %dx%d", MessageStrings[msgid], fuRows, fuColumns);
|
||||
MMVimController *vc = [self vimController];
|
||||
[vc sendMessage:msgid data:data];
|
||||
[[vimView textView] setMaxRows:fuRows columns:fuColumns];
|
||||
|
||||
// Indicate that window was resized
|
||||
return YES;
|
||||
}
|
||||
|
||||
// Indicate that window was not resized
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification
|
||||
|
||||
Reference in New Issue
Block a user