From 8e223fdcd985db79d966b7fa2d1334c20c404f0f Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 21:54:08 -0400 Subject: [PATCH] Reworked proxy icon, added config options. --- .../Terminal/BaseTerminalController.swift | 8 +++++++- .../Features/Terminal/TerminalController.swift | 4 ++++ .../Features/Terminal/TerminalView.swift | 17 ++++++++++++++++- macos/Sources/Ghostty/Ghostty.Config.swift | 10 ++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 96c9188a7..f67fe83cc 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -236,8 +236,14 @@ class BaseTerminalController: NSWindowController, // Set the main window title window.title = to + } + + func proxyIconURLDidChange(to: URL?){ + + guard let window else { return } + // Get the current working directory from the focused surface - if let pwd = focusedSurface?.pwd { + if ghostty.config.macosTitlebarProxyIcon == "visible", let pwd = focusedSurface?.pwd { // Set the window's representedURL to the current working directory window.representedURL = URL(fileURLWithPath: pwd) } else { diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 0b1ff3b72..8a7d0fdeb 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -307,6 +307,10 @@ class TerminalController: BaseTerminalController { window.standardWindowButton(.closeButton)?.isHidden = true window.standardWindowButton(.miniaturizeButton)?.isHidden = true window.standardWindowButton(.zoomButton)?.isHidden = true + + // Hide document icon button(proxy icon) + window.representedURL = nil + window.standardWindowButton(.documentIconButton)?.isHidden = true // Disallow tabbing if the titlebar is hidden, since that will (should) also hide the tab bar. window.tabbingMode = .disallowed diff --git a/macos/Sources/Features/Terminal/TerminalView.swift b/macos/Sources/Features/Terminal/TerminalView.swift index ec7d7c229..62411a23a 100644 --- a/macos/Sources/Features/Terminal/TerminalView.swift +++ b/macos/Sources/Features/Terminal/TerminalView.swift @@ -10,6 +10,9 @@ protocol TerminalViewDelegate: AnyObject { /// The title of the terminal should change. func titleDidChange(to: String) + + /// The URL of the proxy icon should change. + func proxyIconURLDidChange(to: URL?) /// The cell size changed. func cellSizeDidChange(to: NSSize) @@ -62,7 +65,15 @@ struct TerminalView: View { return title } - + + // The proxy icon URL for our window + private var proxyIconURL: URL? { + guard let proxyURLString = focusedSurface?.pwd else { + return nil + } + return URL(string: proxyURLString) + } + var body: some View { switch ghostty.readiness { case .loading: @@ -87,6 +98,10 @@ struct TerminalView: View { .onChange(of: title) { newValue in self.delegate?.titleDidChange(to: newValue) } + .onChange(of: proxyIconURL) { newValue in + self.delegate?.proxyIconURLDidChange(to: newValue) + + } .onChange(of: cellSize) { newValue in guard let size = newValue else { return } self.delegate?.cellSizeDidChange(to: size) diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index 29639c39e..b4342be8e 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -228,6 +228,16 @@ extension Ghostty { guard let ptr = v else { return defaultValue } return String(cString: ptr) } + + var macosTitlebarProxyIcon: String { + let defaultValue = "visible" + guard let config = self.config else { return defaultValue } + var v: UnsafePointer? = nil + let key = "macos-titlebar-proxy-icon" + guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return defaultValue } + guard let ptr = v else { return defaultValue } + return String(cString: ptr) + } var macosWindowShadow: Bool { guard let config = self.config else { return false }