mirror of
https://github.com/kovidgoyal/kitty.git
synced 2025-12-13 20:36:22 +01:00
Move the code to cycle through OS Windows into glfw
This commit is contained in:
@@ -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 //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<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 (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];
|
||||
|
||||
3
kitty/glfw-wrapper.c
generated
3
kitty/glfw-wrapper.c
generated
@@ -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
|
||||
|
||||
|
||||
4
kitty/glfw-wrapper.h
generated
4
kitty/glfw-wrapper.h
generated
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user