From 9193a20b447de3c81d738c5f6c7fa0e6fa8905ef Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 20 Nov 2020 07:30:46 +0530 Subject: [PATCH] macOS: Fix minimize not working for chromeless windows Fixes #3112 --- docs/changelog.rst | 2 ++ glfw/cocoa_platform.h | 1 + glfw/cocoa_window.m | 33 +++++++++++++++++++++++++++++++++ glfw/glfw.py | 1 + kitty/cocoa_window.m | 24 ------------------------ kitty/glfw-wrapper.c | 2 ++ kitty/glfw-wrapper.h | 4 ++++ kitty/glfw.c | 3 +-- 8 files changed, 44 insertions(+), 26 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index cd52b56d5..0dcdcf1fc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,8 @@ To update |kitty|, :doc:`follow the instructions `. - Fix drawing of a few sextant characters incorrect (:pull:`3105`) +- macOS: Fix minimize not working for chromeless windows (:iss:`3112`) + 0.19.2 [2020-11-13] ------------------- diff --git a/glfw/cocoa_platform.h b/glfw/cocoa_platform.h index 9ea17718c..053bdb046 100644 --- a/glfw/cocoa_platform.h +++ b/glfw/cocoa_platform.h @@ -129,6 +129,7 @@ typedef struct _GLFWwindowNS bool maximized; bool retina; bool in_traditional_fullscreen; + bool titlebar_hidden; unsigned long pre_full_screen_style_mask; // Cached window properties to filter out duplicate events diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index e0f30e79f..2deece35b 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1314,6 +1314,16 @@ void _glfwPlatformUpdateIMEState(_GLFWwindow *w, int which, int a, int b, int c, glfw_window = NULL; } +- (BOOL)validateMenuItem:(NSMenuItem *)item { + if (item.action == @selector(performMiniaturize:)) return YES; + return [super validateMenuItem:item]; +} + +- (void)performMiniaturize:(id)sender +{ + if (glfw_window && (!glfw_window->decorated || glfw_window->ns.titlebar_hidden)) [self miniaturize:self]; + else [super performMiniaturize:sender]; +} - (BOOL)canBecomeKeyWindow { @@ -2293,6 +2303,29 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle) return window->ns.object; } +GLFWAPI void glfwHideCocoaTitlebar(GLFWwindow* handle, bool yes) { + @autoreleasepool { + _GLFWwindow* w = (_GLFWwindow*) handle; + NSWindow *window = w->ns.object; + w->ns.titlebar_hidden = yes; + NSButton *button; + button = [window standardWindowButton: NSWindowCloseButton]; + if (button) button.hidden = yes; + button = [window standardWindowButton: NSWindowMiniaturizeButton]; + if (button) button.hidden = yes; + button = [window standardWindowButton: NSWindowZoomButton]; + [window setTitlebarAppearsTransparent:yes]; + if (button) button.hidden = yes; + if (yes) { + [window setTitleVisibility:NSWindowTitleHidden]; + [window setStyleMask: [window styleMask] | NSWindowStyleMaskFullSizeContentView]; + } else { + [window setTitleVisibility:NSWindowTitleVisible]; + [window setStyleMask: [window styleMask] & ~NSWindowStyleMaskFullSizeContentView]; + } + } // autoreleasepool +} + GLFWAPI GLFWcocoatextinputfilterfun glfwSetCocoaTextInputFilter(GLFWwindow *handle, GLFWcocoatextinputfilterfun callback) { _GLFWwindow* window = (_GLFWwindow*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(nil); diff --git a/glfw/glfw.py b/glfw/glfw.py index 3cd95f30e..6174a25a0 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -199,6 +199,7 @@ def generate_wrappers(glfw_header: str) -> None: functions.append(Function(decl)) for line in '''\ void* glfwGetCocoaWindow(GLFWwindow* window) + void glfwHideCocoaTitlebar(GLFWwindow* window, bool yes) void* glfwGetNSGLContext(GLFWwindow *window) uint32_t glfwGetCocoaMonitor(GLFWmonitor* monitor) GLFWcocoatextinputfilterfun glfwSetCocoaTextInputFilter(GLFWwindow* window, GLFWcocoatextinputfilterfun callback) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index fdac29c06..f6394fa31 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -615,30 +615,6 @@ cocoa_hide_window_title(void *w) } // autoreleasepool } -void -cocoa_hide_titlebar(void *w) -{ - @autoreleasepool { - - cocoa_hide_window_title(w); - - NSWindow *window = (NSWindow*)w; - NSButton *button; - - button = [window standardWindowButton: NSWindowCloseButton]; - if (button) button.hidden = true; - button = [window standardWindowButton: NSWindowMiniaturizeButton]; - if (button) button.hidden = true; - button = [window standardWindowButton: NSWindowZoomButton]; - if (button) button.hidden = true; - - [window setTitlebarAppearsTransparent:YES]; - [window setStyleMask: - [window styleMask] | NSWindowStyleMaskFullSizeContentView]; - - } // autoreleasepool -} - void cocoa_system_beep(void) { NSBeep(); diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index c5629e5d0..637aef8df 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -380,6 +380,8 @@ load_glfw(const char* path) { *(void **) (&glfwGetCocoaWindow_impl) = dlsym(handle, "glfwGetCocoaWindow"); + *(void **) (&glfwHideCocoaTitlebar_impl) = dlsym(handle, "glfwHideCocoaTitlebar"); + *(void **) (&glfwGetNSGLContext_impl) = dlsym(handle, "glfwGetNSGLContext"); *(void **) (&glfwGetCocoaMonitor_impl) = dlsym(handle, "glfwGetCocoaMonitor"); diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index d5d085a97..8a9267e2e 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -2147,6 +2147,10 @@ typedef void* (*glfwGetCocoaWindow_func)(GLFWwindow*); GFW_EXTERN glfwGetCocoaWindow_func glfwGetCocoaWindow_impl; #define glfwGetCocoaWindow glfwGetCocoaWindow_impl +typedef void (*glfwHideCocoaTitlebar_func)(GLFWwindow*, bool); +GFW_EXTERN glfwHideCocoaTitlebar_func glfwHideCocoaTitlebar_impl; +#define glfwHideCocoaTitlebar glfwHideCocoaTitlebar_impl + typedef void* (*glfwGetNSGLContext_func)(GLFWwindow*); GFW_EXTERN glfwGetNSGLContext_func glfwGetNSGLContext_impl; #define glfwGetNSGLContext glfwGetNSGLContext_impl diff --git a/kitty/glfw.c b/kitty/glfw.c index 0617f551a..32c9e8e07 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -14,7 +14,6 @@ extern void cocoa_focus_window(void *w); extern long cocoa_window_number(void *w); extern void cocoa_create_global_menu(void); extern void cocoa_hide_window_title(void *w); -extern void cocoa_hide_titlebar(void *w); extern void cocoa_system_beep(void); extern void cocoa_set_activation_policy(bool); extern void cocoa_set_titlebar_color(void *w, color_type color); @@ -695,7 +694,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { #ifdef __APPLE__ if (glfwGetCocoaWindow) { if (OPT(hide_window_decorations) & 2) { - cocoa_hide_titlebar(glfwGetCocoaWindow(glfw_window)); + glfwHideCocoaTitlebar(glfw_window, true); } else if (!(OPT(macos_show_window_title_in) & WINDOW)) { cocoa_hide_window_title(glfwGetCocoaWindow(glfw_window)); }