diff --git a/glfw/context.c b/glfw/context.c index e194a2ee1..b10eda6a4 100644 --- a/glfw/context.c +++ b/glfw/context.c @@ -476,6 +476,9 @@ GLFWAPI void glfwSwapBuffers(GLFWwindow* handle) return; } +#ifdef _GLFW_WAYLAND + _glfwWaylandBeforeBufferSwap(window); +#endif window->context.swapBuffers(window); #ifdef _GLFW_WAYLAND _glfwWaylandAfterBufferSwap(window); diff --git a/glfw/wl_platform.h b/glfw/wl_platform.h index 62a4118cd..d773eb989 100644 --- a/glfw/wl_platform.h +++ b/glfw/wl_platform.h @@ -185,6 +185,9 @@ typedef struct _GLFWwindowWayland struct zwlr_layer_surface_v1* zwlr_layer_surface_v1; } layer_shell; + struct { + int width, height; + } framebuffer_size_at_last_resize; /* information about axis events on current frame */ struct { @@ -420,6 +423,7 @@ typedef struct _GLFWcursorWayland void _glfwAddOutputWayland(uint32_t name, uint32_t version); +void _glfwWaylandBeforeBufferSwap(_GLFWwindow *window); void _glfwWaylandAfterBufferSwap(_GLFWwindow *window); void _glfwSetupWaylandDataDevice(void); void _glfwSetupWaylandPrimarySelectionDevice(void); diff --git a/glfw/wl_window.c b/glfw/wl_window.c index b3e312fd2..06844d761 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -356,24 +356,25 @@ _glfwWaylandWindowScale(_GLFWwindow *window) { return ans; } -typedef struct with_context { _GLFWwindow *current, *new; } with_context; -static inline void with_context_release(with_context *c) { if (c->current != c->new) glfwMakeContextCurrent((GLFWwindow*)c->current); } -#define RAII_window_context(window) with_context __wc __attribute__((cleanup(with_context_release))) = { .current=(_GLFWwindow*)glfwGetCurrentContext(), .new=window }; if (__wc.current != __wc.new) glfwMakeContextCurrent((GLFWwindow*)__wc.new); - static void resizeFramebuffer(_GLFWwindow* window) { - RAII_window_context(window); // ensure wl_egl_window_resize called with correct context double scale = _glfwWaylandWindowScale(window); int scaled_width = (int)round(window->wl.width * scale); int scaled_height = (int)round(window->wl.height * scale); debug("Resizing framebuffer of window: %llu to: %dx%d window size: %dx%d at scale: %.3f\n", window->id, scaled_width, scaled_height, window->wl.width, window->wl.height, scale); - wl_egl_window_resize(window->wl.native, scaled_width, scaled_height, 0, 0); update_regions(window); window->wl.waiting_for_swap_to_commit = true; + window->wl.framebuffer_size_at_last_resize.width = scaled_width; + window->wl.framebuffer_size_at_last_resize.height = scaled_height; _glfwInputFramebufferSize(window, scaled_width, scaled_height); } +void +_glfwWaylandBeforeBufferSwap(_GLFWwindow* window) { + wl_egl_window_resize(window->wl.native, window->wl.framebuffer_size_at_last_resize.width, window->wl.framebuffer_size_at_last_resize.height, 0, 0); +} + void _glfwWaylandAfterBufferSwap(_GLFWwindow* window) { if (window->wl.temp_buffer_used_during_window_creation) { diff --git a/kitty/glfw.c b/kitty/glfw.c index 2a0a17515..8e7a7465d 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1191,9 +1191,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { if (temp_window) { glfwDestroyWindow(temp_window); temp_window = NULL; } if (glfw_window == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; } glfwMakeContextCurrent(glfw_window); - if (is_first_window) { - gl_init(); - } + if (is_first_window) gl_init(); // Will make the GPU automatically apply SRGB gamma curve on the resulting framebuffer glEnable(GL_FRAMEBUFFER_SRGB); bool is_semi_transparent = glfwGetWindowAttrib(glfw_window, GLFW_TRANSPARENT_FRAMEBUFFER);