mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-27 15:25:19 +00:00
refactor(macos): centralize background opacity toggling across controllers
This commit is contained in:
@@ -767,7 +767,7 @@ class BaseTerminalController: NSWindowController,
|
||||
tree: newTree,
|
||||
position: notification.userInfo?[Notification.Name.ghosttySurfaceDragEndedNoTargetPointKey] as? NSPoint,
|
||||
confirmUndo: false,
|
||||
inheritBackgroundOpacityFrom: self as? TerminalController)
|
||||
inheritBackgroundOpacity: isBackgroundOpaque)
|
||||
}
|
||||
|
||||
// MARK: Local Events
|
||||
@@ -991,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
|
||||
|
||||
@@ -316,11 +316,11 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
||||
tree: SplitTree<Ghostty.SurfaceView>,
|
||||
position: NSPoint? = nil,
|
||||
confirmUndo: Bool = true,
|
||||
inheritBackgroundOpacityFrom parentController: TerminalController? = nil
|
||||
inheritBackgroundOpacity: Bool? = nil
|
||||
) -> TerminalController {
|
||||
let c = TerminalController.init(ghostty, withSurfaceTree: tree)
|
||||
if let parentController {
|
||||
c.isBackgroundOpaque = parentController.isBackgroundOpaque
|
||||
if let inheritBackgroundOpacity {
|
||||
c.isBackgroundOpaque = inheritBackgroundOpacity
|
||||
}
|
||||
|
||||
// Calculate the target frame based on the tree's view bounds
|
||||
@@ -369,7 +369,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
||||
_ = TerminalController.newWindow(
|
||||
ghostty,
|
||||
tree: tree,
|
||||
inheritBackgroundOpacityFrom: parentController
|
||||
inheritBackgroundOpacity: inheritBackgroundOpacity
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -503,30 +503,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
||||
return controller
|
||||
}
|
||||
|
||||
override func toggleBackgroundOpacity() {
|
||||
// Do nothing if config is already fully opaque
|
||||
guard ghostty.config.backgroundOpacity < 1 else { return }
|
||||
|
||||
// Do nothing if in fullscreen (transparency doesn't apply in fullscreen)
|
||||
guard let window, !window.styleMask.contains(.fullScreen) else { return }
|
||||
|
||||
let newValue = !isBackgroundOpaque
|
||||
let controllers: [TerminalController]
|
||||
|
||||
if let tabGroup = window.tabGroup {
|
||||
controllers = tabGroup.windows.compactMap {
|
||||
$0.windowController as? TerminalController
|
||||
}
|
||||
} else {
|
||||
controllers = [self]
|
||||
}
|
||||
|
||||
for controller in controllers {
|
||||
controller.isBackgroundOpaque = newValue
|
||||
controller.syncAppearance()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Methods
|
||||
|
||||
@objc private func ghosttyConfigDidChange(_ notification: Notification) {
|
||||
|
||||
Reference in New Issue
Block a user