Merge pull request #1053 from emersion/xdg-decoration

Add xdg-decoration-unstable-v1 support
This commit is contained in:
Drew DeVault 2018-08-02 09:33:10 -04:00 committed by GitHub
commit 5642c5cc8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 807 additions and 43 deletions

View file

@ -53,6 +53,7 @@ lib_wlr_types = static_library(
'wlr_virtual_keyboard_v1.c',
'wlr_wl_shell.c',
'wlr_xcursor_manager.c',
'wlr_xdg_decoration_v1.c',
'wlr_xdg_output.c',
'wlr_screencopy_v1.c',
),

View file

@ -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);
}

View file

@ -111,6 +111,7 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client,
struct wlr_xdg_surface_configure *configure, *tmp;
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
if (configure->serial < serial) {
wlr_signal_emit_safe(&surface->events.ack_configure, configure);
xdg_surface_configure_destroy(configure);
} else if (configure->serial == serial) {
found = true;
@ -140,6 +141,7 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client,
surface->configured = true;
surface->configure_serial = serial;
wlr_signal_emit_safe(&surface->events.ack_configure, configure);
xdg_surface_configure_destroy(configure);
}
@ -157,6 +159,7 @@ static void surface_send_configure(void *user_data) {
wl_list_insert(surface->configure_list.prev, &configure->link);
configure->serial = surface->configure_next_serial;
configure->surface = surface;
switch (surface->role) {
case WLR_XDG_SURFACE_ROLE_NONE:
@ -174,26 +177,15 @@ static void surface_send_configure(void *user_data) {
break;
}
wlr_signal_emit_safe(&surface->events.configure, configure);
xdg_surface_send_configure(surface->resource, configure->serial);
}
uint32_t schedule_xdg_surface_configure(
struct wlr_xdg_surface *surface) {
static uint32_t schedule_configure(struct wlr_xdg_surface *surface,
bool pending_same) {
struct wl_display *display = wl_client_get_display(surface->client->client);
struct wl_event_loop *loop = wl_display_get_event_loop(display);
bool pending_same = false;
switch (surface->role) {
case WLR_XDG_SURFACE_ROLE_NONE:
assert(0 && "not reached");
break;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
pending_same =
compare_xdg_surface_toplevel_state(surface->toplevel);
break;
case WLR_XDG_SURFACE_ROLE_POPUP:
break;
}
if (surface->configure_idle != NULL) {
if (!pending_same) {
@ -218,6 +210,27 @@ uint32_t schedule_xdg_surface_configure(
}
}
uint32_t schedule_xdg_surface_configure(struct wlr_xdg_surface *surface) {
bool pending_same = false;
switch (surface->role) {
case WLR_XDG_SURFACE_ROLE_NONE:
assert(0 && "not reached");
break;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
pending_same = compare_xdg_surface_toplevel_state(surface->toplevel);
break;
case WLR_XDG_SURFACE_ROLE_POPUP:
break;
}
return schedule_configure(surface, pending_same);
}
uint32_t wlr_xdg_surface_schedule_configure(struct wlr_xdg_surface *surface) {
return schedule_configure(surface, false);
}
static void xdg_surface_handle_get_popup(struct wl_client *client,
struct wl_resource *resource, uint32_t id,
struct wl_resource *parent_resource,
@ -417,6 +430,8 @@ struct wlr_xdg_surface *create_xdg_surface(
wl_signal_init(&xdg_surface->events.new_popup);
wl_signal_init(&xdg_surface->events.map);
wl_signal_init(&xdg_surface->events.unmap);
wl_signal_init(&xdg_surface->events.configure);
wl_signal_init(&xdg_surface->events.ack_configure);
wl_signal_add(&xdg_surface->surface->events.destroy,
&xdg_surface->surface_destroy);

View file

@ -200,7 +200,7 @@ void handle_xdg_surface_toplevel_committed(struct wlr_xdg_surface *surface) {
static const struct xdg_toplevel_interface xdg_toplevel_implementation;
static struct wlr_xdg_surface *xdg_surface_from_xdg_toplevel_resource(
struct wlr_xdg_surface *wlr_xdg_surface_from_toplevel_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &xdg_toplevel_interface,
&xdg_toplevel_implementation));
@ -210,11 +210,11 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_toplevel_resource(
static void xdg_toplevel_handle_set_parent(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *parent_resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
struct wlr_xdg_surface *parent = NULL;
if (parent_resource != NULL) {
parent = xdg_surface_from_xdg_toplevel_resource(parent_resource);
parent = wlr_xdg_surface_from_toplevel_resource(parent_resource);
}
surface->toplevel->parent = parent;
@ -224,7 +224,7 @@ static void xdg_toplevel_handle_set_parent(struct wl_client *client,
static void xdg_toplevel_handle_set_title(struct wl_client *client,
struct wl_resource *resource, const char *title) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
char *tmp;
tmp = strdup(title);
@ -240,7 +240,7 @@ static void xdg_toplevel_handle_set_title(struct wl_client *client,
static void xdg_toplevel_handle_set_app_id(struct wl_client *client,
struct wl_resource *resource, const char *app_id) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
char *tmp;
tmp = strdup(app_id);
@ -257,7 +257,7 @@ static void xdg_toplevel_handle_show_window_menu(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, int32_t x, int32_t y) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
struct wlr_seat_client *seat =
wlr_seat_client_from_resource(seat_resource);
@ -288,7 +288,7 @@ static void xdg_toplevel_handle_move(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
struct wlr_seat_client *seat =
wlr_seat_client_from_resource(seat_resource);
@ -317,7 +317,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial, uint32_t edges) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
struct wlr_seat_client *seat =
wlr_seat_client_from_resource(seat_resource);
@ -346,7 +346,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client,
static void xdg_toplevel_handle_set_max_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
surface->toplevel->client_pending.max_width = width;
surface->toplevel->client_pending.max_height = height;
}
@ -354,7 +354,7 @@ static void xdg_toplevel_handle_set_max_size(struct wl_client *client,
static void xdg_toplevel_handle_set_min_size(struct wl_client *client,
struct wl_resource *resource, int32_t width, int32_t height) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
surface->toplevel->client_pending.min_width = width;
surface->toplevel->client_pending.min_height = height;
}
@ -362,7 +362,7 @@ static void xdg_toplevel_handle_set_min_size(struct wl_client *client,
static void xdg_toplevel_handle_set_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
surface->toplevel->client_pending.maximized = true;
wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface);
}
@ -370,7 +370,7 @@ static void xdg_toplevel_handle_set_maximized(struct wl_client *client,
static void xdg_toplevel_handle_unset_maximized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
surface->toplevel->client_pending.maximized = false;
wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface);
}
@ -378,7 +378,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client,
static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output_resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
struct wlr_output *output = NULL;
if (output_resource != NULL) {
@ -399,7 +399,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client,
static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
surface->toplevel->client_pending.fullscreen = false;
@ -415,7 +415,7 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client,
static void xdg_toplevel_handle_set_minimized(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
wlr_signal_emit_safe(&surface->toplevel->events.request_minimize, surface);
}
@ -443,7 +443,7 @@ static const struct xdg_toplevel_interface xdg_toplevel_implementation = {
static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface *surface =
xdg_surface_from_xdg_toplevel_resource(resource);
wlr_xdg_surface_from_toplevel_resource(resource);
if (surface != NULL) {
destroy_xdg_toplevel(surface);
}