diff --git a/macos/Sources/Features/Terminal/TerminalToolbar.swift b/macos/Sources/Features/Terminal/TerminalToolbar.swift index 3f095294a..5b4760642 100644 --- a/macos/Sources/Features/Terminal/TerminalToolbar.swift +++ b/macos/Sources/Features/Terminal/TerminalToolbar.swift @@ -3,8 +3,8 @@ import Cocoa // Custom NSToolbar subclass that displays a centered window title, // in order to accommodate the titlebar tabs feature. class TerminalToolbar: NSToolbar, NSToolbarDelegate { - static private let identifier = NSToolbarItem.Identifier("TitleText") - private let titleTextField = NSTextField(labelWithString: "👻 Ghostty") + static private let identifier = NSToolbarItem.Identifier("TitleText") + private let titleTextField = NSTextField(labelWithString: "👻 Ghostty") var titleText: String { get { @@ -15,35 +15,35 @@ class TerminalToolbar: NSToolbar, NSToolbarDelegate { titleTextField.stringValue = newValue } } - - override init(identifier: NSToolbar.Identifier) { - super.init(identifier: identifier) + + override init(identifier: NSToolbar.Identifier) { + super.init(identifier: identifier) - delegate = self + delegate = self - if #available(macOS 13.0, *) { - centeredItemIdentifiers.insert(Self.identifier) - } else { - centeredItemIdentifier = Self.identifier - } - } - - func toolbar(_ toolbar: NSToolbar, - itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, + if #available(macOS 13.0, *) { + centeredItemIdentifiers.insert(Self.identifier) + } else { + centeredItemIdentifier = Self.identifier + } + } + + func toolbar(_ toolbar: NSToolbar, + itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { - guard itemIdentifier == Self.identifier else { return nil } - - let toolbarItem = NSToolbarItem(itemIdentifier: itemIdentifier) - toolbarItem.isEnabled = true - toolbarItem.view = self.titleTextField - return toolbarItem - } - - func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { - return [Self.identifier] - } - - func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { - return [Self.identifier] - } + guard itemIdentifier == Self.identifier else { return nil } + + let toolbarItem = NSToolbarItem(itemIdentifier: itemIdentifier) + toolbarItem.isEnabled = true + toolbarItem.view = self.titleTextField + return toolbarItem + } + + func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { + return [Self.identifier] + } + + func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { + return [Self.identifier] + } } diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index 77c08722c..c26b525eb 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -21,7 +21,7 @@ extension Ghostty { /// Return the errors found while loading the configuration. var errors: [String] { guard let cfg = self.config else { return [] } - + var errors: [String] = []; let errCount = ghostty_config_errors_count(cfg) for i in 0..? = nil @@ -164,7 +164,7 @@ extension Ghostty { guard let ptr = v else { return "" } return String(cString: ptr) } - + var windowDecorations: Bool { guard let config = self.config else { return true } var v = false; @@ -197,39 +197,39 @@ extension Ghostty { _ = ghostty_config_get(config, &v, key, UInt(key.count)) return v } - - var macosTitlebarTabs: Bool { - guard let config = self.config else { return false } - var v = false; - let key = "macos-titlebar-tabs" - _ = ghostty_config_get(config, &v, key, UInt(key.count)) - return v - } + + var macosTitlebarTabs: Bool { + guard let config = self.config else { return false } + var v = false; + let key = "macos-titlebar-tabs" + _ = ghostty_config_get(config, &v, key, UInt(key.count)) + return v + } var backgroundColor: Color { var rgb: UInt32 = 0 let bg_key = "background" if (!ghostty_config_get(config, &rgb, bg_key, UInt(bg_key.count))) { - #if os(macOS) +#if os(macOS) return Color(NSColor.windowBackgroundColor) - #elseif os(iOS) +#elseif os(iOS) return Color(UIColor.systemBackground) - #else - #error("unsupported") - #endif +#else +#error("unsupported") +#endif } let red = Double(rgb & 0xff) let green = Double((rgb >> 8) & 0xff) let blue = Double((rgb >> 16) & 0xff) - + return Color( red: red / 255, green: green / 255, blue: blue / 255 ) } - + var backgroundOpacity: Double { guard let config = self.config else { return 1 } var v: Double = 1 @@ -255,11 +255,11 @@ extension Ghostty { let bg_key = "background" _ = ghostty_config_get(config, &rgb, bg_key, UInt(bg_key.count)); } - + let red = Double(rgb & 0xff) let green = Double((rgb >> 8) & 0xff) let blue = Double((rgb >> 16) & 0xff) - + return Color( red: red / 255, green: green / 255,