From f86102ab88c40b8ce86eadb0f10b71e0d24fdd7f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 19 May 2024 20:43:38 +0530 Subject: [PATCH] macOS: Fix --start-as=fullscreen not working when another window is already fullscreen Apparently, we need to make the window visible before full screening it. Sigh. I dont know why Apple insisted on this horrible "fancy" fullscreen of theirs, it's full of bugs and dog slow. Fixes #7448 --- docs/changelog.rst | 2 ++ glfw/cocoa_window.m | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index ce87f8705..295c5476c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -96,6 +96,8 @@ Detailed list of changes - launch --hold: Fix hold not working if kernel signals process group with SIGINT (:iss:`7466`) +- macOS: Fix --start-as=fullscreen not working when another window is already fullscreen (:iss:`7448`) + 0.34.1 [2024-04-19] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 003668b63..132073750 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -2647,6 +2647,20 @@ bool _glfwPlatformIsFullscreen(_GLFWwindow* w, unsigned int flags) { return sm & NSWindowStyleMaskFullScreen; } +static void +make_window_fullscreen_after_show(unsigned long long timer_id, void* data) { + (void)timer_id; + unsigned long long window_id = (uintptr_t)data; + for (_GLFWwindow *w = _glfw.windowListHead; w; w = w->next) { + if (w->id == window_id) { + NSWindow *window = w->ns.object; + [window toggleFullScreen: nil]; + update_titlebar_button_visibility_after_fullscreen_transition(w, false, true); + break; + } + } +} + bool _glfwPlatformToggleFullscreen(_GLFWwindow* w, unsigned int flags) { NSWindow *window = w->ns.object; bool made_fullscreen = true; @@ -2688,6 +2702,13 @@ bool _glfwPlatformToggleFullscreen(_GLFWwindow* w, unsigned int flags) { [w->ns.delegate performSelector:@selector(windowDidResize:) withObject:notification afterDelay:0]; } else { bool in_fullscreen = sm & NSWindowStyleMaskFullScreen; + if (!in_fullscreen && !_glfwPlatformWindowVisible(w)) { + // Bug in Apple's fullscreen implementation causes fullscreen to + // not work before window is shown (at creation) if another window + // is already fullscreen. Le sigh. https://github.com/kovidgoyal/kitty/issues/7448 + _glfwPlatformAddTimer(0, false, make_window_fullscreen_after_show, (void*)(uintptr_t)(w->id), NULL); + return made_fullscreen; + } if (in_fullscreen) made_fullscreen = false; [window toggleFullScreen: nil]; }