mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-05-28 19:18:45 +03:00
Merge pull request #2492 from johnseth97/macos-proxy-icon-fix
Macos proxy icon fix
This commit is contained in:
@ -236,16 +236,20 @@ class BaseTerminalController: NSWindowController,
|
|||||||
// Set the main window title
|
// Set the main window title
|
||||||
window.title = to
|
window.title = to
|
||||||
|
|
||||||
// Get the current working directory from the focused surface
|
}
|
||||||
if let pwd = focusedSurface?.pwd {
|
|
||||||
// Set the window's representedURL to the current working directory
|
func pwdDidChange(to: URL?) {
|
||||||
window.representedURL = URL(fileURLWithPath: pwd)
|
guard let window else { return }
|
||||||
|
|
||||||
|
if ghostty.config.macosTitlebarProxyIcon == .visible {
|
||||||
|
// Use the 'to' URL directly
|
||||||
|
window.representedURL = to
|
||||||
} else {
|
} else {
|
||||||
// If we don't have a pwd, set representedURL to nil
|
|
||||||
window.representedURL = nil
|
window.representedURL = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func cellSizeDidChange(to: NSSize) {
|
func cellSizeDidChange(to: NSSize) {
|
||||||
guard ghostty.config.windowStepResize else { return }
|
guard ghostty.config.windowStepResize else { return }
|
||||||
self.window?.contentResizeIncrements = to
|
self.window?.contentResizeIncrements = to
|
||||||
|
@ -310,6 +310,14 @@ class TerminalController: BaseTerminalController {
|
|||||||
|
|
||||||
// Disallow tabbing if the titlebar is hidden, since that will (should) also hide the tab bar.
|
// Disallow tabbing if the titlebar is hidden, since that will (should) also hide the tab bar.
|
||||||
window.tabbingMode = .disallowed
|
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
|
// In various situations, macOS automatically tabs new windows. Ghostty handles
|
||||||
|
@ -11,6 +11,9 @@ protocol TerminalViewDelegate: AnyObject {
|
|||||||
/// The title of the terminal should change.
|
/// The title of the terminal should change.
|
||||||
func titleDidChange(to: String)
|
func titleDidChange(to: String)
|
||||||
|
|
||||||
|
/// The URL of the pwd should change.
|
||||||
|
func pwdDidChange(to: URL?)
|
||||||
|
|
||||||
/// The cell size changed.
|
/// The cell size changed.
|
||||||
func cellSizeDidChange(to: NSSize)
|
func cellSizeDidChange(to: NSSize)
|
||||||
|
|
||||||
@ -63,6 +66,15 @@ struct TerminalView<ViewModel: TerminalViewModel>: View {
|
|||||||
return title
|
return title
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The proxy icon URL for our window
|
||||||
|
private var proxyIconURL: URL? {
|
||||||
|
guard let proxyURLString = focusedSurface?.pwd else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Use fileURLWithPath initializer for file paths
|
||||||
|
return URL(fileURLWithPath: proxyURLString)
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
switch ghostty.readiness {
|
switch ghostty.readiness {
|
||||||
case .loading:
|
case .loading:
|
||||||
@ -87,6 +99,9 @@ struct TerminalView<ViewModel: TerminalViewModel>: View {
|
|||||||
.onChange(of: title) { newValue in
|
.onChange(of: title) { newValue in
|
||||||
self.delegate?.titleDidChange(to: newValue)
|
self.delegate?.titleDidChange(to: newValue)
|
||||||
}
|
}
|
||||||
|
.onChange(of: proxyIconURL) { newValue in
|
||||||
|
self.delegate?.pwdDidChange(to: newValue)
|
||||||
|
}
|
||||||
.onChange(of: cellSize) { newValue in
|
.onChange(of: cellSize) { newValue in
|
||||||
guard let size = newValue else { return }
|
guard let size = newValue else { return }
|
||||||
self.delegate?.cellSizeDidChange(to: size)
|
self.delegate?.cellSizeDidChange(to: size)
|
||||||
|
@ -229,6 +229,17 @@ extension Ghostty {
|
|||||||
return String(cString: ptr)
|
return String(cString: ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var macosTitlebarProxyIcon: MacOSTitlebarProxyIcon {
|
||||||
|
let defaultValue = MacOSTitlebarProxyIcon.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 }
|
||||||
|
let str = String(cString: ptr)
|
||||||
|
return MacOSTitlebarProxyIcon(rawValue: str) ?? defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
var macosWindowShadow: Bool {
|
var macosWindowShadow: Bool {
|
||||||
guard let config = self.config else { return false }
|
guard let config = self.config else { return false }
|
||||||
var v = false;
|
var v = false;
|
||||||
|
@ -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
|
// MARK: Surface Notifications
|
||||||
|
@ -1444,6 +1444,22 @@ keybind: Keybinds = .{},
|
|||||||
/// Changing this option at runtime only applies to new windows.
|
/// Changing this option at runtime only applies to new windows.
|
||||||
@"macos-titlebar-style": MacTitlebarStyle = .transparent,
|
@"macos-titlebar-style": MacTitlebarStyle = .transparent,
|
||||||
|
|
||||||
|
/// 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
|
/// 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 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
|
/// sequences on macOS if you use them via the *Alt* key. You may set this to
|
||||||
@ -4430,6 +4446,12 @@ pub const MacTitlebarStyle = enum {
|
|||||||
hidden,
|
hidden,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// See macos-titlebar-proxy-icon
|
||||||
|
pub const MacTitlebarProxyIcon: type = enum {
|
||||||
|
visible,
|
||||||
|
hidden,
|
||||||
|
};
|
||||||
|
|
||||||
/// See gtk-single-instance
|
/// See gtk-single-instance
|
||||||
pub const GtkSingleInstance = enum {
|
pub const GtkSingleInstance = enum {
|
||||||
desktop,
|
desktop,
|
||||||
|
Reference in New Issue
Block a user