2013-05-03 13:51:22 -04:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Kristian Høgsberg
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The file is based on src/data-device.c from Weston */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "meta-wayland-data-device.h"
|
|
|
|
#include "meta-wayland-seat.h"
|
|
|
|
#include "meta-wayland-pointer.h"
|
2013-08-30 12:03:30 -04:00
|
|
|
#include "meta-wayland-private.h"
|
2013-05-03 13:51:22 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_accept (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
guint32 serial,
|
|
|
|
const char *mime_type)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
/* FIXME: Check that client is currently focused by the input
|
|
|
|
* device that is currently dragging this data source. Should
|
|
|
|
* this be a wl_data_device request? */
|
|
|
|
|
|
|
|
if (offer->source)
|
|
|
|
offer->source->accept (offer->source, serial, mime_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_receive (struct wl_client *client, struct wl_resource *resource,
|
|
|
|
const char *mime_type, int32_t fd)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
if (offer->source)
|
|
|
|
offer->source->send (offer->source, mime_type, fd);
|
|
|
|
else
|
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer = wl_resource_get_user_data (resource);
|
|
|
|
|
|
|
|
if (offer->source)
|
|
|
|
wl_list_remove (&offer->source_destroy_listener.link);
|
|
|
|
free (offer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_offer_data_source (struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer;
|
|
|
|
|
|
|
|
offer = wl_container_of (listener, offer, source_destroy_listener);
|
|
|
|
|
|
|
|
offer->source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wl_resource *
|
|
|
|
meta_wayland_data_source_send_offer (MetaWaylandDataSource *source,
|
|
|
|
struct wl_resource *target)
|
|
|
|
{
|
|
|
|
MetaWaylandDataOffer *offer;
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
offer = malloc (sizeof *offer);
|
|
|
|
if (offer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
offer->source = source;
|
|
|
|
offer->source_destroy_listener.notify = destroy_offer_data_source;
|
|
|
|
|
2013-09-10 07:03:37 -04:00
|
|
|
offer->resource = wl_resource_create (wl_resource_get_client (target),
|
|
|
|
&wl_data_offer_interface,
|
2013-09-10 07:45:27 -04:00
|
|
|
MIN (META_WL_DATA_OFFER_VERSION,
|
|
|
|
wl_resource_get_version (target)), 0);
|
2013-09-10 07:03:37 -04:00
|
|
|
wl_resource_set_implementation (offer->resource, &data_offer_interface,
|
|
|
|
offer, destroy_data_offer);
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_resource_add_destroy_listener (source->resource,
|
|
|
|
&offer->source_destroy_listener);
|
|
|
|
|
|
|
|
wl_data_device_send_data_offer (target, offer->resource);
|
|
|
|
|
|
|
|
wl_array_for_each (p, &source->mime_types)
|
|
|
|
wl_data_offer_send_offer (offer->resource, *p);
|
|
|
|
|
|
|
|
return offer->resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_offer (struct wl_client *client,
|
|
|
|
struct wl_resource *resource, const char *type)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
p = wl_array_add (&source->mime_types, sizeof *p);
|
|
|
|
if (p)
|
|
|
|
*p = strdup (type);
|
|
|
|
if (!p || !*p)
|
|
|
|
wl_resource_post_no_memory (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_destroy (struct wl_client *client, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wl_data_source_interface data_source_interface = {
|
|
|
|
data_source_offer,
|
|
|
|
data_source_destroy
|
|
|
|
};
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
typedef struct {
|
|
|
|
MetaWaylandPointerGrab generic;
|
|
|
|
|
|
|
|
MetaWaylandSeat *seat;
|
|
|
|
struct wl_client *drag_client;
|
|
|
|
|
|
|
|
MetaWaylandSurface *drag_focus;
|
|
|
|
struct wl_resource *drag_focus_data_device;
|
|
|
|
struct wl_listener drag_focus_listener;
|
|
|
|
|
|
|
|
MetaWaylandSurface *drag_surface;
|
|
|
|
struct wl_listener drag_icon_listener;
|
|
|
|
|
|
|
|
MetaWaylandDataSource *drag_data_source;
|
|
|
|
struct wl_listener drag_data_source_listener;
|
|
|
|
} MetaWaylandDragGrab;
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
static void
|
|
|
|
destroy_drag_focus (struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *grab = wl_container_of (listener, grab, drag_focus_listener);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
grab->drag_focus_data_device = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_focus (MetaWaylandPointerGrab *grab,
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab;
|
|
|
|
MetaWaylandSeat *seat = drag_grab->seat;
|
2013-05-03 13:51:22 -04:00
|
|
|
struct wl_resource *resource, *offer = NULL;
|
|
|
|
struct wl_display *display;
|
|
|
|
guint32 serial;
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_fixed_t sx, sy;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (drag_grab->drag_focus == surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (drag_grab->drag_focus_data_device)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_data_device_send_leave (drag_grab->drag_focus_data_device);
|
|
|
|
wl_list_remove (&drag_grab->drag_focus_listener.link);
|
|
|
|
drag_grab->drag_focus_data_device = NULL;
|
|
|
|
drag_grab->drag_focus = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return;
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (!drag_grab->drag_data_source &&
|
|
|
|
wl_resource_get_client (surface->resource) != drag_grab->drag_client)
|
2013-05-03 13:51:22 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
resource =
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_resource_find_for_client (&seat->data_device_resource_list,
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_resource_get_client (surface->resource));
|
|
|
|
if (!resource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
display = wl_client_get_display (wl_resource_get_client (resource));
|
|
|
|
serial = wl_display_next_serial (display);
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (drag_grab->drag_data_source)
|
|
|
|
offer = meta_wayland_data_source_send_offer (drag_grab->drag_data_source,
|
2013-05-03 13:51:22 -04:00
|
|
|
resource);
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
meta_wayland_pointer_get_relative_coordinates (grab->pointer, surface, &sx, &sy);
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_data_device_send_enter (resource, serial, surface->resource,
|
2013-09-11 08:06:05 -04:00
|
|
|
sx, sy, offer);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_focus = surface;
|
|
|
|
|
|
|
|
drag_grab->drag_focus_data_device = resource;
|
|
|
|
drag_grab->drag_focus_listener.notify = destroy_drag_focus;
|
|
|
|
wl_resource_add_destroy_listener (resource, &drag_grab->drag_focus_listener);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_motion (MetaWaylandPointerGrab *grab,
|
2013-09-11 08:06:05 -04:00
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab;
|
|
|
|
wl_fixed_t sx, sy;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (drag_grab->drag_focus_data_device)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_get_relative_coordinates (grab->pointer,
|
|
|
|
drag_grab->drag_focus,
|
|
|
|
&sx, &sy);
|
|
|
|
wl_data_device_send_motion (drag_grab->drag_focus_data_device,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
sx, sy);
|
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-11 08:06:05 -04:00
|
|
|
data_device_end_drag_grab (MetaWaylandDragGrab *drag_grab)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
if (drag_grab->drag_surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_surface = NULL;
|
|
|
|
wl_list_remove (&drag_grab->drag_icon_listener.link);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (drag_grab->drag_data_source)
|
|
|
|
wl_list_remove (&drag_grab->drag_data_source_listener.link);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab_focus (&drag_grab->generic, NULL, NULL);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
meta_wayland_pointer_end_grab (drag_grab->generic.pointer);
|
|
|
|
g_slice_free (MetaWaylandDragGrab, drag_grab);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_button (MetaWaylandPointerGrab *grab,
|
2013-09-11 08:06:05 -04:00
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab;
|
|
|
|
MetaWaylandSeat *seat = drag_grab->seat;
|
|
|
|
ClutterEventType event_type = clutter_event_type (event);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (drag_grab->drag_focus_data_device &&
|
|
|
|
drag_grab->generic.pointer->grab_button == clutter_event_get_button (event) &&
|
|
|
|
event_type == CLUTTER_BUTTON_RELEASE)
|
|
|
|
wl_data_device_send_drop (drag_grab->drag_focus_data_device);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
|
|
|
if (seat->pointer.button_count == 0 &&
|
2013-09-11 08:06:05 -04:00
|
|
|
event_type == CLUTTER_BUTTON_RELEASE)
|
|
|
|
data_device_end_drag_grab (drag_grab);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MetaWaylandPointerGrabInterface drag_grab_interface = {
|
|
|
|
drag_grab_focus,
|
|
|
|
drag_grab_motion,
|
|
|
|
drag_grab_button,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_device_source (struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *drag_grab =
|
|
|
|
wl_container_of (listener, drag_grab, drag_data_source_listener);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_data_source = NULL;
|
|
|
|
data_device_end_drag_grab (drag_grab);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_device_icon (struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *drag_grab =
|
|
|
|
wl_container_of (listener, drag_grab, drag_data_source_listener);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_surface = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_start_drag (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *source_resource,
|
|
|
|
struct wl_resource *origin_resource,
|
|
|
|
struct wl_resource *icon_resource, guint32 serial)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *drag_grab;
|
2013-05-03 13:51:22 -04:00
|
|
|
/* FIXME: Check that client has implicit grab on the origin
|
|
|
|
* surface that matches the given time. */
|
|
|
|
|
|
|
|
/* FIXME: Check that the data source type array isn't empty. */
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (seat->pointer.grab != &seat->pointer.default_grab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drag_grab = g_slice_new0 (MetaWaylandDragGrab);
|
|
|
|
|
|
|
|
drag_grab->generic.interface = &drag_grab_interface;
|
|
|
|
drag_grab->generic.pointer = &seat->pointer;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_client = client;
|
2014-03-11 15:12:53 -04:00
|
|
|
drag_grab->seat = seat;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
|
|
|
if (source_resource)
|
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_data_source = wl_resource_get_user_data (source_resource);
|
|
|
|
drag_grab->drag_data_source_listener.notify = destroy_data_device_source;
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_resource_add_destroy_listener (source_resource,
|
2013-09-11 08:06:05 -04:00
|
|
|
&drag_grab->drag_data_source_listener);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (icon_resource)
|
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_surface = wl_resource_get_user_data (icon_resource);
|
|
|
|
drag_grab->drag_icon_listener.notify = destroy_data_device_icon;
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_resource_add_destroy_listener (icon_resource,
|
2013-09-11 08:06:05 -04:00
|
|
|
&drag_grab->drag_icon_listener);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
meta_wayland_pointer_set_focus (&seat->pointer, NULL);
|
|
|
|
meta_wayland_pointer_start_grab (&seat->pointer, (MetaWaylandPointerGrab*)drag_grab);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_selection_data_source (struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat =
|
|
|
|
wl_container_of (listener, seat, selection_data_source_listener);
|
|
|
|
struct wl_resource *data_device;
|
|
|
|
struct wl_resource *focus = NULL;
|
|
|
|
|
|
|
|
seat->selection_data_source = NULL;
|
|
|
|
|
|
|
|
focus = seat->keyboard.focus_resource;
|
|
|
|
|
|
|
|
if (focus)
|
|
|
|
{
|
|
|
|
data_device =
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_resource_find_for_client (&seat->data_device_resource_list,
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_resource_get_client (focus));
|
|
|
|
if (data_device)
|
|
|
|
wl_data_device_send_selection (data_device, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_seat_set_selection (MetaWaylandSeat *seat,
|
|
|
|
MetaWaylandDataSource *source,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
|
|
|
struct wl_resource *data_device, *offer;
|
|
|
|
struct wl_resource *focus = NULL;
|
|
|
|
|
|
|
|
if (seat->selection_data_source &&
|
|
|
|
seat->selection_serial - serial < UINT32_MAX / 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (seat->selection_data_source)
|
|
|
|
{
|
|
|
|
seat->selection_data_source->cancel (seat->selection_data_source);
|
|
|
|
wl_list_remove (&seat->selection_data_source_listener.link);
|
|
|
|
seat->selection_data_source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
seat->selection_data_source = source;
|
|
|
|
seat->selection_serial = serial;
|
|
|
|
|
|
|
|
focus = seat->keyboard.focus_resource;
|
|
|
|
|
|
|
|
if (focus)
|
|
|
|
{
|
|
|
|
data_device =
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_resource_find_for_client (&seat->data_device_resource_list,
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_resource_get_client (focus));
|
|
|
|
if (data_device && source)
|
|
|
|
{
|
|
|
|
offer =
|
|
|
|
meta_wayland_data_source_send_offer (seat->selection_data_source,
|
|
|
|
data_device);
|
|
|
|
wl_data_device_send_selection (data_device, offer);
|
|
|
|
}
|
|
|
|
else if (data_device)
|
|
|
|
{
|
|
|
|
wl_data_device_send_selection (data_device, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
seat->selection_data_source_listener.notify =
|
|
|
|
destroy_selection_data_source;
|
|
|
|
wl_resource_add_destroy_listener (source->resource,
|
|
|
|
&seat->selection_data_source_listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_set_selection (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *source_resource,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
|
|
|
if (!source_resource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* FIXME: Store serial and check against incoming serial here. */
|
|
|
|
meta_wayland_seat_set_selection (wl_resource_get_user_data (resource),
|
|
|
|
wl_resource_get_user_data (source_resource),
|
|
|
|
serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_device_interface data_device_interface = {
|
|
|
|
data_device_start_drag,
|
|
|
|
data_device_set_selection,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_source (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = wl_container_of (resource, source, resource);
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
wl_array_for_each (p, &source->mime_types) free (*p);
|
|
|
|
|
|
|
|
wl_array_release (&source->mime_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_source_accept (MetaWaylandDataSource *source,
|
|
|
|
guint32 time, const char *mime_type)
|
|
|
|
{
|
|
|
|
wl_data_source_send_target (source->resource, mime_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_source_send (MetaWaylandDataSource *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 (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
wl_data_source_send_cancelled (source->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_data_source (struct wl_client *client,
|
|
|
|
struct wl_resource *resource, guint32 id)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
|
|
|
source = malloc (sizeof *source);
|
|
|
|
if (source == NULL)
|
|
|
|
{
|
|
|
|
wl_resource_post_no_memory (resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-10 07:03:37 -04:00
|
|
|
source->resource = wl_resource_create (client, &wl_data_source_interface,
|
2013-09-10 07:45:27 -04:00
|
|
|
MIN (META_WL_DATA_SOURCE_VERSION,
|
|
|
|
wl_resource_get_version (resource)), id);
|
2013-09-10 07:03:37 -04:00
|
|
|
wl_resource_set_implementation (source->resource, &data_source_interface,
|
|
|
|
source, destroy_data_source);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
|
|
|
source->accept = client_source_accept;
|
|
|
|
source->send = client_source_send;
|
|
|
|
source->cancel = client_source_cancel;
|
|
|
|
|
|
|
|
wl_array_init (&source->mime_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unbind_data_device (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_data_device (struct wl_client *client,
|
|
|
|
struct wl_resource *manager_resource,
|
|
|
|
guint32 id, struct wl_resource *seat_resource)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-09-10 07:03:37 -04:00
|
|
|
resource = wl_resource_create (client, &wl_data_device_interface,
|
2013-09-10 07:45:27 -04:00
|
|
|
MIN (META_WL_DATA_DEVICE_VERSION,
|
|
|
|
wl_resource_get_version (manager_resource)), id);
|
2013-09-10 07:03:37 -04:00
|
|
|
wl_resource_set_implementation (resource, &data_device_interface, seat, unbind_data_device);
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_list_insert (&seat->data_device_resource_list, wl_resource_get_link (resource));
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_device_manager_interface manager_interface = {
|
|
|
|
create_data_source,
|
|
|
|
get_data_device
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_manager (struct wl_client *client,
|
|
|
|
void *data, guint32 version, guint32 id)
|
|
|
|
{
|
2013-09-10 07:03:37 -04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-09-10 07:45:27 -04:00
|
|
|
resource = wl_resource_create (client, &wl_data_device_manager_interface,
|
|
|
|
MIN (version, META_WL_DATA_DEVICE_MANAGER_VERSION), id);
|
2013-09-10 07:03:37 -04:00
|
|
|
wl_resource_set_implementation (resource, &manager_interface, NULL, NULL);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_device_set_keyboard_focus (MetaWaylandSeat *seat)
|
|
|
|
{
|
|
|
|
struct wl_resource *data_device, *focus, *offer;
|
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
|
|
|
focus = seat->keyboard.focus_resource;
|
|
|
|
if (!focus)
|
|
|
|
return;
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
data_device = wl_resource_find_for_client (&seat->data_device_resource_list,
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_resource_get_client (focus));
|
|
|
|
if (!data_device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
source = seat->selection_data_source;
|
|
|
|
if (source)
|
|
|
|
{
|
|
|
|
offer = meta_wayland_data_source_send_offer (source, data_device);
|
|
|
|
wl_data_device_send_selection (data_device, offer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
meta_wayland_data_device_manager_init (struct wl_display *display)
|
|
|
|
{
|
2013-09-10 07:03:37 -04:00
|
|
|
if (wl_global_create (display,
|
2013-09-10 07:45:27 -04:00
|
|
|
&wl_data_device_manager_interface,
|
|
|
|
META_WL_DATA_DEVICE_MANAGER_VERSION,
|
2013-09-10 07:03:37 -04:00
|
|
|
NULL, bind_manager) == NULL)
|
2013-05-03 13:51:22 -04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|