mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fix(macOS): Restore custom titlebar background
Required for when a transparent background is used in conjunction with non-native fullscreen.
This commit is contained in:
@ -45,6 +45,10 @@ class TerminalWindow: NSWindow {
|
|||||||
self.toolbar = TerminalToolbar(identifier: "Toolbar")
|
self.toolbar = TerminalToolbar(identifier: "Toolbar")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set a custom background on the titlebar - this is required for when
|
||||||
|
// titlebar tabs is used in conjunction with a transparent background.
|
||||||
|
self.restoreTitlebarBackground()
|
||||||
|
|
||||||
// We have to wait before setting the titleVisibility or else it prevents
|
// We have to wait before setting the titleVisibility or else it prevents
|
||||||
// the window from hiding the tab bar when we get down to a single tab.
|
// the window from hiding the tab bar when we get down to a single tab.
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@ -61,8 +65,12 @@ class TerminalWindow: NSWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var storedTitlebarBackgroundColor: CGColor? = nil
|
||||||
|
|
||||||
// Assign a background color to the titlebar area.
|
// Assign a background color to the titlebar area.
|
||||||
func setTitlebarBackground(_ color: CGColor) {
|
func setTitlebarBackground(_ color: CGColor) {
|
||||||
|
storedTitlebarBackgroundColor = color
|
||||||
|
|
||||||
guard let titlebarContainer = contentView?.superview?.subviews.first(where: {
|
guard let titlebarContainer = contentView?.superview?.subviews.first(where: {
|
||||||
$0.className == "NSTitlebarContainerView"
|
$0.className == "NSTitlebarContainerView"
|
||||||
}) else { return }
|
}) else { return }
|
||||||
@ -71,6 +79,13 @@ class TerminalWindow: NSWindow {
|
|||||||
titlebarContainer.layer?.backgroundColor = color
|
titlebarContainer.layer?.backgroundColor = color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the titlebar has the assigned background color.
|
||||||
|
func restoreTitlebarBackground() {
|
||||||
|
guard let color = storedTitlebarBackgroundColor else { return }
|
||||||
|
|
||||||
|
setTitlebarBackground(color)
|
||||||
|
}
|
||||||
|
|
||||||
// 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