From d4cc5aa6988fb9a6ce7fc7c1fe2e862c9026686a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 6 Apr 2024 11:08:12 +0530 Subject: [PATCH] Report errors when attempts are made to perform actions the compositor doesnt support --- glfw/wl_init.c | 5 ++++- glfw/wl_window.c | 42 ++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/glfw/wl_init.c b/glfw/wl_init.c index 2ad3a00bb..743747e5f 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -302,7 +302,10 @@ static void pointerHandleButton(void* data UNUSED, { if (window->wl.decorations.focus != CENTRAL_WINDOW && window->wl.xdg.toplevel) { - xdg_toplevel_show_window_menu(window->wl.xdg.toplevel, _glfw.wl.seat, serial, (int32_t)x, (int32_t)y - window->wl.decorations.metrics.top); + if (window->wl.wm_capabilities.window_menu) xdg_toplevel_show_window_menu( + window->wl.xdg.toplevel, _glfw.wl.seat, serial, (int32_t)x, (int32_t)y - window->wl.decorations.metrics.top); + else + _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland compositor does not support showing wndow menu"); return; } } diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 32d1ac225..97207f70a 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -596,17 +596,19 @@ static bool createSurface(_GLFWwindow* window, return true; } -static void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor, bool on) -{ - if (window->wl.xdg.toplevel) - { - if (on) { - xdg_toplevel_set_fullscreen(window->wl.xdg.toplevel, monitor ? monitor->wl.output : NULL); - csd_set_visible(window, false); - } else { - xdg_toplevel_unset_fullscreen(window->wl.xdg.toplevel); - csd_set_visible(window, true); - } +static void +setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor, bool on) { + if (!window->wl.xdg.toplevel) return; + if (!window->wl.wm_capabilities.fullscreen) { + _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland compositor does not support fullscreen"); + return; + } + if (on) { + xdg_toplevel_set_fullscreen(window->wl.xdg.toplevel, monitor ? monitor->wl.output : NULL); + csd_set_visible(window, false); + } else { + xdg_toplevel_unset_fullscreen(window->wl.xdg.toplevel); + csd_set_visible(window, true); } } @@ -1093,8 +1095,10 @@ create_window_desktop_surface(_GLFWwindow* window) window->maxwidth, window->maxheight); if (window->monitor) { - xdg_toplevel_set_fullscreen(window->wl.xdg.toplevel, - window->monitor->wl.output); + if (window->wl.wm_capabilities.fullscreen) + xdg_toplevel_set_fullscreen(window->wl.xdg.toplevel, window->monitor->wl.output); + else + _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland compositor does not support fullscreen"); } else { if (window->wl.maximize_on_first_show) { window->wl.maximize_on_first_show = false; @@ -1527,8 +1531,10 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) void _glfwPlatformIconifyWindow(_GLFWwindow* window) { - if (window->wl.xdg.toplevel) - xdg_toplevel_set_minimized(window->wl.xdg.toplevel); + if (window->wl.xdg.toplevel) { + if (window->wl.wm_capabilities.minimize) xdg_toplevel_set_minimized(window->wl.xdg.toplevel); + else _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland compositor does not support minimizing windows"); + } } void _glfwPlatformRestoreWindow(_GLFWwindow* window) @@ -1547,9 +1553,9 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformMaximizeWindow(_GLFWwindow* window) { - if (window->wl.xdg.toplevel) - { - xdg_toplevel_set_maximized(window->wl.xdg.toplevel); + if (window->wl.xdg.toplevel) { + if (window->wl.wm_capabilities.maximize) xdg_toplevel_set_maximized(window->wl.xdg.toplevel); + else _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland compositor does not support maximizing windows"); } }