From 55417e4269c3e4789ac0edb299ddf5cd805a73c3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 28 May 2024 09:46:16 +0530 Subject: [PATCH] Move the window context changing during show fix into glfw code It more logically belongs there. --- glfw/wl_window.c | 4 ++++ kitty/glfw.c | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/glfw/wl_window.c b/glfw/wl_window.c index fc83b8ac2..95c6673ae 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -896,6 +896,7 @@ attach_temp_buffer_during_window_creation(_GLFWwindow *window) { static void loop_till_window_fully_created(_GLFWwindow *window) { if (!window->wl.window_fully_created) { + GLFWwindow *ctx = glfwGetCurrentContext(); debug("Waiting for compositor to send fractional scale for window %llu\n", window->id); monotonic_t start = monotonic(); while (!window->wl.window_fully_created && monotonic() - start < ms_to_monotonic_t(300)) { @@ -904,6 +905,9 @@ loop_till_window_fully_created(_GLFWwindow *window) { } } window->wl.window_fully_created = true; + // If other OS windows were resized when this window is shown, the ctx might have been changed by + // user code, restore it to whatever it was at the start. + if (glfwGetCurrentContext() != ctx) glfwMakeContextCurrent(ctx); } } diff --git a/kitty/glfw.c b/kitty/glfw.c index 3f757856b..96bd5ab04 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1226,8 +1226,6 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { #ifndef __APPLE__ is_apple = false; glfwShowWindow(glfw_window); - // On Wayland glfwShowWindow spins the event loop, which could include resize events for other OS Windows causing the context to change - if (glfwGetCurrentContext() != glfw_window) glfwMakeContextCurrent(glfw_window); #endif if (global_state.is_wayland || is_apple) { float n_xscale, n_yscale;