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_free _glfw.wl.libdecor.libdecor_state_free_
typedef struct _GLFWdecorationWayland
typedef struct _GLFWfallbackEdgeWayland
{
struct wl_surface* surface;
struct wl_subsurface* subsurface;
struct wp_viewport* viewport;
} _GLFWdecorationWayland;
} _GLFWfallbackEdgeWayland;
typedef struct _GLFWofferWayland
{
@ -404,7 +404,7 @@ typedef struct _GLFWwindowWayland
struct {
GLFWbool decorations;
struct wl_buffer* buffer;
_GLFWdecorationWayland top, left, right, bottom;
_GLFWfallbackEdgeWayland top, left, right, bottom;
struct wl_surface* focus;
} fallback;
} _GLFWwindowWayland;

View File

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