mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-05-31 23:25:20 +00:00
Merge pull request #1471 from qwerasd205/macos-fix-transparent-titlebar
(macOS) Fix a couple transparent window + titlebar tabs bugs
This commit is contained in:
commit
ae09a98ffe
@ -140,6 +140,18 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
||||
}
|
||||
}
|
||||
|
||||
private func fixTabBar() {
|
||||
// We do this to make sure that the tab bar will always re-composite. If we don't,
|
||||
// then the it will "drag" pieces of the background with it when a transparent
|
||||
// window is moved around.
|
||||
//
|
||||
// There might be a better way to make the tab bar "un-lazy", but I can't find it.
|
||||
if let window = window, !window.isOpaque {
|
||||
window.isOpaque = true
|
||||
window.isOpaque = false
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func onFrameDidChange(_ notification: NSNotification) {
|
||||
// This is a huge hack to set the proper shortcut for tab selection
|
||||
// on tab reordering using the mouse. There is no event, delegate, etc.
|
||||
@ -335,6 +347,11 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
||||
|
||||
func windowDidBecomeKey(_ notification: Notification) {
|
||||
self.relabelTabs()
|
||||
self.fixTabBar()
|
||||
}
|
||||
|
||||
func windowDidMove(_ notification: Notification) {
|
||||
self.fixTabBar()
|
||||
}
|
||||
|
||||
// Called when the window will be encoded. We handle the data encoding here in the
|
||||
|
@ -29,6 +29,7 @@ class TerminalWindow: NSWindow {
|
||||
|
||||
private var windowButtonsBackdrop: NSView? = nil
|
||||
private var windowDragHandle: WindowDragView? = nil
|
||||
private var storedTitlebarBackgroundColor: CGColor? = nil
|
||||
|
||||
// The tab bar controller ID from macOS
|
||||
static private let TabBarController = NSUserInterfaceItemIdentifier("_tabBarController")
|
||||
@ -45,6 +46,10 @@ class TerminalWindow: NSWindow {
|
||||
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
|
||||
// the window from hiding the tab bar when we get down to a single tab.
|
||||
DispatchQueue.main.async {
|
||||
@ -63,6 +68,8 @@ class TerminalWindow: NSWindow {
|
||||
|
||||
// Assign a background color to the titlebar area.
|
||||
func setTitlebarBackground(_ color: CGColor) {
|
||||
storedTitlebarBackgroundColor = color
|
||||
|
||||
guard let titlebarContainer = contentView?.superview?.subviews.first(where: {
|
||||
$0.className == "NSTitlebarContainerView"
|
||||
}) else { return }
|
||||
@ -71,6 +78,12 @@ class TerminalWindow: NSWindow {
|
||||
titlebarContainer.layer?.backgroundColor = color
|
||||
}
|
||||
|
||||
// Make sure the titlebar has the assigned background color.
|
||||
private 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, detect the tab bar being added, and override its behavior.
|
||||
override func addTitlebarAccessoryViewController(_ childViewController: NSTitlebarAccessoryViewController) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user