mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: minor edits
This commit is contained in:
@ -484,11 +484,13 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
|||||||
func titleDidChange(to: String) {
|
func titleDidChange(to: String) {
|
||||||
guard let window = window as? TerminalWindow else { return }
|
guard let window = window as? TerminalWindow else { return }
|
||||||
|
|
||||||
|
// Set the main window title
|
||||||
window.title = to
|
window.title = to
|
||||||
|
|
||||||
// Custom toolbar-based title used when titlebar tabs are enabled.
|
// Custom toolbar-based title used when titlebar tabs are enabled.
|
||||||
guard let toolbar = window.toolbar as? TerminalToolbar else { return }
|
if let toolbar = window.toolbar as? TerminalToolbar {
|
||||||
toolbar.setTitleText(to)
|
toolbar.titleText = to
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cellSizeDidChange(to: NSSize) {
|
func cellSizeDidChange(to: NSSize) {
|
||||||
|
@ -1,44 +1,49 @@
|
|||||||
|
import Cocoa
|
||||||
|
|
||||||
// Custom NSToolbar subclass that displays a centered window title,
|
// Custom NSToolbar subclass that displays a centered window title,
|
||||||
// in order to accommodate the titlebar tabs feature.
|
// in order to accommodate the titlebar tabs feature.
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import Cocoa
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
class TerminalToolbar: NSToolbar, NSToolbarDelegate {
|
class TerminalToolbar: NSToolbar, NSToolbarDelegate {
|
||||||
static private let TitleIdentifier = NSToolbarItem.Identifier("TitleText")
|
static private let identifier = NSToolbarItem.Identifier("TitleText")
|
||||||
private let TitleTextField = NSTextField(
|
private let titleTextField = NSTextField(labelWithString: "👻 Ghostty")
|
||||||
labelWithString: "👻 Ghostty"
|
|
||||||
)
|
var titleText: String {
|
||||||
|
get {
|
||||||
func setTitleText(_ text: String) {
|
titleTextField.stringValue
|
||||||
self.TitleTextField.stringValue = text
|
}
|
||||||
}
|
|
||||||
|
set {
|
||||||
|
titleTextField.stringValue = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override init(identifier: NSToolbar.Identifier) {
|
override init(identifier: NSToolbar.Identifier) {
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
|
|
||||||
delegate = self
|
delegate = self
|
||||||
|
|
||||||
if #available(macOS 13.0, *) {
|
if #available(macOS 13.0, *) {
|
||||||
centeredItemIdentifiers.insert(Self.TitleIdentifier)
|
centeredItemIdentifiers.insert(Self.identifier)
|
||||||
} else {
|
} else {
|
||||||
centeredItemIdentifier = Self.TitleIdentifier
|
centeredItemIdentifier = Self.identifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
|
func toolbar(_ toolbar: NSToolbar,
|
||||||
guard itemIdentifier == Self.TitleIdentifier else { return nil }
|
itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
|
||||||
|
willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
|
||||||
|
guard itemIdentifier == Self.identifier else { return nil }
|
||||||
|
|
||||||
let toolbarItem = NSToolbarItem(itemIdentifier: itemIdentifier)
|
let toolbarItem = NSToolbarItem(itemIdentifier: itemIdentifier)
|
||||||
toolbarItem.isEnabled = true
|
toolbarItem.isEnabled = true
|
||||||
toolbarItem.view = self.TitleTextField
|
toolbarItem.view = self.titleTextField
|
||||||
return toolbarItem
|
return toolbarItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||||
return [Self.TitleIdentifier]
|
return [Self.identifier]
|
||||||
}
|
}
|
||||||
|
|
||||||
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||||
return [Self.TitleIdentifier]
|
return [Self.identifier]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,21 @@ class TerminalWindow: NSWindow {
|
|||||||
if (self.toolbar == nil) {
|
if (self.toolbar == nil) {
|
||||||
self.toolbar = TerminalToolbar(identifier: "Toolbar")
|
self.toolbar = TerminalToolbar(identifier: "Toolbar")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We directly hide the view containing the title text because if we use the
|
// We directly hide the view containing the title text because if we use the
|
||||||
// `titleVisibility` property for this it prevents the window from hiding the
|
// `titleVisibility` property for this it prevents the window from hiding the
|
||||||
// tab bar when we get down to a single tab.
|
// tab bar when we get down to a single tab.
|
||||||
self.hideTitleText()
|
if let toolbarTitleView = contentView?.superview?.subviews.first(where: {
|
||||||
|
$0.className == "NSTitlebarContainerView"
|
||||||
|
})?.subviews.first(where: {
|
||||||
|
$0.className == "NSTitlebarView"
|
||||||
|
})?.subviews.first(where: {
|
||||||
|
$0.className == "NSToolbarView"
|
||||||
|
})?.subviews.first(where: {
|
||||||
|
$0.className == "NSToolbarTitleView"
|
||||||
|
}) {
|
||||||
|
toolbarTitleView.isHidden = true
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// "expanded" places the toolbar below the titlebar, so setting this style and
|
// "expanded" places the toolbar below the titlebar, so setting this style and
|
||||||
// removing the toolbar ensures that the titlebar will be the default height.
|
// removing the toolbar ensures that the titlebar will be the default height.
|
||||||
@ -66,21 +77,6 @@ class TerminalWindow: NSWindow {
|
|||||||
titlebarContainer.layer?.backgroundColor = color
|
titlebarContainer.layer?.backgroundColor = color
|
||||||
}
|
}
|
||||||
|
|
||||||
// Directly hide the view containing the title text
|
|
||||||
func hideTitleText() {
|
|
||||||
guard let toolbarTitleView = contentView?.superview?.subviews.first(where: {
|
|
||||||
$0.className == "NSTitlebarContainerView"
|
|
||||||
})?.subviews.first(where: {
|
|
||||||
$0.className == "NSTitlebarView"
|
|
||||||
})?.subviews.first(where: {
|
|
||||||
$0.className == "NSToolbarView"
|
|
||||||
})?.subviews.first(where: {
|
|
||||||
$0.className == "NSToolbarTitleView"
|
|
||||||
}) else { return }
|
|
||||||
|
|
||||||
toolbarTitleView.isHidden = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is called by macOS for native tabbing in order to add the tab bar. We hook into
|
// This is called by macOS for native tabbing in order to add the tab bar. We hook into
|
||||||
// this, detect the tab bar being added, and override its behavior.
|
// this, detect the tab bar being added, and override its behavior.
|
||||||
override func addTitlebarAccessoryViewController(_ childViewController: NSTitlebarAccessoryViewController) {
|
override func addTitlebarAccessoryViewController(_ childViewController: NSTitlebarAccessoryViewController) {
|
||||||
|
Reference in New Issue
Block a user