Skip to content

Commit f5d7f8f

Browse files
committed
Hide window shadow in mojave when there is a transparent session. Thanks apple
1 parent 062151e commit f5d7f8f

6 files changed

+38
-2
lines changed

sources/PTYTab.m

+1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ - (void)numberOfSessionsDidChange {
490490
if (self.isBroadcasting) {
491491
[[NSNotificationCenter defaultCenter] postNotificationName:iTermBroadcastDomainsDidChangeNotification object:nil];
492492
}
493+
[_delegate numberOfSessionsDidChangeInTab:self];
493494
}
494495

495496
+ (void)_recursiveSetDelegateIn:(NSSplitView *)node to:(id)delegate {

sources/PTYTabDelegate.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ typedef NS_OPTIONS(NSUInteger, PTYTabState) {
4444
image:(NSImage *)image;
4545
- (BOOL)tabCanUseMetal:(PTYTab *)tab reason:(out iTermMetalUnavailableReason *)reason;
4646
- (BOOL)tabShouldUseTransparency:(PTYTab *)tab;
47+
- (void)numberOfSessionsDidChangeInTab:(PTYTab *)tab;
4748

4849
@end

sources/PTYTextView.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,9 @@ - (void)drawRect:(NSRect)rect {
12071207
if (![_delegate textViewShouldDrawRect]) {
12081208
// Metal code path in use
12091209
[super drawRect:rect];
1210-
[self maybeInvalidateWindowShadow];
1210+
if (![iTermAdvancedSettingsModel disableWindowShadowWhenTransparencyOnMojave]) {
1211+
[self maybeInvalidateWindowShadow];
1212+
}
12111213
return;
12121214
}
12131215
if (_dataSource.width <= 0) {

sources/PseudoTerminal.m

+31
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,7 @@ - (BOOL)restoreTabsFromArrangement:(NSDictionary *)arrangement sessions:(NSArray
25882588
return NO;
25892589
}
25902590
}
2591+
[self updateUseTransparency];
25912592
return YES;
25922593
}
25932594

@@ -3769,6 +3770,13 @@ - (void)updateUseTransparency {
37693770
}
37703771
[[self currentTab] recheckBlur];
37713772
[self updateTabColors]; // Updates the window's background color as a side-effect
3773+
[self updateWindowShadow];
3774+
}
3775+
3776+
- (BOOL)anySessionInCurrentTabHasTransparency {
3777+
return [self.currentTab.sessions anyWithBlock:^BOOL(PTYSession *session) {
3778+
return session.textview.transparencyAlpha < 1;
3779+
}];
37723780
}
37733781

37743782
- (IBAction)toggleUseTransparency:(id)sender
@@ -4163,6 +4171,17 @@ - (void)toggleTraditionalFullScreenMode {
41634171
[self didChangeCompactness];
41644172
[self updateTouchBarIfNeeded:NO];
41654173
[self updateUseMetalInAllTabs];
4174+
[self updateWindowShadow];
4175+
}
4176+
4177+
- (void)updateWindowShadow {
4178+
if (@available(macOS 10.14, *)) {
4179+
if ([iTermAdvancedSettingsModel disableWindowShadowWhenTransparencyOnMojave]) {
4180+
const BOOL haveTransparency = [self anySessionInCurrentTabHasTransparency];
4181+
DLog(@"%@: have transparency = %@ for sessions %@ in tab %@", self, @(haveTransparency), self.currentTab.sessions, self.currentTab);
4182+
self.window.hasShadow = !haveTransparency;
4183+
}
4184+
}
41664185
}
41674186

41684187
- (void)didChangeCompactness {
@@ -4287,6 +4306,7 @@ - (void)windowWillEnterFullScreen:(NSNotification *)notification {
42874306
togglingLionFullScreen_ = YES;
42884307
[self didChangeAnyFullScreen];
42894308
[self updateUseMetalInAllTabs];
4309+
[self updateWindowShadow];
42904310
[self repositionWidgets];
42914311
[_contentView didChangeCompactness];
42924312
}
@@ -4319,6 +4339,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification
43194339
}
43204340
[self updateTouchBarIfNeeded:NO];
43214341
[self updateUseMetalInAllTabs];
4342+
[self updateWindowShadow];
43224343
}
43234344

