From 8ecb49d143142b526c9a49f4ef21ebd70e400cec 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 when creating an xdg_surface from a wl_surface that already has a buffer due to EGL buffer swaps. This commit is based on PR #1731 by @ghost, but adapted and altered: - The XDG surface and role are now only created when a window is shown to prevent application lists from showing command-line applications with off-screen-only windows - The special case of Wayland+EGL buffer swap is now in the EGL code to mirror how X11 is handled - Adaption to run-time platform selection and separate credits file Fixes #1492 Closes #1731 (cherry picked from commit 094aa6d3c721397825cb1095c156353463ecafb5) --- CONTRIBUTORS.md | 1 + README.md | 1 + src/egl_context.c | 6 ++++++ src/wl_window.c | 46 +++++++++++----------------------------------- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index da26b569..f3e784ca 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -58,6 +58,7 @@ video tutorials. - TheExileFox - Felipe Ferreira - Michael Fogleman + - Jason Francis - Gerald Franz - Mário Freitas - GeO4d diff --git a/README.md b/README.md index e008b06f..2b8d6004 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: Key repeat could lead to a race condition (#1710) - [Wayland] Bugfix: Activating a window would emit two input focus events - [Wayland] Bugfix: Disable key repeat mechanism when window loses input focus + - [Wayland] Bugfix: Window hiding and showing did not work (#1492,#1731) ## Contact diff --git a/src/egl_context.c b/src/egl_context.c index aa824051..f46b1af5 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -230,6 +230,12 @@ static void swapBuffersEGL(_GLFWwindow* window) return; } +#if defined(_GLFW_WAYLAND) + // NOTE: Swapping buffers on a hidden window on Wayland makes it visible + if (!window->wl.visible) + return; +#endif + eglSwapBuffers(_glfw.egl.display, window->context.egl.surface); } diff --git a/src/wl_window.c b/src/wl_window.c index 924eda9c..73abc550 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -950,29 +950,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (wndconfig->title) window->wl.title = _glfw_strdup(wndconfig->title); - if (wndconfig->visible) - { - if (_glfw.wl.wmBase) - { - if (!createXdgSurface(window)) - return GLFW_FALSE; - } - else - { - if (!createShellSurface(window)) - return GLFW_FALSE; - } - - window->wl.visible = GLFW_TRUE; - } - else - { - window->wl.xdg.surface = NULL; - window->wl.xdg.toplevel = NULL; - window->wl.shellSurface = NULL; - window->wl.visible = GLFW_FALSE; - } - window->wl.currentCursor = NULL; window->wl.monitors = calloc(1, sizeof(_GLFWmonitor*)); @@ -1196,29 +1173,28 @@ void _glfwPlatformShowWindow(_GLFWwindow* window) { if (!window->wl.visible) { + // NOTE: The XDG/shell surface is created here so command-line applications + // with off-screen windows do not appear in for example the Unity dock if (_glfw.wl.wmBase) - createXdgSurface(window); + { + if (!window->wl.xdg.toplevel) + createXdgSurface(window); + } else if (!window->wl.shellSurface) createShellSurface(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; + window->wl.visible = GLFW_FALSE; + wl_surface_attach(window->wl.surface, NULL, 0, 0); + wl_surface_commit(window->wl.surface); } - else if (window->wl.shellSurface) - { - wl_shell_surface_destroy(window->wl.shellSurface); - window->wl.shellSurface = NULL; - } - window->wl.visible = GLFW_FALSE; } void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)