diff --git a/macos/Sources/Features/Primary Window/PrimaryView.swift b/macos/Sources/Features/Primary Window/PrimaryView.swift index cd9f8e920..c3020ba3e 100644 --- a/macos/Sources/Features/Primary Window/PrimaryView.swift +++ b/macos/Sources/Features/Primary Window/PrimaryView.swift @@ -96,6 +96,7 @@ struct PrimaryView: View { Ghostty.TerminalSplit(onClose: Self.closeWindow, baseConfig: self.baseConfig) .ghosttyApp(ghostty.app!) + .ghosttyConfig(ghostty.config!) .background(WindowAccessor(window: $window)) .onReceive(gotoTab) { onGotoTab(notification: $0) } .onReceive(toggleFullscreen) { onToggleFullscreen(notification: $0) } diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index 4b7b85d82..12ece198b 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -350,15 +350,28 @@ private struct GhosttyAppKey: EnvironmentKey { static let defaultValue: ghostty_app_t? = nil } +private struct GhosttyConfigKey: EnvironmentKey { + static let defaultValue: ghostty_config_t? = nil +} + extension EnvironmentValues { var ghosttyApp: ghostty_app_t? { get { self[GhosttyAppKey.self] } set { self[GhosttyAppKey.self] = newValue } } + + var ghosttyConfig: ghostty_config_t? { + get { self[GhosttyConfigKey.self] } + set { self[GhosttyConfigKey.self] = newValue } + } } extension View { func ghosttyApp(_ app: ghostty_app_t?) -> some View { environment(\.ghosttyApp, app) } + + func ghosttyConfig(_ config: ghostty_config_t?) -> some View { + environment(\.ghosttyConfig, config) + } } diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 015600392..ae7f73652 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -48,10 +48,20 @@ extension Ghostty { // Maintain whether our window has focus (is key) or not @State private var windowFocus: Bool = true + @Environment(\.ghosttyConfig) private var ghostty_config + // This is true if the terminal is considered "focused". The terminal is focused if // it is both individually focused and the containing window is key. private var hasFocus: Bool { surfaceFocus && windowFocus } + // The opacity of the rectangle when unfocused. + private var unfocusedOpacity: Double { + var opacity: Double = 0.85 + let key = "unfocused-split-opacity" + _ = ghostty_config_get(ghostty_config, &opacity, key, UInt(key.count)) + return 1 - opacity + } + var body: some View { ZStack { // We use a GeometryReader to get the frame bounds so that our metal surface @@ -130,7 +140,7 @@ extension Ghostty { Rectangle() .fill(.white) .allowsHitTesting(false) - .opacity(0.15) + .opacity(unfocusedOpacity) } } }