commit
5642c5cc8f
@ -0,0 +1,253 @@
|
|||||||
|
#include <GLES2/gl2.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wayland-client.h>
|
||||||
|
#include <wayland-egl.h>
|
||||||
|
#include <wlr/render/egl.h>
|
||||||
|
#include "xdg-shell-client-protocol.h"
|
||||||
|
#include "xdg-decoration-unstable-v1-client-protocol.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Usage: toplevel-decoration [mode]
|
||||||
|
* Creates an xdg-toplevel supporting decoration negotiation. If `mode` is
|
||||||
|
* specified, the client will prefer this decoration mode.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int width = 500, height = 300;
|
||||||
|
|
||||||
|
static struct wl_compositor *compositor = NULL;
|
||||||
|
static struct xdg_wm_base *wm_base = NULL;
|
||||||
|
static struct zxdg_decoration_manager_v1 *decoration_manager = NULL;
|
||||||
|
|
||||||
|
struct wlr_egl egl;
|
||||||
|
struct wl_egl_window *egl_window;
|
||||||
|
struct wlr_egl_surface *egl_surface;
|
||||||
|
|
||||||
|
struct zxdg_toplevel_decoration_v1 *decoration;
|
||||||
|
enum zxdg_toplevel_decoration_v1_mode client_preferred_mode, current_mode;
|
||||||
|
|
||||||
|
static const char *get_mode_name(enum zxdg_toplevel_decoration_v1_mode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE:
|
||||||
|
return "client-side decorations";
|
||||||
|
case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE:
|
||||||
|
return "server-side decorations";
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void request_preferred_mode(void) {
|
||||||
|
enum zxdg_toplevel_decoration_v1_mode mode = client_preferred_mode;
|
||||||
|
if (mode == 0) {
|
||||||
|
printf("Requesting compositor preferred mode\n");
|
||||||
|
zxdg_toplevel_decoration_v1_unset_mode(decoration);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mode == current_mode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Requesting %s\n", get_mode_name(mode));
|
||||||
|
zxdg_toplevel_decoration_v1_set_mode(decoration, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw(void) {
|
||||||
|
eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context);
|
||||||
|
|
||||||
|
float color[] = {1.0, 1.0, 0.0, 1.0};
|
||||||
|
if (current_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE) {
|
||||||
|
color[0] = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
glClearColor(color[0], color[1], color[2], 1.0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
eglSwapBuffers(egl.display, egl_surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void xdg_surface_handle_configure(void *data,
|
||||||
|
struct xdg_surface *xdg_surface, uint32_t serial) {
|
||||||
|
xdg_surface_ack_configure(xdg_surface, serial);
|
||||||
|
wl_egl_window_resize(egl_window, width, height, 0, 0);
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
||||||
|
.configure = xdg_surface_handle_configure,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void xdg_toplevel_handle_configure(void *data,
|
||||||
|
struct xdg_toplevel *xdg_toplevel, int32_t w, int32_t h,
|
||||||
|
struct wl_array *states) {
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
||||||
|
.configure = xdg_toplevel_handle_configure,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void decoration_handle_configure(void *data,
|
||||||
|
struct zxdg_toplevel_decoration_v1 *decoration,
|
||||||
|
enum zxdg_toplevel_decoration_v1_mode mode) {
|
||||||
|
printf("Using %s\n", get_mode_name(mode));
|
||||||
|
current_mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = {
|
||||||
|
.configure = decoration_handle_configure,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
|
||||||
|
uint32_t serial, struct wl_surface *surface,
|
||||||
|
wl_fixed_t sx, wl_fixed_t sy) {
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
|
||||||
|
uint32_t serial, struct wl_surface *surface) {
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
|
||||||
|
uint32_t time, wl_fixed_t sx, wl_fixed_t sy) {
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t serial, uint32_t time, uint32_t button,
|
||||||
|
enum wl_pointer_button_state state) {
|
||||||
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||||
|
// Toggle mode
|
||||||
|
if (client_preferred_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) {
|
||||||
|
client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
|
||||||
|
} else {
|
||||||
|
client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
|
||||||
|
}
|
||||||
|
request_preferred_mode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
uint32_t time, enum wl_pointer_axis axis, wl_fixed_t value) {
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_pointer_listener pointer_listener = {
|
||||||
|
.enter = pointer_handle_enter,
|
||||||
|
.leave = pointer_handle_leave,
|
||||||
|
.motion = pointer_handle_motion,
|
||||||
|
.button = pointer_handle_button,
|
||||||
|
.axis = pointer_handle_axis,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void seat_handle_capabilities(void *data, struct wl_seat *seat,
|
||||||
|
enum wl_seat_capability caps) {
|
||||||
|
if (caps & WL_SEAT_CAPABILITY_POINTER) {
|
||||||
|
struct wl_pointer *pointer = wl_seat_get_pointer(seat);
|
||||||
|
wl_pointer_add_listener(pointer, &pointer_listener, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_seat_listener seat_listener = {
|
||||||
|
.capabilities = seat_handle_capabilities,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void handle_global(void *data, struct wl_registry *registry,
|
||||||
|
uint32_t name, const char *interface, uint32_t version) {
|
||||||
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
||||||
|
compositor = wl_registry_bind(registry, name, &wl_compositor_interface,
|
||||||
|
1);
|
||||||
|
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
|
||||||
|
wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
|
||||||
|
} else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) {
|
||||||
|
decoration_manager = wl_registry_bind(registry, name,
|
||||||
|
&zxdg_decoration_manager_v1_interface, 1);
|
||||||
|
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
||||||
|
struct wl_seat *seat =
|
||||||
|
wl_registry_bind(registry, name, &wl_seat_interface, 1);
|
||||||
|
wl_seat_add_listener(seat, &seat_listener, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_global_remove(void *data, struct wl_registry *registry,
|
||||||
|
uint32_t name) {
|
||||||
|
// Who cares?
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_registry_listener registry_listener = {
|
||||||
|
.global = handle_global,
|
||||||
|
.global_remove = handle_global_remove,
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc == 2) {
|
||||||
|
char *mode = argv[1];
|
||||||
|
if (strcmp(mode, "client") == 0) {
|
||||||
|
client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
|
||||||
|
} else if (strcmp(mode, "server") == 0) {
|
||||||
|
client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Invalid decoration mode\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wl_display *display = wl_display_connect(NULL);
|
||||||
|
if (display == NULL) {
|
||||||
|
fprintf(stderr, "Failed to create display\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wl_registry *registry = wl_display_get_registry(display);
|
||||||
|
wl_registry_add_listener(registry, ®istry_listener, NULL);
|
||||||
|
wl_display_dispatch(display);
|
||||||
|
wl_display_roundtrip(display);
|
||||||
|
|
||||||
|
if (compositor == NULL) {
|
||||||
|
fprintf(stderr, "wl-compositor not available\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
if (wm_base == NULL) {
|
||||||
|
fprintf(stderr, "xdg-shell not available\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
if (decoration_manager == NULL) {
|
||||||
|
fprintf(stderr, "xdg-decoration not available\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL,
|
||||||
|
WL_SHM_FORMAT_ARGB8888);
|
||||||
|
|
||||||
|
struct wl_surface *surface = wl_compositor_create_surface(compositor);
|
||||||
|
struct xdg_surface *xdg_surface =
|
||||||
|
xdg_wm_base_get_xdg_surface(wm_base, surface);
|
||||||
|
struct xdg_toplevel *xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
|
||||||
|
decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(
|
||||||
|
decoration_manager, xdg_toplevel);
|
||||||
|
|
||||||
|
wl_display_roundtrip(display);
|
||||||
|
request_preferred_mode();
|
||||||
|
|
||||||
|
xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, NULL);
|
||||||
|
xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, NULL);
|
||||||
|
zxdg_toplevel_decoration_v1_add_listener(decoration, &decoration_listener,
|
||||||
|
NULL);
|
||||||
|
wl_surface_commit(surface);
|
||||||
|
|
||||||
|
egl_window = wl_egl_window_create(surface, width, height);
|
||||||
|
egl_surface = wlr_egl_create_surface(&egl, egl_window);
|
||||||
|
|
||||||
|
wl_display_roundtrip(display);
|
||||||
|
|
||||||
|
draw();
|
||||||
|
|
||||||
|
while (wl_display_dispatch(display) != -1) {
|
||||||
|
// This space is intentionally left blank
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
#ifndef WLR_TYPES_WLR_XDG_DECORATION_V1
|
||||||
|
#define WLR_TYPES_WLR_XDG_DECORATION_V1
|
||||||
|
|
||||||
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/types/wlr_xdg_shell.h>
|
||||||
|
|
||||||
|
enum wlr_xdg_toplevel_decoration_v1_mode {
|
||||||
|
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE = 0,
|
||||||
|
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE = 1,
|
||||||
|
WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_xdg_decoration_manager_v1 {
|
||||||
|
struct wl_global *global;
|
||||||
|
struct wl_list resources;
|
||||||
|
struct wl_list decorations; // wlr_xdg_toplevel_decoration::link
|
||||||
|
|
||||||
|
struct wl_listener display_destroy;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
struct wl_signal new_toplevel_decoration; // struct wlr_xdg_toplevel_decoration *
|
||||||
|
} events;
|
||||||
|
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1_configure {
|
||||||
|
struct wl_list link; // wlr_xdg_toplevel_decoration::configure_list
|
||||||
|
struct wlr_xdg_surface_configure *surface_configure;
|
||||||
|
enum wlr_xdg_toplevel_decoration_v1_mode mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 {
|
||||||
|
struct wl_resource *resource;
|
||||||
|
struct wlr_xdg_surface *surface;
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager;
|
||||||
|
struct wl_list link; // wlr_xdg_decoration_manager_v1::link
|
||||||
|
|
||||||
|
bool added;
|
||||||
|
enum wlr_xdg_toplevel_decoration_v1_mode current_mode;
|
||||||
|
enum wlr_xdg_toplevel_decoration_v1_mode client_pending_mode;
|
||||||
|
enum wlr_xdg_toplevel_decoration_v1_mode server_pending_mode;
|
||||||
|
|
||||||
|
struct wl_list configure_list; // wlr_xdg_toplevel_decoration_v1_configure::link
|
||||||
|
|
||||||
|
struct {
|
||||||
|
struct wl_signal destroy;
|
||||||
|
struct wl_signal request_mode;
|
||||||
|
} events;
|
||||||
|
|
||||||
|
struct wl_listener surface_destroy;
|
||||||
|
struct wl_listener surface_configure;
|
||||||
|
struct wl_listener surface_ack_configure;
|
||||||
|
struct wl_listener surface_commit;
|
||||||
|
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *
|
||||||
|
wlr_xdg_decoration_manager_v1_create(struct wl_display *display);
|
||||||
|
void wlr_xdg_decoration_manager_v1_destroy(
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager);
|
||||||
|
|
||||||
|
uint32_t wlr_xdg_toplevel_decoration_v1_set_mode(
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration,
|
||||||
|
enum wlr_xdg_toplevel_decoration_v1_mode mode);
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,302 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <wlr/types/wlr_xdg_decoration_v1.h>
|
||||||
|
#include <wlr/util/log.h>
|
||||||
|
#include "util/signal.h"
|
||||||
|
#include "xdg-decoration-unstable-v1-protocol.h"
|
||||||
|
|
||||||
|
#define DECORATION_MANAGER_VERSION 1
|
||||||
|
|
||||||
|
static const struct zxdg_toplevel_decoration_v1_interface
|
||||||
|
toplevel_decoration_impl;
|
||||||
|
|
||||||
|
static struct wlr_xdg_toplevel_decoration_v1 *toplevel_decoration_from_resource(
|
||||||
|
struct wl_resource *resource) {
|
||||||
|
assert(wl_resource_instance_of(resource,
|
||||||
|
&zxdg_toplevel_decoration_v1_interface, &toplevel_decoration_impl));
|
||||||
|
return wl_resource_get_user_data(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_destroy(struct wl_client *client,
|
||||||
|
struct wl_resource *resource) {
|
||||||
|
wl_resource_destroy(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_set_mode(struct wl_client *client,
|
||||||
|
struct wl_resource *resource,
|
||||||
|
enum zxdg_toplevel_decoration_v1_mode mode) {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
toplevel_decoration_from_resource(resource);
|
||||||
|
|
||||||
|
decoration->client_pending_mode =
|
||||||
|
(enum wlr_xdg_toplevel_decoration_v1_mode)mode;
|
||||||
|
wlr_signal_emit_safe(&decoration->events.request_mode, decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_unset_mode(struct wl_client *client,
|
||||||
|
struct wl_resource *resource) {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
toplevel_decoration_from_resource(resource);
|
||||||
|
|
||||||
|
decoration->client_pending_mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE;
|
||||||
|
wlr_signal_emit_safe(&decoration->events.request_mode, decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct zxdg_toplevel_decoration_v1_interface
|
||||||
|
toplevel_decoration_impl = {
|
||||||
|
.destroy = toplevel_decoration_handle_destroy,
|
||||||
|
.set_mode = toplevel_decoration_handle_set_mode,
|
||||||
|
.unset_mode = toplevel_decoration_handle_unset_mode,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t wlr_xdg_toplevel_decoration_v1_set_mode(
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration,
|
||||||
|
enum wlr_xdg_toplevel_decoration_v1_mode mode) {
|
||||||
|
assert(mode != WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE);
|
||||||
|
decoration->server_pending_mode = mode;
|
||||||
|
return wlr_xdg_surface_schedule_configure(decoration->surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_resource_destroy(
|
||||||
|
struct wl_resource *resource) {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
toplevel_decoration_from_resource(resource);
|
||||||
|
wlr_signal_emit_safe(&decoration->events.destroy, decoration);
|
||||||
|
wl_list_remove(&decoration->surface_commit.link);
|
||||||
|
wl_list_remove(&decoration->surface_destroy.link);
|
||||||
|
wl_list_remove(&decoration->surface_configure.link);
|
||||||
|
wl_list_remove(&decoration->surface_ack_configure.link);
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1_configure *configure, *tmp;
|
||||||
|
wl_list_for_each_safe(configure, tmp, &decoration->configure_list, link) {
|
||||||
|
free(configure);
|
||||||
|
}
|
||||||
|
wl_list_remove(&decoration->link);
|
||||||
|
free(decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_surface_destroy(
|
||||||
|
struct wl_listener *listener, void *data) {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
wl_container_of(listener, decoration, surface_destroy);
|
||||||
|
wl_resource_destroy(decoration->resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_surface_configure(
|
||||||
|
struct wl_listener *listener, void *data) {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
wl_container_of(listener, decoration, surface_configure);
|
||||||
|
struct wlr_xdg_surface_configure *surface_configure = data;
|
||||||
|
|
||||||
|
if (decoration->current_mode == decoration->server_pending_mode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1_configure *configure =
|
||||||
|
calloc(1, sizeof(struct wlr_xdg_toplevel_decoration_v1_configure));
|
||||||
|
if (configure == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
configure->surface_configure = surface_configure;
|
||||||
|
configure->mode = decoration->server_pending_mode;
|
||||||
|
wl_list_insert(decoration->configure_list.prev, &configure->link);
|
||||||
|
|
||||||
|
zxdg_toplevel_decoration_v1_send_configure(decoration->resource,
|
||||||
|
configure->mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_surface_ack_configure(
|
||||||
|
struct wl_listener *listener, void *data) {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
wl_container_of(listener, decoration, surface_ack_configure);
|
||||||
|
struct wlr_xdg_surface_configure *surface_configure = data;
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1_configure *configure;
|
||||||
|
wl_list_for_each(configure, &decoration->configure_list, link) {
|
||||||
|
if (configure->surface_configure == surface_configure) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
decoration->current_mode = configure->mode;
|
||||||
|
|
||||||
|
wl_list_remove(&configure->link);
|
||||||
|
free(configure);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toplevel_decoration_handle_surface_commit(
|
||||||
|
struct wl_listener *listener, void *data) {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
wl_container_of(listener, decoration, surface_commit);
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager = decoration->manager;
|
||||||
|
|
||||||
|
if (decoration->surface->added) {
|
||||||
|
wl_list_remove(&decoration->surface_commit.link);
|
||||||
|
wl_list_init(&decoration->surface_commit.link);
|
||||||
|
|
||||||
|
decoration->added = true;
|
||||||
|
wlr_signal_emit_safe(&manager->events.new_toplevel_decoration,
|
||||||
|
decoration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl;
|
||||||
|
|
||||||
|
static struct wlr_xdg_decoration_manager_v1 *
|
||||||
|
decoration_manager_from_resource(struct wl_resource *resource) {
|
||||||
|
assert(wl_resource_instance_of(resource,
|
||||||
|
&zxdg_decoration_manager_v1_interface,
|
||||||
|
&decoration_manager_impl));
|
||||||
|
return wl_resource_get_user_data(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void decoration_manager_handle_get_toplevel_decoration(
|
||||||
|
struct wl_client *client, struct wl_resource *manager_resource,
|
||||||
|
uint32_t id, struct wl_resource *toplevel_resource) {
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager =
|
||||||
|
decoration_manager_from_resource(manager_resource);
|
||||||
|
struct wlr_xdg_surface *surface =
|
||||||
|
wlr_xdg_surface_from_toplevel_resource(toplevel_resource);
|
||||||
|
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
|
||||||
|
|
||||||
|
if (wlr_surface_has_buffer(surface->surface)) {
|
||||||
|
wl_resource_post_error(manager_resource,
|
||||||
|
ZXDG_TOPLEVEL_DECORATION_V1_ERROR_UNCONFIGURED_BUFFER,
|
||||||
|
"xdg_toplevel_decoration must not have a buffer at creation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration =
|
||||||
|
calloc(1, sizeof(struct wlr_xdg_toplevel_decoration_v1));
|
||||||
|
if (decoration == NULL) {
|
||||||
|
wl_client_post_no_memory(client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
decoration->manager = manager;
|
||||||
|
decoration->surface = surface;
|
||||||
|
|
||||||
|
uint32_t version = wl_resource_get_version(manager_resource);
|
||||||
|
decoration->resource = wl_resource_create(client,
|
||||||
|
&zxdg_toplevel_decoration_v1_interface, version, id);
|
||||||
|
if (decoration->resource == NULL) {
|
||||||
|
free(decoration);
|
||||||
|
wl_client_post_no_memory(client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wl_resource_set_implementation(decoration->resource,
|
||||||
|
&toplevel_decoration_impl, decoration,
|
||||||
|
toplevel_decoration_handle_resource_destroy);
|
||||||
|
|
||||||
|
wlr_log(WLR_DEBUG, "new xdg_toplevel_decoration %p (res %p)", decoration,
|
||||||
|
decoration->resource);
|
||||||
|
|
||||||
|
wl_list_init(&decoration->configure_list);
|
||||||
|
wl_signal_init(&decoration->events.destroy);
|
||||||
|
wl_signal_init(&decoration->events.request_mode);
|
||||||
|
|
||||||
|
wl_signal_add(&surface->events.destroy, &decoration->surface_destroy);
|
||||||
|
decoration->surface_destroy.notify =
|
||||||
|
toplevel_decoration_handle_surface_destroy;
|
||||||
|
wl_signal_add(&surface->events.configure, &decoration->surface_configure);
|
||||||
|
decoration->surface_configure.notify =
|
||||||
|
toplevel_decoration_handle_surface_configure;
|
||||||
|
wl_signal_add(&surface->events.ack_configure,
|
||||||
|
&decoration->surface_ack_configure);
|
||||||
|
decoration->surface_ack_configure.notify =
|
||||||
|
toplevel_decoration_handle_surface_ack_configure;
|
||||||
|
wl_list_init(&decoration->surface_commit.link);
|
||||||
|
|
||||||
|
wl_list_insert(&manager->decorations, &decoration->link);
|
||||||
|
|
||||||
|
if (surface->added) {
|
||||||
|
decoration->added = true;
|
||||||
|
wlr_signal_emit_safe(&manager->events.new_toplevel_decoration,
|
||||||
|
decoration);
|
||||||
|
} else {
|
||||||
|
wl_list_remove(&decoration->surface_commit.link);
|
||||||
|
wl_signal_add(&surface->surface->events.commit,
|
||||||
|
&decoration->surface_commit);
|
||||||
|
decoration->surface_commit.notify =
|
||||||
|
toplevel_decoration_handle_surface_commit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct zxdg_decoration_manager_v1_interface
|
||||||
|
decoration_manager_impl = {
|
||||||
|
.get_toplevel_decoration = decoration_manager_handle_get_toplevel_decoration,
|
||||||
|
};
|
||||||
|
|
||||||
|
void decoration_manager_handle_resource_destroy(struct wl_resource *resource) {
|
||||||
|
wl_list_remove(wl_resource_get_link(resource));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void decoration_manager_bind(struct wl_client *client, void *data,
|
||||||
|
uint32_t version, uint32_t id) {
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager = data;
|
||||||
|
|
||||||
|
struct wl_resource *resource = wl_resource_create(client,
|
||||||
|
&zxdg_decoration_manager_v1_interface, version, id);
|
||||||
|
if (resource == NULL) {
|
||||||
|
wl_client_post_no_memory(client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wl_resource_set_implementation(resource, &decoration_manager_impl,
|
||||||
|
manager, decoration_manager_handle_resource_destroy);
|
||||||
|
|
||||||
|
wl_list_insert(&manager->resources, wl_resource_get_link(resource));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager =
|
||||||
|
wl_container_of(listener, manager, display_destroy);
|
||||||
|
wlr_xdg_decoration_manager_v1_destroy(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *
|
||||||
|
wlr_xdg_decoration_manager_v1_create(struct wl_display *display) {
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager =
|
||||||
|
calloc(1, sizeof(struct wlr_xdg_decoration_manager_v1));
|
||||||
|
if (manager == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
manager->global = wl_global_create(display,
|
||||||
|
&zxdg_decoration_manager_v1_interface, DECORATION_MANAGER_VERSION,
|
||||||
|
manager, decoration_manager_bind);
|
||||||
|
if (manager->global == NULL) {
|
||||||
|
free(manager);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
wl_list_init(&manager->resources);
|
||||||
|
wl_list_init(&manager->decorations);
|
||||||
|
wl_signal_init(&manager->events.new_toplevel_decoration);
|
||||||
|
|
||||||
|
manager->display_destroy.notify = handle_display_destroy;
|
||||||
|
wl_display_add_destroy_listener(display, &manager->display_destroy);
|
||||||
|
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_xdg_decoration_manager_v1_destroy(
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *manager) {
|
||||||
|
if (manager == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wl_list_remove(&manager->display_destroy.link);
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *decoration, *tmp_decoration;
|
||||||
|
wl_list_for_each_safe(decoration, tmp_decoration, &manager->decorations,
|
||||||
|
link) {
|
||||||
|
wl_resource_destroy(decoration->resource);
|
||||||
|
}
|
||||||
|
struct wl_resource *resource, *tmp_resource;
|
||||||
|
wl_resource_for_each_safe(resource, tmp_resource, &manager->resources) {
|
||||||
|
wl_resource_destroy(resource);
|
||||||
|
}
|
||||||
|
wl_global_destroy(manager->global);
|
||||||
|
free(manager);
|
||||||
|
}
|
Loading…
Reference in new issue