macos: explicitly update TerminalViewContainer when it's needed

This commit is contained in:
Lukas
2026-02-26 11:47:51 +01:00
parent 4e493a9201
commit 9032096fc7
3 changed files with 19 additions and 42 deletions

View File

@@ -159,6 +159,8 @@ class QuickTerminalController: BaseTerminalController {
// applies if we can be seen.
guard visible else { return }
window?.terminalViewContainer?.updateGlassTintOverlay(isKeyWindow: true)
// Re-hide the dock if we were hiding it before.
hiddenDock?.hide()
}
@@ -172,6 +174,8 @@ class QuickTerminalController: BaseTerminalController {
// ensures we don't run logic twice.
guard visible else { return }
window?.terminalViewContainer?.updateGlassTintOverlay(isKeyWindow: false)
// We don't animate out if there is a modal sheet being shown currently.
// This lets us show alerts without causing the window to disappear.
guard window?.attachedSheet == nil else { return }
@@ -704,6 +708,8 @@ class QuickTerminalController: BaseTerminalController {
self.derivedConfig = DerivedConfig(config)
syncAppearance()
window?.terminalViewContainer?.ghosttyConfigDidChange(config, preferredBackgroundColor: nil)
}
@objc private func onNewTab(notification: SwiftUI.Notification) {

View File

@@ -585,6 +585,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
// Call this last in case it uses any of the properties above.
window.syncAppearance(surfaceConfig)
window.terminalViewContainer?.ghosttyConfigDidChange(ghostty.config, preferredBackgroundColor: window.preferredBackgroundColor)
}
/// Adjusts the given frame for the configured window position.
@@ -1146,6 +1147,12 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
super.windowDidBecomeKey(notification)
self.relabelTabs()
self.fixTabBar()
window?.terminalViewContainer?.updateGlassTintOverlay(isKeyWindow: true)
}
override func windowDidResignKey(_ notification: Notification) {
super.windowDidResignKey(notification)
window?.terminalViewContainer?.updateGlassTintOverlay(isKeyWindow: false)
}
override func windowDidMove(_ notification: Notification) {

View File

@@ -33,10 +33,6 @@ class TerminalViewContainer: NSView {
fatalError("init(coder:) has not been implemented")
}
deinit {
NotificationCenter.default.removeObserver(self)
}
/// To make ``TerminalController/DefaultSize/contentIntrinsicSize``
/// work in ``TerminalController/windowDidLoad()``,
/// we override this to provide the correct size.
@@ -53,27 +49,6 @@ class TerminalViewContainer: NSView {
terminalView.bottomAnchor.constraint(equalTo: bottomAnchor),
terminalView.trailingAnchor.constraint(equalTo: trailingAnchor),
])
NotificationCenter.default.addObserver(
self,
selector: #selector(ghosttyConfigDidChange(_:)),
name: .ghosttyConfigDidChange,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(windowDidBecomeKey(_:)),
name: NSWindow.didBecomeKeyNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(windowDidResignKey(_:)),
name: NSWindow.didResignKeyNotification,
object: nil
)
}
override func viewDidMoveToWindow() {
@@ -98,26 +73,15 @@ class TerminalViewContainer: NSView {
let newValue = DerivedConfig(config: config, preferredBackgroundColor: preferredBackgroundColor, cornerRadius: windowCornerRadius)
guard newValue != derivedConfig else { return }
derivedConfig = newValue
// Add some delay to wait TerminalWindow to update first to ensure
// that some of our properties are updated. This is a HACK to ensure
// light/dark themes work, and we will come up with a better way
// in the future.
DispatchQueue.main.asyncAfter(
deadline: .now() + 0.05,
execute: updateGlassEffectIfNeeded)
DispatchQueue.main.async(execute: updateGlassEffectIfNeeded)
}
}
@objc private func windowDidBecomeKey(_ notification: Notification) {
guard let window = notification.object as? NSWindow,
window == self.window else { return }
updateGlassTintOverlay(isKeyWindow: true)
}
// MARK: - NSWindow + terminalViewContainer
@objc private func windowDidResignKey(_ notification: Notification) {
guard let window = notification.object as? NSWindow,
window == self.window else { return }
updateGlassTintOverlay(isKeyWindow: false)
extension NSWindow {
var terminalViewContainer: TerminalViewContainer? {
contentView as? TerminalViewContainer
}
}