wlr-data-device-mgr: cleanup

This commit is contained in:
Tony Crisci 2017-10-07 14:38:13 -04:00
parent 321c26c2a3
commit d61621e2fa
1 changed files with 43 additions and 32 deletions

View File

@ -7,15 +7,16 @@
#include <wlr/types/wlr_data_source.h>
#include <wlr/types/wlr_seat.h>
static void resource_destroy(struct wl_client *client, struct wl_resource *resource) {
static void resource_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static void wl_cb_data_device_start_drag(struct wl_client *client,
struct wl_resource *res, struct wl_resource *src_res,
static void data_device_start_drag(struct wl_client *client,
struct wl_resource *res, struct wl_resource *source_resource,
struct wl_resource *origin_res, struct wl_resource *icon_res,
uint32_t serial) {
wlr_log(L_DEBUG, "implement data_device:start_drag");
wlr_log(L_DEBUG, "TODO: implement data_device:start_drag");
// Will probably look like this:
// struct wlr_seat_handle *handle = wl_resource_get_user_data(res);
@ -29,68 +30,75 @@ static void wl_cb_data_device_start_drag(struct wl_client *client,
// origin, icon); // will set surface roles and emit signal for user
}
static void wl_cb_data_device_set_selection(struct wl_client *client,
struct wl_resource *res, struct wl_resource *src_res,
static void data_device_set_selection(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *source_resource,
uint32_t serial) {
// TODO: serial validation
struct wlr_seat_handle *handle = wl_resource_get_user_data(res);
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
struct wlr_data_device *device = handle->wlr_seat->data_device;
struct wlr_data_source *src = wl_resource_get_user_data(src_res);
wlr_data_device_set_selection(device, src);
struct wlr_data_source *source = wl_resource_get_user_data(source_resource);
wlr_data_device_set_selection(device, source);
}
static struct wl_data_device_interface data_device_impl = {
.start_drag = wl_cb_data_device_start_drag,
.set_selection = wl_cb_data_device_set_selection,
.start_drag = data_device_start_drag,
.set_selection = data_device_set_selection,
.release = resource_destroy
};
static void data_device_selection_destroy(struct wl_listener *listener, void *data) {
struct wlr_data_device *device = wl_container_of(listener, device, selection_destroyed);
static void data_device_selection_destroy(struct wl_listener *listener,
void *data) {
struct wlr_data_device *device =
wl_container_of(listener, device, selection_destroyed);
assert(data == device->selection);
device->selection = NULL; // make sure no cancel is sent
wlr_data_device_set_selection(device, NULL);
}
static struct wlr_data_device *seat_ensure_data_device(struct wlr_data_device_manager *manager,
struct wlr_seat *seat) {
static struct wlr_data_device *seat_ensure_data_device(
struct wlr_data_device_manager *manager, struct wlr_seat *seat) {
if (seat->data_device) {
return seat->data_device;
}
if (!(seat->data_device = calloc(1, sizeof(*seat->data_device)))) {
seat->data_device = calloc(1, sizeof(*seat->data_device));
if (!seat->data_device) {
wlr_log(L_ERROR, "Failed to allocate wlr_data_device");
return NULL;
}
seat->data_device->seat = seat;
wl_signal_init(&seat->data_device->events.selection_change);
seat->data_device->selection_destroyed.notify = data_device_selection_destroy;
seat->data_device->selection_destroyed.notify =
data_device_selection_destroy;
return seat->data_device;
}
static void data_device_destroy(struct wl_resource *res) {
struct wlr_seat_handle *handle = wl_resource_get_user_data(res);
static void data_device_destroy(struct wl_resource *resource) {
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
handle->data_device = NULL;
}
static void data_device_manager_create_data_source(struct wl_client *client,
struct wl_resource *res, uint32_t id) {
uint32_t version = wl_resource_get_version(res);
struct wl_resource *resource, uint32_t id) {
uint32_t version = wl_resource_get_version(resource);
if (!wlr_wl_data_source_create(client, version, id)) {
wlr_log(L_ERROR, "Failed to create wlr_wl_data_source");
wl_resource_post_no_memory(res);
wl_resource_post_no_memory(resource);
return;
}
}
static void data_device_manager_get_data_device(struct wl_client *client,
struct wl_resource *res, uint32_t id, struct wl_resource *seat_res) {
struct wlr_data_device_manager *manager = wl_resource_get_user_data(res);
struct wlr_seat_handle *seat_handle = wl_resource_get_user_data(seat_res);
struct wl_resource *resource, uint32_t id,
struct wl_resource *seat_resource) {
struct wlr_data_device_manager *manager =
wl_resource_get_user_data(resource);
struct wlr_seat_handle *seat_handle =
wl_resource_get_user_data(seat_resource);
struct wlr_data_device *device;
if (!(device = seat_ensure_data_device(manager, seat_handle->wlr_seat))) {
wl_resource_post_no_memory(res);
wl_resource_post_no_memory(resource);
return;
}
@ -101,10 +109,10 @@ static void data_device_manager_get_data_device(struct wl_client *client,
}
seat_handle->data_device = wl_resource_create(client,
&wl_data_device_interface, wl_resource_get_version(res), id);
&wl_data_device_interface, wl_resource_get_version(resource), id);
if (!seat_handle->data_device) {
wlr_log(L_ERROR, "Failed to create wl_data_device resource");
wl_resource_post_no_memory(res);
wl_resource_post_no_memory(resource);
return;
}
@ -138,15 +146,18 @@ static void data_device_manager_bind(struct wl_client *client, void *data,
manager, NULL);
}
struct wlr_data_device_manager *wlr_data_device_manager_create(struct wl_display *dpy) {
struct wlr_data_device_manager *wlr_data_device_manager_create(
struct wl_display *display) {
struct wlr_data_device_manager *manager = calloc(1, sizeof(*manager));
if (!manager) {
wlr_log(L_ERROR, "Failed to allocated wlr_data_device_manager");
return NULL;
}
manager->global = wl_global_create(dpy, &wl_data_device_manager_interface, 3,
manager, data_device_manager_bind);
manager->global =
wl_global_create(display, &wl_data_device_manager_interface, 3, manager,
data_device_manager_bind);
if (!manager->global) {
wlr_log(L_ERROR, "Failed to create global for wlr_data_device_manager");
free(manager);