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"
|
2014-10-06 11:03:51 -04:00
|
|
|
#include "meta-dnd-actor-private.h"
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2015-05-18 07:24:27 -04:00
|
|
|
struct _MetaWaylandDataOffer
|
2014-07-10 10:15:34 -04:00
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
struct wl_listener source_destroy_listener;
|
2015-05-18 07:24:27 -04:00
|
|
|
};
|
2014-07-10 10:15:34 -04:00
|
|
|
|
2014-07-10 10:19:47 -04:00
|
|
|
static void
|
|
|
|
unbind_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
}
|
|
|
|
|
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)
|
2014-09-30 11:09:11 -04:00
|
|
|
{
|
2014-10-10 12:40:43 -04:00
|
|
|
offer->source->funcs.target (offer->source, mime_type);
|
2014-09-30 11:09:11 -04:00
|
|
|
offer->source->has_target = mime_type != NULL;
|
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2014-10-10 12:40:43 -04:00
|
|
|
meta_wayland_data_source_send (offer->source, mime_type, fd);
|
|
|
|
else
|
|
|
|
close (fd);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-10-10 12:40:43 -04:00
|
|
|
if (offer->source && offer->source->resource)
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_list_remove (&offer->source_destroy_listener.link);
|
2014-03-11 15:18:51 -04:00
|
|
|
|
|
|
|
g_slice_free (MetaWaylandDataOffer, offer);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2014-03-11 15:18:51 -04:00
|
|
|
MetaWaylandDataOffer *offer = g_slice_new0 (MetaWaylandDataOffer);
|
2013-05-03 13:51:22 -04:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
offer->source = source;
|
2014-08-04 10:22:23 -04:00
|
|
|
offer->resource = wl_resource_create (wl_resource_get_client (target), &wl_data_offer_interface, wl_resource_get_version (target), 0);
|
|
|
|
wl_resource_set_implementation (offer->resource, &data_offer_interface, offer, destroy_data_offer);
|
2014-10-10 12:40:43 -04:00
|
|
|
|
|
|
|
if (source->resource)
|
|
|
|
{
|
|
|
|
offer->source_destroy_listener.notify = destroy_offer_data_source;
|
|
|
|
wl_resource_add_destroy_listener (source->resource, &offer->source_destroy_listener);
|
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-10-10 12:40:43 -04:00
|
|
|
if (!meta_wayland_data_source_add_mime_type (source, type))
|
2013-05-03 13:51:22 -04:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2014-09-26 13:08:42 -04:00
|
|
|
struct _MetaWaylandDragGrab {
|
2013-09-11 08:06:05 -04:00
|
|
|
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;
|
2014-09-30 11:01:43 -04:00
|
|
|
|
2014-10-06 11:03:51 -04:00
|
|
|
ClutterActor *feedback_actor;
|
|
|
|
|
2014-09-30 11:01:43 -04:00
|
|
|
MetaWaylandSurface *drag_origin;
|
|
|
|
struct wl_listener drag_origin_listener;
|
|
|
|
|
|
|
|
int drag_start_x, drag_start_y;
|
2014-09-26 13:08:42 -04:00
|
|
|
};
|
2013-09-11 08:06:05 -04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
void
|
|
|
|
meta_wayland_drag_grab_set_focus (MetaWaylandDragGrab *drag_grab,
|
|
|
|
MetaWaylandSurface *surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandSeat *seat = drag_grab->seat;
|
2014-07-10 10:41:30 -04:00
|
|
|
struct wl_client *client;
|
2014-07-10 10:43:04 -04:00
|
|
|
struct wl_resource *data_device_resource, *offer = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (drag_grab->drag_focus == surface)
|
|
|
|
return;
|
|
|
|
|
2015-05-18 07:24:27 -04:00
|
|
|
if (drag_grab->drag_focus)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2015-05-18 07:24:27 -04:00
|
|
|
meta_wayland_surface_drag_dest_focus_out (drag_grab->drag_focus);
|
2013-09-11 08:06:05 -04:00
|
|
|
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;
|
|
|
|
|
2014-07-10 10:41:30 -04:00
|
|
|
client = wl_resource_get_client (surface->resource);
|
|
|
|
|
2014-07-10 10:31:08 -04:00
|
|
|
data_device_resource = wl_resource_find_for_client (&seat->data_device.resource_list, client);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2015-05-18 07:24:27 -04:00
|
|
|
if (drag_grab->drag_data_source && data_device_resource)
|
2013-09-11 08:06:05 -04:00
|
|
|
offer = meta_wayland_data_source_send_offer (drag_grab->drag_data_source,
|
2014-07-10 10:43:04 -04:00
|
|
|
data_device_resource);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_focus = surface;
|
2014-07-10 10:43:04 -04:00
|
|
|
drag_grab->drag_focus_data_device = data_device_resource;
|
2015-05-18 07:24:27 -04:00
|
|
|
|
|
|
|
meta_wayland_surface_drag_dest_focus_in (drag_grab->drag_focus,
|
|
|
|
offer ? wl_resource_get_user_data (offer) : NULL);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
MetaWaylandSurface *
|
|
|
|
meta_wayland_drag_grab_get_focus (MetaWaylandDragGrab *drag_grab)
|
|
|
|
{
|
|
|
|
return drag_grab->drag_focus;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_focus (MetaWaylandPointerGrab *grab,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab;
|
|
|
|
|
|
|
|
meta_wayland_drag_grab_set_focus (drag_grab, surface);
|
|
|
|
}
|
|
|
|
|
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;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2015-05-18 07:24:27 -04:00
|
|
|
if (drag_grab->drag_focus)
|
|
|
|
meta_wayland_surface_drag_dest_motion (drag_grab->drag_focus, event);
|
2014-10-06 11:03:51 -04:00
|
|
|
|
|
|
|
if (drag_grab->drag_surface)
|
|
|
|
meta_feedback_actor_update (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
|
|
|
event);
|
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
|
|
|
{
|
2015-05-12 13:35:28 -04:00
|
|
|
meta_wayland_drag_grab_set_focus (drag_grab, NULL);
|
2015-05-18 07:24:27 -04:00
|
|
|
|
2014-09-30 11:01:43 -04:00
|
|
|
if (drag_grab->drag_origin)
|
|
|
|
{
|
|
|
|
drag_grab->drag_origin = NULL;
|
|
|
|
wl_list_remove (&drag_grab->drag_origin_listener.link);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
if (drag_grab->drag_data_source &&
|
|
|
|
drag_grab->drag_data_source->resource)
|
2014-10-10 12:40:43 -04:00
|
|
|
wl_list_remove (&drag_grab->drag_data_source_listener.link);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-10-06 11:03:51 -04:00
|
|
|
if (drag_grab->feedback_actor)
|
|
|
|
{
|
|
|
|
clutter_actor_remove_all_children (drag_grab->feedback_actor);
|
|
|
|
clutter_actor_destroy (drag_grab->feedback_actor);
|
|
|
|
}
|
|
|
|
|
2014-09-26 13:08:42 -04:00
|
|
|
drag_grab->seat->data_device.current_grab = NULL;
|
|
|
|
|
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
|
|
|
|
2014-10-06 11:03:51 -04:00
|
|
|
if (drag_grab->generic.pointer->grab_button == clutter_event_get_button (event) &&
|
2013-09-11 08:06:05 -04:00
|
|
|
event_type == CLUTTER_BUTTON_RELEASE)
|
2014-10-06 11:03:51 -04:00
|
|
|
{
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
2015-05-18 07:24:27 -04:00
|
|
|
if (drag_grab->drag_data_source->has_target)
|
2014-10-06 11:03:51 -04:00
|
|
|
{
|
2015-05-18 07:24:27 -04:00
|
|
|
meta_wayland_surface_drag_dest_drop (drag_grab->drag_focus);
|
2014-10-06 11:03:51 -04:00
|
|
|
success = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finish drag and let actor self-destruct */
|
|
|
|
meta_dnd_actor_drag_finish (META_DND_ACTOR (drag_grab->feedback_actor),
|
|
|
|
success);
|
|
|
|
drag_grab->feedback_actor = NULL;
|
|
|
|
}
|
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,
|
|
|
|
};
|
|
|
|
|
2014-09-30 11:01:43 -04:00
|
|
|
static void
|
|
|
|
destroy_data_device_origin (struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *drag_grab =
|
|
|
|
wl_container_of (listener, drag_grab, drag_origin_listener);
|
|
|
|
|
|
|
|
drag_grab->drag_origin = NULL;
|
|
|
|
data_device_end_drag_grab (drag_grab);
|
2014-10-10 12:40:43 -04:00
|
|
|
meta_wayland_data_device_set_dnd_source (&drag_grab->seat->data_device, NULL);
|
2014-09-30 11:01:43 -04:00
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
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;
|
2015-05-18 07:24:27 -04:00
|
|
|
drag_grab->seat->data_device.dnd_data_source = NULL;
|
2013-09-11 08:06:05 -04:00
|
|
|
data_device_end_drag_grab (drag_grab);
|
2014-10-10 12:40:43 -04:00
|
|
|
meta_wayland_data_device_set_dnd_source (&drag_grab->seat->data_device, NULL);
|
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 =
|
2015-05-01 12:50:06 -04:00
|
|
|
wl_container_of (listener, drag_grab, drag_icon_listener);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_surface = NULL;
|
2014-10-06 11:03:51 -04:00
|
|
|
|
|
|
|
if (drag_grab->feedback_actor)
|
|
|
|
clutter_actor_remove_all_children (drag_grab->feedback_actor);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
void
|
|
|
|
meta_wayland_data_device_start_drag (MetaWaylandDataDevice *data_device,
|
|
|
|
struct wl_client *client,
|
|
|
|
const MetaWaylandPointerGrabInterface *funcs,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandDataSource *source,
|
|
|
|
MetaWaylandSurface *icon_surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandDragGrab *drag_grab;
|
2015-05-12 13:35:28 -04:00
|
|
|
ClutterPoint pos, stage_pos;
|
2015-02-06 03:12:21 -05:00
|
|
|
|
2014-09-26 13:08:42 -04:00
|
|
|
data_device->current_grab = drag_grab = g_slice_new0 (MetaWaylandDragGrab);
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
drag_grab->generic.interface = funcs;
|
2013-09-11 08:06:05 -04:00
|
|
|
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
|
|
|
|
2014-09-30 11:01:43 -04:00
|
|
|
drag_grab->drag_origin = surface;
|
|
|
|
drag_grab->drag_origin_listener.notify = destroy_data_device_origin;
|
2015-05-12 13:35:28 -04:00
|
|
|
wl_resource_add_destroy_listener (surface->resource,
|
2014-09-30 11:01:43 -04:00
|
|
|
&drag_grab->drag_origin_listener);
|
|
|
|
|
|
|
|
clutter_input_device_get_coords (seat->pointer.device, NULL, &pos);
|
|
|
|
clutter_actor_transform_stage_point (CLUTTER_ACTOR (meta_surface_actor_get_texture (surface->surface_actor)),
|
2015-05-12 13:35:28 -04:00
|
|
|
pos.x, pos.y, &stage_pos.x, &stage_pos.y);
|
|
|
|
drag_grab->drag_start_x = stage_pos.x;
|
|
|
|
drag_grab->drag_start_y = stage_pos.y;
|
2014-09-30 11:01:43 -04:00
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
if (source)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2015-05-12 13:35:28 -04:00
|
|
|
if (source->resource)
|
|
|
|
{
|
|
|
|
drag_grab->drag_data_source_listener.notify = destroy_data_device_source;
|
|
|
|
wl_resource_add_destroy_listener (source->resource,
|
|
|
|
&drag_grab->drag_data_source_listener);
|
|
|
|
}
|
2014-10-10 12:40:43 -04:00
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
drag_grab->drag_data_source = source;
|
2014-10-10 12:40:43 -04:00
|
|
|
meta_wayland_data_device_set_dnd_source (data_device,
|
|
|
|
drag_grab->drag_data_source);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
if (icon_surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2015-05-12 13:35:28 -04:00
|
|
|
drag_grab->drag_surface = icon_surface;
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
drag_grab->drag_icon_listener.notify = destroy_data_device_icon;
|
2015-05-12 13:35:28 -04:00
|
|
|
wl_resource_add_destroy_listener (icon_surface->resource,
|
2013-09-11 08:06:05 -04:00
|
|
|
&drag_grab->drag_icon_listener);
|
2014-10-06 11:03:51 -04:00
|
|
|
|
|
|
|
drag_grab->feedback_actor = meta_dnd_actor_new (CLUTTER_ACTOR (drag_grab->drag_origin->surface_actor),
|
|
|
|
drag_grab->drag_start_x,
|
|
|
|
drag_grab->drag_start_y);
|
|
|
|
meta_feedback_actor_set_anchor (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
|
|
|
-drag_grab->drag_surface->offset_x,
|
|
|
|
-drag_grab->drag_surface->offset_y);
|
|
|
|
clutter_actor_add_child (drag_grab->feedback_actor,
|
|
|
|
CLUTTER_ACTOR (drag_grab->drag_surface->surface_actor));
|
|
|
|
|
|
|
|
meta_feedback_actor_set_position (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
|
|
|
pos.x, pos.y);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2015-05-12 13:35:28 -04:00
|
|
|
meta_wayland_pointer_start_grab (&seat->pointer, (MetaWaylandPointerGrab*) drag_grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_device_end_drag (MetaWaylandDataDevice *data_device)
|
|
|
|
{
|
|
|
|
if (data_device->current_grab)
|
|
|
|
data_device_end_drag_grab (data_device->current_grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
MetaWaylandDataDevice *data_device = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
MetaWaylandSurface *surface = NULL, *icon_surface = NULL;
|
|
|
|
MetaWaylandDataSource *drag_source = NULL;
|
|
|
|
|
|
|
|
if (origin_resource)
|
|
|
|
surface = wl_resource_get_user_data (origin_resource);
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (seat->pointer.button_count == 0 ||
|
|
|
|
seat->pointer.grab_serial != serial ||
|
|
|
|
!seat->pointer.focus_surface ||
|
|
|
|
seat->pointer.focus_surface != surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* FIXME: Check that the data source type array isn't empty. */
|
|
|
|
|
|
|
|
if (data_device->current_grab ||
|
|
|
|
seat->pointer.grab != &seat->pointer.default_grab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (icon_resource)
|
|
|
|
icon_surface = wl_resource_get_user_data (icon_resource);
|
|
|
|
if (source_resource)
|
|
|
|
drag_source = wl_resource_get_user_data (source_resource);
|
|
|
|
|
|
|
|
if (icon_resource &&
|
|
|
|
meta_wayland_surface_set_role (icon_surface,
|
|
|
|
META_WAYLAND_SURFACE_ROLE_DND,
|
|
|
|
resource,
|
|
|
|
WL_DATA_DEVICE_ERROR_ROLE) != 0)
|
|
|
|
return;
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
meta_wayland_pointer_set_focus (&seat->pointer, NULL);
|
2015-05-12 13:35:28 -04:00
|
|
|
meta_wayland_data_device_start_drag (data_device, client,
|
|
|
|
&drag_grab_interface,
|
|
|
|
surface, drag_source, icon_surface);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_selection_data_source (struct wl_listener *listener, void *data)
|
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
MetaWaylandDataDevice *data_device = wl_container_of (listener, data_device, selection_data_source_listener);
|
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
struct wl_resource *data_device_resource;
|
2014-04-16 15:20:07 -04:00
|
|
|
struct wl_client *focus_client = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-07-10 10:31:08 -04:00
|
|
|
data_device->selection_data_source = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-04-16 15:20:07 -04:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard);
|
|
|
|
if (focus_client)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client);
|
|
|
|
if (data_device_resource)
|
|
|
|
wl_data_device_send_selection (data_device_resource, NULL);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 15:36:07 -04:00
|
|
|
static void
|
2014-10-10 12:40:43 -04:00
|
|
|
meta_wayland_source_send (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type,
|
|
|
|
gint fd)
|
|
|
|
{
|
|
|
|
wl_data_source_send_send (source->resource, mime_type, fd);
|
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_source_target (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type)
|
|
|
|
{
|
|
|
|
wl_data_source_send_target (source->resource, mime_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_source_cancel (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
wl_data_source_send_cancelled (source->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MetaWaylandDataSourceFuncs meta_wayland_source_funcs = {
|
|
|
|
meta_wayland_source_send,
|
|
|
|
meta_wayland_source_target,
|
|
|
|
meta_wayland_source_cancel
|
|
|
|
};
|
|
|
|
|
2015-05-18 07:24:27 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_focus_in (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandDataOffer *offer)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
struct wl_display *display;
|
|
|
|
struct wl_client *client;
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
|
|
|
client = wl_resource_get_client (surface->resource);
|
|
|
|
display = wl_client_get_display (client);
|
|
|
|
|
|
|
|
grab->drag_focus_listener.notify = destroy_drag_focus;
|
|
|
|
wl_resource_add_destroy_listener (grab->drag_focus_data_device,
|
|
|
|
&grab->drag_focus_listener);
|
|
|
|
|
|
|
|
meta_wayland_pointer_get_relative_coordinates (grab->generic.pointer,
|
|
|
|
surface, &sx, &sy);
|
|
|
|
wl_data_device_send_enter (grab->drag_focus_data_device,
|
|
|
|
wl_display_next_serial (display),
|
|
|
|
surface->resource, sx, sy, offer->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_focus_out (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
|
|
|
|
wl_data_device_send_leave (grab->drag_focus_data_device);
|
|
|
|
|
|
|
|
wl_list_remove (&grab->drag_focus_listener.link);
|
|
|
|
grab->drag_focus_data_device = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_motion (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
|
|
|
meta_wayland_pointer_get_relative_coordinates (grab->generic.pointer,
|
|
|
|
grab->drag_focus,
|
|
|
|
&sx, &sy);
|
|
|
|
wl_data_device_send_motion (grab->drag_focus_data_device,
|
|
|
|
clutter_event_get_time (event),
|
|
|
|
sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_drag_dest_drop (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *grab = data_device->current_grab;
|
|
|
|
|
|
|
|
wl_data_device_send_drop (grab->drag_focus_data_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MetaWaylandDragDestFuncs meta_wayland_drag_dest_funcs = {
|
|
|
|
meta_wayland_drag_dest_focus_in,
|
|
|
|
meta_wayland_drag_dest_focus_out,
|
|
|
|
meta_wayland_drag_dest_motion,
|
|
|
|
meta_wayland_drag_dest_drop
|
|
|
|
};
|
|
|
|
|
|
|
|
const MetaWaylandDragDestFuncs *
|
|
|
|
meta_wayland_data_device_get_drag_dest_funcs (void)
|
|
|
|
{
|
|
|
|
return &meta_wayland_drag_dest_funcs;
|
|
|
|
}
|
|
|
|
|
2014-10-10 12:40:43 -04:00
|
|
|
void
|
|
|
|
meta_wayland_data_device_set_dnd_source (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
if (data_device->dnd_data_source == source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (data_device->dnd_data_source)
|
|
|
|
meta_wayland_data_source_free (data_device->dnd_data_source);
|
|
|
|
|
|
|
|
data_device->dnd_data_source = source;
|
|
|
|
wl_signal_emit (&data_device->dnd_ownership_signal, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-10 10:31:08 -04:00
|
|
|
meta_wayland_data_device_set_selection (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandDataSource *source,
|
|
|
|
guint32 serial)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
|
|
|
struct wl_resource *data_device_resource, *offer;
|
2014-04-16 15:20:07 -04:00
|
|
|
struct wl_client *focus_client;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-07-10 10:31:08 -04:00
|
|
|
if (data_device->selection_data_source &&
|
|
|
|
data_device->selection_serial - serial < UINT32_MAX / 2)
|
2013-05-03 13:51:22 -04:00
|
|
|
return;
|
|
|
|
|
2014-07-10 10:31:08 -04:00
|
|
|
if (data_device->selection_data_source)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-10-10 12:40:43 -04:00
|
|
|
data_device->selection_data_source->funcs.cancel (data_device->selection_data_source);
|
|
|
|
|
|
|
|
if (data_device->selection_data_source->resource)
|
|
|
|
{
|
|
|
|
wl_list_remove (&data_device->selection_data_source_listener.link);
|
|
|
|
data_device->selection_data_source->resource = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_wayland_data_source_free (data_device->selection_data_source);
|
2014-07-10 10:31:08 -04:00
|
|
|
data_device->selection_data_source = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2014-07-10 10:31:08 -04:00
|
|
|
data_device->selection_data_source = source;
|
|
|
|
data_device->selection_serial = serial;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-04-16 15:20:07 -04:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard);
|
|
|
|
if (focus_client)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client);
|
|
|
|
if (data_device_resource)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
if (data_device->selection_data_source)
|
2014-04-20 11:35:53 -04:00
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
offer = meta_wayland_data_source_send_offer (data_device->selection_data_source, data_device_resource);
|
|
|
|
wl_data_device_send_selection (data_device_resource, offer);
|
2014-04-20 11:35:53 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
wl_data_device_send_selection (data_device_resource, NULL);
|
2014-04-20 11:35:53 -04:00
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
{
|
2014-10-10 12:40:43 -04:00
|
|
|
if (source->resource)
|
|
|
|
{
|
|
|
|
data_device->selection_data_source_listener.notify = destroy_selection_data_source;
|
|
|
|
wl_resource_add_destroy_listener (source->resource, &data_device->selection_data_source_listener);
|
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
2015-05-27 22:20:02 -04:00
|
|
|
|
|
|
|
wl_signal_emit (&data_device->selection_ownership_signal, source);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_set_selection (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *source_resource,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
MetaWaylandDataDevice *data_device = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
2015-05-27 22:20:02 -04:00
|
|
|
if (source_resource)
|
|
|
|
source = wl_resource_get_user_data (source_resource);
|
|
|
|
else
|
|
|
|
source = NULL;
|
2014-07-10 10:31:08 -04:00
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
/* FIXME: Store serial and check against incoming serial here. */
|
2014-07-10 10:31:08 -04:00
|
|
|
meta_wayland_data_device_set_selection (data_device, source, serial);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2014-11-22 15:20:47 -05:00
|
|
|
static void
|
|
|
|
data_device_release(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
static const struct wl_data_device_interface data_device_interface = {
|
|
|
|
data_device_start_drag,
|
|
|
|
data_device_set_selection,
|
2014-11-22 15:20:47 -05:00
|
|
|
data_device_release,
|
2013-05-03 13:51:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_source (struct wl_resource *resource)
|
|
|
|
{
|
2014-03-11 15:29:05 -04:00
|
|
|
MetaWaylandDataSource *source = wl_resource_get_user_data (resource);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-10-10 12:40:43 -04:00
|
|
|
source->resource = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_data_source (struct wl_client *client,
|
|
|
|
struct wl_resource *resource, guint32 id)
|
|
|
|
{
|
2014-10-10 12:40:43 -04:00
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
struct wl_resource *source_resource;
|
|
|
|
|
|
|
|
source_resource = wl_resource_create (client, &wl_data_source_interface,
|
|
|
|
wl_resource_get_version (resource), id);
|
|
|
|
source = meta_wayland_data_source_new (&meta_wayland_source_funcs,
|
|
|
|
source_resource, NULL);
|
|
|
|
wl_resource_set_implementation (source_resource, &data_source_interface,
|
|
|
|
source, destroy_data_source);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-07-10 10:19:47 -04:00
|
|
|
struct wl_resource *cr;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-08-04 10:22:23 -04:00
|
|
|
cr = wl_resource_create (client, &wl_data_device_interface, wl_resource_get_version (manager_resource), id);
|
2014-07-10 10:31:08 -04:00
|
|
|
wl_resource_set_implementation (cr, &data_device_interface, &seat->data_device, unbind_resource);
|
|
|
|
wl_list_insert (&seat->data_device.resource_list, wl_resource_get_link (cr));
|
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;
|
2014-08-04 10:24:59 -04:00
|
|
|
resource = wl_resource_create (client, &wl_data_device_manager_interface, 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
|
|
|
}
|
|
|
|
|
2014-04-22 18:05:44 -04:00
|
|
|
void
|
|
|
|
meta_wayland_data_device_manager_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
if (wl_global_create (compositor->wayland_display,
|
|
|
|
&wl_data_device_manager_interface,
|
|
|
|
META_WL_DATA_DEVICE_MANAGER_VERSION,
|
|
|
|
NULL, bind_manager) == NULL)
|
|
|
|
g_error ("Could not create data_device");
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
void
|
2014-07-10 10:31:08 -04:00
|
|
|
meta_wayland_data_device_init (MetaWaylandDataDevice *data_device)
|
|
|
|
{
|
|
|
|
wl_list_init (&data_device->resource_list);
|
2014-10-10 12:40:43 -04:00
|
|
|
wl_signal_init (&data_device->selection_ownership_signal);
|
|
|
|
wl_signal_init (&data_device->dnd_ownership_signal);
|
2014-07-10 10:31:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_device_set_keyboard_focus (MetaWaylandDataDevice *data_device)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device);
|
2014-04-16 15:20:07 -04:00
|
|
|
struct wl_client *focus_client;
|
2014-07-10 10:31:08 -04:00
|
|
|
struct wl_resource *data_device_resource, *offer;
|
2013-05-03 13:51:22 -04:00
|
|
|
MetaWaylandDataSource *source;
|
|
|
|
|
2014-04-16 15:20:07 -04:00
|
|
|
focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard);
|
|
|
|
if (!focus_client)
|
2013-05-03 13:51:22 -04:00
|
|
|
return;
|
|
|
|
|
2014-07-10 10:31:08 -04:00
|
|
|
data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client);
|
|
|
|
if (!data_device_resource)
|
2013-05-03 13:51:22 -04:00
|
|
|
return;
|
|
|
|
|
2014-07-10 10:31:08 -04:00
|
|
|
source = data_device->selection_data_source;
|
2013-05-03 13:51:22 -04:00
|
|
|
if (source)
|
|
|
|
{
|
2014-07-10 10:31:08 -04:00
|
|
|
offer = meta_wayland_data_source_send_offer (source, data_device_resource);
|
|
|
|
wl_data_device_send_selection (data_device_resource, offer);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
2015-05-27 22:20:02 -04:00
|
|
|
else
|
|
|
|
wl_data_device_send_selection (data_device_resource, NULL);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
2014-10-06 11:07:43 -04:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_data_device_is_dnd_surface (MetaWaylandDataDevice *data_device,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
return data_device->current_grab &&
|
|
|
|
data_device->current_grab->drag_surface == surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_device_update_dnd_surface (MetaWaylandDataDevice *data_device)
|
|
|
|
{
|
|
|
|
MetaWaylandDragGrab *drag_grab;
|
|
|
|
|
|
|
|
if (!data_device->current_grab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drag_grab = data_device->current_grab;
|
|
|
|
|
|
|
|
if (!drag_grab->feedback_actor || !drag_grab->drag_surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_feedback_actor_set_anchor (META_FEEDBACK_ACTOR (drag_grab->feedback_actor),
|
|
|
|
-drag_grab->drag_surface->offset_x,
|
|
|
|
-drag_grab->drag_surface->offset_y);
|
|
|
|
}
|
2014-10-10 12:40:43 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_source_send (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type,
|
|
|
|
gint fd)
|
|
|
|
{
|
|
|
|
source->funcs.send (source, mime_type, fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_data_source_has_mime_type (const MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type)
|
|
|
|
{
|
|
|
|
gchar **p;
|
|
|
|
|
|
|
|
wl_array_for_each (p, &source->mime_types)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (mime_type, *p) == 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaWaylandDataSource *
|
|
|
|
meta_wayland_data_source_new (const MetaWaylandDataSourceFuncs *funcs,
|
|
|
|
struct wl_resource *wl_resource,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaWaylandDataSource *source = g_slice_new0 (MetaWaylandDataSource);
|
|
|
|
|
|
|
|
source->funcs = *funcs;
|
|
|
|
source->resource = wl_resource;
|
|
|
|
source->user_data = user_data;
|
|
|
|
wl_array_init (&source->mime_types);
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_data_source_free (MetaWaylandDataSource *source)
|
|
|
|
{
|
|
|
|
char **pos;
|
|
|
|
|
|
|
|
if (source->resource)
|
|
|
|
wl_resource_destroy (source->resource);
|
|
|
|
|
|
|
|
wl_array_for_each (pos, &source->mime_types)
|
|
|
|
{
|
|
|
|
g_free (*pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_array_release (&source->mime_types);
|
|
|
|
g_slice_free (MetaWaylandDataSource, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_data_source_add_mime_type (MetaWaylandDataSource *source,
|
|
|
|
const gchar *mime_type)
|
|
|
|
{
|
|
|
|
gchar **pos;
|
|
|
|
|
|
|
|
pos = wl_array_add (&source->mime_types, sizeof (*pos));
|
|
|
|
|
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
*pos = g_strdup (mime_type);
|
|
|
|
return *pos != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|