From 00967cbb8a4a51ea8ff6f8b8a7efcf1f761cc664 Mon Sep 17 00:00:00 2001 From: TheBrokenRail <17478432+TheBrokenRail@users.noreply.github.com> Date: Thu, 15 Dec 2022 14:18:59 -0500 Subject: [PATCH 01/23] Linux: Fix joystick input being disabled Closes #2192 --- src/wl_init.c | 2 +- src/x11_init.c | 2 +- src/x11_window.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wl_init.c b/src/wl_init.c index 4e6b4294..7a9157a4 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -394,7 +394,7 @@ GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform) _glfwGetKeyScancodeWayland, _glfwSetClipboardStringWayland, _glfwGetClipboardStringWayland, -#if defined(_GLFW_LINUX_JOYSTICK) +#if defined(GLFW_BUILD_LINUX_JOYSTICK) _glfwInitJoysticksLinux, _glfwTerminateJoysticksLinux, _glfwPollJoystickLinux, diff --git a/src/x11_init.c b/src/x11_init.c index 1c69c0f6..a0100f2f 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -1184,7 +1184,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform) _glfwGetKeyScancodeX11, _glfwSetClipboardStringX11, _glfwGetClipboardStringX11, -#if defined(_GLFW_LINUX_JOYSTICK) +#if defined(GLFW_BUILD_LINUX_JOYSTICK) _glfwInitJoysticksLinux, _glfwTerminateJoysticksLinux, _glfwPollJoystickLinux, diff --git a/src/x11_window.c b/src/x11_window.c index 2c46bfff..7da9b965 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -88,7 +88,7 @@ static GLFWbool waitForAnyEvent(double* timeout) { _glfw.x11.emptyEventPipe[0], POLLIN } }; -#if defined(_GLFW_LINUX_JOYSTICK) +#if defined(GLFW_BUILD_LINUX_JOYSTICK) if (_glfw.joysticksInitialized) fds[count++] = (struct pollfd) { _glfw.linjs.inotify, POLLIN }; #endif @@ -2783,7 +2783,7 @@ void _glfwPollEventsX11(void) { drainEmptyEvents(); -#if defined(_GLFW_LINUX_JOYSTICK) +#if defined(GLFW_BUILD_LINUX_JOYSTICK) if (_glfw.joysticksInitialized) _glfwDetectJoystickConnectionLinux(); #endif From 41d8da1cea55732867b5c3a7159215071b87b790 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Fri, 16 Dec 2022 21:40:36 +0900 Subject: [PATCH 02/23] Wayland: Fix wrong array size for _GLFWofferWayland Closes #2225 --- src/wl_window.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wl_window.c b/src/wl_window.c index c4d097b7..a227c16f 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1640,7 +1640,8 @@ static void dataDeviceHandleDataOffer(void* userData, struct wl_data_offer* offer) { _GLFWofferWayland* offers = - _glfw_realloc(_glfw.wl.offers, _glfw.wl.offerCount + 1); + _glfw_realloc(_glfw.wl.offers, + sizeof(_GLFWofferWayland) * (_glfw.wl.offerCount + 1)); if (!offers) { _glfwInputError(GLFW_OUT_OF_MEMORY, NULL); From 57cbded0760a50b9039ee0cb3f3c14f60145567c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 16 Dec 2022 13:44:59 +0100 Subject: [PATCH 03/23] Add credit Related to #2225 --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 110ed4cd..47301dae 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -8,6 +8,7 @@ video tutorials. - Bobyshev Alexander - Laurent Aphecetche - Matt Arsenault + - Takuro Ashie - ashishgamedev - David Avedissian - Luca Bacci From 8f470597d625ae28758c16b4293dd42d63e8a83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 26 Jan 2023 18:41:46 +0100 Subject: [PATCH 04/23] Add support for manually running build workflow --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f798851..4e4c72e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ on: pull_request: push: branches: [ ci, master, latest, 3.3-stable ] + workflow_dispatch: permissions: statuses: write contents: read From e0ae1c45df35c6068c9219006e09a24de216bfa3 Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Sat, 21 Jan 2023 11:30:13 -0700 Subject: [PATCH 05/23] Remove setting of CMake policy CMP0054 This policy is already set to NEW by requiring CMake 3.4. Related to #2256 --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5e538bf..38910cb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,6 @@ project(GLFW VERSION 3.4.0 LANGUAGES C) set(CMAKE_LEGACY_CYGWIN_WIN32 OFF) -if (POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif() - if (POLICY CMP0069) cmake_policy(SET CMP0069 NEW) endif() From 30b91c8b60a29d2c921bee494542b980710b59a7 Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Sat, 21 Jan 2023 11:30:56 -0700 Subject: [PATCH 06/23] Remove CMAKE_LEGACY_CYGWIN_WIN32 CMake option This was needed for compatibility with CMake versions before 2.8.4. Related to #2256 --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38910cb5..22e71864 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.4...3.20 FATAL_ERROR) project(GLFW VERSION 3.4.0 LANGUAGES C) -set(CMAKE_LEGACY_CYGWIN_WIN32 OFF) - if (POLICY CMP0069) cmake_policy(SET CMP0069 NEW) endif() From 1c9fcdc9df3c479cc7adab369df20e10ea179418 Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Sat, 21 Jan 2023 11:33:41 -0700 Subject: [PATCH 07/23] Simplify setting of GLFW_STANDALONE CMake variable Use string(COMPARE EQUAL ...) instead of a whole if() statement. Related to #2256 --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22e71864..dd256a0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,9 +12,7 @@ endif() set_property(GLOBAL PROPERTY USE_FOLDERS ON) -if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(GLFW_STANDALONE TRUE) -endif() +string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} GLFW_STANDALONE) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE}) From 9b1f63bad99e584ac961769bd1ae157613cdaef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 2 Mar 2023 17:47:36 +0100 Subject: [PATCH 08/23] Add credit Closes #2256 --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 47301dae..49d92aed 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -188,6 +188,7 @@ video tutorials. - pthom - Martin Pulec - Guillaume Racicot + - Juan Ramos - Christian Rauch - Philip Rideout - Eddie Ringle From 5c463a9070a5d9df5a3ac5465e6b5807abcaef67 Mon Sep 17 00:00:00 2001 From: Yoshinori Sano Date: Mon, 10 Oct 2022 09:18:25 +0900 Subject: [PATCH 09/23] Win32: Fix typo in error description Closes #2199 --- src/win32_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win32_init.c b/src/win32_init.c index 64393e77..ef2615f1 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -384,7 +384,7 @@ static GLFWbool createHelperWindow(void) if (!_glfw.win32.helperWindowClass) { _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "WIn32: Failed to register helper window class"); + "Win32: Failed to register helper window class"); return GLFW_FALSE; } From 2b580012da0dc11b60fdaf46ae7310e4b6e51c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 3 Mar 2023 14:46:43 +0100 Subject: [PATCH 10/23] Add credit Related to #2199 --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 49d92aed..020bb26e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -201,6 +201,7 @@ video tutorials. - Aleksey Rybalkin - Mikko Rytkönen - Riku Salminen + - Yoshinori Sano - Brandon Schaefer - Sebastian Schuberth - Christian Sdunek From 9a87635686c7fcb63ca63149c5b179b85a53a725 Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Sat, 21 Jan 2023 11:18:35 -0700 Subject: [PATCH 11/23] Update to actions/checkout@v3 Fixes the following CI warning: "Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: actions/checkout@v2..." Closes #2255 --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e4c72e0..c7b30df8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: CC: clang CFLAGS: -Werror steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install dependencies run: | sudo apt update @@ -39,7 +39,7 @@ jobs: CC: clang CFLAGS: -Werror steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install dependencies run: | sudo apt update @@ -62,7 +62,7 @@ jobs: CFLAGS: -Werror MACOSX_DEPLOYMENT_TARGET: 10.8 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Configure static library run: cmake -S . -B build-static @@ -80,7 +80,7 @@ jobs: env: CFLAGS: /WX steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Configure static library run: cmake -S . -B build-static -G "Visual Studio 17 2022" From 82e77dbff4a6695fb8ed3f3e9ed58c4814dd62b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 8 Jan 2023 16:53:21 +0100 Subject: [PATCH 12/23] Wayland: Pick more plausible default cursor size This is not intended as a replacement for actually querying the desktop for the correct size, but it appears to be a better fallback value. --- src/wl_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wl_init.c b/src/wl_init.c index 7a9157a4..42dd75ba 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -339,7 +339,7 @@ static void createKeyTables(void) static GLFWbool loadCursorTheme(void) { - int cursorSize = 32; + int cursorSize = 16; const char* sizeString = getenv("XCURSOR_SIZE"); if (sizeString) From 228428fa4f0a6efc0504f03c0b7f12d8a997a6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 28 Dec 2022 23:35:06 +0100 Subject: [PATCH 13/23] Wayland: Simplify test for fallback decorations The GLFW fallback decorations only exist when the window is visible, decorated and in windowed mode. --- src/wl_window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wl_window.c b/src/wl_window.c index a227c16f..75fe329c 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -2006,7 +2006,7 @@ void _glfwGetWindowFrameSizeWayland(_GLFWwindow* window, int* left, int* top, int* right, int* bottom) { - if (window->decorated && !window->monitor && window->wl.decorations.top.surface) + if (window->wl.decorations.top.surface) { if (top) *top = GLFW_CAPTION_HEIGHT; From 735fc101f5f690370b8943116e183b5b032356e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Dec 2022 18:34:08 +0100 Subject: [PATCH 14/23] Wayland: Fix decorations not always being created If a window was initially fullscreen then it would not get an XDG decoration object. If the window was later switched to windowed mode it would then get fallback decorations instead of XDG ones. --- src/wl_window.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 75fe329c..805161d6 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -633,30 +633,30 @@ static GLFWbool createShellObjects(_GLFWwindow* window) xdg_toplevel_set_maximized(window->wl.xdg.toplevel); setIdleInhibitor(window, GLFW_FALSE); + } - if (_glfw.wl.decorationManager) - { - window->wl.xdg.decoration = - zxdg_decoration_manager_v1_get_toplevel_decoration( - _glfw.wl.decorationManager, window->wl.xdg.toplevel); - zxdg_toplevel_decoration_v1_add_listener(window->wl.xdg.decoration, - &xdgDecorationListener, - window); + if (_glfw.wl.decorationManager) + { + window->wl.xdg.decoration = + zxdg_decoration_manager_v1_get_toplevel_decoration( + _glfw.wl.decorationManager, window->wl.xdg.toplevel); + zxdg_toplevel_decoration_v1_add_listener(window->wl.xdg.decoration, + &xdgDecorationListener, + window); - uint32_t mode; + uint32_t mode; - if (window->decorated) - mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; - else - mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; - - zxdg_toplevel_decoration_v1_set_mode(window->wl.xdg.decoration, mode); - } + if (window->decorated) + mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; else - { - if (window->decorated) - createFallbackDecorations(window); - } + mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; + + zxdg_toplevel_decoration_v1_set_mode(window->wl.xdg.decoration, mode); + } + else + { + if (window->decorated && !window->monitor) + createFallbackDecorations(window); } if (window->minwidth != GLFW_DONT_CARE && window->minheight != GLFW_DONT_CARE) From 8397b39afa30df18eeec0453acca3510fe160dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 8 Jan 2023 22:12:56 +0100 Subject: [PATCH 15/23] Wayland: Fix some missing window refresh events --- src/wl_window.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wl_window.c b/src/wl_window.c index 805161d6..34b7a7a4 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -358,6 +358,9 @@ void _glfwUpdateContentScaleWayland(_GLFWwindow* window) wl_surface_set_buffer_scale(window->wl.surface, maxScale); _glfwInputWindowContentScale(window, maxScale, maxScale); resizeWindow(window); + + if (window->wl.visible) + _glfwInputWindowDamage(window); } } @@ -1938,6 +1941,9 @@ void _glfwSetWindowSizeWayland(_GLFWwindow* window, int width, int height) window->wl.width = width; window->wl.height = height; resizeWindow(window); + + if (window->wl.visible) + _glfwInputWindowDamage(window); } } @@ -1990,6 +1996,9 @@ void _glfwSetWindowAspectRatioWayland(_GLFWwindow* window, int numer, int denom) window->wl.width = window->wl.height * targetRatio; resizeWindow(window); + + if (window->wl.visible) + _glfwInputWindowDamage(window); } } From c1a79c1c41456a6fb0d2490a449eb4b2e0144302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 8 Jan 2023 22:13:45 +0100 Subject: [PATCH 16/23] Wayland: Emit size event when setting aspect ratio --- src/wl_window.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 34b7a7a4..654dc783 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1986,17 +1986,26 @@ void _glfwSetWindowAspectRatioWayland(_GLFWwindow* window, int numer, int denom) if (window->wl.maximized || window->wl.fullscreen) return; + int width = window->wl.width, height = window->wl.height; + if (numer != GLFW_DONT_CARE && denom != GLFW_DONT_CARE) { - const float aspectRatio = (float) window->wl.width / (float) window->wl.height; + const float aspectRatio = (float) width / (float) height; const float targetRatio = (float) numer / (float) denom; if (aspectRatio < targetRatio) - window->wl.height = window->wl.width / targetRatio; + height /= targetRatio; else if (aspectRatio > targetRatio) - window->wl.width = window->wl.height * targetRatio; + width *= targetRatio; + } + if (width != window->wl.width || height != window->wl.height) + { + window->wl.width = width; + window->wl.height = height; resizeWindow(window); + _glfwInputWindowSize(window, width, height); + if (window->wl.visible) _glfwInputWindowDamage(window); } From 4cf510511ca067af7c028c98b2cb90695199052f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 3 Nov 2022 20:54:32 +0100 Subject: [PATCH 17/23] Wayland: Stop manually tracking interface versions This is already tracked by the proxies we care about. --- src/wl_init.c | 8 +++----- src/wl_platform.h | 3 --- src/wl_window.c | 5 ++++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/wl_init.c b/src/wl_init.c index 42dd75ba..e83c6992 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -102,10 +102,9 @@ static void registryHandleGlobal(void* userData, { if (strcmp(interface, "wl_compositor") == 0) { - _glfw.wl.compositorVersion = _glfw_min(3, version); _glfw.wl.compositor = wl_registry_bind(registry, name, &wl_compositor_interface, - _glfw.wl.compositorVersion); + _glfw_min(3, version)); } else if (strcmp(interface, "wl_subcompositor") == 0) { @@ -125,10 +124,9 @@ static void registryHandleGlobal(void* userData, { if (!_glfw.wl.seat) { - _glfw.wl.seatVersion = _glfw_min(4, version); _glfw.wl.seat = wl_registry_bind(registry, name, &wl_seat_interface, - _glfw.wl.seatVersion); + _glfw_min(4, version)); _glfwAddSeatListenerWayland(_glfw.wl.seat); } } @@ -666,7 +664,7 @@ int _glfwInitWayland(void) wl_display_roundtrip(_glfw.wl.display); #ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION - if (_glfw.wl.seatVersion >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) + if (wl_seat_get_version(_glfw.wl.seat) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { _glfw.wl.keyRepeatTimerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); diff --git a/src/wl_platform.h b/src/wl_platform.h index 238e1ed4..f28038de 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -311,9 +311,6 @@ typedef struct _GLFWlibraryWayland _GLFWwindow* dragFocus; uint32_t dragSerial; - int compositorVersion; - int seatVersion; - struct wl_cursor_theme* cursorTheme; struct wl_cursor_theme* cursorThemeHiDPI; struct wl_surface* cursorSurface; diff --git a/src/wl_window.c b/src/wl_window.c index 654dc783..b49ebc50 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -342,8 +342,11 @@ static void resizeWindow(_GLFWwindow* window) void _glfwUpdateContentScaleWayland(_GLFWwindow* window) { - if (_glfw.wl.compositorVersion < WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION) + if (wl_compositor_get_version(_glfw.wl.compositor) < + WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION) + { return; + } // Get the scale factor from the highest scale monitor. int maxScale = 1; From 6d9083af03d04996829b02316770ad755fb6252c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 3 Nov 2022 20:58:15 +0100 Subject: [PATCH 18/23] Wayland: Remove duplicate setting of user data The surface user data is already set by wl_surface_add_listener. --- src/wl_window.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index b49ebc50..697b6a0e 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -733,8 +733,6 @@ static GLFWbool createNativeSurface(_GLFWwindow* window, &surfaceListener, window); - wl_surface_set_user_data(window->wl.surface, window); - window->wl.width = wndconfig->width; window->wl.height = wndconfig->height; window->wl.scale = 1; From 91c837ace563cb2bf188dc8ac8e0ae60f616ffe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 3 Nov 2022 21:51:29 +0100 Subject: [PATCH 19/23] Wayland: Use tags to verify proxy ownership This is in preparation for adding support for libdecor, which creates its own proxies on our display. It will likely also be helpful to some people using native access on Wayland. This is partly based on the implementation of libdecor support in PR #1693 by @ christianrauch. --- src/wl_init.c | 10 +++++++++- src/wl_monitor.c | 1 + src/wl_platform.h | 8 ++++++++ src/wl_window.c | 26 ++++++++++++++++++++++++-- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/wl_init.c b/src/wl_init.c index e83c6992..cbd9d4ec 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -507,6 +507,8 @@ int _glfwInitWayland(void) _glfw.wl.keyRepeatTimerfd = -1; _glfw.wl.cursorTimerfd = -1; + _glfw.wl.tag = glfwGetVersionString(); + _glfw.wl.client.display_flush = (PFN_wl_display_flush) _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_flush"); _glfw.wl.client.display_cancel_read = (PFN_wl_display_cancel_read) @@ -537,6 +539,10 @@ int _glfwInitWayland(void) _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_get_user_data"); _glfw.wl.client.proxy_set_user_data = (PFN_wl_proxy_set_user_data) _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_set_user_data"); + _glfw.wl.client.proxy_get_tag = (PFN_wl_proxy_get_tag) + _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_get_tag"); + _glfw.wl.client.proxy_set_tag = (PFN_wl_proxy_set_tag) + _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_set_tag"); _glfw.wl.client.proxy_get_version = (PFN_wl_proxy_get_version) _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_get_version"); _glfw.wl.client.proxy_marshal_flags = (PFN_wl_proxy_marshal_flags) @@ -556,7 +562,9 @@ int _glfwInitWayland(void) !_glfw.wl.client.proxy_marshal_constructor || !_glfw.wl.client.proxy_marshal_constructor_versioned || !_glfw.wl.client.proxy_get_user_data || - !_glfw.wl.client.proxy_set_user_data) + !_glfw.wl.client.proxy_set_user_data || + !_glfw.wl.client.proxy_get_tag || + !_glfw.wl.client.proxy_set_tag) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Failed to load libwayland-client entry point"); diff --git a/src/wl_monitor.c b/src/wl_monitor.c index 3d4fcbb8..c847eb7e 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -191,6 +191,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version) monitor->wl.output = output; monitor->wl.name = name; + wl_proxy_set_tag((struct wl_proxy*) output, &_glfw.wl.tag); wl_output_add_listener(output, &outputListener, monitor); } diff --git a/src/wl_platform.h b/src/wl_platform.h index f28038de..81e6b5d7 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -61,6 +61,8 @@ typedef struct wl_proxy* (* PFN_wl_proxy_marshal_constructor)(struct wl_proxy*,u typedef struct wl_proxy* (* PFN_wl_proxy_marshal_constructor_versioned)(struct wl_proxy*,uint32_t,const struct wl_interface*,uint32_t,...); typedef void* (* PFN_wl_proxy_get_user_data)(struct wl_proxy*); typedef void (* PFN_wl_proxy_set_user_data)(struct wl_proxy*,void*); +typedef void (* PFN_wl_proxy_set_tag)(struct wl_proxy*,const char*const*); +typedef const char* const* (* PFN_wl_proxy_get_tag)(struct wl_proxy*); typedef uint32_t (* PFN_wl_proxy_get_version)(struct wl_proxy*); typedef struct wl_proxy* (* PFN_wl_proxy_marshal_flags)(struct wl_proxy*,uint32_t,const struct wl_interface*,uint32_t,uint32_t,...); #define wl_display_flush _glfw.wl.client.display_flush @@ -78,6 +80,8 @@ typedef struct wl_proxy* (* PFN_wl_proxy_marshal_flags)(struct wl_proxy*,uint32_ #define wl_proxy_marshal_constructor_versioned _glfw.wl.client.proxy_marshal_constructor_versioned #define wl_proxy_get_user_data _glfw.wl.client.proxy_get_user_data #define wl_proxy_set_user_data _glfw.wl.client.proxy_set_user_data +#define wl_proxy_get_tag _glfw.wl.client.proxy_get_tag +#define wl_proxy_set_tag _glfw.wl.client.proxy_set_tag #define wl_proxy_get_version _glfw.wl.client.proxy_get_version #define wl_proxy_marshal_flags _glfw.wl.client.proxy_marshal_flags @@ -311,6 +315,8 @@ typedef struct _GLFWlibraryWayland _GLFWwindow* dragFocus; uint32_t dragSerial; + const char* tag; + struct wl_cursor_theme* cursorTheme; struct wl_cursor_theme* cursorThemeHiDPI; struct wl_surface* cursorSurface; @@ -388,6 +394,8 @@ typedef struct _GLFWlibraryWayland PFN_wl_proxy_marshal_constructor_versioned proxy_marshal_constructor_versioned; PFN_wl_proxy_get_user_data proxy_get_user_data; PFN_wl_proxy_set_user_data proxy_set_user_data; + PFN_wl_proxy_get_tag proxy_get_tag; + PFN_wl_proxy_set_tag proxy_set_tag; PFN_wl_proxy_get_version proxy_get_version; PFN_wl_proxy_marshal_flags proxy_marshal_flags; } client; diff --git a/src/wl_window.c b/src/wl_window.c index 697b6a0e..5b194e89 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -199,6 +199,7 @@ static void createFallbackDecoration(_GLFWdecorationWayland* decoration, int width, int height) { decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor); + wl_proxy_set_tag((struct wl_proxy*) decoration->surface, &_glfw.wl.tag); decoration->subsurface = wl_subcompositor_get_subsurface(_glfw.wl.subcompositor, decoration->surface, parent); @@ -371,6 +372,9 @@ static void surfaceHandleEnter(void* userData, struct wl_surface* surface, struct wl_output* output) { + if (wl_proxy_get_tag((struct wl_proxy*) output) != &_glfw.wl.tag) + return; + _GLFWwindow* window = userData; _GLFWmonitor* monitor = wl_output_get_user_data(output); @@ -391,6 +395,9 @@ static void surfaceHandleLeave(void* userData, struct wl_surface* surface, struct wl_output* output) { + if (wl_proxy_get_tag((struct wl_proxy*) output) != &_glfw.wl.tag) + return; + _GLFWwindow* window = userData; _GLFWmonitor* monitor = wl_output_get_user_data(output); GLFWbool found = GLFW_FALSE; @@ -729,6 +736,7 @@ static GLFWbool createNativeSurface(_GLFWwindow* window, return GLFW_FALSE; } + wl_proxy_set_tag((struct wl_proxy*) window->wl.surface, &_glfw.wl.tag); wl_surface_add_listener(window->wl.surface, &surfaceListener, window); @@ -1063,6 +1071,9 @@ static void pointerHandleEnter(void* userData, if (!surface) return; + if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) + return; + _GLFWdecorationSideWayland focus = mainWindow; _GLFWwindow* window = wl_surface_get_user_data(surface); if (!window) @@ -1088,8 +1099,13 @@ static void pointerHandleLeave(void* userData, uint32_t serial, struct wl_surface* surface) { - _GLFWwindow* window = _glfw.wl.pointerFocus; + if (!surface) + return; + if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) + return; + + _GLFWwindow* window = _glfw.wl.pointerFocus; if (!window) return; @@ -1681,7 +1697,10 @@ static void dataDeviceHandleEnter(void* userData, _GLFWwindow* window = NULL; if (surface) - window = wl_surface_get_user_data(surface); + { + if (wl_proxy_get_tag((struct wl_proxy*) surface) == &_glfw.wl.tag) + window = wl_surface_get_user_data(surface); + } if (window && _glfw.wl.offers[i].text_uri_list) { @@ -1696,6 +1715,9 @@ static void dataDeviceHandleEnter(void* userData, } } + if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) + return; + if (_glfw.wl.dragOffer) wl_data_offer_accept(offer, serial, "text/uri-list"); else From efa9297a41fb88b1c34ea3835d16463607e7a9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 8 Nov 2022 20:33:29 +0100 Subject: [PATCH 20/23] Wayland: Simplify per-window ouput scales tracking This replaces (one case of) manual management of weak links between windows and monitors, both objects with complex life times, with wl_object pointers used as opaque key values. --- src/wl_monitor.c | 13 ++++++----- src/wl_platform.h | 16 ++++++++----- src/wl_window.c | 57 +++++++++++++++++++++++++---------------------- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/wl_monitor.c b/src/wl_monitor.c index c847eb7e..0b1a3d8d 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -114,14 +114,15 @@ static void outputHandleScale(void* userData, { struct _GLFWmonitor* monitor = userData; - monitor->wl.scale = factor; + monitor->wl.contentScale = factor; for (_GLFWwindow* window = _glfw.windowListHead; window; window = window->next) { - for (int i = 0; i < window->wl.monitorsCount; i++) + for (int i = 0; i < window->wl.scaleCount; i++) { - if (window->wl.monitors[i] == monitor) + if (window->wl.scales[i].output == monitor->wl.output) { + window->wl.scales[i].factor = monitor->wl.contentScale; _glfwUpdateContentScaleWayland(window); break; } @@ -187,7 +188,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version) // The actual name of this output will be set in the geometry handler _GLFWmonitor* monitor = _glfwAllocMonitor("", 0, 0); - monitor->wl.scale = 1; + monitor->wl.contentScale = 1; monitor->wl.output = output; monitor->wl.name = name; @@ -218,9 +219,9 @@ void _glfwGetMonitorContentScaleWayland(_GLFWmonitor* monitor, float* xscale, float* yscale) { if (xscale) - *xscale = (float) monitor->wl.scale; + *xscale = (float) monitor->wl.contentScale; if (yscale) - *yscale = (float) monitor->wl.scale; + *yscale = (float) monitor->wl.contentScale; } void _glfwGetMonitorWorkareaWayland(_GLFWmonitor* monitor, diff --git a/src/wl_platform.h b/src/wl_platform.h index 81e6b5d7..24006312 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -225,6 +225,12 @@ typedef struct _GLFWofferWayland GLFWbool text_uri_list; } _GLFWofferWayland; +typedef struct _GLFWscaleWayland +{ + struct wl_output* output; + int factor; +} _GLFWscaleWayland; + // Wayland-specific per-window data // typedef struct _GLFWwindowWayland @@ -266,10 +272,10 @@ typedef struct _GLFWwindowWayland // We need to track the monitors the window spans on to calculate the // optimal scaling factor. - int scale; - _GLFWmonitor** monitors; - int monitorsCount; - int monitorsSize; + int contentScale; + _GLFWscaleWayland* scales; + int scaleCount; + int scaleSize; struct zwp_relative_pointer_v1* relativePointer; struct zwp_locked_pointer_v1* lockedPointer; @@ -428,7 +434,7 @@ typedef struct _GLFWmonitorWayland int x; int y; - int scale; + int contentScale; } _GLFWmonitorWayland; // Wayland-specific per-cursor data diff --git a/src/wl_window.c b/src/wl_window.c index 5b194e89..5d23cda0 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -307,7 +307,7 @@ static void setContentAreaOpaque(_GLFWwindow* window) static void resizeWindow(_GLFWwindow* window) { - int scale = window->wl.scale; + int scale = window->wl.contentScale; int scaledWidth = window->wl.width * scale; int scaledHeight = window->wl.height * scale; @@ -352,13 +352,13 @@ void _glfwUpdateContentScaleWayland(_GLFWwindow* window) // Get the scale factor from the highest scale monitor. int maxScale = 1; - for (int i = 0; i < window->wl.monitorsCount; i++) - maxScale = _glfw_max(window->wl.monitors[i]->wl.scale, maxScale); + for (int i = 0; i < window->wl.scaleCount; i++) + maxScale = _glfw_max(window->wl.scales[i].factor, maxScale); // Only change the framebuffer size if the scale changed. - if (window->wl.scale != maxScale) + if (window->wl.contentScale != maxScale) { - window->wl.scale = maxScale; + window->wl.contentScale = maxScale; wl_surface_set_buffer_scale(window->wl.surface, maxScale); _glfwInputWindowContentScale(window, maxScale, maxScale); resizeWindow(window); @@ -377,16 +377,20 @@ static void surfaceHandleEnter(void* userData, _GLFWwindow* window = userData; _GLFWmonitor* monitor = wl_output_get_user_data(output); + if (!window || !monitor) + return; - if (window->wl.monitorsCount + 1 > window->wl.monitorsSize) + if (window->wl.scaleCount + 1 > window->wl.scaleSize) { - ++window->wl.monitorsSize; - window->wl.monitors = - _glfw_realloc(window->wl.monitors, - window->wl.monitorsSize * sizeof(_GLFWmonitor*)); + window->wl.scaleSize++; + window->wl.scales = + _glfw_realloc(window->wl.scales, + window->wl.scaleSize * sizeof(_GLFWscaleWayland)); } - window->wl.monitors[window->wl.monitorsCount++] = monitor; + window->wl.scaleCount++; + window->wl.scales[window->wl.scaleCount - 1].factor = monitor->wl.contentScale; + window->wl.scales[window->wl.scaleCount - 1].output = output; _glfwUpdateContentScaleWayland(window); } @@ -399,17 +403,16 @@ static void surfaceHandleLeave(void* userData, return; _GLFWwindow* window = userData; - _GLFWmonitor* monitor = wl_output_get_user_data(output); - GLFWbool found = GLFW_FALSE; - for (int i = 0; i < window->wl.monitorsCount - 1; ++i) + for (int i = 0; i < window->wl.scaleCount; i++) { - if (monitor == window->wl.monitors[i]) - found = GLFW_TRUE; - if (found) - window->wl.monitors[i] = window->wl.monitors[i + 1]; + if (window->wl.scales[i].output == output) + { + window->wl.scales[i] = window->wl.scales[window->wl.scaleCount - 1]; + window->wl.scaleCount--; + break; + } } - window->wl.monitors[--window->wl.monitorsCount] = NULL; _glfwUpdateContentScaleWayland(window); } @@ -743,7 +746,7 @@ static GLFWbool createNativeSurface(_GLFWwindow* window, window->wl.width = wndconfig->width; window->wl.height = wndconfig->height; - window->wl.scale = 1; + window->wl.contentScale = 1; window->wl.title = _glfw_strdup(wndconfig->title); window->wl.appId = _glfw_strdup(wndconfig->wl.appId); @@ -770,7 +773,7 @@ static void setCursorImage(_GLFWwindow* window, buffer = cursorWayland->buffer; else { - if (window->wl.scale > 1 && cursorWayland->cursorHiDPI) + if (window->wl.contentScale > 1 && cursorWayland->cursorHiDPI) { wlCursor = cursorWayland->cursorHiDPI; scale = 2; @@ -1126,7 +1129,7 @@ static void setCursor(_GLFWwindow* window, const char* name) struct wl_cursor_theme* theme = _glfw.wl.cursorTheme; int scale = 1; - if (window->wl.scale > 1 && _glfw.wl.cursorThemeHiDPI) + if (window->wl.contentScale > 1 && _glfw.wl.cursorThemeHiDPI) { // We only support up to scale=2 for now, since libwayland-cursor // requires us to load a different theme for each size. @@ -1908,7 +1911,7 @@ void _glfwDestroyWindowWayland(_GLFWwindow* window) _glfw_free(window->wl.title); _glfw_free(window->wl.appId); - _glfw_free(window->wl.monitors); + _glfw_free(window->wl.scales); } void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title) @@ -2038,9 +2041,9 @@ void _glfwGetFramebufferSizeWayland(_GLFWwindow* window, int* width, int* height { _glfwGetWindowSizeWayland(window, width, height); if (width) - *width *= window->wl.scale; + *width *= window->wl.contentScale; if (height) - *height *= window->wl.scale; + *height *= window->wl.contentScale; } void _glfwGetWindowFrameSizeWayland(_GLFWwindow* window, @@ -2064,9 +2067,9 @@ void _glfwGetWindowContentScaleWayland(_GLFWwindow* window, float* xscale, float* yscale) { if (xscale) - *xscale = (float) window->wl.scale; + *xscale = (float) window->wl.contentScale; if (yscale) - *yscale = (float) window->wl.scale; + *yscale = (float) window->wl.contentScale; } void _glfwIconifyWindowWayland(_GLFWwindow* window) From 39f0e8622898f9533f43aa805ac0667945c1c26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 1 Dec 2022 13:10:07 +0100 Subject: [PATCH 21/23] Wayland: Clean up enum value names --- src/wl_platform.h | 10 +++++----- src/wl_window.c | 42 +++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/wl_platform.h b/src/wl_platform.h index 24006312..423d1026 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -204,11 +204,11 @@ typedef xkb_keysym_t (* PFN_xkb_compose_state_get_one_sym)(struct xkb_compose_st typedef enum _GLFWdecorationSideWayland { - mainWindow, - topDecoration, - leftDecoration, - rightDecoration, - bottomDecoration, + GLFW_MAIN_WINDOW, + GLFW_TOP_DECORATION, + GLFW_LEFT_DECORATION, + GLFW_RIGHT_DECORATION, + GLFW_BOTTOM_DECORATION } _GLFWdecorationSideWayland; typedef struct _GLFWdecorationWayland diff --git a/src/wl_window.c b/src/wl_window.c index 5d23cda0..caaa54fb 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -809,7 +809,7 @@ static void incrementCursorImage(_GLFWwindow* window) { _GLFWcursor* cursor; - if (!window || window->wl.decorations.focus != mainWindow) + if (!window || window->wl.decorations.focus != GLFW_MAIN_WINDOW) return; cursor = window->wl.currentCursor; @@ -1040,22 +1040,22 @@ static _GLFWwindow* findWindowFromDecorationSurface(struct wl_surface* surface, { if (surface == window->wl.decorations.top.surface) { - *which = topDecoration; + *which = GLFW_TOP_DECORATION; break; } if (surface == window->wl.decorations.left.surface) { - *which = leftDecoration; + *which = GLFW_LEFT_DECORATION; break; } if (surface == window->wl.decorations.right.surface) { - *which = rightDecoration; + *which = GLFW_RIGHT_DECORATION; break; } if (surface == window->wl.decorations.bottom.surface) { - *which = bottomDecoration; + *which = GLFW_BOTTOM_DECORATION; break; } window = window->next; @@ -1077,7 +1077,7 @@ static void pointerHandleEnter(void* userData, if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) return; - _GLFWdecorationSideWayland focus = mainWindow; + _GLFWdecorationSideWayland focus = GLFW_MAIN_WINDOW; _GLFWwindow* window = wl_surface_get_user_data(surface); if (!window) { @@ -1187,29 +1187,29 @@ static void pointerHandleMotion(void* userData, switch (window->wl.decorations.focus) { - case mainWindow: + case GLFW_MAIN_WINDOW: _glfw.wl.cursorPreviousName = NULL; _glfwInputCursorPos(window, x, y); return; - case topDecoration: + case GLFW_TOP_DECORATION: if (y < GLFW_BORDER_SIZE) cursorName = "n-resize"; else cursorName = "left_ptr"; break; - case leftDecoration: + case GLFW_LEFT_DECORATION: if (y < GLFW_BORDER_SIZE) cursorName = "nw-resize"; else cursorName = "w-resize"; break; - case rightDecoration: + case GLFW_RIGHT_DECORATION: if (y < GLFW_BORDER_SIZE) cursorName = "ne-resize"; else cursorName = "e-resize"; break; - case bottomDecoration: + case GLFW_BOTTOM_DECORATION: if (x < GLFW_BORDER_SIZE) cursorName = "sw-resize"; else if (x > window->wl.width + GLFW_BORDER_SIZE) @@ -1241,27 +1241,27 @@ static void pointerHandleButton(void* userData, { switch (window->wl.decorations.focus) { - case mainWindow: + case GLFW_MAIN_WINDOW: break; - case topDecoration: + case GLFW_TOP_DECORATION: if (window->wl.cursorPosY < GLFW_BORDER_SIZE) edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP; else xdg_toplevel_move(window->wl.xdg.toplevel, _glfw.wl.seat, serial); break; - case leftDecoration: + case GLFW_LEFT_DECORATION: if (window->wl.cursorPosY < GLFW_BORDER_SIZE) edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT; else edges = XDG_TOPLEVEL_RESIZE_EDGE_LEFT; break; - case rightDecoration: + case GLFW_RIGHT_DECORATION: if (window->wl.cursorPosY < GLFW_BORDER_SIZE) edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT; else edges = XDG_TOPLEVEL_RESIZE_EDGE_RIGHT; break; - case bottomDecoration: + case GLFW_BOTTOM_DECORATION: if (window->wl.cursorPosX < GLFW_BORDER_SIZE) edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT; else if (window->wl.cursorPosX > window->wl.width + GLFW_BORDER_SIZE) @@ -1281,7 +1281,8 @@ static void pointerHandleButton(void* userData, } else if (button == BTN_RIGHT) { - if (window->wl.decorations.focus != mainWindow && window->wl.xdg.toplevel) + if (window->wl.decorations.focus != GLFW_MAIN_WINDOW && + window->wl.xdg.toplevel) { xdg_toplevel_show_window_menu(window->wl.xdg.toplevel, _glfw.wl.seat, serial, @@ -1292,7 +1293,7 @@ static void pointerHandleButton(void* userData, } // Don’t pass the button to the user if it was related to a decoration. - if (window->wl.decorations.focus != mainWindow) + if (window->wl.decorations.focus != GLFW_MAIN_WINDOW) return; _glfw.wl.serial = serial; @@ -2629,8 +2630,11 @@ void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor) // If we're not in the correct window just save the cursor // the next time the pointer enters the window the cursor will change - if (window != _glfw.wl.pointerFocus || window->wl.decorations.focus != mainWindow) + if (window != _glfw.wl.pointerFocus || + window->wl.decorations.focus != GLFW_MAIN_WINDOW) + { return; + } // Update pointer lock to match cursor mode if (window->cursorMode == GLFW_CURSOR_DISABLED) From cd466cf9fd741a9ff704ce773f12dbfee8713640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 28 Dec 2022 16:40:00 +0100 Subject: [PATCH 22/23] Wayland: Simplify decoration side detection This commit simplifies the detection of which element of a fallback decorated window the pointer has entered. Instead of looping through the list of windows, the user pointer of fallback decoration surfaces is set to the GLFW window object. --- src/wl_window.c | 78 +++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 54 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index caaa54fb..70fb6423 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -192,13 +192,15 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image) return buffer; } -static void createFallbackDecoration(_GLFWdecorationWayland* decoration, +static void createFallbackDecoration(_GLFWwindow* window, + _GLFWdecorationWayland* decoration, struct wl_surface* parent, struct wl_buffer* buffer, int x, int y, int width, int height) { decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor); + wl_surface_set_user_data(decoration->surface, window); wl_proxy_set_tag((struct wl_proxy*) decoration->surface, &_glfw.wl.tag); decoration->subsurface = wl_subcompositor_get_subsurface(_glfw.wl.subcompositor, @@ -229,19 +231,19 @@ static void createFallbackDecorations(_GLFWwindow* window) if (!window->wl.decorations.buffer) return; - createFallbackDecoration(&window->wl.decorations.top, window->wl.surface, + createFallbackDecoration(window, &window->wl.decorations.top, window->wl.surface, window->wl.decorations.buffer, 0, -GLFW_CAPTION_HEIGHT, window->wl.width, GLFW_CAPTION_HEIGHT); - createFallbackDecoration(&window->wl.decorations.left, window->wl.surface, + createFallbackDecoration(window, &window->wl.decorations.left, window->wl.surface, window->wl.decorations.buffer, -GLFW_BORDER_SIZE, -GLFW_CAPTION_HEIGHT, GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT); - createFallbackDecoration(&window->wl.decorations.right, window->wl.surface, + createFallbackDecoration(window, &window->wl.decorations.right, window->wl.surface, window->wl.decorations.buffer, window->wl.width, -GLFW_CAPTION_HEIGHT, GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT); - createFallbackDecoration(&window->wl.decorations.bottom, window->wl.surface, + createFallbackDecoration(window, &window->wl.decorations.bottom, window->wl.surface, window->wl.decorations.buffer, -GLFW_BORDER_SIZE, window->wl.height, window->wl.width + GLFW_BORDER_SIZE * 2, GLFW_BORDER_SIZE); @@ -1029,40 +1031,6 @@ static char* readDataOfferAsString(struct wl_data_offer* offer, const char* mime return string; } -static _GLFWwindow* findWindowFromDecorationSurface(struct wl_surface* surface, - _GLFWdecorationSideWayland* which) -{ - _GLFWdecorationSideWayland focus; - _GLFWwindow* window = _glfw.windowListHead; - if (!which) - which = &focus; - while (window) - { - if (surface == window->wl.decorations.top.surface) - { - *which = GLFW_TOP_DECORATION; - break; - } - if (surface == window->wl.decorations.left.surface) - { - *which = GLFW_LEFT_DECORATION; - break; - } - if (surface == window->wl.decorations.right.surface) - { - *which = GLFW_RIGHT_DECORATION; - break; - } - if (surface == window->wl.decorations.bottom.surface) - { - *which = GLFW_BOTTOM_DECORATION; - break; - } - window = window->next; - } - return window; -} - static void pointerHandleEnter(void* userData, struct wl_pointer* pointer, uint32_t serial, @@ -1077,16 +1045,19 @@ static void pointerHandleEnter(void* userData, if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) return; - _GLFWdecorationSideWayland focus = GLFW_MAIN_WINDOW; _GLFWwindow* window = wl_surface_get_user_data(surface); - if (!window) - { - window = findWindowFromDecorationSurface(surface, &focus); - if (!window) - return; - } - window->wl.decorations.focus = focus; + if (surface == window->wl.decorations.top.surface) + window->wl.decorations.focus = GLFW_TOP_DECORATION; + else if (surface == window->wl.decorations.left.surface) + window->wl.decorations.focus = GLFW_LEFT_DECORATION; + else if (surface == window->wl.decorations.right.surface) + window->wl.decorations.focus = GLFW_RIGHT_DECORATION; + else if (surface == window->wl.decorations.bottom.surface) + window->wl.decorations.focus = GLFW_BOTTOM_DECORATION; + else + window->wl.decorations.focus = GLFW_MAIN_WINDOW; + _glfw.wl.serial = serial; _glfw.wl.pointerEnterSerial = serial; _glfw.wl.pointerFocus = window; @@ -1447,13 +1418,12 @@ static void keyboardHandleEnter(void* userData, if (!surface) return; + if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) + return; + _GLFWwindow* window = wl_surface_get_user_data(surface); - if (!window) - { - window = findWindowFromDecorationSurface(surface, NULL); - if (!window) - return; - } + if (surface != window->wl.surface) + return; _glfw.wl.serial = serial; _glfw.wl.keyboardFocus = window; @@ -1706,7 +1676,7 @@ static void dataDeviceHandleEnter(void* userData, window = wl_surface_get_user_data(surface); } - if (window && _glfw.wl.offers[i].text_uri_list) + if (surface == window->wl.surface && _glfw.wl.offers[i].text_uri_list) { _glfw.wl.dragOffer = offer; _glfw.wl.dragFocus = window; From fbdb53b9ca457ab01675e20d9127cb62d8db88b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 27 Dec 2022 14:37:27 +0100 Subject: [PATCH 23/23] Wayland: Add initial support for libdecor This is partly based on the implementation of libdecor support in PR #1693 by @ christianrauch. Where available, the libdecor library is loaded at init and becomes the preferred method for window decorations. On compositors that support XDG decorations, libdecor in turn uses those. If not, libdecor has a plug-in archtecture and may load additional libraries to either use compositor-specific decorations or draw its own. If necessary, support for libdecor can be disabled with the GLFW_WAYLAND_LIBDECOR init hint. This is mostly in case some part of the dynamic loading or duplication of header material added here turns out to cause problems with future versions of libdecor-0.so.0. Fixes #1639 Closes #1693 Related to #1725 --- README.md | 1 + docs/compat.dox | 8 ++ docs/intro.dox | 10 ++ docs/news.dox | 13 ++ include/GLFW/glfw3.h | 8 ++ src/init.c | 6 + src/internal.h | 3 + src/wl_init.c | 119 +++++++++++++++++ src/wl_platform.h | 154 ++++++++++++++++++++++ src/wl_window.c | 303 ++++++++++++++++++++++++++++++++++++++++--- 10 files changed, 607 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8b4a1546..08a3ba5b 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,7 @@ information on what to include when reporting a bug. - [X11] Bugfix: The OSMesa libray was not unloaded on termination - [X11] Bugfix: A malformed response during selection transfer could cause a segfault - [X11] Bugfix: Some calls would reset Xlib to the default error handler (#2108) + - [Wayland] Added improved fallback window decorations via libdecor (#1639,#1693) - [Wayland] Added dynamic loading of all Wayland libraries - [Wayland] Added support for key names via xkbcommon - [Wayland] Added support for file path drop events (#2040) diff --git a/docs/compat.dox b/docs/compat.dox index 94372197..e9506c57 100644 --- a/docs/compat.dox +++ b/docs/compat.dox @@ -128,6 +128,14 @@ wayland-protocols 1.6, and mandatory at build time. If the running compositor does not support this protocol, the screensaver may start even for full screen windows. +GLFW uses the [libdecor library](https://gitlab.freedesktop.org/libdecor/libdecor) +for window decorations, where available. This in turn provides good quality +client-side decorations (drawn by the application) on desktop systems that do +not support server-side decorations (drawn by the window manager). On systems +that do not provide either libdecor or xdg-decoration, very basic window +decorations are provided. These do not include the window title or any caption +buttons. + GLFW uses the [xdg-decoration protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml) to request decorations to be drawn around its windows. This protocol is part diff --git a/docs/intro.dox b/docs/intro.dox index 79348323..36ec0ef5 100644 --- a/docs/intro.dox +++ b/docs/intro.dox @@ -144,6 +144,15 @@ the `VK_KHR_xlib_surface` extension. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This is ignored on other platforms. +@subsubsection init_hints_wayland Wayland specific init hints + +@anchor GLFW_WAYLAND_LIBDECOR_hint +__GLFW_WAYLAND_LIBDECOR__ specifies whether to use +[libdecor](https://gitlab.freedesktop.org/libdecor/libdecor) for window +decorations where available. Possible values are `GLFW_WAYLAND_PREFER_LIBDECOR` +and `GLFW_WAYLAND_DISABLE_LIBDECOR`. This is ignored on other platforms. + + @subsubsection init_hints_values Supported and default values Initialization hint | Default value | Supported values @@ -154,6 +163,7 @@ Initialization hint | Default value | Supported v @ref GLFW_COCOA_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @ref GLFW_COCOA_MENUBAR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @ref GLFW_X11_XCB_VULKAN_SURFACE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` +@ref GLFW_WAYLAND_LIBDECOR | `GLFW_WAYLAND_PREFER_LIBDECOR` | `GLFW_WAYLAND_PREFER_LIBDECOR` or `GLFW_WAYLAND_DISABLE_LIBDECOR` @subsection platform Runtime platform selection diff --git a/docs/news.dox b/docs/news.dox index b8854a0a..e16267b2 100644 --- a/docs/news.dox +++ b/docs/news.dox @@ -43,6 +43,16 @@ to whatever window is behind it. This can also be changed after window creation with the matching [window attribute](@ref GLFW_MOUSE_PASSTHROUGH_attrib). +@subsubsection wayland_libdecor_34 Wayland libdecor decorations + +GLFW now supports improved fallback window decorations via +[libdecor](https://gitlab.freedesktop.org/libdecor/libdecor). + +Support for libdecor can be toggled before GLFW is initialized with the +[GLFW_WAYLAND_LIBDECOR](@ref GLFW_WAYLAND_LIBDECOR_hint) init hint. It is +enabled by default. + + @subsubsection wayland_app_id_34 Wayland app_id specification GLFW now supports specifying the app_id for a Wayland window using the @@ -267,6 +277,9 @@ then GLFW will fail to initialize. - @ref GLFW_POSITION_X - @ref GLFW_POSITION_Y - @ref GLFW_ANY_POSITION + - @ref GLFW_WAYLAND_LIBDECOR + - @ref GLFW_WAYLAND_PREFER_LIBDECOR + - @ref GLFW_WAYLAND_DISABLE_LIBDECOR @section news_archive Release notes for earlier versions diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index d4b40dd4..58b395cd 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1164,6 +1164,9 @@ extern "C" { #define GLFW_ANGLE_PLATFORM_TYPE_VULKAN 0x00037007 #define GLFW_ANGLE_PLATFORM_TYPE_METAL 0x00037008 +#define GLFW_WAYLAND_PREFER_LIBDECOR 0x00038001 +#define GLFW_WAYLAND_DISABLE_LIBDECOR 0x00038002 + #define GLFW_ANY_POSITION 0x80000000 /*! @defgroup shapes Standard cursor shapes @@ -1307,6 +1310,11 @@ extern "C" { * X11 specific [init hint](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint). */ #define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001 +/*! @brief Wayland specific init hint. + * + * Wayland specific [init hint](@ref GLFW_WAYLAND_LIBDECOR_hint). + */ +#define GLFW_WAYLAND_LIBDECOR 0x00053001 /*! @} */ /*! @addtogroup init diff --git a/src/init.c b/src/init.c index d07a492e..06dbb3f2 100644 --- a/src/init.c +++ b/src/init.c @@ -62,6 +62,9 @@ static _GLFWinitconfig _glfwInitHints = { GLFW_TRUE, // X11 XCB Vulkan surface }, + { + GLFW_WAYLAND_PREFER_LIBDECOR // Wayland libdecor mode + }, }; // The allocation function used when no custom allocator is set @@ -479,6 +482,9 @@ GLFWAPI void glfwInitHint(int hint, int value) case GLFW_X11_XCB_VULKAN_SURFACE: _glfwInitHints.x11.xcbVulkanSurface = value; return; + case GLFW_WAYLAND_LIBDECOR: + _glfwInitHints.wl.libdecorMode = value; + return; } _glfwInputError(GLFW_INVALID_ENUM, diff --git a/src/internal.h b/src/internal.h index 781c8cdc..fe0369aa 100644 --- a/src/internal.h +++ b/src/internal.h @@ -379,6 +379,9 @@ struct _GLFWinitconfig struct { GLFWbool xcbVulkanSurface; } x11; + struct { + int libdecorMode; + } wl; }; // Window configuration diff --git a/src/wl_init.c b/src/wl_init.c index cbd9d4ec..66d77dca 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -202,6 +202,20 @@ static const struct wl_registry_listener registryListener = registryHandleGlobalRemove }; +void libdecorHandleError(struct libdecor* context, + enum libdecor_error error, + const char* message) +{ + _glfwInputError(GLFW_PLATFORM_ERROR, + "Wayland: libdecor error %u: %s", + error, message); +} + +static const struct libdecor_interface libdecorInterface = +{ + libdecorHandleError +}; + // Create key code translation tables // static void createKeyTables(void) @@ -652,6 +666,93 @@ int _glfwInitWayland(void) _glfw.wl.xkb.compose_state_get_one_sym = (PFN_xkb_compose_state_get_one_sym) _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_get_one_sym"); + if (_glfw.hints.init.wl.libdecorMode == GLFW_WAYLAND_PREFER_LIBDECOR) + _glfw.wl.libdecor.handle = _glfwPlatformLoadModule("libdecor-0.so.0"); + + if (_glfw.wl.libdecor.handle) + { + _glfw.wl.libdecor.libdecor_new_ = (PFN_libdecor_new) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_new"); + _glfw.wl.libdecor.libdecor_unref_ = (PFN_libdecor_unref) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_unref"); + _glfw.wl.libdecor.libdecor_get_fd_ = (PFN_libdecor_get_fd) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_get_fd"); + _glfw.wl.libdecor.libdecor_dispatch_ = (PFN_libdecor_dispatch) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_dispatch"); + _glfw.wl.libdecor.libdecor_decorate_ = (PFN_libdecor_decorate) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_decorate"); + _glfw.wl.libdecor.libdecor_frame_unref_ = (PFN_libdecor_frame_unref) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unref"); + _glfw.wl.libdecor.libdecor_frame_set_app_id_ = (PFN_libdecor_frame_set_app_id) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_app_id"); + _glfw.wl.libdecor.libdecor_frame_set_title_ = (PFN_libdecor_frame_set_title) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_title"); + _glfw.wl.libdecor.libdecor_frame_set_minimized_ = (PFN_libdecor_frame_set_minimized) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_minimized"); + _glfw.wl.libdecor.libdecor_frame_set_fullscreen_ = (PFN_libdecor_frame_set_fullscreen) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_fullscreen"); + _glfw.wl.libdecor.libdecor_frame_unset_fullscreen_ = (PFN_libdecor_frame_unset_fullscreen) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unset_fullscreen"); + _glfw.wl.libdecor.libdecor_frame_map_ = (PFN_libdecor_frame_map) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_map"); + _glfw.wl.libdecor.libdecor_frame_commit_ = (PFN_libdecor_frame_commit) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_commit"); + _glfw.wl.libdecor.libdecor_frame_set_min_content_size_ = (PFN_libdecor_frame_set_min_content_size) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_min_content_size"); + _glfw.wl.libdecor.libdecor_frame_set_max_content_size_ = (PFN_libdecor_frame_set_max_content_size) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_max_content_size"); + _glfw.wl.libdecor.libdecor_frame_set_maximized_ = (PFN_libdecor_frame_set_maximized) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_maximized"); + _glfw.wl.libdecor.libdecor_frame_unset_maximized_ = (PFN_libdecor_frame_unset_maximized) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unset_maximized"); + _glfw.wl.libdecor.libdecor_frame_set_capabilities_ = (PFN_libdecor_frame_set_capabilities) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_capabilities"); + _glfw.wl.libdecor.libdecor_frame_unset_capabilities_ = (PFN_libdecor_frame_unset_capabilities) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unset_capabilities"); + _glfw.wl.libdecor.libdecor_frame_set_visibility_ = (PFN_libdecor_frame_set_visibility) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_visibility"); + _glfw.wl.libdecor.libdecor_frame_get_xdg_toplevel_ = (PFN_libdecor_frame_get_xdg_toplevel) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_get_xdg_toplevel"); + _glfw.wl.libdecor.libdecor_configuration_get_content_size_ = (PFN_libdecor_configuration_get_content_size) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_configuration_get_content_size"); + _glfw.wl.libdecor.libdecor_configuration_get_window_state_ = (PFN_libdecor_configuration_get_window_state) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_configuration_get_window_state"); + _glfw.wl.libdecor.libdecor_state_new_ = (PFN_libdecor_state_new) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_state_new"); + _glfw.wl.libdecor.libdecor_state_free_ = (PFN_libdecor_state_free) + _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_state_free"); + + if (!_glfw.wl.libdecor.libdecor_new_ || + !_glfw.wl.libdecor.libdecor_unref_ || + !_glfw.wl.libdecor.libdecor_get_fd_ || + !_glfw.wl.libdecor.libdecor_dispatch_ || + !_glfw.wl.libdecor.libdecor_decorate_ || + !_glfw.wl.libdecor.libdecor_frame_unref_ || + !_glfw.wl.libdecor.libdecor_frame_set_app_id_ || + !_glfw.wl.libdecor.libdecor_frame_set_title_ || + !_glfw.wl.libdecor.libdecor_frame_set_minimized_ || + !_glfw.wl.libdecor.libdecor_frame_set_fullscreen_ || + !_glfw.wl.libdecor.libdecor_frame_unset_fullscreen_ || + !_glfw.wl.libdecor.libdecor_frame_map_ || + !_glfw.wl.libdecor.libdecor_frame_commit_ || + !_glfw.wl.libdecor.libdecor_frame_set_min_content_size_ || + !_glfw.wl.libdecor.libdecor_frame_set_max_content_size_ || + !_glfw.wl.libdecor.libdecor_frame_set_maximized_ || + !_glfw.wl.libdecor.libdecor_frame_unset_maximized_ || + !_glfw.wl.libdecor.libdecor_frame_set_capabilities_ || + !_glfw.wl.libdecor.libdecor_frame_unset_capabilities_ || + !_glfw.wl.libdecor.libdecor_frame_set_visibility_ || + !_glfw.wl.libdecor.libdecor_frame_get_xdg_toplevel_ || + !_glfw.wl.libdecor.libdecor_configuration_get_content_size_ || + !_glfw.wl.libdecor.libdecor_configuration_get_window_state_ || + !_glfw.wl.libdecor.libdecor_state_new_ || + !_glfw.wl.libdecor.libdecor_state_free_) + { + _glfwPlatformFreeModule(_glfw.wl.libdecor.handle); + memset(&_glfw.wl.libdecor, 0, sizeof(_glfw.wl.libdecor)); + } + } + _glfw.wl.registry = wl_display_get_registry(_glfw.wl.display); wl_registry_add_listener(_glfw.wl.registry, ®istryListener, NULL); @@ -671,6 +772,15 @@ int _glfwInitWayland(void) // Sync so we got all initial output events wl_display_roundtrip(_glfw.wl.display); + if (_glfw.wl.libdecor.handle) + { + _glfw.wl.libdecor.context = libdecor_new(_glfw.wl.display, &libdecorInterface); + + // Allow libdecor to receive its globals before proceeding + if (_glfw.wl.libdecor.context) + libdecor_dispatch(_glfw.wl.libdecor.context, 1); + } + #ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION if (wl_seat_get_version(_glfw.wl.seat) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { @@ -712,6 +822,15 @@ void _glfwTerminateWayland(void) _glfwTerminateEGL(); _glfwTerminateOSMesa(); + if (_glfw.wl.libdecor.context) + libdecor_unref(_glfw.wl.libdecor.context); + + if (_glfw.wl.libdecor.handle) + { + _glfwPlatformFreeModule(_glfw.wl.libdecor.handle); + _glfw.wl.libdecor.handle = NULL; + } + if (_glfw.wl.egl.handle) { _glfwPlatformFreeModule(_glfw.wl.egl.handle); diff --git a/src/wl_platform.h b/src/wl_platform.h index 423d1026..e9dd0b4a 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -28,6 +28,8 @@ #include #include +#include + typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; typedef struct VkWaylandSurfaceCreateInfoKHR @@ -86,6 +88,7 @@ typedef struct wl_proxy* (* PFN_wl_proxy_marshal_flags)(struct wl_proxy*,uint32_ #define wl_proxy_marshal_flags _glfw.wl.client.proxy_marshal_flags struct wl_shm; +struct wl_output; #define wl_display_interface _glfw_wl_display_interface #define wl_subcompositor_interface _glfw_wl_subcompositor_interface @@ -202,6 +205,122 @@ typedef xkb_keysym_t (* PFN_xkb_compose_state_get_one_sym)(struct xkb_compose_st #define xkb_compose_state_get_status _glfw.wl.xkb.compose_state_get_status #define xkb_compose_state_get_one_sym _glfw.wl.xkb.compose_state_get_one_sym +struct libdecor; +struct libdecor_frame; +struct libdecor_state; +struct libdecor_configuration; + +enum libdecor_error +{ + LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE, + LIBDECOR_ERROR_INVALID_FRAME_CONFIGURATION, +}; + +enum libdecor_window_state +{ + LIBDECOR_WINDOW_STATE_NONE = 0, + LIBDECOR_WINDOW_STATE_ACTIVE = 1, + LIBDECOR_WINDOW_STATE_MAXIMIZED = 2, + LIBDECOR_WINDOW_STATE_FULLSCREEN = 4, + LIBDECOR_WINDOW_STATE_TILED_LEFT = 8, + LIBDECOR_WINDOW_STATE_TILED_RIGHT = 16, + LIBDECOR_WINDOW_STATE_TILED_TOP = 32, + LIBDECOR_WINDOW_STATE_TILED_BOTTOM = 64 +}; + +enum libdecor_capabilities +{ + LIBDECOR_ACTION_MOVE = 1, + LIBDECOR_ACTION_RESIZE = 2, + LIBDECOR_ACTION_MINIMIZE = 4, + LIBDECOR_ACTION_FULLSCREEN = 8, + LIBDECOR_ACTION_CLOSE = 16 +}; + +struct libdecor_interface +{ + void (* error)(struct libdecor*,enum libdecor_error,const char*); + void (* reserved0)(void); + void (* reserved1)(void); + void (* reserved2)(void); + void (* reserved3)(void); + void (* reserved4)(void); + void (* reserved5)(void); + void (* reserved6)(void); + void (* reserved7)(void); + void (* reserved8)(void); + void (* reserved9)(void); +}; + +struct libdecor_frame_interface +{ + void (* configure)(struct libdecor_frame*,struct libdecor_configuration*,void*); + void (* close)(struct libdecor_frame*,void*); + void (* commit)(struct libdecor_frame*,void*); + void (* dismiss_popup)(struct libdecor_frame*,const char*,void*); + void (* reserved0)(void); + void (* reserved1)(void); + void (* reserved2)(void); + void (* reserved3)(void); + void (* reserved4)(void); + void (* reserved5)(void); + void (* reserved6)(void); + void (* reserved7)(void); + void (* reserved8)(void); + void (* reserved9)(void); +}; + +typedef struct libdecor* (* PFN_libdecor_new)(struct wl_display*,const struct libdecor_interface*); +typedef void (* PFN_libdecor_unref)(struct libdecor*); +typedef int (* PFN_libdecor_get_fd)(struct libdecor*); +typedef int (* PFN_libdecor_dispatch)(struct libdecor*,int); +typedef struct libdecor_frame* (* PFN_libdecor_decorate)(struct libdecor*,struct wl_surface*,const struct libdecor_frame_interface*,void*); +typedef void (* PFN_libdecor_frame_unref)(struct libdecor_frame*); +typedef void (* PFN_libdecor_frame_set_app_id)(struct libdecor_frame*,const char*); +typedef void (* PFN_libdecor_frame_set_title)(struct libdecor_frame*,const char*); +typedef void (* PFN_libdecor_frame_set_minimized)(struct libdecor_frame*); +typedef void (* PFN_libdecor_frame_set_fullscreen)(struct libdecor_frame*,struct wl_output*); +typedef void (* PFN_libdecor_frame_unset_fullscreen)(struct libdecor_frame*); +typedef void (* PFN_libdecor_frame_map)(struct libdecor_frame*); +typedef void (* PFN_libdecor_frame_commit)(struct libdecor_frame*,struct libdecor_state*,struct libdecor_configuration*); +typedef void (* PFN_libdecor_frame_set_min_content_size)(struct libdecor_frame*,int,int); +typedef void (* PFN_libdecor_frame_set_max_content_size)(struct libdecor_frame*,int,int); +typedef void (* PFN_libdecor_frame_set_maximized)(struct libdecor_frame*); +typedef void (* PFN_libdecor_frame_unset_maximized)(struct libdecor_frame*); +typedef void (* PFN_libdecor_frame_set_capabilities)(struct libdecor_frame*,enum libdecor_capabilities); +typedef void (* PFN_libdecor_frame_unset_capabilities)(struct libdecor_frame*,enum libdecor_capabilities); +typedef void (* PFN_libdecor_frame_set_visibility)(struct libdecor_frame*,bool visible); +typedef struct xdg_toplevel* (* PFN_libdecor_frame_get_xdg_toplevel)(struct libdecor_frame*); +typedef bool (* PFN_libdecor_configuration_get_content_size)(struct libdecor_configuration*,struct libdecor_frame*,int*,int*); +typedef bool (* PFN_libdecor_configuration_get_window_state)(struct libdecor_configuration*,enum libdecor_window_state*); +typedef struct libdecor_state* (* PFN_libdecor_state_new)(int,int); +typedef void (* PFN_libdecor_state_free)(struct libdecor_state*); +#define libdecor_new _glfw.wl.libdecor.libdecor_new_ +#define libdecor_unref _glfw.wl.libdecor.libdecor_unref_ +#define libdecor_get_fd _glfw.wl.libdecor.libdecor_get_fd_ +#define libdecor_dispatch _glfw.wl.libdecor.libdecor_dispatch_ +#define libdecor_decorate _glfw.wl.libdecor.libdecor_decorate_ +#define libdecor_frame_unref _glfw.wl.libdecor.libdecor_frame_unref_ +#define libdecor_frame_set_app_id _glfw.wl.libdecor.libdecor_frame_set_app_id_ +#define libdecor_frame_set_title _glfw.wl.libdecor.libdecor_frame_set_title_ +#define libdecor_frame_set_minimized _glfw.wl.libdecor.libdecor_frame_set_minimized_ +#define libdecor_frame_set_fullscreen _glfw.wl.libdecor.libdecor_frame_set_fullscreen_ +#define libdecor_frame_unset_fullscreen _glfw.wl.libdecor.libdecor_frame_unset_fullscreen_ +#define libdecor_frame_map _glfw.wl.libdecor.libdecor_frame_map_ +#define libdecor_frame_commit _glfw.wl.libdecor.libdecor_frame_commit_ +#define libdecor_frame_set_min_content_size _glfw.wl.libdecor.libdecor_frame_set_min_content_size_ +#define libdecor_frame_set_max_content_size _glfw.wl.libdecor.libdecor_frame_set_max_content_size_ +#define libdecor_frame_set_maximized _glfw.wl.libdecor.libdecor_frame_set_maximized_ +#define libdecor_frame_unset_maximized _glfw.wl.libdecor.libdecor_frame_unset_maximized_ +#define libdecor_frame_set_capabilities _glfw.wl.libdecor.libdecor_frame_set_capabilities_ +#define libdecor_frame_unset_capabilities _glfw.wl.libdecor.libdecor_frame_unset_capabilities_ +#define libdecor_frame_set_visibility _glfw.wl.libdecor.libdecor_frame_set_visibility_ +#define libdecor_frame_get_xdg_toplevel _glfw.wl.libdecor.libdecor_frame_get_xdg_toplevel_ +#define libdecor_configuration_get_content_size _glfw.wl.libdecor.libdecor_configuration_get_content_size_ +#define libdecor_configuration_get_window_state _glfw.wl.libdecor.libdecor_configuration_get_window_state_ +#define libdecor_state_new _glfw.wl.libdecor.libdecor_state_new_ +#define libdecor_state_free _glfw.wl.libdecor.libdecor_state_free_ + typedef enum _GLFWdecorationSideWayland { GLFW_MAIN_WINDOW, @@ -264,6 +383,11 @@ typedef struct _GLFWwindowWayland uint32_t decorationMode; } xdg; + struct { + struct libdecor_frame* frame; + int mode; + } libdecor; + _GLFWcursor* currentCursor; double cursorPosX, cursorPosY; @@ -422,6 +546,36 @@ typedef struct _GLFWlibraryWayland PFN_wl_egl_window_destroy window_destroy; PFN_wl_egl_window_resize window_resize; } egl; + + struct { + void* handle; + struct libdecor* context; + PFN_libdecor_new libdecor_new_; + PFN_libdecor_unref libdecor_unref_; + PFN_libdecor_get_fd libdecor_get_fd_; + PFN_libdecor_dispatch libdecor_dispatch_; + PFN_libdecor_decorate libdecor_decorate_; + PFN_libdecor_frame_unref libdecor_frame_unref_; + PFN_libdecor_frame_set_app_id libdecor_frame_set_app_id_; + PFN_libdecor_frame_set_title libdecor_frame_set_title_; + PFN_libdecor_frame_set_minimized libdecor_frame_set_minimized_; + PFN_libdecor_frame_set_fullscreen libdecor_frame_set_fullscreen_; + PFN_libdecor_frame_unset_fullscreen libdecor_frame_unset_fullscreen_; + PFN_libdecor_frame_map libdecor_frame_map_; + PFN_libdecor_frame_commit libdecor_frame_commit_; + PFN_libdecor_frame_set_min_content_size libdecor_frame_set_min_content_size_; + PFN_libdecor_frame_set_max_content_size libdecor_frame_set_max_content_size_; + PFN_libdecor_frame_set_maximized libdecor_frame_set_maximized_; + PFN_libdecor_frame_unset_maximized libdecor_frame_unset_maximized_; + PFN_libdecor_frame_set_capabilities libdecor_frame_set_capabilities_; + PFN_libdecor_frame_unset_capabilities libdecor_frame_unset_capabilities_; + PFN_libdecor_frame_set_visibility libdecor_frame_set_visibility_; + PFN_libdecor_frame_get_xdg_toplevel libdecor_frame_get_xdg_toplevel_; + PFN_libdecor_configuration_get_content_size libdecor_configuration_get_content_size_; + PFN_libdecor_configuration_get_window_state libdecor_configuration_get_window_state_; + PFN_libdecor_state_new libdecor_state_new_; + PFN_libdecor_state_free libdecor_state_free_; + } libdecor; } _GLFWlibraryWayland; // Wayland-specific per-monitor data diff --git a/src/wl_window.c b/src/wl_window.c index 70fb6423..5a35c001 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -447,7 +447,12 @@ static void setIdleInhibitor(_GLFWwindow* window, GLFWbool enable) // static void acquireMonitor(_GLFWwindow* window) { - if (window->wl.xdg.toplevel) + if (window->wl.libdecor.frame) + { + libdecor_frame_set_fullscreen(window->wl.libdecor.frame, + window->monitor->wl.output); + } + else if (window->wl.xdg.toplevel) { xdg_toplevel_set_fullscreen(window->wl.xdg.toplevel, window->monitor->wl.output); @@ -463,12 +468,15 @@ static void acquireMonitor(_GLFWwindow* window) // static void releaseMonitor(_GLFWwindow* window) { - if (window->wl.xdg.toplevel) + if (window->wl.libdecor.frame) + libdecor_frame_unset_fullscreen(window->wl.libdecor.frame); + else if (window->wl.xdg.toplevel) xdg_toplevel_unset_fullscreen(window->wl.xdg.toplevel); setIdleInhibitor(window, GLFW_FALSE); - if (window->wl.xdg.decorationMode != ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) + if (!window->wl.libdecor.frame && + window->wl.xdg.decorationMode != ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) { if (window->decorated) createFallbackDecorations(window); @@ -611,7 +619,190 @@ static const struct xdg_surface_listener xdgSurfaceListener = xdgSurfaceHandleConfigure }; -static GLFWbool createShellObjects(_GLFWwindow* window) +void libdecorFrameHandleConfigure(struct libdecor_frame* frame, + struct libdecor_configuration* config, + void* userData) +{ + _GLFWwindow* window = userData; + int width, height; + + enum libdecor_window_state windowState; + GLFWbool fullscreen, activated, maximized; + + if (libdecor_configuration_get_window_state(config, &windowState)) + { + fullscreen = (windowState & LIBDECOR_WINDOW_STATE_FULLSCREEN) != 0; + activated = (windowState & LIBDECOR_WINDOW_STATE_ACTIVE) != 0; + maximized = (windowState & LIBDECOR_WINDOW_STATE_MAXIMIZED) != 0; + } + else + { + fullscreen = window->wl.fullscreen; + activated = window->wl.activated; + maximized = window->wl.maximized; + } + + if (!libdecor_configuration_get_content_size(config, frame, &width, &height)) + { + width = window->wl.width; + height = window->wl.height; + } + + if (!maximized && !fullscreen) + { + if (window->numer != GLFW_DONT_CARE && window->denom != GLFW_DONT_CARE) + { + const float aspectRatio = (float) width / (float) height; + const float targetRatio = (float) window->numer / (float) window->denom; + if (aspectRatio < targetRatio) + height = width / targetRatio; + else if (aspectRatio > targetRatio) + width = height * targetRatio; + } + } + + struct libdecor_state* frameState = libdecor_state_new(width, height); + libdecor_frame_commit(frame, frameState, config); + libdecor_state_free(frameState); + + if (window->wl.activated != activated) + { + window->wl.activated = activated; + if (!window->wl.activated) + { + if (window->monitor && window->autoIconify) + libdecor_frame_set_minimized(window->wl.libdecor.frame); + } + } + + if (window->wl.maximized != maximized) + { + window->wl.maximized = maximized; + _glfwInputWindowMaximize(window, window->wl.maximized); + } + + window->wl.fullscreen = fullscreen; + + GLFWbool damaged = GLFW_FALSE; + + if (!window->wl.visible) + { + window->wl.visible = GLFW_TRUE; + damaged = GLFW_TRUE; + } + + if (width != window->wl.width || height != window->wl.height) + { + window->wl.width = width; + window->wl.height = height; + resizeWindow(window); + + _glfwInputWindowSize(window, width, height); + damaged = GLFW_TRUE; + } + + if (damaged) + _glfwInputWindowDamage(window); + else + wl_surface_commit(window->wl.surface); +} + +void libdecorFrameHandleClose(struct libdecor_frame* frame, void* userData) +{ + _GLFWwindow* window = userData; + _glfwInputWindowCloseRequest(window); +} + +void libdecorFrameHandleCommit(struct libdecor_frame* frame, void* userData) +{ + _GLFWwindow* window = userData; + wl_surface_commit(window->wl.surface); +} + +void libdecorFrameHandleDismissPopup(struct libdecor_frame* frame, + const char* seatName, + void* userData) +{ +} + +static const struct libdecor_frame_interface libdecorFrameInterface = +{ + libdecorFrameHandleConfigure, + libdecorFrameHandleClose, + libdecorFrameHandleCommit, + libdecorFrameHandleDismissPopup +}; + +static GLFWbool createLibdecorFrame(_GLFWwindow* window) +{ + window->wl.libdecor.frame = libdecor_decorate(_glfw.wl.libdecor.context, + window->wl.surface, + &libdecorFrameInterface, + window); + if (!window->wl.libdecor.frame) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Wayland: Failed to create libdecor frame"); + return GLFW_FALSE; + } + + if (strlen(window->wl.appId)) + libdecor_frame_set_app_id(window->wl.libdecor.frame, window->wl.appId); + + if (strlen(window->wl.title)) + libdecor_frame_set_title(window->wl.libdecor.frame, window->wl.title); + + if (window->minwidth != GLFW_DONT_CARE && + window->minheight != GLFW_DONT_CARE) + { + libdecor_frame_set_min_content_size(window->wl.libdecor.frame, + window->minwidth, + window->minheight); + } + + if (window->maxwidth != GLFW_DONT_CARE && + window->maxheight != GLFW_DONT_CARE) + { + libdecor_frame_set_max_content_size(window->wl.libdecor.frame, + window->maxwidth, + window->maxheight); + } + + if (!window->resizable) + { + libdecor_frame_unset_capabilities(window->wl.libdecor.frame, + LIBDECOR_ACTION_RESIZE); + } + + if (window->monitor) + { + // HACK: Allow libdecor to finish initialization of itself and its + // plugin so it will create the xdg_toplevel for the frame + // This needs to exist when setting the frame to fullscreen + while (!libdecor_frame_get_xdg_toplevel(window->wl.libdecor.frame)) + _glfwWaitEventsWayland(); + + libdecor_frame_set_fullscreen(window->wl.libdecor.frame, + window->monitor->wl.output); + setIdleInhibitor(window, GLFW_TRUE); + } + else + { + if (window->wl.maximized) + libdecor_frame_set_maximized(window->wl.libdecor.frame); + + if (!window->decorated) + libdecor_frame_set_visibility(window->wl.libdecor.frame, false); + + setIdleInhibitor(window, GLFW_FALSE); + } + + libdecor_frame_map(window->wl.libdecor.frame); + wl_display_roundtrip(_glfw.wl.display); + return GLFW_TRUE; +} + +static GLFWbool createXdgShellObjects(_GLFWwindow* window) { window->wl.xdg.surface = xdg_wm_base_get_xdg_surface(_glfw.wl.wmBase, window->wl.surface); @@ -707,14 +898,27 @@ static GLFWbool createShellObjects(_GLFWwindow* window) wl_surface_commit(window->wl.surface); wl_display_roundtrip(_glfw.wl.display); - return GLFW_TRUE; } +static GLFWbool createShellObjects(_GLFWwindow* window) +{ + if (_glfw.wl.libdecor.context) + { + if (createLibdecorFrame(window)) + return GLFW_TRUE; + } + + return createXdgShellObjects(window); +} + static void destroyShellObjects(_GLFWwindow* window) { destroyFallbackDecorations(window); + if (window->wl.libdecor.frame) + libdecor_frame_unref(window->wl.libdecor.frame); + if (window->wl.xdg.decoration) zxdg_toplevel_decoration_v1_destroy(window->wl.xdg.decoration); @@ -724,6 +928,7 @@ static void destroyShellObjects(_GLFWwindow* window) if (window->wl.xdg.surface) xdg_surface_destroy(window->wl.xdg.surface); + window->wl.libdecor.frame = NULL; window->wl.xdg.decoration = NULL; window->wl.xdg.decorationMode = 0; window->wl.xdg.toplevel = NULL; @@ -891,13 +1096,17 @@ static void inputText(_GLFWwindow* window, uint32_t scancode) static void handleEvents(double* timeout) { GLFWbool event = GLFW_FALSE; - struct pollfd fds[] = + struct pollfd fds[4] = { { wl_display_get_fd(_glfw.wl.display), POLLIN }, { _glfw.wl.keyRepeatTimerfd, POLLIN }, { _glfw.wl.cursorTimerfd, POLLIN }, + { -1, POLLIN } }; + if (_glfw.wl.libdecor.context) + fds[3].fd = libdecor_get_fd(_glfw.wl.libdecor.context); + while (!event) { while (wl_display_prepare_read(_glfw.wl.display) != 0) @@ -919,7 +1128,7 @@ static void handleEvents(double* timeout) return; } - if (!_glfwPollPOSIX(fds, 3, timeout)) + if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout)) { wl_display_cancel_read(_glfw.wl.display); return; @@ -964,6 +1173,9 @@ static void handleEvents(double* timeout) event = GLFW_TRUE; } } + + if (fds[3].revents & POLLIN) + libdecor_dispatch(_glfw.wl.libdecor.context, 0); } } @@ -1891,7 +2103,9 @@ void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title) _glfw_free(window->wl.title); window->wl.title = copy; - if (window->wl.xdg.toplevel) + if (window->wl.libdecor.frame) + libdecor_frame_set_title(window->wl.libdecor.frame, title); + else if (window->wl.xdg.toplevel) xdg_toplevel_set_title(window->wl.xdg.toplevel, title); } @@ -1939,6 +2153,13 @@ void _glfwSetWindowSizeWayland(_GLFWwindow* window, int width, int height) window->wl.height = height; resizeWindow(window); + if (window->wl.libdecor.frame) + { + struct libdecor_state* frameState = libdecor_state_new(width, height); + libdecor_frame_commit(window->wl.libdecor.frame, frameState, NULL); + libdecor_state_free(frameState); + } + if (window->wl.visible) _glfwInputWindowDamage(window); } @@ -1948,7 +2169,20 @@ void _glfwSetWindowSizeLimitsWayland(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight) { - if (window->wl.xdg.toplevel) + if (window->wl.libdecor.frame) + { + if (minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE) + minwidth = minheight = 0; + + if (maxwidth == GLFW_DONT_CARE || maxheight == GLFW_DONT_CARE) + maxwidth = maxheight = 0; + + libdecor_frame_set_min_content_size(window->wl.libdecor.frame, + minwidth, minheight); + libdecor_frame_set_max_content_size(window->wl.libdecor.frame, + maxwidth, maxheight); + } + else if (window->wl.xdg.toplevel) { if (minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE) minwidth = minheight = 0; @@ -2001,6 +2235,13 @@ void _glfwSetWindowAspectRatioWayland(_GLFWwindow* window, int numer, int denom) window->wl.height = height; resizeWindow(window); + if (window->wl.libdecor.frame) + { + struct libdecor_state* frameState = libdecor_state_new(width, height); + libdecor_frame_commit(window->wl.libdecor.frame, frameState, NULL); + libdecor_state_free(frameState); + } + _glfwInputWindowSize(window, width, height); if (window->wl.visible) @@ -2045,7 +2286,9 @@ void _glfwGetWindowContentScaleWayland(_GLFWwindow* window, void _glfwIconifyWindowWayland(_GLFWwindow* window) { - if (window->wl.xdg.toplevel) + if (window->wl.libdecor.frame) + libdecor_frame_set_minimized(window->wl.libdecor.frame); + else if (window->wl.xdg.toplevel) xdg_toplevel_set_minimized(window->wl.xdg.toplevel); } @@ -2062,7 +2305,9 @@ void _glfwRestoreWindowWayland(_GLFWwindow* window) if (window->wl.maximized) { - if (window->wl.xdg.toplevel) + if (window->wl.libdecor.frame) + libdecor_frame_unset_maximized(window->wl.libdecor.frame); + else if (window->wl.xdg.toplevel) xdg_toplevel_unset_maximized(window->wl.xdg.toplevel); else window->wl.maximized = GLFW_FALSE; @@ -2072,7 +2317,9 @@ void _glfwRestoreWindowWayland(_GLFWwindow* window) void _glfwMaximizeWindowWayland(_GLFWwindow* window) { - if (window->wl.xdg.toplevel) + if (window->wl.libdecor.frame) + libdecor_frame_set_maximized(window->wl.libdecor.frame); + else if (window->wl.xdg.toplevel) xdg_toplevel_set_maximized(window->wl.xdg.toplevel); else window->wl.maximized = GLFW_TRUE; @@ -2080,7 +2327,7 @@ void _glfwMaximizeWindowWayland(_GLFWwindow* window) void _glfwShowWindowWayland(_GLFWwindow* window) { - if (!window->wl.xdg.toplevel) + if (!window->wl.libdecor.frame && !window->wl.xdg.toplevel) { // NOTE: The XDG surface and role are created here so command-line applications // with off-screen windows do not appear in for example the Unity dock @@ -2172,14 +2419,34 @@ GLFWbool _glfwFramebufferTransparentWayland(_GLFWwindow* window) void _glfwSetWindowResizableWayland(_GLFWwindow* window, GLFWbool enabled) { - // TODO - _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, - "Wayland: Window attribute setting not implemented yet"); + if (window->wl.libdecor.frame) + { + if (enabled) + { + libdecor_frame_set_capabilities(window->wl.libdecor.frame, + LIBDECOR_ACTION_RESIZE); + } + else + { + libdecor_frame_unset_capabilities(window->wl.libdecor.frame, + LIBDECOR_ACTION_RESIZE); + } + } + else + { + // TODO + _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, + "Wayland: Window attribute setting not implemented yet"); + } } void _glfwSetWindowDecoratedWayland(_GLFWwindow* window, GLFWbool enabled) { - if (window->wl.xdg.decoration) + if (window->wl.libdecor.frame) + { + libdecor_frame_set_visibility(window->wl.libdecor.frame, enabled); + } + else if (window->wl.xdg.decoration) { uint32_t mode; @@ -2190,7 +2457,7 @@ void _glfwSetWindowDecoratedWayland(_GLFWwindow* window, GLFWbool enabled) zxdg_toplevel_decoration_v1_set_mode(window->wl.xdg.decoration, mode); } - else + else if (window->wl.xdg.toplevel) { if (enabled) createFallbackDecorations(window);