Skip to content

Commit

Permalink
Merge pull request #2343 from ghostty-org/push-prytryysmvqw
Browse files Browse the repository at this point in the history
macos: apply background opacity to quick terminal
  • Loading branch information
mitchellh authored Oct 1, 2024
2 parents 8c5afbb + 78b9636 commit a92c241
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
31 changes: 31 additions & 0 deletions macos/Sources/Features/QuickTerminal/QuickTerminalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class QuickTerminalController: BaseTerminalController {
selector: #selector(onToggleFullscreen),
name: Ghostty.Notification.ghosttyToggleFullscreen,
object: nil)
center.addObserver(
self,
selector: #selector(ghosttyDidReloadConfig),
name: Ghostty.Notification.ghosttyDidReloadConfig,
object: nil)
}

required init?(coder: NSCoder) {
Expand All @@ -58,6 +63,9 @@ class QuickTerminalController: BaseTerminalController {
// make this restorable, but it isn't currently implemented.
window.isRestorable = false

// Setup our configured appearance that we support.
syncAppearance()

// Setup our initial size based on our configured position
position.setLoaded(window)

Expand Down Expand Up @@ -242,6 +250,25 @@ class QuickTerminalController: BaseTerminalController {
})
}

private func syncAppearance() {
guard let window else { return }

// If we have window transparency then set it transparent. Otherwise set it opaque.
if (ghostty.config.backgroundOpacity < 1) {
window.isOpaque = false

// 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)

ghostty_set_window_background_blur(ghostty.app, Unmanaged.passUnretained(window).toOpaque())
} else {
window.isOpaque = true
window.backgroundColor = .windowBackgroundColor
}
}

// MARK: First Responder

@IBAction override func closeWindow(_ sender: Any) {
Expand Down Expand Up @@ -273,4 +300,8 @@ class QuickTerminalController: BaseTerminalController {
// We ignore the requested mode and always use non-native for the quick terminal
toggleFullscreen(mode: .nonNative)
}

@objc private func ghosttyDidReloadConfig(notification: SwiftUI.Notification) {
syncAppearance()
}
}
5 changes: 5 additions & 0 deletions macos/Sources/Ghostty/Ghostty.App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ extension Ghostty {
delegate.configDidReload(state)
}

// Send an event out
NotificationCenter.default.post(
name: Ghostty.Notification.ghosttyDidReloadConfig,
object: nil)

return newConfig.config
}

Expand Down
3 changes: 3 additions & 0 deletions macos/Sources/Ghostty/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ extension Ghostty.Notification {
/// Used to pass a configuration along when creating a new tab/window/split.
static let NewSurfaceConfigKey = "com.mitchellh.ghostty.newSurfaceConfig"

/// Posted when the application configuration is reloaded.
static let ghosttyDidReloadConfig = Notification.Name("com.mitchellh.ghostty.didReloadConfig")

/// Posted when a new split is requested. The sending object will be the surface that had focus. The
/// userdata has one key "direction" with the direction to split to.
static let ghosttyNewSplit = Notification.Name("com.mitchellh.ghostty.newSplit")
Expand Down

0 comments on commit a92c241

Please sign in to comment.