Move the code to cycle through OS Windows into glfw

This commit is contained in:
Kovid Goyal
2025-11-12 12:02:38 +05:30
parent 7fe38ae579
commit 81f429d52b
7 changed files with 39 additions and 26 deletions

View File

@@ -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<NSWindow *> *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 //////
//////////////////////////////////////////////////////////////////////////

View File

@@ -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)