data-device: Don't implement data source through data offer object

The wl_data_source object used to specify the implementation for data
offers created for it.  This means you need a data offer to retrieve the
data from the source, which makes it awkward to use in-process in a
compositor.  Now we instead have three virtual functions that can be
connected to a protocol object or in-process data-sources such as an
X server proxy or clipboard.
This commit is contained in:
Kristian Høgsberg 2012-06-03 17:30:12 -04:00
parent dff84e5638
commit 68f058ffd3
2 changed files with 39 additions and 22 deletions

View file

@ -38,8 +38,7 @@ data_offer_accept(struct wl_client *client, struct wl_resource *resource,
* this be a wl_data_device request? */
if (offer->source)
wl_data_source_send_target(&offer->source->resource,
mime_type);
offer->source->accept(offer->source, serial, mime_type);
}
static void
@ -49,10 +48,9 @@ data_offer_receive(struct wl_client *client, struct wl_resource *resource,
struct wl_data_offer *offer = resource->data;
if (offer->source)
wl_data_source_send_send(&offer->source->resource,
mime_type, fd);
close(fd);
offer->source->send(offer->source, mime_type, fd);
else
close(fd);
}
static void
@ -61,6 +59,12 @@ data_offer_destroy(struct wl_client *client, struct wl_resource *resource)
wl_resource_destroy(resource);
}
static const struct wl_data_offer_interface data_offer_interface = {
data_offer_accept,
data_offer_receive,
data_offer_destroy,
};
static void
destroy_data_offer(struct wl_resource *resource)
{
@ -70,12 +74,6 @@ destroy_data_offer(struct wl_resource *resource)
free(offer);
}
static const struct wl_data_offer_interface data_offer_interface = {
data_offer_accept,
data_offer_receive,
data_offer_destroy,
};
static void
destroy_offer_data_source(struct wl_listener *listener, void *data)
{
@ -87,12 +85,6 @@ destroy_offer_data_source(struct wl_listener *listener, void *data)
offer->source = NULL;
}
static void
data_source_cancel(struct wl_data_source *source)
{
wl_data_source_send_cancelled(&source->resource);
}
static struct wl_resource *
wl_data_source_send_offer(struct wl_data_source *source,
struct wl_resource *target)
@ -108,7 +100,7 @@ wl_data_source_send_offer(struct wl_data_source *source,
offer->resource.object.id = 0;
offer->resource.object.interface = &wl_data_offer_interface;
offer->resource.object.implementation =
(void (**)(void)) source->offer_interface;
(void (**)(void)) &data_offer_interface;
offer->resource.data = offer;
wl_signal_init(&offer->resource.destroy_signal);
@ -440,6 +432,27 @@ destroy_data_source(struct wl_resource *resource)
source->resource.object.id = 0;
}
static void
client_source_accept(struct wl_data_source *source,
uint32_t time, const char *mime_type)
{
wl_data_source_send_target(&source->resource, mime_type);
}
static void
client_source_send(struct wl_data_source *source,
const char *mime_type, int32_t fd)
{
wl_data_source_send_send(&source->resource, mime_type, fd);
close(fd);
}
static void
client_source_cancel(struct wl_data_source *source)
{
wl_data_source_send_cancelled(&source->resource);
}
static void
create_data_source(struct wl_client *client,
struct wl_resource *resource, uint32_t id)
@ -460,8 +473,9 @@ create_data_source(struct wl_client *client,
source->resource.data = source;
wl_signal_init(&source->resource.destroy_signal);
source->offer_interface = &data_offer_interface;
source->cancel = data_source_cancel;
source->accept = client_source_accept;
source->send = client_source_send;
source->cancel = client_source_cancel;
wl_array_init(&source->mime_types);
wl_client_add_resource(client, &source->resource);

View file

@ -232,7 +232,10 @@ struct wl_data_source {
struct wl_resource resource;
struct wl_array mime_types;
const struct wl_data_offer_interface *offer_interface;
void (*accept)(struct wl_data_source *source,
uint32_t serial, const char *mime_type);
void (*send)(struct wl_data_source *source,
const char *mime_type, int32_t fd);
void (*cancel)(struct wl_data_source *source);
};