mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-06-04 06:28:38 +03:00
macos: use Ghostty.AppState as @EnvironmentObject
This is a small cleanup change. This provides the Ghostty.AppState object to any view that needs it within the TerminalSplit view hierarchy without needing to explicitly define EnvironmentKeys.
This commit is contained in:
@ -85,8 +85,6 @@ struct TerminalView<ViewModel: TerminalViewModel>: View {
|
||||
|
||||
Ghostty.TerminalSplit(node: $viewModel.surfaceTree)
|
||||
.environmentObject(ghostty)
|
||||
.ghosttyApp(ghostty.app!)
|
||||
.ghosttyConfig(ghostty.config!)
|
||||
.focused($focused)
|
||||
.onAppear { self.focused = true }
|
||||
.onChange(of: focusedSurface) { newValue in
|
||||
|
@ -582,35 +582,3 @@ extension Ghostty {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: AppState Environment Keys
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ import GhosttyKit
|
||||
extension Ghostty {
|
||||
/// Render a terminal for the active app in the environment.
|
||||
struct Terminal: View {
|
||||
@Environment(\.ghosttyApp) private var app
|
||||
@EnvironmentObject private var ghostty: Ghostty.AppState
|
||||
@FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle: String?
|
||||
|
||||
var body: some View {
|
||||
if let app = self.app {
|
||||
if let app = self.ghostty.app {
|
||||
SurfaceForApp(app) { surfaceView in
|
||||
SurfaceWrapper(surfaceView: surfaceView)
|
||||
}
|
||||
@ -48,7 +48,7 @@ extension Ghostty {
|
||||
// Maintain whether our window has focus (is key) or not
|
||||
@State private var windowFocus: Bool = true
|
||||
|
||||
@Environment(\.ghosttyConfig) private var ghostty_config
|
||||
@EnvironmentObject private var ghostty: Ghostty.AppState
|
||||
|
||||
// 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.
|
||||
@ -58,7 +58,7 @@ extension Ghostty {
|
||||
private var unfocusedOpacity: Double {
|
||||
var opacity: Double = 0.85
|
||||
let key = "unfocused-split-opacity"
|
||||
_ = ghostty_config_get(ghostty_config, &opacity, key, UInt(key.count))
|
||||
_ = ghostty_config_get(ghostty.config, &opacity, key, UInt(key.count))
|
||||
return 1 - opacity
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user