From 93f70ce237e369e67ff5fed59a111ea86034b8d6 Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 21:52:13 -0400 Subject: [PATCH 01/10] added macos-titlebar-proxy-icon to config --- src/config/Config.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/config/Config.zig b/src/config/Config.zig index 9097051ad..05e1255c0 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1444,6 +1444,11 @@ keybind: Keybinds = .{}, /// Changing this option at runtime only applies to new windows. @"macos-titlebar-style": MacTitlebarStyle = .transparent, +/// State of the proxy icon for the macOS titlebar. +/// The "hidden" style hides the proxy icon. +/// The default value is "visible". +@"macos-titlebar-proxy-icon": MacTitlebarProxyIcon = .visible, + /// If `true`, the *Option* key will be treated as *Alt*. This makes terminal /// sequences expecting *Alt* to work properly, but will break Unicode input /// sequences on macOS if you use them via the *Alt* key. You may set this to @@ -4430,6 +4435,12 @@ pub const MacTitlebarStyle = enum { hidden, }; +/// See macos-titlebar-proxy-icon +pub const MacTitlebarProxyIcon: type = enum { + visible, + hidden, +}; + /// See gtk-single-instance pub const GtkSingleInstance = enum { desktop, 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 02/10] 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 } From 7301afa83e26dcce9843531f6bc0f3563d9af45e Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 22:12:29 -0400 Subject: [PATCH 03/10] Removed uneeded code --- macos/Sources/Features/Terminal/TerminalController.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 8a7d0fdeb..0b1ff3b72 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -307,10 +307,6 @@ 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 From fc094ee9249f407343cb1509a104dfe4816ed18b Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 22:15:31 -0400 Subject: [PATCH 04/10] Fixed formatting --- macos/Sources/Features/Terminal/TerminalView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/macos/Sources/Features/Terminal/TerminalView.swift b/macos/Sources/Features/Terminal/TerminalView.swift index 62411a23a..d24dbaecc 100644 --- a/macos/Sources/Features/Terminal/TerminalView.swift +++ b/macos/Sources/Features/Terminal/TerminalView.swift @@ -100,7 +100,6 @@ struct TerminalView: View { } .onChange(of: proxyIconURL) { newValue in self.delegate?.proxyIconURLDidChange(to: newValue) - } .onChange(of: cellSize) { newValue in guard let size = newValue else { return } From f78ddabc15000ee24a5593e8cca1dc4511e70752 Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:01:54 -0400 Subject: [PATCH 05/10] refactored proxyIconURLDidChange to pwdDidChange --- .../Sources/Features/Terminal/BaseTerminalController.swift | 2 +- macos/Sources/Features/Terminal/TerminalView.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index f67fe83cc..5d0d11fef 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -238,7 +238,7 @@ class BaseTerminalController: NSWindowController, } - func proxyIconURLDidChange(to: URL?){ + func pwdDidChange(to: URL?){ guard let window else { return } diff --git a/macos/Sources/Features/Terminal/TerminalView.swift b/macos/Sources/Features/Terminal/TerminalView.swift index d24dbaecc..633ed5989 100644 --- a/macos/Sources/Features/Terminal/TerminalView.swift +++ b/macos/Sources/Features/Terminal/TerminalView.swift @@ -11,8 +11,8 @@ 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 URL of the pwd should change. + func pwdDidChange(to: URL?) /// The cell size changed. func cellSizeDidChange(to: NSSize) @@ -99,7 +99,7 @@ struct TerminalView: View { self.delegate?.titleDidChange(to: newValue) } .onChange(of: proxyIconURL) { newValue in - self.delegate?.proxyIconURLDidChange(to: newValue) + self.delegate?.pwdDidChange(to: newValue) } .onChange(of: cellSize) { newValue in guard let size = newValue else { return } From c3efda93f4f42d3d8be1223d28a9b11c37559ef6 Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:02:50 -0400 Subject: [PATCH 06/10] Converted config declaration to an enum --- macos/Sources/Ghostty/Ghostty.Config.swift | 7 ++++--- macos/Sources/Ghostty/Package.swift | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index b4342be8e..ae6069525 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -229,14 +229,15 @@ extension Ghostty { return String(cString: ptr) } - var macosTitlebarProxyIcon: String { - let defaultValue = "visible" + var macosTitlebarProxyIcon: Ghostty.MacOSTitlebarProxyIcon { + let defaultValue = Ghostty.MacOSTitlebarProxyIcon.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) + let str = String(cString: ptr) + return Ghostty.MacOSTitlebarProxyIcon(rawValue: str) ?? defaultValue } var macosWindowShadow: Bool { diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index f6fab532e..25d012ec5 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -194,6 +194,13 @@ extension Ghostty { } } } + + /// Enum for the macos-titlebar-proxy-icon config option + enum MacOSTitlebarProxyIcon: String { + case visible + case hidden + } + } // MARK: Surface Notifications From 6c37fe2c264befe695d1db8feb908c56cfdc5b39 Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:06:18 -0400 Subject: [PATCH 07/10] Fixed conversion error between string and enum --- macos/Sources/Features/Terminal/BaseTerminalController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 5d0d11fef..bdbd9c989 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -243,7 +243,7 @@ class BaseTerminalController: NSWindowController, guard let window else { return } // Get the current working directory from the focused surface - if ghostty.config.macosTitlebarProxyIcon == "visible", 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 { From e11fb62627fda96e92557afdb307a9f9b766832f Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:47:34 -0400 Subject: [PATCH 08/10] Fixed type conversion garbage --- .../Features/Terminal/BaseTerminalController.swift | 12 +++++------- macos/Sources/Features/Terminal/TerminalView.swift | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index bdbd9c989..6e4807c1a 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -238,20 +238,18 @@ class BaseTerminalController: NSWindowController, } - func pwdDidChange(to: URL?){ - + func pwdDidChange(to: URL?) { guard let window else { return } - // Get the current working directory from the focused surface - if ghostty.config.macosTitlebarProxyIcon == .visible, let pwd = focusedSurface?.pwd { - // Set the window's representedURL to the current working directory - window.representedURL = URL(fileURLWithPath: pwd) + if ghostty.config.macosTitlebarProxyIcon == .visible { + // Use the 'to' URL directly + window.representedURL = to } else { - // If we don't have a pwd, set representedURL to nil window.representedURL = nil } } + func cellSizeDidChange(to: NSSize) { guard ghostty.config.windowStepResize else { return } self.window?.contentResizeIncrements = to diff --git a/macos/Sources/Features/Terminal/TerminalView.swift b/macos/Sources/Features/Terminal/TerminalView.swift index 633ed5989..768f57d30 100644 --- a/macos/Sources/Features/Terminal/TerminalView.swift +++ b/macos/Sources/Features/Terminal/TerminalView.swift @@ -71,7 +71,8 @@ struct TerminalView: View { guard let proxyURLString = focusedSurface?.pwd else { return nil } - return URL(string: proxyURLString) + // Use fileURLWithPath initializer for file paths + return URL(fileURLWithPath: proxyURLString) } var body: some View { From 495925355a9472f3ac05766dbb83f4f5a8626e1c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 24 Oct 2024 20:56:33 -0700 Subject: [PATCH 09/10] config: make the proxy icon documentation more detailed --- macos/Sources/Ghostty/Ghostty.Config.swift | 6 +++--- src/config/Config.zig | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index ae6069525..6e961b31c 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -229,15 +229,15 @@ extension Ghostty { return String(cString: ptr) } - var macosTitlebarProxyIcon: Ghostty.MacOSTitlebarProxyIcon { - let defaultValue = Ghostty.MacOSTitlebarProxyIcon.visible + var macosTitlebarProxyIcon: MacOSTitlebarProxyIcon { + let defaultValue = MacOSTitlebarProxyIcon.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 } let str = String(cString: ptr) - return Ghostty.MacOSTitlebarProxyIcon(rawValue: str) ?? defaultValue + return MacOSTitlebarProxyIcon(rawValue: str) ?? defaultValue } var macosWindowShadow: Bool { diff --git a/src/config/Config.zig b/src/config/Config.zig index 05e1255c0..6dec34dfc 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1444,9 +1444,20 @@ keybind: Keybinds = .{}, /// Changing this option at runtime only applies to new windows. @"macos-titlebar-style": MacTitlebarStyle = .transparent, -/// State of the proxy icon for the macOS titlebar. -/// The "hidden" style hides the proxy icon. -/// The default value is "visible". +/// Whether the proxy icon in the macOS titlebar is visible. The proxy icon +/// is the icon that represents the folder of the current working directory. +/// You can see this very clearly in the macOS built-in Terminal.app +/// titlebar. +/// +/// The proxy icon is only visible with the native macOS titlebar style. +/// +/// The default value is `visible`. +/// +/// This setting can be changed at runtime and will affect all currently +/// open windows but only after their working directory changes again. +/// Therefore, to make this work after changing the setting, you must +/// usually `cd` to a different directory, open a different file in an +/// editor, etc. @"macos-titlebar-proxy-icon": MacTitlebarProxyIcon = .visible, /// If `true`, the *Option* key will be treated as *Alt*. This makes terminal From 67bc9fa0bc7eea61c206aa63b191f68b8989aa0f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 24 Oct 2024 21:06:32 -0700 Subject: [PATCH 10/10] macos: nuke the titlebar from orbit when hidden --- .../Features/Terminal/BaseTerminalController.swift | 4 ++-- macos/Sources/Features/Terminal/TerminalController.swift | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 6e4807c1a..432345627 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -235,12 +235,12 @@ class BaseTerminalController: NSWindowController, // Set the main window title window.title = to - + } func pwdDidChange(to: URL?) { guard let window else { return } - + if ghostty.config.macosTitlebarProxyIcon == .visible { // Use the 'to' URL directly window.representedURL = to diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 0b1ff3b72..c22ac7042 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -310,6 +310,14 @@ class TerminalController: BaseTerminalController { // Disallow tabbing if the titlebar is hidden, since that will (should) also hide the tab bar. window.tabbingMode = .disallowed + + // Nuke it from orbit -- hide the titlebar container entirely, just in case. There are + // some operations that appear to bring back the titlebar visibility so this ensures + // it is gone forever. + if let themeFrame = window.contentView?.superview, + let titleBarContainer = themeFrame.firstDescendant(withClassName: "NSTitlebarContainerView") { + titleBarContainer.isHidden = true + } } // In various situations, macOS automatically tabs new windows. Ghostty handles