From 1a92f92762ccff81e6e27030fcce57797e057e1e Mon Sep 17 00:00:00 2001 From: Jason Francis Date: Sun, 12 Jul 2020 20:47:50 -0400 Subject: [PATCH] Wayland: Fix window hiding Corrects the protocol violation with attaching an xdg_surface to a wl_surface that already has a buffer. Fixes #1492 --- README.md | 2 ++ src/context.c | 2 +- src/egl_context.c | 2 +- src/wl_window.c | 25 ++++++++++++++++--------- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e6440d519..da809dd7b 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ information on what to include when reporting a bug. ## Changelog + - [Wayland] Bugfix: Window hiding not working (#1492) - Added `GLFW_RESIZE_NWSE_CURSOR`, `GLFW_RESIZE_NESW_CURSOR`, `GLFW_RESIZE_ALL_CURSOR` and `GLFW_NOT_ALLOWED_CURSOR` cursor shapes (#427) - Added `GLFW_RESIZE_EW_CURSOR` alias for `GLFW_HRESIZE_CURSOR` (#427) @@ -271,6 +272,7 @@ skills. - Siavash Eliasi - Felipe Ferreira - Michael Fogleman + - Jason Francis - Gerald Franz - Mário Freitas - GeO4d diff --git a/src/context.c b/src/context.c index 48311e5fd..6ea366ce0 100644 --- a/src/context.c +++ b/src/context.c @@ -566,7 +566,7 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, // Clearing the front buffer to black to avoid garbage pixels left over from // previous uses of our bit of VRAM - { + if (_glfwPlatformWindowVisible(window)) { PFNGLCLEARPROC glClear = (PFNGLCLEARPROC) window->context.getProcAddress("glClear"); glClear(GL_COLOR_BUFFER_BIT); diff --git a/src/egl_context.c b/src/egl_context.c index 533ed8e72..8eba0382e 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -221,7 +221,7 @@ static void makeContextCurrentEGL(_GLFWwindow* window) _glfwPlatformSetTls(&_glfw.contextSlot, window); } -static void swapBuffersEGL(_GLFWwindow* window) +void swapBuffersEGL(_GLFWwindow* window) { if (window != _glfwPlatformGetTls(&_glfw.contextSlot)) { diff --git a/src/wl_window.c b/src/wl_window.c index d1dad0659..cc0bb2223 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -777,6 +777,14 @@ static void handleEvents(int timeout) } } +void swapBuffersEGL(_GLFWwindow* window); + +static void swapBuffersWL(_GLFWwindow* window) +{ + if (window->wl.visible) + swapBuffersEGL(window); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// @@ -800,6 +808,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, return GLFW_FALSE; if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; + window->context.swapBuffers = swapBuffersWL; } else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API) { @@ -813,10 +822,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (wndconfig->title) window->wl.title = _glfw_strdup(wndconfig->title); + if (!createXdgSurface(window)) + return GLFW_FALSE; + if (wndconfig->visible) { - if (!createXdgSurface(window)) - return GLFW_FALSE; window->wl.visible = GLFW_TRUE; } @@ -1019,21 +1029,18 @@ void _glfwPlatformShowWindow(_GLFWwindow* window) { if (!window->wl.visible) { - createXdgSurface(window); window->wl.visible = GLFW_TRUE; } } void _glfwPlatformHideWindow(_GLFWwindow* window) { - if (window->wl.xdg.toplevel) + if (window->wl.visible) { - xdg_toplevel_destroy(window->wl.xdg.toplevel); - xdg_surface_destroy(window->wl.xdg.surface); - window->wl.xdg.toplevel = NULL; - window->wl.xdg.surface = NULL; + wl_surface_attach(window->wl.surface, NULL, 0, 0); + wl_surface_commit(window->wl.surface); + window->wl.visible = GLFW_FALSE; } - window->wl.visible = GLFW_FALSE; } void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)