macos: move old toolbar into ventura file
parent
59812c3b02
commit
f7f0514b9f
|
|
@ -120,7 +120,6 @@
|
|||
A5E112972AF7401B00C6E0C2 /* ClipboardConfirmationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E112962AF7401B00C6E0C2 /* ClipboardConfirmationView.swift */; };
|
||||
A5FEB3002ABB69450068369E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FEB2FF2ABB69450068369E /* main.swift */; };
|
||||
AEE8B3452B9AA39600260C5E /* NSPasteboard+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE8B3442B9AA39600260C5E /* NSPasteboard+Extension.swift */; };
|
||||
AEF9CE242B6AD07A0017E195 /* TerminalToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */; };
|
||||
C159E81D2B66A06B00FDFE9C /* OSColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */; };
|
||||
C159E89D2B69A2EF00FDFE9C /* OSColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */; };
|
||||
C1F26EA72B738B9900404083 /* NSView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1F26EA62B738B9900404083 /* NSView+Extension.swift */; };
|
||||
|
|
@ -239,7 +238,6 @@
|
|||
A5E112962AF7401B00C6E0C2 /* ClipboardConfirmationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClipboardConfirmationView.swift; sourceTree = "<group>"; };
|
||||
A5FEB2FF2ABB69450068369E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||
AEE8B3442B9AA39600260C5E /* NSPasteboard+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSPasteboard+Extension.swift"; sourceTree = "<group>"; };
|
||||
AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalToolbar.swift; sourceTree = "<group>"; };
|
||||
C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OSColor+Extension.swift"; sourceTree = "<group>"; };
|
||||
C1F26EA62B738B9900404083 /* NSView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSView+Extension.swift"; sourceTree = "<group>"; };
|
||||
C1F26EE72B76CBFC00404083 /* VibrantLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VibrantLayer.h; sourceTree = "<group>"; };
|
||||
|
|
@ -507,7 +505,6 @@
|
|||
A596309B2AEE1C9E00D64628 /* TerminalController.swift */,
|
||||
A5D0AF3A2B36A1DE00D21823 /* TerminalRestorable.swift */,
|
||||
A596309D2AEE1D6C00D64628 /* TerminalView.swift */,
|
||||
AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */,
|
||||
A535B9D9299C569B0017E2E4 /* ErrorView.swift */,
|
||||
A54D786B2CA79788001B19B1 /* BaseTerminalController.swift */,
|
||||
);
|
||||
|
|
@ -799,7 +796,6 @@
|
|||
A596309E2AEE1D6C00D64628 /* TerminalView.swift in Sources */,
|
||||
A58636662DEF964100E04A10 /* TerminalSplitTreeView.swift in Sources */,
|
||||
A52FFF592CAA4FF3000C6A5B /* Fullscreen.swift in Sources */,
|
||||
AEF9CE242B6AD07A0017E195 /* TerminalToolbar.swift in Sources */,
|
||||
C159E81D2B66A06B00FDFE9C /* OSColor+Extension.swift in Sources */,
|
||||
A5CEAFDE29B8058B00646FDA /* SplitView.Divider.swift in Sources */,
|
||||
A5E112972AF7401B00C6E0C2 /* ClipboardConfirmationView.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -1,130 +0,0 @@
|
|||
import Cocoa
|
||||
|
||||
// Custom NSToolbar subclass that displays a centered window title,
|
||||
// in order to accommodate the titlebar tabs feature.
|
||||
class TerminalToolbar: NSToolbar, NSToolbarDelegate {
|
||||
private let titleTextField = CenteredDynamicLabel(labelWithString: "👻 Ghostty")
|
||||
|
||||
var titleText: String {
|
||||
get {
|
||||
titleTextField.stringValue
|
||||
}
|
||||
|
||||
set {
|
||||
titleTextField.stringValue = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var titleFont: NSFont? {
|
||||
get {
|
||||
titleTextField.font
|
||||
}
|
||||
|
||||
set {
|
||||
titleTextField.font = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var titleIsHidden: Bool {
|
||||
get {
|
||||
titleTextField.isHidden
|
||||
}
|
||||
|
||||
set {
|
||||
titleTextField.isHidden = newValue
|
||||
}
|
||||
}
|
||||
|
||||
override init(identifier: NSToolbar.Identifier) {
|
||||
super.init(identifier: identifier)
|
||||
|
||||
delegate = self
|
||||
centeredItemIdentifiers.insert(.titleText)
|
||||
}
|
||||
|
||||
func toolbar(_ toolbar: NSToolbar,
|
||||
itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
|
||||
willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
|
||||
var item: NSToolbarItem
|
||||
|
||||
switch itemIdentifier {
|
||||
case .titleText:
|
||||
item = NSToolbarItem(itemIdentifier: .titleText)
|
||||
item.view = self.titleTextField
|
||||
item.visibilityPriority = .user
|
||||
|
||||
// This ensures the title text field doesn't disappear when shrinking the view
|
||||
self.titleTextField.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.titleTextField.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||
self.titleTextField.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||
|
||||
// Add constraints to the toolbar item's view
|
||||
NSLayoutConstraint.activate([
|
||||
// Set the height constraint to match the toolbar's height
|
||||
self.titleTextField.heightAnchor.constraint(equalToConstant: 22), // Adjust as needed
|
||||
])
|
||||
|
||||
item.isEnabled = true
|
||||
case .resetZoom:
|
||||
item = NSToolbarItem(itemIdentifier: .resetZoom)
|
||||
default:
|
||||
item = NSToolbarItem(itemIdentifier: itemIdentifier)
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
return [.titleText, .flexibleSpace, .space, .resetZoom]
|
||||
}
|
||||
|
||||
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
// These space items are here to ensure that the title remains centered when it starts
|
||||
// getting smaller than the max size so starts clipping. Lucky for us, two of the
|
||||
// built-in spacers plus the un-zoom button item seems to exactly match the space
|
||||
// on the left that's reserved for the window buttons.
|
||||
return [.flexibleSpace, .titleText, .flexibleSpace]
|
||||
}
|
||||
}
|
||||
|
||||
/// A label that expands to fit whatever text you put in it and horizontally centers itself in the current window.
|
||||
fileprivate class CenteredDynamicLabel: NSTextField {
|
||||
override func viewDidMoveToSuperview() {
|
||||
// Configure the text field
|
||||
isEditable = false
|
||||
isBordered = false
|
||||
drawsBackground = false
|
||||
alignment = .center
|
||||
lineBreakMode = .byTruncatingTail
|
||||
cell?.truncatesLastVisibleLine = true
|
||||
|
||||
// Use Auto Layout
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
// Set content hugging and compression resistance priorities
|
||||
setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||
setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||
}
|
||||
|
||||
// Vertically center the text
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
guard let attributedString = self.attributedStringValue.mutableCopy() as? NSMutableAttributedString else {
|
||||
super.draw(dirtyRect)
|
||||
return
|
||||
}
|
||||
|
||||
let textSize = attributedString.size()
|
||||
|
||||
let yOffset = (self.bounds.height - textSize.height) / 2 - 1 // -1 to center it better
|
||||
|
||||
let centeredRect = NSRect(x: self.bounds.origin.x, y: self.bounds.origin.y + yOffset,
|
||||
width: self.bounds.width, height: textSize.height)
|
||||
|
||||
attributedString.draw(in: centeredRect)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSToolbarItem.Identifier {
|
||||
static let resetZoom = NSToolbarItem.Identifier("ResetZoom")
|
||||
static let titleText = NSToolbarItem.Identifier("TitleText")
|
||||
}
|
||||
|
|
@ -609,3 +609,134 @@ fileprivate class WindowButtonsBackdropView: NSView {
|
|||
layer?.addSublayer(overlayLayer)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Toolbar
|
||||
|
||||
// Custom NSToolbar subclass that displays a centered window title,
|
||||
// in order to accommodate the titlebar tabs feature.
|
||||
fileprivate class TerminalToolbar: NSToolbar, NSToolbarDelegate {
|
||||
private let titleTextField = CenteredDynamicLabel(labelWithString: "👻 Ghostty")
|
||||
|
||||
var titleText: String {
|
||||
get {
|
||||
titleTextField.stringValue
|
||||
}
|
||||
|
||||
set {
|
||||
titleTextField.stringValue = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var titleFont: NSFont? {
|
||||
get {
|
||||
titleTextField.font
|
||||
}
|
||||
|
||||
set {
|
||||
titleTextField.font = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var titleIsHidden: Bool {
|
||||
get {
|
||||
titleTextField.isHidden
|
||||
}
|
||||
|
||||
set {
|
||||
titleTextField.isHidden = newValue
|
||||
}
|
||||
}
|
||||
|
||||
override init(identifier: NSToolbar.Identifier) {
|
||||
super.init(identifier: identifier)
|
||||
|
||||
delegate = self
|
||||
centeredItemIdentifiers.insert(.titleText)
|
||||
}
|
||||
|
||||
func toolbar(_ toolbar: NSToolbar,
|
||||
itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
|
||||
willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
|
||||
var item: NSToolbarItem
|
||||
|
||||
switch itemIdentifier {
|
||||
case .titleText:
|
||||
item = NSToolbarItem(itemIdentifier: .titleText)
|
||||
item.view = self.titleTextField
|
||||
item.visibilityPriority = .user
|
||||
|
||||
// This ensures the title text field doesn't disappear when shrinking the view
|
||||
self.titleTextField.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.titleTextField.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||
self.titleTextField.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||
|
||||
// Add constraints to the toolbar item's view
|
||||
NSLayoutConstraint.activate([
|
||||
// Set the height constraint to match the toolbar's height
|
||||
self.titleTextField.heightAnchor.constraint(equalToConstant: 22), // Adjust as needed
|
||||
])
|
||||
|
||||
item.isEnabled = true
|
||||
case .resetZoom:
|
||||
item = NSToolbarItem(itemIdentifier: .resetZoom)
|
||||
default:
|
||||
item = NSToolbarItem(itemIdentifier: itemIdentifier)
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
return [.titleText, .flexibleSpace, .space, .resetZoom]
|
||||
}
|
||||
|
||||
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
||||
// These space items are here to ensure that the title remains centered when it starts
|
||||
// getting smaller than the max size so starts clipping. Lucky for us, two of the
|
||||
// built-in spacers plus the un-zoom button item seems to exactly match the space
|
||||
// on the left that's reserved for the window buttons.
|
||||
return [.flexibleSpace, .titleText, .flexibleSpace]
|
||||
}
|
||||
}
|
||||
|
||||
/// A label that expands to fit whatever text you put in it and horizontally centers itself in the current window.
|
||||
fileprivate class CenteredDynamicLabel: NSTextField {
|
||||
override func viewDidMoveToSuperview() {
|
||||
// Configure the text field
|
||||
isEditable = false
|
||||
isBordered = false
|
||||
drawsBackground = false
|
||||
alignment = .center
|
||||
lineBreakMode = .byTruncatingTail
|
||||
cell?.truncatesLastVisibleLine = true
|
||||
|
||||
// Use Auto Layout
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
// Set content hugging and compression resistance priorities
|
||||
setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||
setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||
}
|
||||
|
||||
// Vertically center the text
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
guard let attributedString = self.attributedStringValue.mutableCopy() as? NSMutableAttributedString else {
|
||||
super.draw(dirtyRect)
|
||||
return
|
||||
}
|
||||
|
||||
let textSize = attributedString.size()
|
||||
|
||||
let yOffset = (self.bounds.height - textSize.height) / 2 - 1 // -1 to center it better
|
||||
|
||||
let centeredRect = NSRect(x: self.bounds.origin.x, y: self.bounds.origin.y + yOffset,
|
||||
width: self.bounds.width, height: textSize.height)
|
||||
|
||||
attributedString.draw(in: centeredRect)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSToolbarItem.Identifier {
|
||||
static let resetZoom = NSToolbarItem.Identifier("ResetZoom")
|
||||
static let titleText = NSToolbarItem.Identifier("TitleText")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue