Reworked proxy icon, added config options.

This commit is contained in:
johnseth97
2024-10-24 21:54:08 -04:00
parent 93f70ce237
commit 8e223fdcd9
4 changed files with 37 additions and 2 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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<ViewModel: TerminalViewModel>: 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<ViewModel: TerminalViewModel>: 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)

View File

@ -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<Int8>? = 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 }