Fix primary clipboard issues

This commit is contained in:
emersion 2017-12-22 23:45:07 +01:00
parent a95d09d561
commit 4476f79850
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 21 additions and 19 deletions

View File

@ -20,10 +20,7 @@ struct wlr_primary_selection_source {
struct wlr_seat_client *seat_client; struct wlr_seat_client *seat_client;
struct wl_array mime_types; struct wl_array mime_types;
bool accepted;
void (*accept)(struct wlr_primary_selection_source *source, uint32_t serial,
const char *mime_type);
void (*send)(struct wlr_primary_selection_source *source, void (*send)(struct wlr_primary_selection_source *source,
const char *mime_type, int32_t fd); const char *mime_type, int32_t fd);
void (*cancel)(struct wlr_primary_selection_source *source); void (*cancel)(struct wlr_primary_selection_source *source);
@ -40,6 +37,8 @@ struct wlr_primary_selection_offer {
struct wlr_primary_selection_source *source; struct wlr_primary_selection_source *source;
struct wl_listener source_destroy; struct wl_listener source_destroy;
void *data;
}; };
struct wlr_primary_selection_device_manager * struct wlr_primary_selection_device_manager *

View File

@ -7,9 +7,6 @@
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
static void client_source_accept(struct wlr_primary_selection_source *source,
uint32_t serial, const char *mime_type) {}
static void client_source_send(struct wlr_primary_selection_source *source, static void client_source_send(struct wlr_primary_selection_source *source,
const char *mime_type, int32_t fd) { const char *mime_type, int32_t fd) {
gtk_primary_selection_source_send_send(source->resource, mime_type, fd); gtk_primary_selection_source_send_send(source->resource, mime_type, fd);
@ -24,7 +21,14 @@ static void client_source_cancel(
static void offer_handle_receive(struct wl_client *client, static void offer_handle_receive(struct wl_client *client,
struct wl_resource *resource, const char *mime_type, int32_t fd) { struct wl_resource *resource, const char *mime_type, int32_t fd) {
// TODO struct wlr_primary_selection_offer *offer =
wl_resource_get_user_data(resource);
if (offer->source && offer == offer->source->offer) {
offer->source->send(offer->source, mime_type, fd);
} else {
close(fd);
}
} }
static void offer_handle_destroy(struct wl_client *client, static void offer_handle_destroy(struct wl_client *client,
@ -52,7 +56,7 @@ static void offer_resource_handle_destroy(struct wl_resource *resource) {
} }
if (offer->source->resource) { if (offer->source->resource) {
wl_data_source_send_cancelled(offer->source->resource); gtk_primary_selection_source_send_cancelled(offer->source->resource);
} }
offer->source->offer = NULL; offer->source->offer = NULL;
@ -72,7 +76,7 @@ static void offer_handle_source_destroy(struct wl_listener *listener,
static struct wlr_primary_selection_offer *source_send_offer( static struct wlr_primary_selection_offer *source_send_offer(
struct wlr_primary_selection_source *source, struct wlr_primary_selection_source *source,
struct wlr_seat_client *target) { struct wlr_seat_client *target) {
if (wl_list_empty(&target->data_devices)) { if (wl_list_empty(&target->primary_selection_devices)) {
return NULL; return NULL;
} }
@ -83,9 +87,9 @@ static struct wlr_primary_selection_offer *source_send_offer(
} }
uint32_t version = wl_resource_get_version( uint32_t version = wl_resource_get_version(
wl_resource_from_link(target->data_devices.next)); wl_resource_from_link(target->primary_selection_devices.next));
offer->resource = wl_resource_create(target->client, offer->resource = wl_resource_create(target->client,
&wl_data_offer_interface, version, 0); &gtk_primary_selection_offer_interface, version, 0);
if (offer->resource == NULL) { if (offer->resource == NULL) {
free(offer); free(offer);
return NULL; return NULL;
@ -97,18 +101,18 @@ static struct wlr_primary_selection_offer *source_send_offer(
wl_signal_add(&source->events.destroy, &offer->source_destroy); wl_signal_add(&source->events.destroy, &offer->source_destroy);
struct wl_resource *target_resource; struct wl_resource *target_resource;
wl_resource_for_each(target_resource, &target->data_devices) { wl_resource_for_each(target_resource, &target->primary_selection_devices) {
wl_data_device_send_data_offer(target_resource, offer->resource); gtk_primary_selection_device_send_data_offer(target_resource,
offer->resource);
} }
char **p; char **p;
wl_array_for_each(p, &source->mime_types) { wl_array_for_each(p, &source->mime_types) {
wl_data_offer_send_offer(offer->resource, *p); gtk_primary_selection_offer_send_offer(offer->resource, *p);
} }
offer->source = source; offer->source = source;
source->offer = offer; source->offer = offer;
source->accepted = false;
return offer; return offer;
} }
@ -160,12 +164,12 @@ void wlr_seat_client_send_primary_selection(
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &seat_client->primary_selection_devices) { wl_resource_for_each(resource, &seat_client->primary_selection_devices) {
wl_data_device_send_selection(resource, offer->resource); gtk_primary_selection_device_send_selection(resource, offer->resource);
} }
} else { } else {
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &seat_client->primary_selection_devices) { wl_resource_for_each(resource, &seat_client->primary_selection_devices) {
wl_data_device_send_selection(resource, NULL); gtk_primary_selection_device_send_selection(resource, NULL);
} }
} }
} }
@ -179,7 +183,7 @@ static void seat_client_primary_selection_source_destroy(
if (seat_client && seat->keyboard_state.focused_surface) { if (seat_client && seat->keyboard_state.focused_surface) {
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &seat_client->primary_selection_devices) { wl_resource_for_each(resource, &seat_client->primary_selection_devices) {
wl_data_device_send_selection(resource, NULL); gtk_primary_selection_device_send_selection(resource, NULL);
} }
} }
@ -270,7 +274,6 @@ static void device_manager_handle_create_source(struct wl_client *client,
wl_resource_set_implementation(source->resource, &source_impl, source, wl_resource_set_implementation(source->resource, &source_impl, source,
source_resource_handle_destroy); source_resource_handle_destroy);
source->accept = client_source_accept;
source->send = client_source_send; source->send = client_source_send;
source->cancel = client_source_cancel; source->cancel = client_source_cancel;