From 283eba9667733485becc79a6752b350083b571ad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 6 Apr 2024 17:29:17 +0530 Subject: [PATCH] Wayland: Respect top level bounds sent by compositor --- glfw/internal.h | 8 ++++++++ glfw/wl_client_side_decorations.c | 2 ++ glfw/wl_window.c | 1 + 3 files changed, 11 insertions(+) diff --git a/glfw/internal.h b/glfw/internal.h index 6a505c0fd..019f33d83 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -111,6 +111,13 @@ typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*); #define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc #define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008 +#define MAX(x, y) __extension__ ({ \ + __typeof__ (x) a = (x); __typeof__ (y) b = (y); \ + a > b ? a : b;}) +#define MIN(x, y) __extension__ ({ \ + __typeof__ (x) a = (x); __typeof__ (y) b = (y); \ + a < b ? a : b;}) + typedef int GLint; typedef unsigned int GLuint; typedef unsigned int GLenum; @@ -875,3 +882,4 @@ int _glfwPlatformSetWindowBlur(_GLFWwindow* handle, int value); char* _glfw_strdup(const char* source); void _glfw_free_clipboard_data(_GLFWClipboardData *cd); + diff --git a/glfw/wl_client_side_decorations.c b/glfw/wl_client_side_decorations.c index 8700870d3..7b22dcbbe 100644 --- a/glfw/wl_client_side_decorations.c +++ b/glfw/wl_client_side_decorations.c @@ -469,6 +469,8 @@ set_csd_window_geometry(_GLFWwindow *window, int32_t *width, int32_t *height) { if (!size_specified_by_compositor) { *width = window->wl.user_requested_content_size.width; *height = window->wl.user_requested_content_size.height; + if (window->wl.xdg.top_level_bounds.width > 0) *width = MIN(*width, window->wl.xdg.top_level_bounds.width); + if (window->wl.xdg.top_level_bounds.height > 0) *height = MIN(*height, window->wl.xdg.top_level_bounds.height); if (has_csd) *height += decs.metrics.visible_titlebar_height; } decs.geometry.x = 0; decs.geometry.y = 0; diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 4f5752f56..d8c4e7f89 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -719,6 +719,7 @@ xdg_toplevel_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel UNUS _GLFWwindow *window = data; window->wl.xdg.top_level_bounds.width = width; window->wl.xdg.top_level_bounds.height = height; + debug("Compositor set top-level bounds of: %dx%d\n", width, height); } static const struct xdg_toplevel_listener xdgToplevelListener = {