macos: opacity-toggle setting persists between tabs in a window and to a newly created window (#11583)

pull/12711/head
Lukas 2026-05-17 00:45:24 +02:00 committed by GitHub
commit b6c6f7630a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 6 deletions

View File

@ -766,7 +766,8 @@ class BaseTerminalController: NSWindowController,
ghostty,
tree: newTree,
position: notification.userInfo?[Notification.Name.ghosttySurfaceDragEndedNoTargetPointKey] as? NSPoint,
confirmUndo: false)
confirmUndo: false,
inheritBackgroundOpacity: isBackgroundOpaque)
}
// MARK: Local Events
@ -990,11 +991,15 @@ class BaseTerminalController: NSWindowController,
// Do nothing if in fullscreen (transparency doesn't apply in fullscreen)
guard let window, !window.styleMask.contains(.fullScreen) else { return }
// Toggle between transparent and opaque
isBackgroundOpaque.toggle()
let newValue = !isBackgroundOpaque
let controllers = NSApplication.shared.windows.compactMap {
$0.windowController as? BaseTerminalController
}
// Update our appearance
syncAppearance()
for controller in controllers {
controller.isBackgroundOpaque = newValue
controller.syncAppearance()
}
}
/// Override this to resync any appearance related properties. This will be called automatically

View File

@ -256,6 +256,9 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
// Get our parent. Our parent is the one explicitly given to us,
// otherwise the focused terminal, otherwise an arbitrary one.
let parent: NSWindow? = explicitParent ?? preferredParent?.window
if let parentController = parent?.windowController as? TerminalController {
c.isBackgroundOpaque = parentController.isBackgroundOpaque
}
if let parent, parent.styleMask.contains(.fullScreen) {
// If our previous window was fullscreen then we want our new window to
@ -339,8 +342,12 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
tree: SplitTree<Ghostty.SurfaceView>,
position: NSPoint? = nil,
confirmUndo: Bool = true,
inheritBackgroundOpacity: Bool? = nil
) -> TerminalController {
let c = TerminalController.init(ghostty, withSurfaceTree: tree)
if let inheritBackgroundOpacity {
c.isBackgroundOpaque = inheritBackgroundOpacity
}
// Calculate the target frame based on the tree's view bounds
let treeSize: CGSize? = tree.root?.viewBounds()
@ -385,7 +392,11 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
withTarget: ghostty,
expiresAfter: target.undoExpiration
) { ghostty in
_ = TerminalController.newWindow(ghostty, tree: tree)
_ = TerminalController.newWindow(
ghostty,
tree: tree,
inheritBackgroundOpacity: inheritBackgroundOpacity
)
}
}
}
@ -420,6 +431,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
// Create a new window and add it to the parent
let controller = TerminalController.init(ghostty, withBaseConfig: baseConfig)
controller.isBackgroundOpaque = parentController.isBackgroundOpaque
guard let window = controller.window else { return controller }
// If the parent is miniaturized, then macOS exhibits really strange behaviors