macos: base config plumbed through

This commit is contained in:
Mitchell Hashimoto
2023-10-30 11:53:05 -07:00
parent 61451942e8
commit ed1741730e
3 changed files with 13 additions and 5 deletions

View File

@ -9,14 +9,18 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele
/// The app instance that this terminal view will represent. /// The app instance that this terminal view will represent.
let ghostty: Ghostty.AppState let ghostty: Ghostty.AppState
/// The base configuration for the new window
let baseConfig: Ghostty.SurfaceConfiguration?
/// The currently focused surface. /// The currently focused surface.
var focusedSurface: Ghostty.SurfaceView? = nil var focusedSurface: Ghostty.SurfaceView? = nil
/// Fullscreen state management. /// Fullscreen state management.
private let fullscreenHandler = FullScreenHandler() private let fullscreenHandler = FullScreenHandler()
init(_ ghostty: Ghostty.AppState) { init(_ ghostty: Ghostty.AppState, withBaseConfig base: Ghostty.SurfaceConfiguration? = nil) {
self.ghostty = ghostty self.ghostty = ghostty
self.baseConfig = base
super.init(window: nil) super.init(window: nil)
let center = NotificationCenter.default let center = NotificationCenter.default
@ -64,7 +68,8 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele
// Initialize our content view to the SwiftUI root // Initialize our content view to the SwiftUI root
window.contentView = NSHostingView(rootView: TerminalView( window.contentView = NSHostingView(rootView: TerminalView(
ghostty: self.ghostty, ghostty: self.ghostty,
delegate: self delegate: self,
baseConfig: baseConfig
)) ))
} }

View File

@ -89,9 +89,9 @@ class TerminalManager {
} }
/// Creates a window controller, adds it to our managed list, and returns it. /// Creates a window controller, adds it to our managed list, and returns it.
private func createWindow(withBaseConfig: Ghostty.SurfaceConfiguration?) -> TerminalController { private func createWindow(withBaseConfig base: Ghostty.SurfaceConfiguration?) -> TerminalController {
// Initialize our controller to load the window // Initialize our controller to load the window
let c = TerminalController(ghostty) let c = TerminalController(ghostty, withBaseConfig: base)
// Create a listener for when the window is closed so we can remove it. // Create a listener for when the window is closed so we can remove it.
let pubClose = NotificationCenter.default.publisher( let pubClose = NotificationCenter.default.publisher(

View File

@ -28,6 +28,9 @@ struct TerminalView: View {
// An optional delegate to receive information about terminal changes. // An optional delegate to receive information about terminal changes.
weak var delegate: TerminalViewDelegate? = nil weak var delegate: TerminalViewDelegate? = nil
// If this is set, this is the base configuration that we build our surface out of.
let baseConfig: Ghostty.SurfaceConfiguration?
// This seems like a crutch after switching from SwiftUI to AppKit lifecycle. // This seems like a crutch after switching from SwiftUI to AppKit lifecycle.
@FocusState private var focused: Bool @FocusState private var focused: Bool
@ -70,7 +73,7 @@ struct TerminalView: View {
DebugBuildWarningView() DebugBuildWarningView()
} }
Ghostty.TerminalSplit(onClose: onClose, baseConfig: nil) Ghostty.TerminalSplit(onClose: onClose, baseConfig: baseConfig)
.ghosttyApp(ghostty.app!) .ghosttyApp(ghostty.app!)
.ghosttyConfig(ghostty.config!) .ghosttyConfig(ghostty.config!)
.focused($focused) .focused($focused)