diff --git a/glfw/glfw.py b/glfw/glfw.py index e34cb0ae4..a498bbb38 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -192,6 +192,7 @@ def generate_wrappers(glfw_header, glfw_native_header): functions.append(Function(decl)) for line in '''\ void* glfwGetCocoaWindow(GLFWwindow* window) + void* glfwGetNSGLContext(GLFWwindow *window) uint32_t glfwGetCocoaMonitor(GLFWmonitor* monitor) GLFWcocoatextinputfilterfun glfwSetCocoaTextInputFilter(GLFWwindow* window, GLFWcocoatextinputfilterfun callback) GLFWcocoatogglefullscreenfun glfwSetCocoaToggleFullscreenIntercept(GLFWwindow *window, GLFWcocoatogglefullscreenfun callback) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index fbeb22c46..d3198b399 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -99,6 +99,12 @@ cocoa_set_new_window_trigger(PyObject *self UNUSED, PyObject *args) { Py_RETURN_FALSE; } +void +cocoa_update_nsgl_context(void* id) { + NSOpenGLContext *ctx = id; + [ctx update]; +} + void cocoa_create_global_menu(void) { NSString* app_name = find_app_name(); diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index 2e0d257f9..fc25dda53 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -358,6 +358,8 @@ load_glfw(const char* path) { *(void **) (&glfwGetCocoaWindow_impl) = dlsym(handle, "glfwGetCocoaWindow"); + *(void **) (&glfwGetNSGLContext_impl) = dlsym(handle, "glfwGetNSGLContext"); + *(void **) (&glfwGetCocoaMonitor_impl) = dlsym(handle, "glfwGetCocoaMonitor"); *(void **) (&glfwSetCocoaTextInputFilter_impl) = dlsym(handle, "glfwSetCocoaTextInputFilter"); diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 500a88099..b13ee1f54 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1848,6 +1848,10 @@ typedef void* (*glfwGetCocoaWindow_func)(GLFWwindow*); glfwGetCocoaWindow_func glfwGetCocoaWindow_impl; #define glfwGetCocoaWindow glfwGetCocoaWindow_impl +typedef void* (*glfwGetNSGLContext_func)(GLFWwindow*); +glfwGetNSGLContext_func glfwGetNSGLContext_impl; +#define glfwGetNSGLContext glfwGetNSGLContext_impl + typedef uint32_t (*glfwGetCocoaMonitor_func)(GLFWmonitor*); glfwGetCocoaMonitor_func glfwGetCocoaMonitor_impl; #define glfwGetCocoaMonitor glfwGetCocoaMonitor_impl diff --git a/kitty/glfw.c b/kitty/glfw.c index 2e7b9fb7c..e333134fa 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -14,6 +14,8 @@ extern bool cocoa_toggle_fullscreen(void *w, bool); extern void cocoa_create_global_menu(void); extern void cocoa_set_hide_from_tasks(void); extern void cocoa_set_titlebar_color(void *w, color_type color); +extern void cocoa_update_nsgl_context(void* id); + #if GLFW_KEY_LAST >= MAX_KEY_COUNT #error "glfw has too many keys, you should increase MAX_KEY_COUNT" @@ -808,6 +810,11 @@ hide_mouse(OSWindow *w) { void swap_window_buffers(OSWindow *w) { +#ifdef __APPLE__ + if (w->nsgl_ctx_updated++ < 2) { + cocoa_update_nsgl_context(glfwGetNSGLContext(w->handle)); + } +#endif glfwSwapBuffers(w->handle); } diff --git a/kitty/state.h b/kitty/state.h index 94a6f7038..282f52e0b 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -126,6 +126,7 @@ typedef struct { FONTS_DATA_HANDLE fonts_data; id_type temp_font_group_id; double pending_scroll_pixels; + unsigned int nsgl_ctx_updated; } OSWindow;