Skip to content

Commit 94564fd

Browse files
committed
Fix NSWindowStyleMaskTexturedBackground deprecation warning
Seems like the flag has been completely useless since macOS 11. We previously kept it around despite its deprecation status because it seems to make the title bar not show a black line, but since macOS 11 it has been showing that anyway, so remove usage of it. Also, clean up misc pre-Lion-era code and block them behind ifdef. Can remove those code in future if we want to clean up.
1 parent 2faa285 commit 94564fd

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/MacVim/MMVimView.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ - (BOOL)isOpaque
192192
return textView.defaultBackgroundColor.alphaComponent == 1;
193193
}
194194

195+
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
196+
// The core logic should not be reachable in 10.7 or above and is deprecated code.
197+
// See documentation for showsResizeIndicator and placeScrollbars: comments.
198+
// As such, just ifdef out the whole thing as we no longer support 10.7.
195199
- (void)drawRect:(NSRect)rect
196200
{
197201
// On Leopard, we want to have a textured window background for nice
@@ -202,9 +206,6 @@ - (void)drawRect:(NSRect)rect
202206
|| !([[self window] styleMask] & NSWindowStyleMaskTexturedBackground))
203207
return;
204208

205-
// This should not be reachable in 10.7 or above and is deprecated code.
206-
// See documentation for showsResizeIndicator and placeScrollbars: comments.
207-
208209
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
209210
int sw = [NSScroller scrollerWidthForControlSize:NSControlSizeRegular scrollerStyle:NSScrollerStyleLegacy];
210211
#else
@@ -243,6 +244,7 @@ - (void)drawRect:(NSRect)rect
243244
[path stroke];
244245
}
245246
}
247+
#endif
246248

247249
- (MMTextView *)textView
248250
{

src/MacVim/MMWindowController.m

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,27 @@ - (id)initWithVimController:(MMVimController *)controller
128128
{
129129
backgroundDark = NO;
130130

131-
unsigned styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable
132-
| NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable
133-
| NSWindowStyleMaskUnifiedTitleAndToolbar
134-
| NSWindowStyleMaskTexturedBackground;
131+
unsigned styleMask = NSWindowStyleMaskTitled
132+
| NSWindowStyleMaskClosable
133+
| NSWindowStyleMaskMiniaturizable
134+
| NSWindowStyleMaskResizable
135+
| NSWindowStyleMaskUnifiedTitleAndToolbar;
136+
137+
// Textured background has been a deprecated feature for a while. For a
138+
// while we kept using it to avoid showing a black line below the title
139+
// bar, but since macOS 11.0 this flag is completely ignored and
140+
// deprecated. Since it's hard to test older versions of macOS well, simply
141+
// preserve the existing functionality on older macOS versions, while not
142+
// setting it in macOS 11+.
143+
BOOL usingTexturedBackground = NO;
144+
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
145+
if (@available(macos 11.0, *)) {
146+
// Don't set the textured background because it's been completely deprecated and won't do anything.
147+
} else {
148+
styleMask = styleMask | NSWindowStyleMaskTexturedBackground;
149+
usingTexturedBackground = YES;
150+
}
151+
#endif
135152

136153
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
137154
if ([userDefaults boolForKey:MMNoTitleBarWindowKey]) {
@@ -179,7 +196,7 @@ - (id)initWithVimController:(MMVimController *)controller
179196
[win setDelegate:self];
180197
[win setInitialFirstResponder:[vimView textView]];
181198

182-
if ([win styleMask] & NSWindowStyleMaskTexturedBackground) {
199+
if (usingTexturedBackground) {
183200
// On Leopard, we want to have a textured window to have nice
184201
// looking tabs. But the textured window look implies rounded
185202
// corners, which looks really weird -- disable them. This is a
@@ -1722,10 +1739,18 @@ - (void)updateTablineSeparator
17221739
{
17231740
BOOL tabBarVisible = ![[vimView tabBarControl] isHidden];
17241741
BOOL toolbarHidden = [decoratedWindow toolbar] == nil;
1725-
BOOL windowTextured = ([decoratedWindow styleMask] &
1726-
NSWindowStyleMaskTexturedBackground) != 0;
17271742
BOOL hideSeparator = NO;
17281743

1744+
// See initWithVimController: for textured background deprecation notes.
1745+
BOOL windowTextured = NO;
1746+
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
1747+
if (@available(macos 11.0, *)) {
1748+
} else {
1749+
windowTextured = ([decoratedWindow styleMask] &
1750+
NSWindowStyleMaskTexturedBackground) != 0;
1751+
}
1752+
#endif
1753+
17291754
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_10) {
17301755
// The tabline separator is mostly an old feature and not necessary
17311756
// modern macOS versions.

0 commit comments

Comments
 (0)