diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index f5b500b70..cc631eb72 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -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 diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 7e9b91b19..bcccef8f9 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -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, 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