-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: auto-match sidebar background to Ghostty terminal theme #2254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13730,6 +13730,7 @@ private struct TitlebarLeadingInsetReader: NSViewRepresentable { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private struct SidebarBackdrop: View { | ||||||||||||||||||
| @AppStorage(SidebarThemeSettings.modeKey) private var sidebarTheme = SidebarThemeSettings.defaultMode.rawValue | ||||||||||||||||||
| @AppStorage("sidebarTintOpacity") private var sidebarTintOpacity = SidebarTintDefaults.opacity | ||||||||||||||||||
| @AppStorage("sidebarTintHex") private var sidebarTintHex = SidebarTintDefaults.hex | ||||||||||||||||||
| @AppStorage("sidebarTintHexLight") private var sidebarTintHexLight: String? | ||||||||||||||||||
|
|
@@ -13740,26 +13741,61 @@ private struct SidebarBackdrop: View { | |||||||||||||||||
| @AppStorage("sidebarCornerRadius") private var sidebarCornerRadius = 0.0 | ||||||||||||||||||
| @AppStorage("sidebarBlurOpacity") private var sidebarBlurOpacity = 1.0 | ||||||||||||||||||
| @Environment(\.colorScheme) private var colorScheme | ||||||||||||||||||
| @State private var refreshGeneration = 0 | ||||||||||||||||||
|
|
||||||||||||||||||
| var body: some View { | ||||||||||||||||||
| let materialOption = SidebarMaterialOption(rawValue: sidebarMaterial) | ||||||||||||||||||
| let preferredColorScheme: GhosttyConfig.ColorSchemePreference = colorScheme == .dark ? .dark : .light | ||||||||||||||||||
| let ghosttyConfig = GhosttyConfig.load(preferredColorScheme: preferredColorScheme) | ||||||||||||||||||
| let selectedSidebarTheme = SidebarThemeSettings.mode(for: sidebarTheme) | ||||||||||||||||||
| let blendingMode = SidebarBlendModeOption(rawValue: sidebarBlendMode)?.mode ?? .behindWindow | ||||||||||||||||||
| let state = SidebarStateOption(rawValue: sidebarState)?.state ?? .active | ||||||||||||||||||
| let resolvedHex: String = { | ||||||||||||||||||
| let resolvedCustomHex: String = { | ||||||||||||||||||
| if colorScheme == .dark, let dark = sidebarTintHexDark { | ||||||||||||||||||
| return dark | ||||||||||||||||||
| } else if colorScheme == .light, let light = sidebarTintHexLight { | ||||||||||||||||||
| return light | ||||||||||||||||||
| } | ||||||||||||||||||
| return sidebarTintHex | ||||||||||||||||||
| }() | ||||||||||||||||||
| let tintColor = (NSColor(hex: resolvedHex) ?? NSColor(hex: sidebarTintHex) ?? .black).withAlphaComponent(sidebarTintOpacity) | ||||||||||||||||||
| let customTintColor = (NSColor(hex: resolvedCustomHex) ?? NSColor(hex: sidebarTintHex) ?? .black) | ||||||||||||||||||
| .withAlphaComponent(sidebarTintOpacity) | ||||||||||||||||||
| let explicitSidebarBackground: NSColor? = { | ||||||||||||||||||
| if colorScheme == .dark, let dark = ghosttyConfig.sidebarBackgroundDark { | ||||||||||||||||||
| return dark | ||||||||||||||||||
| } else if colorScheme == .light, let light = ghosttyConfig.sidebarBackgroundLight { | ||||||||||||||||||
| return light | ||||||||||||||||||
| } | ||||||||||||||||||
| return ghosttyConfig.sidebarBackground | ||||||||||||||||||
| }() | ||||||||||||||||||
| let hasExplicitSidebarBackground = ghosttyConfig.rawSidebarBackground != nil && explicitSidebarBackground != nil | ||||||||||||||||||
| let tintColor: NSColor = { | ||||||||||||||||||
| guard let explicitSidebarBackground else { | ||||||||||||||||||
| return customTintColor | ||||||||||||||||||
| } | ||||||||||||||||||
| let resolvedOpacity = ghosttyConfig.sidebarTintOpacity ?? sidebarTintOpacity | ||||||||||||||||||
| return explicitSidebarBackground.withAlphaComponent(resolvedOpacity) | ||||||||||||||||||
| }() | ||||||||||||||||||
| let baseColor: NSColor? = | ||||||||||||||||||
| hasExplicitSidebarBackground || selectedSidebarTheme == .custom | ||||||||||||||||||
| ? nil | ||||||||||||||||||
| : GhosttyBackgroundTheme.currentColor() | ||||||||||||||||||
| let materialOption: SidebarMaterialOption? = { | ||||||||||||||||||
| if hasExplicitSidebarBackground || selectedSidebarTheme == .custom { | ||||||||||||||||||
| return SidebarMaterialOption(rawValue: sidebarMaterial) | ||||||||||||||||||
| } | ||||||||||||||||||
| return SidebarMaterialOption.none | ||||||||||||||||||
| }() | ||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| let cornerRadius = CGFloat(max(0, sidebarCornerRadius)) | ||||||||||||||||||
| let useLiquidGlass = materialOption?.usesLiquidGlass ?? false | ||||||||||||||||||
| let useWindowLevelGlass = useLiquidGlass && blendingMode == .behindWindow | ||||||||||||||||||
|
|
||||||||||||||||||
| return ZStack { | ||||||||||||||||||
| if let material = materialOption?.material { | ||||||||||||||||||
| if let baseColor { | ||||||||||||||||||
| SidebarSolidColorBackground(color: baseColor) | ||||||||||||||||||
| if tintColor.alphaComponent > 0.0001 { | ||||||||||||||||||
| SidebarSolidColorBackground(color: tintColor) | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+13795
to
+13799
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the The result is that the sidebar is always 18% darker than the actual Ghostty terminal background, so "Match Ghostty" does not produce a pixel-accurate match for new users. The tint overlay should be gated on if let baseColor {
SidebarSolidColorBackground(color: baseColor)
if selectedSidebarTheme == .custom, tintColor.alphaComponent > 0.0001 {
SidebarSolidColorBackground(color: tintColor)
}
} else if let material = materialOption?.material { |
||||||||||||||||||
| } else if let material = materialOption?.material { | ||||||||||||||||||
| // When using liquidGlass + behindWindow, window handles glass + tint | ||||||||||||||||||
| // Sidebar is fully transparent | ||||||||||||||||||
| if !useWindowLevelGlass { | ||||||||||||||||||
|
|
@@ -13777,10 +13813,69 @@ private struct SidebarBackdrop: View { | |||||||||||||||||
| Color(nsColor: tintColor) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } else { | ||||||||||||||||||
| // No material — render solid tint color (used when sidebar | ||||||||||||||||||
| // matches the terminal theme background). Uses a custom | ||||||||||||||||||
| // NSView instead of SwiftUI Color because | ||||||||||||||||||
| // makeViewHierarchyTransparent clears layer.backgroundColor | ||||||||||||||||||
| // on all views when the terminal has background-opacity < 1. | ||||||||||||||||||
| SidebarSolidColorBackground(color: tintColor) | ||||||||||||||||||
| } | ||||||||||||||||||
| // When material is none or useWindowLevelGlass, render nothing | ||||||||||||||||||
| } | ||||||||||||||||||
| .clipShape(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)) | ||||||||||||||||||
| .onReceive(NotificationCenter.default.publisher(for: .ghosttyDefaultBackgroundDidChange)) { _ in | ||||||||||||||||||
| refreshGeneration &+= 1 | ||||||||||||||||||
| } | ||||||||||||||||||
| .onReceive(NotificationCenter.default.publisher(for: .ghosttyConfigDidReload)) { _ in | ||||||||||||||||||
| GhosttyConfig.invalidateLoadCache() | ||||||||||||||||||
| refreshGeneration &+= 1 | ||||||||||||||||||
| } | ||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /// Renders a solid color using the same compositing path as the terminal's | ||||||||||||||||||
| /// CAMetalLayer (bgra8Unorm / sRGB blending). Uses a display link callback | ||||||||||||||||||
| /// to re-apply layer.backgroundColor after makeViewHierarchyTransparent | ||||||||||||||||||
|
||||||||||||||||||
| /// Renders a solid color using the same compositing path as the terminal's | |
| /// CAMetalLayer (bgra8Unorm / sRGB blending). Uses a display link callback | |
| /// to re-apply layer.backgroundColor after makeViewHierarchyTransparent | |
| /// Renders a solid color using the same compositing path as the terminal's | |
| /// CAMetalLayer (bgra8Unorm / sRGB blending). Uses `viewDidMoveToWindow` with a | |
| /// deferred main-queue dispatch to re-apply `layer.backgroundColor` after | |
| /// `makeViewHierarchyTransparent` clears it on transparent windows. | |
| private struct SidebarSolidColorBackground: NSViewRepresentable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshGenerationis never read inbodyrefreshGenerationis incremented in both.onReceivehandlers to force a re-render when the Ghostty background changes, but it is never accessed inside thebodycomputed property. Today this still triggers a re-render because any@Statemutation invalidates a SwiftUI view regardless of body access, but the intent is entirely implicit.Add
let _ = refreshGenerationat the top ofbodyto make the re-render dependency explicit and linter-clean.