diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 7c0e1ab38..feba4fdaf 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -3480,6 +3480,36 @@ glfwGetCocoaKeyEquivalent(uint32_t glfw_key, int glfw_mods, int *cocoa_mods) { GLFWAPI bool glfwIsLayerShellSupported(void) { return true; } +GLFWAPI void +glfwCocoaCycleThroughOSWindows(bool backwards) { + NSArray *allWindows = [NSApp windows]; + if (allWindows.count < 2) return; + NSMutableArray *filteredWindows = [NSMutableArray array]; + for (NSWindow *window in allWindows) { + NSRect windowFrame = [window frame]; + // Exclude zero size windows which are likely zombie windows from the Tahoe bug + // if ([obj isMemberOfClass:[MyClass class]]) { + if ( + windowFrame.size.width > 0 && windowFrame.size.height > 0 && \ + !window.isMiniaturized && window.isVisible && \ + [window isMemberOfClass:[GLFWWindow class]] + ) [filteredWindows addObject:window]; + } + if (filteredWindows.count < 2) return; + NSWindow *keyWindow = [NSApp keyWindow]; + NSUInteger index = [filteredWindows indexOfObject:keyWindow]; + NSUInteger nextIndex = 0; + if (index != NSNotFound) { + if (backwards) { + nextIndex = (index == 0) ? [filteredWindows count] - 1 : index - 1; + } else nextIndex = (index + 1) % filteredWindows.count; + } + NSWindow *nextWindow = filteredWindows[nextIndex]; + [nextWindow makeKeyAndOrderFront:nil]; +} + + + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/glfw/glfw.py b/glfw/glfw.py index e5d7ab3d9..2d1dd3f09 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -313,6 +313,7 @@ def generate_wrappers(glfw_header: str) -> None: void* glfwGetX11Display(void) unsigned long glfwGetX11Window(GLFWwindow* window) void glfwSetPrimarySelectionString(GLFWwindow* window, const char* string) + void glfwCocoaCycleThroughOSWindows(bool backwards) void glfwCocoaSetWindowChrome(GLFWwindow* window, unsigned int color, bool use_system_color, unsigned int system_color,\ int background_blur, unsigned int hide_window_decorations, bool show_text_in_titlebar, int color_space, float background_opacity, bool resizable) const char* glfwGetPrimarySelectionString(GLFWwindow* window, void) diff --git a/kitty/cocoa_window.h b/kitty/cocoa_window.h index b9d916380..b7587f989 100644 --- a/kitty/cocoa_window.h +++ b/kitty/cocoa_window.h @@ -52,7 +52,6 @@ void cocoa_system_beep(const char*); void cocoa_set_activation_policy(bool); bool cocoa_alt_option_key_pressed(unsigned long); void cocoa_toggle_secure_keyboard_entry(void); -void cocoa_cycle_through_os_windows(bool); void cocoa_hide(void); void cocoa_clear_global_shortcuts(void); void cocoa_hide_others(void); diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 7f3d947c0..a2d533098 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -927,30 +927,6 @@ cocoa_toggle_secure_keyboard_entry(void) { [[NSUserDefaults standardUserDefaults] setBool:k.isDesired forKey:@"SecureKeyboardEntry"]; } -void -cocoa_cycle_through_os_windows(bool backwards) { - NSArray *allWindows = [NSApp windows]; - if (allWindows.count < 2) return; - NSMutableArray *filteredWindows = [NSMutableArray array]; - for (NSWindow *window in allWindows) { - NSRect windowFrame = [window frame]; - // Exclude zero size windows which are likely zombie windows from the Tahoe bug - if (windowFrame.size.width > 0 && windowFrame.size.height > 0 && !window.isMiniaturized && window.isVisible) [filteredWindows addObject:window]; - } - if (filteredWindows.count < 2) return; - NSWindow *keyWindow = [NSApp keyWindow]; - NSUInteger index = [filteredWindows indexOfObject:keyWindow]; - NSUInteger nextIndex = 0; - if (index != NSNotFound) { - if (backwards) { - nextIndex = (index == 0) ? [filteredWindows count] - 1 : index - 1; - } else nextIndex = (index + 1) % filteredWindows.count; - } - NSWindow *nextWindow = filteredWindows[nextIndex]; - [nextWindow makeKeyAndOrderFront:nil]; -} - - void cocoa_hide(void) { [[NSApplication sharedApplication] performSelectorOnMainThread:@selector(hide:) withObject:nil waitUntilDone:NO]; diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index fdc2f427d..8e257fcc0 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -473,6 +473,9 @@ load_glfw(const char* path) { *(void **) (&glfwSetPrimarySelectionString_impl) = dlsym(handle, "glfwSetPrimarySelectionString"); if (glfwSetPrimarySelectionString_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwCocoaCycleThroughOSWindows_impl) = dlsym(handle, "glfwCocoaCycleThroughOSWindows"); + if (glfwCocoaCycleThroughOSWindows_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwCocoaSetWindowChrome_impl) = dlsym(handle, "glfwCocoaSetWindowChrome"); if (glfwCocoaSetWindowChrome_impl == NULL) dlerror(); // clear error indicator diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index f1553d42e..74850dbf2 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -2330,6 +2330,10 @@ typedef void (*glfwSetPrimarySelectionString_func)(GLFWwindow*, const char*); GFW_EXTERN glfwSetPrimarySelectionString_func glfwSetPrimarySelectionString_impl; #define glfwSetPrimarySelectionString glfwSetPrimarySelectionString_impl +typedef void (*glfwCocoaCycleThroughOSWindows_func)(bool); +GFW_EXTERN glfwCocoaCycleThroughOSWindows_func glfwCocoaCycleThroughOSWindows_impl; +#define glfwCocoaCycleThroughOSWindows glfwCocoaCycleThroughOSWindows_impl + typedef void (*glfwCocoaSetWindowChrome_func)(GLFWwindow*, unsigned int, bool, unsigned int, int, unsigned int, bool, int, float, bool); GFW_EXTERN glfwCocoaSetWindowChrome_func glfwCocoaSetWindowChrome_impl; #define glfwCocoaSetWindowChrome glfwCocoaSetWindowChrome_impl diff --git a/kitty/glfw.c b/kitty/glfw.c index b641633d9..54556a95b 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1924,7 +1924,7 @@ toggle_secure_input(PYNOARG) { static PyObject* macos_cycle_through_os_windows(PyObject *self UNUSED, PyObject *backwards) { #ifdef __APPLE__ - cocoa_cycle_through_os_windows(PyObject_IsTrue(backwards)); + glfwCocoaCycleThroughOSWindows(PyObject_IsTrue(backwards)); #else (void)backwards; #endif