From 4b7aac4999233fe7125d61c9f912d3fecddf3a94 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Jul 2026 08:43:06 +0530 Subject: [PATCH] macOS: Use a private API to ensure OS window is shown on the currently active space when toggled Fixes #8740 --- docs/changelog.rst | 2 ++ glfw/cocoa_window.m | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index b0a6cb318..771a38022 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -236,6 +236,8 @@ Detailed list of changes - Add support for DECSTR soft screen reset escape code (:iss:`10263`) +- macOS: Fix quick-access-terminal appearing on the wrong space (the fullscreen app's space) when triggered from a different space on macOS Tahoe (:iss:`8740`) + 0.47.4 [2026-06-15] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 17d567fcc..86cd79f87 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -3006,12 +3006,23 @@ void _glfwPlatformShowWindow(_GLFWwindow* window, bool move_to_active_screen) // fullscreening an application, the window does not get added // to the current space even though it has NSWindowCollectionBehaviorCanJoinAllSpaces // probably because it wasnt added to the temp space used for - // fullscreen. So to work around that, we change the collection - // behavior temporarily to NSWindowCollectionBehaviorMoveToActiveSpace - // and then change it back asynchronously. + // fullscreen. // See https://github.com/kovidgoyal/kitty/issues/8740 + // + // Work around this by explicitly assigning the window + // to the current active space via the private CGS API before showing it. NSWindowCollectionBehavior old = nw.collectionBehavior; - nw.collectionBehavior = (old & !NSWindowCollectionBehaviorCanJoinAllSpaces) | NSWindowCollectionBehaviorMoveToActiveSpace; + nw.collectionBehavior = (old & ~NSWindowCollectionBehaviorCanJoinAllSpaces) | NSWindowCollectionBehaviorMoveToActiveSpace; + extern int _CGSDefaultConnection(void); + extern int CGSGetActiveSpace(int cid); + extern void CGSAddWindowsToSpaces(int cid, CFArrayRef windows, CFArrayRef spaces); + int cid = _CGSDefaultConnection(); + int activeSpace = CGSGetActiveSpace(cid); + if (activeSpace > 0) { + NSArray *windowArray = @[@([nw windowNumber])]; + NSArray *spaceArray = @[@(activeSpace)]; + CGSAddWindowsToSpaces(cid, (__bridge CFArrayRef)windowArray, (__bridge CFArrayRef)spaceArray); + } [nw orderFront:nil]; __block __typeof__(nw) weakSelf = nw; dispatch_async(dispatch_get_main_queue(), ^{