mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Optimize background opacity toggle implementation
This commit is contained in:

committed by
Mitchell Hashimoto

parent
9c1ee09e48
commit
52b270bce3
@ -597,26 +597,25 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc private func ghosttyBackgroundOpacityDidToggle() {
|
@objc private func ghosttyBackgroundOpacityDidToggle() {
|
||||||
guard self.derivedConfig.backgroundOpacity < 1 else { return }
|
guard let window = self.window as? TerminalWindow else { return }
|
||||||
|
|
||||||
// Toggle the window's background opacity
|
// Don't toggle transparency if opacity is 1+ or in fullscreen mode
|
||||||
if let window = self.window as? TerminalWindow {
|
if self.derivedConfig.backgroundOpacity >= 1 || window.styleMask.contains(.fullScreen) {
|
||||||
let newOpaque = !window.isOpaque
|
return
|
||||||
window.isOpaque = newOpaque
|
}
|
||||||
|
|
||||||
// Update the window background color based on opacity state
|
// Toggle opacity state
|
||||||
if newOpaque {
|
window.isOpaque = !window.isOpaque
|
||||||
|
|
||||||
|
if window.isOpaque {
|
||||||
window.backgroundColor = NSColor(self.derivedConfig.backgroundColor)
|
window.backgroundColor = NSColor(self.derivedConfig.backgroundColor)
|
||||||
} else {
|
} else {
|
||||||
// Use a very small alpha component to match Terminal.app's look
|
// This is weird, but we don't use ".clear" because this creates a look that
|
||||||
|
// matches Terminal.app much more closer. This lets users transition from
|
||||||
|
// Terminal.app more easily.
|
||||||
window.backgroundColor = .white.withAlphaComponent(0.001)
|
window.backgroundColor = .white.withAlphaComponent(0.001)
|
||||||
// Apply background blur
|
guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else { return }
|
||||||
if let app = (NSApplication.shared.delegate as? AppDelegate)?.ghostty.app {
|
ghostty_set_window_background_blur(appDelegate.ghostty.app, Unmanaged.passUnretained(window).toOpaque())
|
||||||
ghostty_set_window_background_blur(app, Unmanaged.passUnretained(window).toOpaque())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ghostty.logger.warning("toggle background opacity: no terminal window found")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user