Skip to content

Commit c93f9c0

Browse files
authored
Merge pull request #1521 from ychin/fullscreen-tests-fuopt-fixes
Contains the following: 1. Fix non-native full screen misc background color and transparency issues. 2. Fix non-native full screen bad interaction with window delegate. 3. Add tests for full screen code
2 parents 73de6ef + 762a8c8 commit c93f9c0

File tree

10 files changed

+324
-39
lines changed

10 files changed

+324
-39
lines changed

runtime/doc/options.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,15 +3981,19 @@ A jump table for the options with a short description can be found at |Q_op|.
39813981
of columns fitting on the screen in fullscreen mode. If unset,
39823982
'columns' will be unchanged when entering fullscreen mode.
39833983
background:color
3984-
When entering fullscreen, 'color' defines the color of the part
3985-
of the screen that is not occupied by the Vim control. If
3986-
'color' is an 8-digit hexadecimal number preceded by '#',
3987-
it is interpreted as an explicit color value '#aarrggbb', with
3988-
one byte each for the alpha, red, green, and blue values.
3989-
Otherwise, 'color' is interpreted as a highlight group name,
3984+
When entering fullscreen, "color" defines the color of the part
3985+
of the screen that is not occupied by the Vim control,
3986+
including the "notch" area for MacBook laptops.
3987+
If "color" is a 6 or 8-digit hexadecimal number preceded by
3988+
'#', it is interpreted as an explicit color value '#rrggbb' /
3989+
'#aarrggbb', with one byte each for the alpha, red, green, and
3990+
blue values. The alpha value is ignored (use 'transparency'
3991+
instead for a translucent window).
3992+
Otherwise, "color" is interpreted as a highlight group name,
39903993
and the fullscreen background is filled with that highlight
39913994
group's background color, as defined by the current color
39923995
scheme.
3996+
If unset, the default value is black (#FF000000).
39933997

39943998
Examples:
39953999
Don't change size when entering fullscreen: >

src/MacVim/MMBackend.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ - (void)leaveFullScreen
11881188
- (void)setFullScreenBackgroundColor:(int)color
11891189
{
11901190
NSMutableData *data = [NSMutableData data];
1191-
color = MM_COLOR(color);
1191+
color = MM_COLOR_WITH_TRANSP(color,p_transp);
11921192
[data appendBytes:&color length:sizeof(int)];
11931193

11941194
[self queueMessage:SetFullScreenColorMsgID data:data];

src/MacVim/MMCoreTextView.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ - (void)drawRect:(NSRect)rect
831831

832832
// Function to draw all rows
833833
void (^drawAllRows)(void (^)(CGContextRef,CGRect,int)) = ^(void (^drawFunc)(CGContextRef,CGRect,int)){
834-
for (size_t r = 0; r < grid.rows; r++) {
834+
for (int r = 0; r < grid.rows; r++) {
835835
const CGRect rowRect = [self rectForRow:(int)r
836836
column:0
837837
numRows:1
@@ -1276,6 +1276,9 @@ - (NSSize)constrainRows:(int *)rows columns:(int *)cols toSize:(NSSize)size
12761276
if (fh < 1.0f) fh = 1.0f;
12771277

12781278
desiredRows = floor((size.height - ih)/fh);
1279+
// Sanity checking in case unusual window sizes lead to degenerate results
1280+
if (desiredRows < 1)
1281+
desiredRows = 1;
12791282
desiredSize.height = fh*desiredRows + ih;
12801283
}
12811284

@@ -1285,6 +1288,9 @@ - (NSSize)constrainRows:(int *)rows columns:(int *)cols toSize:(NSSize)size
12851288
if (fw < 1.0f) fw = 1.0f;
12861289

12871290
desiredCols = floor((size.width - iw)/fw);
1291+
// Sanity checking in case unusual window sizes lead to degenerate results
1292+
if (desiredCols < 1)
1293+
desiredCols = 1;
12881294
desiredSize.width = fw*desiredCols + iw;
12891295
}
12901296

src/MacVim/MMFullScreenWindow.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ - (void)enterFullScreen
136136
{
137137
ASLogDebug(@"Enter full-screen now");
138138

139+
// Detach the window delegate right now to prevent any stray window
140+
// messages (e.g. it may get resized when setting presentationOptions
141+
// below) being sent to the window controller while we are in the middle of
142+
// setting up the full screen window.
143+
NSWindowController *winController = [target windowController];
144+
id delegate = [target delegate];
145+
[winController setWindow:nil];
146+
[target setDelegate:nil];
147+
139148
// Hide Dock and menu bar when going to full screen. Only do so if the current screen
140149
// has a menu bar and dock.
141150
if ([self screenHasDockAndMenu]) {
@@ -162,13 +171,6 @@ - (void)enterFullScreen
162171
// this call so set the frame again just in case.
163172
[self setFrame:[[target screen] frame] display:NO];
164173

165-
// fool delegate
166-
id delegate = [target delegate];
167-
[target setDelegate:nil];
168-
169-
// make target's window controller believe that it's now controlling us
170-
[[target windowController] setWindow:self];
171-
172174
oldTabBarStyle = [[view tabBarControl] styleName];
173175

174176
NSString *style =
@@ -181,7 +183,7 @@ - (void)enterFullScreen
181183
[view removeFromSuperviewWithoutNeedingDisplay];
182184
[[self contentView] addSubview:view];
183185
[self setInitialFirstResponder:[view textView]];
184-
186+
185187
// NOTE: Calling setTitle:nil causes an exception to be raised (and it is
186188
// possible that 'target' has no title when we get here).
187189
if ([target title]) {
@@ -196,8 +198,10 @@ - (void)enterFullScreen
196198

197199
[self setOpaque:[target isOpaque]];
198200

201+
// reassign target's window controller to believe that it's now controlling us
199202
// don't set this sooner, so we don't get an additional
200-
// focus gained message
203+
// focus gained message
204+
[winController setWindow:self];
201205
[self setDelegate:delegate];
202206

203207
// Store view dimension used before entering full-screen, then resize the

src/MacVim/MMTextStorage.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,9 @@ - (NSSize)fitToSize:(NSSize)size rows:(int *)rows columns:(int *)columns
895895
if (fh < 1.0f) fh = 1.0f;
896896

897897
fitRows = floor(size.height/fh);
898+
// Sanity checking in case unusual window sizes lead to degenerate results
899+
if (fitRows < 1)
900+
fitRows = 1;
898901
fitSize.height = fh*fitRows;
899902
}
900903

@@ -903,6 +906,9 @@ - (NSSize)fitToSize:(NSSize)size rows:(int *)rows columns:(int *)columns
903906
if (fw < 1.0f) fw = 1.0f;
904907

905908
fitCols = floor(size.width/fw);
909+
// Sanity checking in case unusual window sizes lead to degenerate results
910+
if (fitCols < 1)
911+
fitCols = 1;
906912
fitSize.width = fw*fitCols;
907913
}
908914

src/MacVim/MMVimController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ - (void)handleMessage:(int)msgid data:(NSData *)data
11291129
case SetFullScreenColorMsgID:
11301130
{
11311131
const int *bg = (const int*)[data bytes];
1132-
NSColor *color = [NSColor colorWithRgbInt:*bg];
1132+
NSColor *color = [NSColor colorWithArgbInt:*bg];
11331133

11341134
[windowController setFullScreenBackgroundColor:color];
11351135
}

src/MacVim/MMWindowController.m

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -699,25 +699,32 @@ - (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
699699
// window, so we need to set a transparency color here to make the
700700
// transparency show through.
701701
if ([back alphaComponent] == 1) {
702-
// Here, any solid color would do, but setting it with "back" has an
703-
// interesting effect where the title bar gets subtly tinted by it
704-
// as well, so do that. (Note that this won't play well in <=10.12
705-
// since we are using the deprecated
706-
// NSWindowStyleMaskTexturedBackground which makes the titlebars
707-
// transparent in those. Consider not using textured background.)
702+
// The window's background color affects the title bar tint and
703+
// if we are using a transparent title bar this color will show
704+
// up as well.
705+
// (Note that this won't play well in <=10.12 since we are using
706+
// the deprecated NSWindowStyleMaskTexturedBackground which makes
707+
// the titlebars transparent in those. Consider not using textured
708+
// background.)
708709
[decoratedWindow setBackgroundColor:back];
710+
711+
// Note: We leave the full screen window's background color alone
712+
// because it is affected by 'fuoptions' instead. We just change the
713+
// alpha back to 1 in case it was changed previously because transparency
714+
// was set.
709715
if (fullScreenWindow) {
710-
[fullScreenWindow setBackgroundColor:back];
716+
[fullScreenWindow setBackgroundColor:
717+
[fullScreenWindow.backgroundColor colorWithAlphaComponent:1]];
711718
}
712719
} else {
713720
// HACK! We really want a transparent background color to avoid
714721
// double blending the transparency, but setting alpha=0 leads to
715722
// the window border disappearing and also drag-to-resize becomes a
716723
// lot slower. So hack around it by making it virtually transparent.
717-
NSColor *clearColor = [back colorWithAlphaComponent:0.001];
718-
[decoratedWindow setBackgroundColor:clearColor];
724+
[decoratedWindow setBackgroundColor:[back colorWithAlphaComponent:0.001]];
719725
if (fullScreenWindow) {
720-
[fullScreenWindow setBackgroundColor:clearColor];
726+
[fullScreenWindow setBackgroundColor:
727+
[fullScreenWindow.backgroundColor colorWithAlphaComponent:0.001]];
721728
}
722729
}
723730
}
@@ -1046,9 +1053,17 @@ - (void)leaveFullScreen
10461053
}
10471054
}
10481055

1056+
/// Called when the window is in non-native full-screen mode and the user has
1057+
/// updated the background color.
10491058
- (void)setFullScreenBackgroundColor:(NSColor *)back
10501059
{
10511060
if (fullScreenWindow)
1061+
// See setDefaultColorsBackground: for why set a transparent
1062+
// background color, and why 0.001 instead of 0.
1063+
if ([back alphaComponent] != 1) {
1064+
back = [back colorWithAlphaComponent:0.001];
1065+
}
1066+
10521067
[fullScreenWindow setBackgroundColor:back];
10531068
}
10541069

@@ -1307,9 +1322,7 @@ - (void)windowDidResize:(id)sender
13071322
// Calling setFrameSizeKeepGUISize: instead of setFrameSize: prevents a
13081323
// degenerate case where frameSizeMayHaveChanged: ends up resizing the window
13091324
// *again* causing windowDidResize: to be called.
1310-
if (fullScreenWindow == nil) {
1311-
[vimView setFrameSizeKeepGUISize:[self contentSize]];
1312-
} else {
1325+
if (fullScreenEnabled && fullScreenWindow != nil) {
13131326
// Non-native full screen mode is more complicated and needs to
13141327
// re-layout the Vim view to properly account for the menu bar / notch,
13151328
// and misc fuopt configuration.
@@ -1318,6 +1331,9 @@ - (void)windowDidResize:(id)sender
13181331
[vimView setFrameOrigin:desiredFrame.origin];
13191332
[vimView setFrameSizeKeepGUISize:desiredFrame.size];
13201333
}
1334+
else {
1335+
[vimView setFrameSizeKeepGUISize:[self contentSize]];
1336+
}
13211337
}
13221338

13231339
- (void)windowDidChangeBackingProperties:(NSNotification *)notification

0 commit comments

Comments
 (0)