Wayland: Make fallback concepts more distinct

This commit is contained in:
Camilla Löwy 2024-02-08 00:39:13 +01:00
parent 72164e6921
commit e25c1cc74f
2 changed files with 52 additions and 52 deletions

View File

@ -323,12 +323,12 @@ typedef void (* PFN_libdecor_state_free)(struct libdecor_state*);
#define libdecor_state_new _glfw.wl.libdecor.libdecor_state_new_ #define libdecor_state_new _glfw.wl.libdecor.libdecor_state_new_
#define libdecor_state_free _glfw.wl.libdecor.libdecor_state_free_ #define libdecor_state_free _glfw.wl.libdecor.libdecor_state_free_
typedef struct _GLFWdecorationWayland typedef struct _GLFWfallbackEdgeWayland
{ {
struct wl_surface* surface; struct wl_surface* surface;
struct wl_subsurface* subsurface; struct wl_subsurface* subsurface;
struct wp_viewport* viewport; struct wp_viewport* viewport;
} _GLFWdecorationWayland; } _GLFWfallbackEdgeWayland;
typedef struct _GLFWofferWayland typedef struct _GLFWofferWayland
{ {
@ -404,7 +404,7 @@ typedef struct _GLFWwindowWayland
struct { struct {
GLFWbool decorations; GLFWbool decorations;
struct wl_buffer* buffer; struct wl_buffer* buffer;
_GLFWdecorationWayland top, left, right, bottom; _GLFWfallbackEdgeWayland top, left, right, bottom;
struct wl_surface* focus; struct wl_surface* focus;
} fallback; } fallback;
} _GLFWwindowWayland; } _GLFWwindowWayland;

View File

@ -192,29 +192,28 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image)
return buffer; return buffer;
} }
static void createFallbackDecoration(_GLFWwindow* window, static void createFallbackEdge(_GLFWwindow* window,
_GLFWdecorationWayland* decoration, _GLFWfallbackEdgeWayland* edge,
struct wl_surface* parent, struct wl_surface* parent,
struct wl_buffer* buffer, struct wl_buffer* buffer,
int x, int y, int x, int y,
int width, int height) int width, int height)
{ {
decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor); edge->surface = wl_compositor_create_surface(_glfw.wl.compositor);
wl_surface_set_user_data(decoration->surface, window); wl_surface_set_user_data(edge->surface, window);
wl_proxy_set_tag((struct wl_proxy*) decoration->surface, &_glfw.wl.tag); wl_proxy_set_tag((struct wl_proxy*) edge->surface, &_glfw.wl.tag);
decoration->subsurface = edge->subsurface = wl_subcompositor_get_subsurface(_glfw.wl.subcompositor,
wl_subcompositor_get_subsurface(_glfw.wl.subcompositor, edge->surface, parent);
decoration->surface, parent); wl_subsurface_set_position(edge->subsurface, x, y);
wl_subsurface_set_position(decoration->subsurface, x, y); edge->viewport = wp_viewporter_get_viewport(_glfw.wl.viewporter,
decoration->viewport = wp_viewporter_get_viewport(_glfw.wl.viewporter, edge->surface);
decoration->surface); wp_viewport_set_destination(edge->viewport, width, height);
wp_viewport_set_destination(decoration->viewport, width, height); wl_surface_attach(edge->surface, buffer, 0, 0);
wl_surface_attach(decoration->surface, buffer, 0, 0);
struct wl_region* region = wl_compositor_create_region(_glfw.wl.compositor); struct wl_region* region = wl_compositor_create_region(_glfw.wl.compositor);
wl_region_add(region, 0, 0, width, height); wl_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(decoration->surface, region); wl_surface_set_opaque_region(edge->surface, region);
wl_surface_commit(decoration->surface); wl_surface_commit(edge->surface);
wl_region_destroy(region); wl_region_destroy(region);
} }
@ -231,47 +230,48 @@ static void createFallbackDecorations(_GLFWwindow* window)
if (!window->wl.fallback.buffer) if (!window->wl.fallback.buffer)
return; return;
createFallbackDecoration(window, &window->wl.fallback.top, window->wl.surface, createFallbackEdge(window, &window->wl.fallback.top, window->wl.surface,
window->wl.fallback.buffer, window->wl.fallback.buffer,
0, -GLFW_CAPTION_HEIGHT, 0, -GLFW_CAPTION_HEIGHT,
window->wl.width, GLFW_CAPTION_HEIGHT); window->wl.width, GLFW_CAPTION_HEIGHT);
createFallbackDecoration(window, &window->wl.fallback.left, window->wl.surface, createFallbackEdge(window, &window->wl.fallback.left, window->wl.surface,
window->wl.fallback.buffer, window->wl.fallback.buffer,
-GLFW_BORDER_SIZE, -GLFW_CAPTION_HEIGHT, -GLFW_BORDER_SIZE, -GLFW_CAPTION_HEIGHT,
GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT); GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT);
createFallbackDecoration(window, &window->wl.fallback.right, window->wl.surface, createFallbackEdge(window, &window->wl.fallback.right, window->wl.surface,
window->wl.fallback.buffer, window->wl.fallback.buffer,
window->wl.width, -GLFW_CAPTION_HEIGHT, window->wl.width, -GLFW_CAPTION_HEIGHT,
GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT); GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT);
createFallbackDecoration(window, &window->wl.fallback.bottom, window->wl.surface, createFallbackEdge(window, &window->wl.fallback.bottom, window->wl.surface,
window->wl.fallback.buffer, window->wl.fallback.buffer,
-GLFW_BORDER_SIZE, window->wl.height, -GLFW_BORDER_SIZE, window->wl.height,
window->wl.width + GLFW_BORDER_SIZE * 2, GLFW_BORDER_SIZE); window->wl.width + GLFW_BORDER_SIZE * 2, GLFW_BORDER_SIZE);
window->wl.fallback.decorations = GLFW_TRUE; window->wl.fallback.decorations = GLFW_TRUE;
} }
static void destroyFallbackDecoration(_GLFWdecorationWayland* decoration) static void destroyFallbackEdge(_GLFWfallbackEdgeWayland* edge)
{ {
if (decoration->subsurface) if (edge->subsurface)
wl_subsurface_destroy(decoration->subsurface); wl_subsurface_destroy(edge->subsurface);
if (decoration->surface) if (edge->surface)
wl_surface_destroy(decoration->surface); wl_surface_destroy(edge->surface);
if (decoration->viewport) if (edge->viewport)
wp_viewport_destroy(decoration->viewport); wp_viewport_destroy(edge->viewport);
decoration->surface = NULL;
decoration->subsurface = NULL; edge->surface = NULL;
decoration->viewport = NULL; edge->subsurface = NULL;
edge->viewport = NULL;
} }
static void destroyFallbackDecorations(_GLFWwindow* window) static void destroyFallbackDecorations(_GLFWwindow* window)
{ {
window->wl.fallback.decorations = GLFW_FALSE; window->wl.fallback.decorations = GLFW_FALSE;
destroyFallbackDecoration(&window->wl.fallback.top); destroyFallbackEdge(&window->wl.fallback.top);
destroyFallbackDecoration(&window->wl.fallback.left); destroyFallbackEdge(&window->wl.fallback.left);
destroyFallbackDecoration(&window->wl.fallback.right); destroyFallbackEdge(&window->wl.fallback.right);
destroyFallbackDecoration(&window->wl.fallback.bottom); destroyFallbackEdge(&window->wl.fallback.bottom);
} }
static void xdgDecorationHandleConfigure(void* userData, static void xdgDecorationHandleConfigure(void* userData,