43244345
- (void)windowDidFailToEnterFullScreen:(NSWindow *)window {
@@ -4353,6 +4374,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification
43534374
[self repositionWidgets];
43544375
self.window.hasShadow = YES;
43554376
[self updateUseMetalInAllTabs];
4377+
[self updateWindowShadow];
43564378
}
43574379

43584380
- (void)windowDidExitFullScreen:(NSNotification *)notification
@@ -4385,6 +4407,7 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification
43854407
[self updateUseMetalInAllTabs];
43864408
[_contentView didChangeCompactness];
43874409
[_contentView layoutSubviews];
4410+
[self updateWindowShadow];
43884411
}
43894412

43904413
- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame {
@@ -4707,6 +4730,7 @@ - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabVi
47074730
[self updateCurrentLocation];
47084731
[self updateUseMetalInAllTabs];
47094732
[self.scope setValue:self.currentTab.variables forVariableNamed:iTermVariableKeyWindowCurrentTab];
4733+
[self updateWindowShadow];
47104734
[[NSNotificationCenter defaultCenter] postNotificationName:iTermSelectedTabDidChange object:tab];
47114735
}
47124736

@@ -8691,6 +8715,7 @@ - (void)tabSessionDidChangeBackgroundColor:(PTYTab *)tab {
86918715
if (preferredStyle == TAB_STYLE_MINIMAL) {
86928716
[self.contentView setNeedsDisplay:YES];
86938717
}
8718+
[self updateWindowShadow];
86948719
}
86958720

86968721
- (void)tab:(PTYTab *)tab didChangeToState:(PTYTabState)newState {
@@ -8732,6 +8757,12 @@ - (void)currentSessionWordAtCursorDidBecome:(NSString *)word {
87328757
}];
87338758
}
87348759

8760+
- (void)numberOfSessionsDidChangeInTab:(PTYTab *)tab {
8761+
if (tab == self.currentTab) {
8762+
[self updateUseTransparency];
8763+
}
8764+
}
8765+
87358766
#pragma mark - Toolbelt
87368767

87378768
- (void)toolbeltUpdateMouseCursor {

sources/iTermAdvancedSettingsModel.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extern NSString *const iTermAdvancedSettingsDidChange;
6565
+ (BOOL)disableMetalWhenIdle;
6666
+ (BOOL)disablePasswordManagerAnimations;
6767
+ (BOOL)disablePotentiallyInsecureEscapeSequences;
68+
+ (BOOL)disableWindowShadowWhenTransparencyOnMojave;
6869
+ (BOOL)disableWindowSizeSnap;
6970
+ (BOOL)disallowCopyEmptyString;
7071
+ (BOOL)dockIconTogglesWindow DEPRECATED_ATTRIBUTE;

sources/iTermAdvancedSettingsModel.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ + (void)enumerateDictionaries:(void (^)(NSDictionary *))block {
423423
DEFINE_BOOL(fontChangeAffectsBroadcastingSessions, NO, SECTION_WINDOWS @"Should growing or shrinking the font in a session that's broadcasting input affect all session that broadcast input?\nThis only applies to changing the font size with Make Text Bigger, Make Text Normal Size, and Make Text Smaller");
424424
DEFINE_BOOL(serializeOpeningMultipleFullScreenWindows, YES, SECTION_WINDOWS @"When opening multiple fullscreen windows, enter fullscreen one window at a time.");
425425
DEFINE_BOOL(trackingRunloopForLiveResize, YES, SECTION_WINDOWS @"Use a tracking runloop for live resizing.\nThis allows the terminal to redraw during a resizing drag.");
426-
DEFINE_BOOL(invalidateShadowAfterEachDraw, YES, SECTION_WINDOWS @"Invalidate shadow after each draw to prevent ghosting.");
427426
DEFINE_FLOAT(invalidateShadowTimesPerSecond, 15, SECTION_WINDOWS @"How many times per second to update the shadow of transparent windows to prevent ghosting.\nThis works around a macOS Mojave bug that leaves a ghost of past window contents behind in transparent windows. It hurts performance to do it frequently, especially in large windows. Set to 0 to disable.");
427+
DEFINE_BOOL(disableWindowShadowWhenTransparencyOnMojave, YES, SECTION_WINDOWS @"Disable the window shadow on Mojave when the window has a transparent session to improve performance.");
428428

429429
#pragma mark tmux
430430

0 commit comments

Comments
 (0)