diff --git a/sources/NSAppearance+iTerm.h b/sources/NSAppearance+iTerm.h index 8f9942bb58..3ee21eaef5 100644 --- a/sources/NSAppearance+iTerm.h +++ b/sources/NSAppearance+iTerm.h @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN // Converts a tab style if automatic. - (iTermPreferencesTabStyle)it_tabStyle:(iTermPreferencesTabStyle)tabStyle; + (instancetype)it_appearanceForCurrentTheme; ++ (instancetype)it_appearanceForCurrentSessionWithBackgroundColor:(nullable NSColor *)backgroundColor; + (void)it_performBlockWithCurrentAppearanceSetToAppearanceForCurrentTheme:(void (^)(void))block; - (void)it_performAsCurrentDrawingAppearance:(void (^NS_NOESCAPE)(void))block; diff --git a/sources/NSAppearance+iTerm.m b/sources/NSAppearance+iTerm.m index d1f78c6f59..a57460c2ba 100644 --- a/sources/NSAppearance+iTerm.m +++ b/sources/NSAppearance+iTerm.m @@ -7,6 +7,7 @@ #import "NSAppearance+iTerm.h" #import "DebugLogging.h" +#import "NSColor+iTerm.h" #import "iTermPreferences.h" @implementation NSAppearance (iTerm) @@ -41,6 +42,25 @@ + (instancetype)it_appearanceForCurrentTheme { } } ++ (instancetype)it_appearanceForCurrentSessionWithBackgroundColor:(nullable NSColor *)backgroundColor { + iTermPreferencesTabStyle preferredStyle = [iTermPreferences intForKey:kPreferenceKeyTabStyle]; + switch (preferredStyle) { + case TAB_STYLE_MINIMAL: + case TAB_STYLE_COMPACT: + if (backgroundColor) { + BOOL isDark = backgroundColor.perceivedBrightness < 0.5; + return [NSAppearance appearanceNamed:isDark ? NSAppearanceNameDarkAqua : NSAppearanceNameAqua]; + } + return NSApp.effectiveAppearance; + case TAB_STYLE_AUTOMATIC: + case TAB_STYLE_LIGHT: + case TAB_STYLE_LIGHT_HIGH_CONTRAST: + case TAB_STYLE_DARK: + case TAB_STYLE_DARK_HIGH_CONTRAST: + return [self it_appearanceForCurrentTheme]; + } +} + + (void)it_performBlockWithCurrentAppearanceSetToAppearanceForCurrentTheme:(void (^)(void))block { NSAppearance *appearance = [self it_appearanceForCurrentTheme]; [appearance performAsCurrentDrawingAppearance:block]; diff --git a/sources/PTYSession.m b/sources/PTYSession.m index 100306c76d..27d6f1278f 100644 --- a/sources/PTYSession.m +++ b/sources/PTYSession.m @@ -18098,6 +18098,10 @@ - (BOOL)popupWindowShouldAvoidChangingWindowOrderOnClose { return [iTermPreferences boolForKey:kPreferenceKeyFocusFollowsMouse] && ![self.delegate sessionBelongsToHotkeyWindow:self]; } +- (NSColor *)popupWindowBackgroundColor { + return self.effectiveUnprocessedBackgroundColor; +} + - (VT100Screen *)popupVT100Screen { return _screen; } diff --git a/sources/ToastWindowController.m b/sources/ToastWindowController.m index 74e2320b17..e5a73d6f23 100644 --- a/sources/ToastWindowController.m +++ b/sources/ToastWindowController.m @@ -8,7 +8,9 @@ #import "ToastWindowController.h" #import +#import "NSAppearance+iTerm.h" #import "NSScreen+iTerm.h" +#import "PTYSession.h" #import "PseudoTerminal.h" #import "RoundedRectView.h" #import "iTermController.h" @@ -58,15 +60,19 @@ + (void)showToastWithMessage:(NSString *)message duration:(NSInteger)duration to + (void)showToastWithMessage:(NSString *)message duration:(NSInteger)duration screenCoordinate:(NSPoint)screenCoordinate pointSize:(CGFloat)pointSize center:(BOOL)center { ToastWindowController *toast = [[ToastWindowController alloc] init]; + PTYSession *session = [[iTermController sharedInstance] currentTerminal].currentSession; + NSAppearance *sessionAppearance = [NSAppearance it_appearanceForCurrentSessionWithBackgroundColor:session.effectiveUnprocessedBackgroundColor]; + BOOL isDark = sessionAppearance.it_isDark; + NSTextField *textField = [[NSTextField alloc] init]; - [textField setTextColor:[NSColor whiteColor]]; + [textField setTextColor:isDark ? [NSColor whiteColor] : [NSColor blackColor]]; [textField setBackgroundColor:[NSColor clearColor]]; [textField setFont:[NSFont systemFontOfSize:pointSize weight:NSFontWeightMedium]]; [textField setBordered:NO]; [textField setStringValue:message]; [textField setEditable:NO]; NSShadow *textShadow = [[NSShadow alloc] init]; - textShadow.shadowColor = [[NSColor blackColor] colorWithAlphaComponent:0.3]; + textShadow.shadowColor = [isDark ? [NSColor blackColor] : [NSColor whiteColor] colorWithAlphaComponent:0.3]; textShadow.shadowOffset = NSMakeSize(0, -1); textShadow.shadowBlurRadius = 2.0; [textField setShadow:textShadow]; @@ -138,8 +144,8 @@ + (void)showToastWithMessage:(NSString *)message duration:(NSInteger)duration sc vev.wantsLayer = YES; vev.blendingMode = NSVisualEffectBlendingModeBehindWindow; vev.state = NSVisualEffectStateActive; - vev.material = NSVisualEffectMaterialHUDWindow; - vev.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark]; + vev.material = isDark ? NSVisualEffectMaterialHUDWindow : NSVisualEffectMaterialSheet; + vev.appearance = [NSAppearance appearanceNamed:isDark ? NSAppearanceNameVibrantDark : NSAppearanceNameVibrantLight]; vev.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; vev.maskImage = maskImage; [container addSubview:vev]; diff --git a/sources/iTermGlobalSearchWindowController.m b/sources/iTermGlobalSearchWindowController.m index 100e155038..806a9b15fc 100644 --- a/sources/iTermGlobalSearchWindowController.m +++ b/sources/iTermGlobalSearchWindowController.m @@ -10,6 +10,7 @@ #import "FindContext.h" #import "iTerm2SharedARC-Swift.h" #import "iTermController.h" +#import "NSAppearance+iTerm.h" #import "iTermFocusReportingTextField.h" #import "iTermGlobalSearchEngine.h" #import "iTermGlobalSearchOutlineView.h" @@ -58,6 +59,8 @@ - (instancetype)init { - (void)windowDidLoad { self.window.delegate = self; self.window.level = NSFloatingWindowLevel; + PTYSession *session = [[iTermController sharedInstance] currentTerminal].currentSession; + self.window.appearance = [NSAppearance it_appearanceForCurrentSessionWithBackgroundColor:session.effectiveUnprocessedBackgroundColor]; [_outlineView expandItem:nil expandChildren:YES]; _panel.becomesKeyOnlyIfNeeded = YES; [_findType selectItemWithTag:[iTermUserDefaults globalSearchMode]]; diff --git a/sources/iTermInstantReplayWindowController.m b/sources/iTermInstantReplayWindowController.m index 7f1c56ba6e..727e35e11f 100644 --- a/sources/iTermInstantReplayWindowController.m +++ b/sources/iTermInstantReplayWindowController.m @@ -9,6 +9,10 @@ #import "iTermInstantReplayWindowController.h" #import "DebugLogging.h" +#import "iTermController.h" +#import "NSAppearance+iTerm.h" +#import "PTYSession.h" +#import "PseudoTerminal.h" static const float kAlphaValue = 0.9; @@ -138,6 +142,8 @@ - (void)windowDidLoad self.window.level = NSFloatingWindowLevel; self.window.alphaValue = kAlphaValue; + PTYSession *session = [[iTermController sharedInstance] currentTerminal].currentSession; + self.window.appearance = [NSAppearance it_appearanceForCurrentSessionWithBackgroundColor:session.effectiveUnprocessedBackgroundColor]; } - (void)windowWillClose:(NSNotification *)notification { diff --git a/sources/iTermOpenQuicklyWindowController.m b/sources/iTermOpenQuicklyWindowController.m index d6407dc206..cf77c56990 100644 --- a/sources/iTermOpenQuicklyWindowController.m +++ b/sources/iTermOpenQuicklyWindowController.m @@ -18,7 +18,6 @@ #import "iTermSnippetsMenuController.h" #import "DebugLogging.h" #import "NSAppearance+iTerm.h" -#import "NSColor+iTerm.h" #import "NSObject+iTerm.h" #import "NSTextField+iTerm.h" #import "NSWindow+iTerm.h" diff --git a/sources/iTermPopupWindowController.h b/sources/iTermPopupWindowController.h index 51c9f04575..58381c98a5 100644 --- a/sources/iTermPopupWindowController.h +++ b/sources/iTermPopupWindowController.h @@ -35,6 +35,9 @@ // If the cursor is preceded by whitespace the last word will be empty. Words go in reverse order. - (NSArray *)popupWordsBeforeInsertionPoint:(int)count; - (BOOL)popupWindowShouldAvoidChangingWindowOrderOnClose; + +@optional +- (NSColor *)popupWindowBackgroundColor; @end @protocol iTermPopupWindowHosting diff --git a/sources/iTermPopupWindowController.m b/sources/iTermPopupWindowController.m index adbdc81e74..030288eeb8 100644 --- a/sources/iTermPopupWindowController.m +++ b/sources/iTermPopupWindowController.m @@ -4,6 +4,8 @@ #import "DebugLogging.h" #import "iTermAdvancedSettingsModel.h" #import "iTermPreferences.h" +#import "NSAppearance+iTerm.h" +#import "NSColor+iTerm.h" #import "NSObject+iTerm.h" #import "NSTextField+iTerm.h" #import "NSView+iTerm.h" @@ -161,6 +163,9 @@ - (void)popWithDelegate:(id)delegate [self.popupWindow setOwningWindow:owningWindow]; + NSColor *bgColor = [delegate respondsToSelector:@selector(popupWindowBackgroundColor)] ? [delegate popupWindowBackgroundColor] : nil; + self.window.appearance = [NSAppearance it_appearanceForCurrentSessionWithBackgroundColor:bgColor]; + static const NSTimeInterval kAnimationDuration = 0.15; self.window.alphaValue = 0; if (delegate.popupWindowIsInFloatingHotkeyWindow) { diff --git a/sources/iTermStatusBarLargeComposerViewController.m b/sources/iTermStatusBarLargeComposerViewController.m index 4e7c299d0c..5a895adde3 100644 --- a/sources/iTermStatusBarLargeComposerViewController.m +++ b/sources/iTermStatusBarLargeComposerViewController.m @@ -365,6 +365,10 @@ - (BOOL)popupWindowShouldAvoidChangingWindowOrderOnClose { return NO; } +- (NSColor *)popupWindowBackgroundColor { + return nil; +} + - (NSRect)popupScreenVisibleFrame { return self.view.window.screen.visibleFrame; }