From d61621e2fa25a4c03cb9f488c0a65c4c2e198b2b Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 7 Oct 2017 14:38:13 -0400 Subject: [PATCH 1/4] wlr-data-device-mgr: cleanup --- types/wlr_data_device_manager.c | 75 +++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/types/wlr_data_device_manager.c b/types/wlr_data_device_manager.c index fb3bd901..d5a6cca9 100644 --- a/types/wlr_data_device_manager.c +++ b/types/wlr_data_device_manager.c @@ -7,15 +7,16 @@ #include #include -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; } @@ -135,18 +143,21 @@ static void data_device_manager_bind(struct wl_client *client, void *data, return; } wl_resource_set_implementation(resource, &data_device_manager_impl, - manager, NULL); + 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); From 51de39888501bfaa2772063e78ba90e821b27c7e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 7 Oct 2017 16:33:09 -0400 Subject: [PATCH 2/4] bug: fix clipboard --- types/wlr_data_device_manager.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/wlr_data_device_manager.c b/types/wlr_data_device_manager.c index d5a6cca9..a813754c 100644 --- a/types/wlr_data_device_manager.c +++ b/types/wlr_data_device_manager.c @@ -33,6 +33,10 @@ static void data_device_start_drag(struct wl_client *client, static void data_device_set_selection(struct wl_client *client, struct wl_resource *resource, struct wl_resource *source_resource, uint32_t serial) { + if (!source_resource) { + return; + } + // TODO: serial validation struct wlr_seat_handle *handle = wl_resource_get_user_data(resource); struct wlr_data_device *device = handle->wlr_seat->data_device; @@ -176,6 +180,10 @@ void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) { void wlr_data_device_set_selection(struct wlr_data_device *device, struct wlr_data_source *source) { + if (device->selection == source) { + return; + } + if (device->selection) { wl_list_remove(&device->selection_destroyed.link); wlr_data_source_cancelled(device->selection); From 1fd81ebf2d91e6851a1d3d744822ba6fd5cef0eb Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 7 Oct 2017 16:39:03 -0400 Subject: [PATCH 3/4] wlr-data-source: add set_actions stub --- types/wlr_data_source.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/types/wlr_data_source.c b/types/wlr_data_source.c index 542b1135..be9547cf 100644 --- a/types/wlr_data_source.c +++ b/types/wlr_data_source.c @@ -85,9 +85,15 @@ static void data_source_destroy(struct wl_client *client, struct wl_resource *re wl_resource_destroy(resource); } +static void data_source_set_actions(struct wl_client *client, + struct wl_resource *resource, uint32_t dnd_actions) { + wlr_log(L_DEBUG, "TODO: data source set actions"); +} + static struct wl_data_source_interface wl_data_source_impl = { .offer = data_source_offer, - .destroy = data_source_destroy + .destroy = data_source_destroy, + .set_actions = data_source_set_actions, }; static void destroy_wl_data_source(struct wl_resource *resource) { From 9721dc80e162b23c35736043223643452a1634bb Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 7 Oct 2017 16:41:45 -0400 Subject: [PATCH 4/4] wlr-data-source: cleanup --- types/wlr_data_source.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/types/wlr_data_source.c b/types/wlr_data_source.c index be9547cf..83064fac 100644 --- a/types/wlr_data_source.c +++ b/types/wlr_data_source.c @@ -27,7 +27,8 @@ void wlr_data_source_finish(struct wlr_data_source *source) { } } -void wlr_data_source_send(struct wlr_data_source *src, const char *type, int fd) { +void wlr_data_source_send(struct wlr_data_source *src, const char *type, + int fd) { assert(src && src->impl && src->impl->send); src->impl->send(src, type, fd); } @@ -53,7 +54,8 @@ static void data_source_send(struct wlr_data_source *src, close(fd); } -static void data_source_accepted(struct wlr_data_source *src, const char *type) { +static void data_source_accepted(struct wlr_data_source *src, + const char *type) { struct wlr_wl_data_source *wl_src = (struct wlr_wl_data_source *) src; wl_data_source_send_target(wl_src->resource, type); } @@ -69,7 +71,8 @@ static struct wlr_data_source_impl data_source_wl_impl = { .cancelled = data_source_cancelled, }; -static void data_source_offer(struct wl_client *client, struct wl_resource *resource, +static void data_source_offer(struct wl_client *client, + struct wl_resource *resource, const char *type) { struct wlr_wl_data_source *src = wl_resource_get_user_data(resource); char *dtype = strdup(type); @@ -81,7 +84,8 @@ static void data_source_offer(struct wl_client *client, struct wl_resource *reso list_add(src->base.types, dtype); } -static void data_source_destroy(struct wl_client *client, struct wl_resource *resource) { +static void data_source_destroy(struct wl_client *client, + struct wl_resource *resource) { wl_resource_destroy(resource); }