mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
macos: fix retain cycle preventing window from freeing (#4689)
This commit is contained in:
@ -424,35 +424,35 @@ class AppDelegate: NSObject,
|
|||||||
// If we have a main window then we don't process any of the keys
|
// If we have a main window then we don't process any of the keys
|
||||||
// because we let it capture and propagate.
|
// because we let it capture and propagate.
|
||||||
guard NSApp.mainWindow == nil else { return event }
|
guard NSApp.mainWindow == nil else { return event }
|
||||||
|
|
||||||
// If this event as-is would result in a key binding then we send it.
|
// If this event as-is would result in a key binding then we send it.
|
||||||
if let app = ghostty.app,
|
if let app = ghostty.app,
|
||||||
ghostty_app_key_is_binding(
|
ghostty_app_key_is_binding(
|
||||||
app,
|
app,
|
||||||
event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS)) {
|
event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS)) {
|
||||||
ghostty_app_key(app, event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS))
|
ghostty_app_key(app, event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this event would be handled by our menu then we do nothing.
|
// If this event would be handled by our menu then we do nothing.
|
||||||
if let mainMenu = NSApp.mainMenu,
|
if let mainMenu = NSApp.mainMenu,
|
||||||
mainMenu.performKeyEquivalent(with: event) {
|
mainMenu.performKeyEquivalent(with: event) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reach this point then we try to process the key event
|
// If we reach this point then we try to process the key event
|
||||||
// through the Ghostty key mechanism.
|
// through the Ghostty key mechanism.
|
||||||
|
|
||||||
// Ghostty must be loaded
|
// Ghostty must be loaded
|
||||||
guard let ghostty = self.ghostty.app else { return event }
|
guard let ghostty = self.ghostty.app else { return event }
|
||||||
|
|
||||||
// Build our event input and call ghostty
|
// Build our event input and call ghostty
|
||||||
if (ghostty_app_key(ghostty, event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS))) {
|
if (ghostty_app_key(ghostty, event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS))) {
|
||||||
// The key was used so we want to stop it from going to our Mac app
|
// The key was used so we want to stop it from going to our Mac app
|
||||||
Ghostty.logger.debug("local key event handled event=\(event)")
|
Ghostty.logger.debug("local key event handled event=\(event)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,12 +667,16 @@ fileprivate class WindowDragView: NSView {
|
|||||||
|
|
||||||
// A view that matches the color of selected and unselected tabs in the adjacent tab bar.
|
// A view that matches the color of selected and unselected tabs in the adjacent tab bar.
|
||||||
fileprivate class WindowButtonsBackdropView: NSView {
|
fileprivate class WindowButtonsBackdropView: NSView {
|
||||||
private let terminalWindow: TerminalWindow
|
// This must be weak because the window has this view. Otherwise
|
||||||
|
// a retain cycle occurs.
|
||||||
|
private weak var terminalWindow: TerminalWindow?
|
||||||
private let isLightTheme: Bool
|
private let isLightTheme: Bool
|
||||||
private let overlayLayer = VibrantLayer()
|
private let overlayLayer = VibrantLayer()
|
||||||
|
|
||||||
var isHighlighted: Bool = true {
|
var isHighlighted: Bool = true {
|
||||||
didSet {
|
didSet {
|
||||||
|
guard let terminalWindow else { return }
|
||||||
|
|
||||||
if isLightTheme {
|
if isLightTheme {
|
||||||
overlayLayer.isHidden = isHighlighted
|
overlayLayer.isHidden = isHighlighted
|
||||||
layer?.backgroundColor = .clear
|
layer?.backgroundColor = .clear
|
||||||
|
Reference in New Issue
Block a user