Move CSD metrics into the window object

Makes them potentially configurable
This commit is contained in:
Kovid Goyal 2021-03-25 12:52:09 +05:30
parent 63a50ec066
commit 44df11c443
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 38 additions and 36 deletions

22
glfw/wl_init.c vendored
View File

@ -202,27 +202,27 @@ static void pointerHandleMotion(void* data UNUSED,
_glfw.wl.cursorPreviousShape = GLFW_INVALID_CURSOR;
return;
case topDecoration:
if (y < _GLFW_DECORATION_WIDTH)
if (y < window->wl.decoration_metrics.width)
cursorShape = GLFW_VRESIZE_CURSOR;
else
cursorShape = GLFW_ARROW_CURSOR;
break;
case leftDecoration:
if (y < _GLFW_DECORATION_WIDTH)
if (y < window->wl.decoration_metrics.width)
cursorShape = GLFW_NW_RESIZE_CURSOR;
else
cursorShape = GLFW_HRESIZE_CURSOR;
break;
case rightDecoration:
if (y < _GLFW_DECORATION_WIDTH)
if (y < window->wl.decoration_metrics.width)
cursorShape = GLFW_NE_RESIZE_CURSOR;
else
cursorShape = GLFW_HRESIZE_CURSOR;
break;
case bottomDecoration:
if (x < _GLFW_DECORATION_WIDTH)
if (x < window->wl.decoration_metrics.width)
cursorShape = GLFW_SW_RESIZE_CURSOR;
else if (x > window->wl.width + _GLFW_DECORATION_WIDTH)
else if (x > window->wl.width + window->wl.decoration_metrics.width)
cursorShape = GLFW_SE_RESIZE_CURSOR;
else
cursorShape = GLFW_VRESIZE_CURSOR;
@ -254,7 +254,7 @@ static void pointerHandleButton(void* data UNUSED,
case mainWindow:
break;
case topDecoration:
if (y < _GLFW_DECORATION_WIDTH)
if (y < window->wl.decoration_metrics.width)
edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP;
else
{
@ -263,21 +263,21 @@ static void pointerHandleButton(void* data UNUSED,
}
break;
case leftDecoration:
if (y < _GLFW_DECORATION_WIDTH)
if (y < window->wl.decoration_metrics.width)
edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT;
else
edges = XDG_TOPLEVEL_RESIZE_EDGE_LEFT;
break;
case rightDecoration:
if (y < _GLFW_DECORATION_WIDTH)
if (y < window->wl.decoration_metrics.width)
edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT;
else
edges = XDG_TOPLEVEL_RESIZE_EDGE_RIGHT;
break;
case bottomDecoration:
if (x < _GLFW_DECORATION_WIDTH)
if (x < window->wl.decoration_metrics.width)
edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT;
else if (x > window->wl.width + _GLFW_DECORATION_WIDTH)
else if (x > window->wl.width + window->wl.decoration_metrics.width)
edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT;
else
edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM;
@ -295,7 +295,7 @@ static void pointerHandleButton(void* data UNUSED,
{
if (window->wl.decorations.focus != mainWindow && window->wl.xdg.toplevel)
{
xdg_toplevel_show_window_menu(window->wl.xdg.toplevel, _glfw.wl.seat, serial, (int32_t)x, (int32_t)y - _GLFW_DECORATION_TOP);
xdg_toplevel_show_window_menu(window->wl.xdg.toplevel, _glfw.wl.seat, serial, (int32_t)x, (int32_t)y - window->wl.decoration_metrics.top);
return;
}
}

8
glfw/wl_platform.h vendored
View File

@ -89,11 +89,6 @@ typedef void (* PFN_wl_egl_window_resize)(struct wl_egl_window*, int, int, int,
#define wl_egl_window_destroy _glfw.wl.egl.window_destroy
#define wl_egl_window_resize _glfw.wl.egl.window_resize
#define _GLFW_DECORATION_WIDTH 4
#define _GLFW_DECORATION_TOP 24
#define _GLFW_DECORATION_VERTICAL (_GLFW_DECORATION_TOP + _GLFW_DECORATION_WIDTH)
#define _GLFW_DECORATION_HORIZONTAL (2 * _GLFW_DECORATION_WIDTH)
typedef enum _GLFWdecorationSideWayland
{
mainWindow,
@ -167,6 +162,9 @@ typedef struct _GLFWwindowWayland
struct wl_callback *current_wl_callback;
} frameCallbackData;
struct {
unsigned int width, top, horizontal, vertical;
} decoration_metrics;
} _GLFWwindowWayland;

44
glfw/wl_window.c vendored
View File

@ -171,26 +171,26 @@ static void resizeFramebuffer(_GLFWwindow* window)
// Top decoration.
wp_viewport_set_destination(window->wl.decorations.top.viewport,
window->wl.width, _GLFW_DECORATION_TOP);
window->wl.width, window->wl.decoration_metrics.top);
wl_surface_commit(window->wl.decorations.top.surface);
// Left decoration.
wp_viewport_set_destination(window->wl.decorations.left.viewport,
_GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
window->wl.decoration_metrics.width, window->wl.height + window->wl.decoration_metrics.top);
wl_surface_commit(window->wl.decorations.left.surface);
// Right decoration.
wl_subsurface_set_position(window->wl.decorations.right.subsurface,
window->wl.width, -_GLFW_DECORATION_TOP);
window->wl.width, -window->wl.decoration_metrics.top);
wp_viewport_set_destination(window->wl.decorations.right.viewport,
_GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
window->wl.decoration_metrics.width, window->wl.height + window->wl.decoration_metrics.top);
wl_surface_commit(window->wl.decorations.right.surface);
// Bottom decoration.
wl_subsurface_set_position(window->wl.decorations.bottom.subsurface,
-_GLFW_DECORATION_WIDTH, window->wl.height);
-window->wl.decoration_metrics.width, window->wl.height);
wp_viewport_set_destination(window->wl.decorations.bottom.viewport,
window->wl.width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH);
window->wl.width + window->wl.decoration_metrics.horizontal, window->wl.decoration_metrics.width);
wl_surface_commit(window->wl.decorations.bottom.surface);
}
@ -394,20 +394,20 @@ static void createDecorations(_GLFWwindow* window)
createDecoration(&window->wl.decorations.top, window->wl.surface,
window->wl.decorations.buffer, opaque,
0, -_GLFW_DECORATION_TOP,
window->wl.width, _GLFW_DECORATION_TOP);
0, -window->wl.decoration_metrics.top,
window->wl.width, window->wl.decoration_metrics.top);
createDecoration(&window->wl.decorations.left, window->wl.surface,
window->wl.decorations.buffer, opaque,
-_GLFW_DECORATION_WIDTH, -_GLFW_DECORATION_TOP,
_GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
-window->wl.decoration_metrics.width, -window->wl.decoration_metrics.top,
window->wl.decoration_metrics.width, window->wl.height + window->wl.decoration_metrics.top);
createDecoration(&window->wl.decorations.right, window->wl.surface,
window->wl.decorations.buffer, opaque,
window->wl.width, -_GLFW_DECORATION_TOP,
_GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
window->wl.width, -window->wl.decoration_metrics.top,
window->wl.decoration_metrics.width, window->wl.height + window->wl.decoration_metrics.top);
createDecoration(&window->wl.decorations.bottom, window->wl.surface,
window->wl.decorations.buffer, opaque,
-_GLFW_DECORATION_WIDTH, window->wl.height,
window->wl.width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH);
-window->wl.decoration_metrics.width, window->wl.height,
window->wl.width + window->wl.decoration_metrics.horizontal, window->wl.decoration_metrics.width);
}
static void destroyDecoration(_GLFWdecorationWayland* decoration)
@ -622,8 +622,8 @@ static void xdgToplevelHandleConfigure(void* data,
window->wl.fullscreened = fullscreen;
if (!fullscreen) {
if (window->decorated && !window->wl.decorations.serverSide && window->wl.decorations.buffer) {
width -= _GLFW_DECORATION_HORIZONTAL;
height -= _GLFW_DECORATION_VERTICAL;
width -= window->wl.decoration_metrics.horizontal;
height -= window->wl.decoration_metrics.vertical;
}
}
dispatchChangesAfterConfigure(window, width, height);
@ -882,6 +882,10 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
{
window->wl.decoration_metrics.width = 4;
window->wl.decoration_metrics.top = 24;
window->wl.decoration_metrics.horizontal = 2 * window->wl.decoration_metrics.width;
window->wl.decoration_metrics.vertical = window->wl.decoration_metrics.width + window->wl.decoration_metrics.top;
window->wl.transparent = fbconfig->transparent;
strncpy(window->wl.appId, wndconfig->wl.appId, sizeof(window->wl.appId));
@ -1086,13 +1090,13 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
if (window->decorated && !window->monitor && !window->wl.decorations.serverSide)
{
if (top)
*top = _GLFW_DECORATION_TOP;
*top = window->wl.decoration_metrics.top;
if (left)
*left = _GLFW_DECORATION_WIDTH;
*left = window->wl.decoration_metrics.width;
if (right)
*right = _GLFW_DECORATION_WIDTH;
*right = window->wl.decoration_metrics.width;
if (bottom)
*bottom = _GLFW_DECORATION_WIDTH;
*bottom = window->wl.decoration_metrics.width;
}
}