mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-04-22 01:18:36 +03:00

Fixes #2409 This is one of the weirder macOS quirks (bugs? who knows!) I've seen recently. The bug as described in #2409: when you have at least two monitors ("screens" in AppKit parlance), Ghostty on one, a focused app on the other, and you toggle the quick terminal, the quick terminal does not have focus. We already knew and accounted for the fact that `window.makeKeyAndOrderFront(nil)` does not work until the window is visible and on the target screen. To do this, we only called this once the animation was complete. For the same NSScreen, this works, but for another screen, it does not. Using one DispatchQueue.async tick also does not work. Based on testing, it takes anywhere from 2 to 5 ticks to get the window focus API to work properly. Okay. The solution I came up with here is to retry the focus operation every 25ms up to 250ms. This has worked consistently for me within the first 5 ticks but it is obviously a hack so I'm not sure if this is all right. This fixes the issue but if there's a better way to do this, I'm all ears!