mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00

This fixes an issue where pressing the red close button in a window or the "x" button on a tab couldn't differentiate and would always close the tab or close the window (depending on tab counts). It seems like in both cases, AppKit triggers the `windowShouldClose` delegate method on the controller, but for the close window case it triggers this on ALL the windows in the group, not just the one that was clicked. I implemented a kind of silly coordinator that debounces `windowShouldClose` calls over 100ms and uses that to differentiate between the two cases.
19 lines
683 B
Swift
19 lines
683 B
Swift
import AppKit
|
||
|
||
extension NSWindow {
|
||
/// Get the CGWindowID type for the window (used for low level CoreGraphics APIs).
|
||
var cgWindowId: CGWindowID? {
|
||
// "If the window doesn’t have a window device, the value of this
|
||
// property is equal to or less than 0." - Docs. In practice I've
|
||
// found this is true if a window is not visible.
|
||
guard windowNumber > 0 else { return nil }
|
||
return CGWindowID(windowNumber)
|
||
}
|
||
|
||
/// True if this is the first window in the tab group.
|
||
var isFirstWindowInTabGroup: Bool {
|
||
guard let firstWindow = tabGroup?.windows.first else { return true }
|
||
return firstWindow === self
|
||
}
|
||
}
|