mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
59 lines
1.8 KiB
Swift
59 lines
1.8 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
class TabsTitlebarTerminalWindow: TerminalWindow, NSToolbarDelegate {
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
|
|
// We must hide the title since we're going to be moving tabs into
|
|
// the titlebar which have their own title.
|
|
titleVisibility = .hidden
|
|
|
|
// Create a toolbar
|
|
let toolbar = NSToolbar(identifier: "TerminalToolbar")
|
|
toolbar.delegate = self
|
|
toolbar.centeredItemIdentifiers.insert(.title)
|
|
self.toolbar = toolbar
|
|
//toolbarStyle = .unifiedCompact
|
|
}
|
|
|
|
// MARK: NSToolbarDelegate
|
|
|
|
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
|
return [.title, .flexibleSpace, .space]
|
|
}
|
|
|
|
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
|
|
return [.flexibleSpace, .title, .flexibleSpace]
|
|
}
|
|
|
|
func toolbar(_ toolbar: NSToolbar,
|
|
itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
|
|
willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
|
|
switch itemIdentifier {
|
|
case .title:
|
|
let item = NSToolbarItem(itemIdentifier: .title)
|
|
item.view = NSHostingView(rootView: TitleItem())
|
|
item.visibilityPriority = .user
|
|
item.isEnabled = true
|
|
return item
|
|
default:
|
|
return NSToolbarItem(itemIdentifier: itemIdentifier)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension NSToolbarItem.Identifier {
|
|
/// Displays the title of the window
|
|
static let title = NSToolbarItem.Identifier("Title")
|
|
}
|
|
|
|
extension TabsTitlebarTerminalWindow {
|
|
struct TitleItem: View {
|
|
var body: some View {
|
|
Text("HELLO THIS IS A PRETTY LONG TITLE")
|
|
}
|
|
}
|
|
}
|