From 72164e6921fb0e333d773a0fdf93aa791792593f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 8 Feb 2024 00:22:26 +0100 Subject: [PATCH] Wayland: Remove fallback decoration edge enum --- src/wl_platform.h | 10 +--- src/wl_window.c | 135 +++++++++++++++++++++++----------------------- 2 files changed, 68 insertions(+), 77 deletions(-) diff --git a/src/wl_platform.h b/src/wl_platform.h index eb361027..0d5d3dfd 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -323,14 +323,6 @@ typedef void (* PFN_libdecor_state_free)(struct libdecor_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_TOP_DECORATION, - GLFW_LEFT_DECORATION, - GLFW_RIGHT_DECORATION, - GLFW_BOTTOM_DECORATION -} _GLFWdecorationSideWayland; - typedef struct _GLFWdecorationWayland { struct wl_surface* surface; @@ -413,7 +405,7 @@ typedef struct _GLFWwindowWayland GLFWbool decorations; struct wl_buffer* buffer; _GLFWdecorationWayland top, left, right, bottom; - _GLFWdecorationSideWayland focus; + struct wl_surface* focus; } fallback; } _GLFWwindowWayland; diff --git a/src/wl_window.c b/src/wl_window.c index c4d96b80..4071b4a5 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1284,18 +1284,6 @@ static void pointerHandleEnter(void* userData, _GLFWwindow* window = wl_surface_get_user_data(surface); - if (window->wl.fallback.decorations) - { - if (surface == window->wl.fallback.top.surface) - window->wl.fallback.focus = GLFW_TOP_DECORATION; - else if (surface == window->wl.fallback.left.surface) - window->wl.fallback.focus = GLFW_LEFT_DECORATION; - else if (surface == window->wl.fallback.right.surface) - window->wl.fallback.focus = GLFW_RIGHT_DECORATION; - else if (surface == window->wl.fallback.bottom.surface) - window->wl.fallback.focus = GLFW_BOTTOM_DECORATION; - } - _glfw.wl.serial = serial; _glfw.wl.pointerEnterSerial = serial; _glfw.wl.pointerFocus = window; @@ -1306,6 +1294,11 @@ static void pointerHandleEnter(void* userData, _glfwSetCursorWayland(window, window->wl.currentCursor); _glfwInputCursorEnter(window, GLFW_TRUE); } + else + { + if (window->wl.fallback.decorations) + window->wl.fallback.focus = surface; + } } static void pointerHandleLeave(void* userData, @@ -1332,6 +1325,11 @@ static void pointerHandleLeave(void* userData, window->wl.hovered = GLFW_FALSE; _glfwInputCursorEnter(window, GLFW_FALSE); } + else + { + if (window->wl.fallback.decorations) + window->wl.fallback.focus = NULL; + } } static void pointerHandleMotion(void* userData, @@ -1363,36 +1361,35 @@ static void pointerHandleMotion(void* userData, { const char* cursorName = NULL; - switch (window->wl.fallback.focus) + if (window->wl.fallback.focus == window->wl.fallback.top.surface) { - case GLFW_TOP_DECORATION: - if (ypos < GLFW_BORDER_SIZE) - cursorName = "n-resize"; - else - cursorName = "left_ptr"; - break; - case GLFW_LEFT_DECORATION: - if (ypos < GLFW_BORDER_SIZE) - cursorName = "nw-resize"; - else - cursorName = "w-resize"; - break; - case GLFW_RIGHT_DECORATION: - if (ypos < GLFW_BORDER_SIZE) - cursorName = "ne-resize"; - else - cursorName = "e-resize"; - break; - case GLFW_BOTTOM_DECORATION: - if (xpos < GLFW_BORDER_SIZE) - cursorName = "sw-resize"; - else if (xpos > window->wl.width + GLFW_BORDER_SIZE) - cursorName = "se-resize"; - else - cursorName = "s-resize"; - break; - default: - assert(0); + if (ypos < GLFW_BORDER_SIZE) + cursorName = "n-resize"; + else + cursorName = "left_ptr"; + } + else if (window->wl.fallback.focus == window->wl.fallback.left.surface) + { + if (ypos < GLFW_BORDER_SIZE) + cursorName = "nw-resize"; + else + cursorName = "w-resize"; + } + else if (window->wl.fallback.focus == window->wl.fallback.right.surface) + { + if (ypos < GLFW_BORDER_SIZE) + cursorName = "ne-resize"; + else + cursorName = "e-resize"; + } + else if (window->wl.fallback.focus == window->wl.fallback.bottom.surface) + { + if (xpos < GLFW_BORDER_SIZE) + cursorName = "sw-resize"; + else if (xpos > window->wl.width + GLFW_BORDER_SIZE) + cursorName = "se-resize"; + else + cursorName = "s-resize"; } if (_glfw.wl.cursorPreviousName != cursorName) @@ -1464,35 +1461,37 @@ static void pointerHandleButton(void* userData, { uint32_t edges = XDG_TOPLEVEL_RESIZE_EDGE_NONE; - switch (window->wl.fallback.focus) + if (window->wl.fallback.focus == window->wl.fallback.top.surface) { - 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 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 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 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) - edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT; - else - edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM; - break; + 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); } + else if (window->wl.fallback.focus == window->wl.fallback.left.surface) + { + if (window->wl.cursorPosY < GLFW_BORDER_SIZE) + edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT; + else + edges = XDG_TOPLEVEL_RESIZE_EDGE_LEFT; + } + else if (window->wl.fallback.focus == window->wl.fallback.right.surface) + { + if (window->wl.cursorPosY < GLFW_BORDER_SIZE) + edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT; + else + edges = XDG_TOPLEVEL_RESIZE_EDGE_RIGHT; + } + else if (window->wl.fallback.focus == window->wl.fallback.bottom.surface) + { + 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) + edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT; + else + edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM; + } + if (edges != XDG_TOPLEVEL_RESIZE_EDGE_NONE) { xdg_toplevel_resize(window->wl.xdg.toplevel, _glfw.wl.seat,