From 3638adda6c05fc25704b9559bb420c0efb86f674 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 18 Aug 2025 16:01:51 +0530 Subject: [PATCH] macOS: Elaborate dance to work around yet another Cocoa bug Fixes #8740 --- docs/changelog.rst | 4 ++++ glfw/cocoa_window.m | 23 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 86d2b2b6a..9b025c8c6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -141,6 +141,10 @@ Detailed list of changes - macOS: Fix hiding quick access terminal window not restoring focus to previously active application (:disc:`8840`) +- macOS: Fix showing the quick access terminal on a space other than the space + it was last active on, after full screening some application causes the quick + access terminal to appear on the old space (:iss:`8740`) + - Allow using backspace to move the cursor onto the previous line in cooked mode. This is indicated by the `bw` property in kitty's terminfo (:iss:`8841`) - Watchers: A new event for global watchers corresponding to the tab bar being changed (:disc:`8842`) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index bd606d739..e32092800 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -2229,9 +2229,26 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window) { - if (window->ns.layer_shell.is_active && window->ns.layer_shell.config.type == GLFW_LAYER_SHELL_BACKGROUND) { - [window->ns.object orderBack:nil]; - } else [window->ns.object orderFront:nil]; + const bool is_background = window->ns.layer_shell.is_active && window->ns.layer_shell.config.type == GLFW_LAYER_SHELL_BACKGROUND; + NSWindow *nw = window->ns.object; + if (is_background) { + [nw orderBack:nil]; + } else { + // Cocoa has a bug where when showing a hidden window after + // 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. + // See https://github.com/kovidgoyal/kitty/issues/8740 + NSWindowCollectionBehavior old = nw.collectionBehavior; + nw.collectionBehavior = (old & !NSWindowCollectionBehaviorCanJoinAllSpaces) | NSWindowCollectionBehaviorMoveToActiveSpace; + [nw orderFront:nil]; + dispatch_async(dispatch_get_main_queue(), ^{ + nw.collectionBehavior = old; + }); + } } void _glfwPlatformHideWindow(_GLFWwindow* window)