2013-04-18 19:07:39 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "compositor.h"
|
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag {
|
|
|
|
struct wl_client *client;
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *data_source;
|
2013-05-08 19:27:47 +00:00
|
|
|
struct wl_listener data_source_listener;
|
|
|
|
struct weston_surface *focus;
|
|
|
|
struct wl_resource *focus_resource;
|
|
|
|
struct wl_listener focus_listener;
|
|
|
|
struct weston_pointer_grab grab;
|
2013-05-08 19:30:42 +00:00
|
|
|
struct weston_surface *icon;
|
|
|
|
struct wl_listener icon_destroy_listener;
|
2013-05-08 19:27:47 +00:00
|
|
|
int32_t dx, dy;
|
|
|
|
};
|
|
|
|
|
2013-05-07 15:18:46 +00:00
|
|
|
static void
|
|
|
|
empty_region(pixman_region32_t *region)
|
|
|
|
{
|
|
|
|
pixman_region32_fini(region);
|
|
|
|
pixman_region32_init(region);
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static void
|
|
|
|
data_offer_accept(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t serial, const char *mime_type)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer = wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer = wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer = wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-07-25 23:09:37 +00:00
|
|
|
offer = container_of(listener, struct weston_data_offer,
|
2013-04-18 19:07:39 +00:00
|
|
|
source_destroy_listener);
|
|
|
|
|
|
|
|
offer->source = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wl_resource *
|
2013-07-25 22:52:14 +00:00
|
|
|
weston_data_source_send_offer(struct weston_data_source *source,
|
|
|
|
struct wl_resource *target)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-07-25 23:09:37 +00:00
|
|
|
struct weston_data_offer *offer;
|
2013-04-18 19:07:39 +00:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
offer = malloc(sizeof *offer);
|
|
|
|
if (offer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
offer->resource =
|
|
|
|
wl_resource_create(wl_resource_get_client(target),
|
|
|
|
&wl_data_offer_interface, 1, 0);
|
2013-08-06 17:24:04 +00:00
|
|
|
if (offer->resource == NULL) {
|
|
|
|
free(offer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
wl_resource_set_implementation(offer->resource, &data_offer_interface,
|
|
|
|
offer, destroy_data_offer);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
offer->source = source;
|
|
|
|
offer->source_destroy_listener.notify = destroy_offer_data_source;
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_add(&source->destroy_signal,
|
2013-04-18 19:07:39 +00:00
|
|
|
&offer->source_destroy_listener);
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_device_send_data_offer(target, offer->resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
wl_array_for_each(p, &source->mime_types)
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_offer_send_offer(offer->resource, *p);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
return offer->resource;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_source_offer(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
const char *type)
|
|
|
|
{
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
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-05-07 15:18:46 +00:00
|
|
|
static void
|
|
|
|
drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
|
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag = es->configure_private;
|
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
2013-05-08 02:42:28 +00:00
|
|
|
struct wl_list *list;
|
2013-05-08 02:53:43 +00:00
|
|
|
float fx, fy;
|
2013-05-08 02:42:28 +00:00
|
|
|
|
|
|
|
if (!weston_surface_is_mapped(es) && es->buffer_ref.buffer) {
|
2013-05-08 19:02:05 +00:00
|
|
|
if (pointer->sprite && weston_surface_is_mapped(pointer->sprite))
|
|
|
|
list = &pointer->sprite->layer_link;
|
2013-05-08 02:42:28 +00:00
|
|
|
else
|
2013-05-08 19:27:47 +00:00
|
|
|
list = &es->compositor->cursor_layer.surface_list;
|
2013-05-08 02:42:28 +00:00
|
|
|
|
|
|
|
wl_list_insert(list, &es->layer_link);
|
|
|
|
weston_surface_update_transform(es);
|
|
|
|
empty_region(&es->pending.input);
|
|
|
|
}
|
2013-05-07 15:18:46 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->dx += sx;
|
|
|
|
drag->dy += sy;
|
2013-05-08 02:53:43 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
fx = wl_fixed_to_double(pointer->x) + drag->dx;
|
|
|
|
fy = wl_fixed_to_double(pointer->y) + drag->dy;
|
2013-05-08 02:53:43 +00:00
|
|
|
weston_surface_configure(es, fx, fy, width, height);
|
2013-05-07 15:18:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static void
|
|
|
|
destroy_drag_focus(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag =
|
|
|
|
container_of(listener, struct weston_drag, focus_listener);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->focus_resource = NULL;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-09 02:02:59 +00:00
|
|
|
weston_drag_set_focus(struct weston_drag *drag, struct weston_surface *surface,
|
|
|
|
wl_fixed_t sx, wl_fixed_t sy)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-05-09 02:02:59 +00:00
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
2013-04-18 19:07:39 +00:00
|
|
|
struct wl_resource *resource, *offer = NULL;
|
|
|
|
struct wl_display *display;
|
|
|
|
uint32_t serial;
|
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
if (drag->focus_resource) {
|
|
|
|
wl_data_device_send_leave(drag->focus_resource);
|
|
|
|
wl_list_remove(&drag->focus_listener.link);
|
|
|
|
drag->focus_resource = NULL;
|
|
|
|
drag->focus = NULL;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return;
|
|
|
|
|
2013-06-07 03:34:41 +00:00
|
|
|
if (!drag->data_source &&
|
|
|
|
wl_resource_get_client(surface->resource) != drag->client)
|
2013-04-18 19:07:39 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
resource = wl_resource_find_for_client(&pointer->seat->drag_resource_list,
|
|
|
|
wl_resource_get_client(surface->resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
if (!resource)
|
|
|
|
return;
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
display = wl_client_get_display(wl_resource_get_client(resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
serial = wl_display_next_serial(display);
|
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
if (drag->data_source)
|
2013-07-25 22:52:14 +00:00
|
|
|
offer = weston_data_source_send_offer(drag->data_source,
|
|
|
|
resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-06-07 03:34:41 +00:00
|
|
|
wl_data_device_send_enter(resource, serial, surface->resource,
|
2013-05-09 02:02:59 +00:00
|
|
|
sx, sy, offer);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->focus = surface;
|
|
|
|
drag->focus_listener.notify = destroy_drag_focus;
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_resource_add_destroy_listener(resource, &drag->focus_listener);
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->focus_resource = resource;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 02:02:59 +00:00
|
|
|
static void
|
|
|
|
drag_grab_focus(struct weston_pointer_grab *grab)
|
|
|
|
{
|
|
|
|
struct weston_drag *drag =
|
|
|
|
container_of(grab, struct weston_drag, grab);
|
|
|
|
struct weston_pointer *pointer = grab->pointer;
|
|
|
|
struct weston_surface *surface;
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
|
|
|
surface = weston_compositor_pick_surface(pointer->seat->compositor,
|
|
|
|
pointer->x, pointer->y,
|
|
|
|
&sx, &sy);
|
|
|
|
if (drag->focus != surface)
|
|
|
|
weston_drag_set_focus(drag, surface, sx, sy);
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
static void
|
2013-05-09 01:03:21 +00:00
|
|
|
drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag =
|
|
|
|
container_of(grab, struct weston_drag, grab);
|
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
2013-05-08 02:53:43 +00:00
|
|
|
float fx, fy;
|
2013-05-09 01:03:21 +00:00
|
|
|
wl_fixed_t sx, sy;
|
2013-05-08 02:53:43 +00:00
|
|
|
|
2013-05-08 19:30:42 +00:00
|
|
|
if (drag->icon) {
|
2013-05-08 19:27:47 +00:00
|
|
|
fx = wl_fixed_to_double(pointer->x) + drag->dx;
|
|
|
|
fy = wl_fixed_to_double(pointer->y) + drag->dy;
|
2013-05-08 19:30:42 +00:00
|
|
|
weston_surface_set_position(drag->icon, fx, fy);
|
|
|
|
weston_surface_schedule_repaint(drag->icon);
|
2013-05-08 02:53:43 +00:00
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-09 01:03:21 +00:00
|
|
|
if (drag->focus_resource) {
|
|
|
|
weston_surface_from_global_fixed(drag->focus,
|
|
|
|
pointer->x, pointer->y,
|
|
|
|
&sx, &sy);
|
|
|
|
|
|
|
|
wl_data_device_send_motion(drag->focus_resource, time, sx, sy);
|
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-08 19:27:47 +00:00
|
|
|
data_device_end_drag_grab(struct weston_drag *drag)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-05-08 19:47:52 +00:00
|
|
|
if (drag->icon) {
|
|
|
|
if (weston_surface_is_mapped(drag->icon))
|
|
|
|
weston_surface_unmap(drag->icon);
|
|
|
|
|
|
|
|
drag->icon->configure = NULL;
|
|
|
|
empty_region(&drag->icon->pending.input);
|
|
|
|
wl_list_remove(&drag->icon_destroy_listener.link);
|
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-09 02:02:59 +00:00
|
|
|
weston_drag_set_focus(drag, NULL, 0, 0);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
weston_pointer_end_grab(drag->grab.pointer);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
free(drag);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-07 02:15:05 +00:00
|
|
|
drag_grab_button(struct weston_pointer_grab *grab,
|
2013-04-18 19:07:39 +00:00
|
|
|
uint32_t time, uint32_t button, uint32_t state_w)
|
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag =
|
|
|
|
container_of(grab, struct weston_drag, grab);
|
|
|
|
struct weston_pointer *pointer = drag->grab.pointer;
|
2013-04-18 19:07:39 +00:00
|
|
|
enum wl_pointer_button_state state = state_w;
|
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
if (drag->focus_resource &&
|
|
|
|
pointer->grab_button == button &&
|
2013-04-18 19:07:39 +00:00
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
2013-05-08 19:27:47 +00:00
|
|
|
wl_data_device_send_drop(drag->focus_resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
if (pointer->button_count == 0 &&
|
2013-04-18 19:07:39 +00:00
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
2013-05-08 19:27:47 +00:00
|
|
|
if (drag->data_source)
|
|
|
|
wl_list_remove(&drag->data_source_listener.link);
|
|
|
|
data_device_end_drag_grab(drag);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 02:15:05 +00:00
|
|
|
static const struct weston_pointer_grab_interface drag_grab_interface = {
|
2013-04-18 19:07:39 +00:00
|
|
|
drag_grab_focus,
|
|
|
|
drag_grab_motion,
|
|
|
|
drag_grab_button,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_data_device_source(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag = container_of(listener, struct weston_drag,
|
|
|
|
data_source_listener);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
data_device_end_drag_grab(drag);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 15:18:46 +00:00
|
|
|
static void
|
2013-05-08 19:30:42 +00:00
|
|
|
handle_drag_icon_destroy(struct wl_listener *listener, void *data)
|
2013-05-07 15:18:46 +00:00
|
|
|
{
|
2013-05-08 19:27:47 +00:00
|
|
|
struct weston_drag *drag = container_of(listener, struct weston_drag,
|
2013-05-08 19:30:42 +00:00
|
|
|
icon_destroy_listener);
|
2013-05-07 15:18:46 +00:00
|
|
|
|
2013-05-08 19:30:42 +00:00
|
|
|
drag->icon = NULL;
|
2013-05-07 15:18:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 19:07:39 +00: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, uint32_t serial)
|
|
|
|
{
|
2013-06-14 15:08:01 +00:00
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(resource);
|
2013-06-25 15:28:18 +00:00
|
|
|
struct weston_drag *drag;
|
2013-05-08 19:47:52 +00:00
|
|
|
struct weston_surface *icon = NULL;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:53:42 +00:00
|
|
|
if (seat->pointer->button_count == 0 ||
|
|
|
|
seat->pointer->grab_serial != serial ||
|
2013-06-14 15:07:53 +00:00
|
|
|
seat->pointer->focus != wl_resource_get_user_data(origin_resource))
|
2013-05-08 19:53:42 +00:00
|
|
|
return;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
/* FIXME: Check that the data source type array isn't empty. */
|
|
|
|
|
2013-05-08 19:47:52 +00:00
|
|
|
if (icon_resource)
|
2013-06-14 15:07:53 +00:00
|
|
|
icon = wl_resource_get_user_data(icon_resource);
|
2013-05-08 19:47:52 +00:00
|
|
|
if (icon && icon->configure) {
|
|
|
|
wl_resource_post_error(icon_resource,
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"surface->configure already set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
drag = malloc(sizeof *drag);
|
|
|
|
if (drag == NULL) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-05-08 19:27:47 +00:00
|
|
|
memset(drag, 0, sizeof *drag);
|
|
|
|
drag->grab.interface = &drag_grab_interface;
|
|
|
|
drag->client = client;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
if (source_resource) {
|
2013-06-14 15:07:55 +00:00
|
|
|
drag->data_source = wl_resource_get_user_data(source_resource);
|
2013-05-08 19:27:47 +00:00
|
|
|
drag->data_source_listener.notify = destroy_data_device_source;
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_resource_add_destroy_listener(source_resource,
|
|
|
|
&drag->data_source_listener);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-08 19:47:52 +00:00
|
|
|
if (icon) {
|
|
|
|
drag->icon = icon;
|
|
|
|
drag->icon_destroy_listener.notify = handle_drag_icon_destroy;
|
2013-06-07 03:34:41 +00:00
|
|
|
wl_signal_add(&icon->destroy_signal,
|
2013-05-08 19:47:52 +00:00
|
|
|
&drag->icon_destroy_listener);
|
|
|
|
|
|
|
|
icon->configure = drag_surface_configure;
|
|
|
|
icon->configure_private = drag;
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 02:15:05 +00:00
|
|
|
weston_pointer_set_focus(seat->pointer, NULL,
|
|
|
|
wl_fixed_from_int(0), wl_fixed_from_int(0));
|
2013-05-08 19:27:47 +00:00
|
|
|
weston_pointer_start_grab(seat->pointer, &drag->grab);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_selection_data_source(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-05-07 03:19:49 +00:00
|
|
|
struct weston_seat *seat = container_of(listener, struct weston_seat,
|
|
|
|
selection_data_source_listener);
|
2013-04-18 19:07:39 +00:00
|
|
|
struct wl_resource *data_device;
|
|
|
|
struct wl_resource *focus = NULL;
|
|
|
|
|
|
|
|
seat->selection_data_source = NULL;
|
|
|
|
|
|
|
|
if (seat->keyboard)
|
|
|
|
focus = seat->keyboard->focus_resource;
|
|
|
|
if (focus) {
|
2013-06-14 15:07:55 +00:00
|
|
|
data_device = wl_resource_find_for_client(&seat->drag_resource_list,
|
|
|
|
wl_resource_get_client(focus));
|
2013-04-18 19:07:39 +00:00
|
|
|
if (data_device)
|
|
|
|
wl_data_device_send_selection(data_device, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_signal_emit(&seat->selection_signal, seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2013-05-07 03:19:49 +00:00
|
|
|
weston_seat_set_selection(struct weston_seat *seat,
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source, uint32_t serial)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (seat->keyboard)
|
|
|
|
focus = seat->keyboard->focus_resource;
|
|
|
|
if (focus) {
|
2013-06-14 15:07:55 +00:00
|
|
|
data_device = wl_resource_find_for_client(&seat->drag_resource_list,
|
|
|
|
wl_resource_get_client(focus));
|
2013-04-18 19:07:39 +00:00
|
|
|
if (data_device && source) {
|
2013-07-25 22:52:14 +00:00
|
|
|
offer = weston_data_source_send_offer(seat->selection_data_source,
|
|
|
|
data_device);
|
2013-04-18 19:07:39 +00:00
|
|
|
wl_data_device_send_selection(data_device, offer);
|
|
|
|
} else if (data_device) {
|
|
|
|
wl_data_device_send_selection(data_device, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_signal_emit(&seat->selection_signal, seat);
|
|
|
|
|
|
|
|
if (source) {
|
|
|
|
seat->selection_data_source_listener.notify =
|
|
|
|
destroy_selection_data_source;
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_add(&source->destroy_signal,
|
2013-04-18 19:07:39 +00:00
|
|
|
&seat->selection_data_source_listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* FIXME: Store serial and check against incoming serial here. */
|
2013-06-14 15:07:55 +00:00
|
|
|
weston_seat_set_selection(wl_resource_get_user_data(resource),
|
|
|
|
wl_resource_get_user_data(source_resource),
|
2013-05-07 03:19:49 +00:00
|
|
|
serial);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
char **p;
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_emit(&source->destroy_signal, source);
|
|
|
|
|
2013-04-18 19:07:39 +00:00
|
|
|
wl_array_for_each(p, &source->mime_types)
|
|
|
|
free(*p);
|
|
|
|
|
|
|
|
wl_array_release(&source->mime_types);
|
|
|
|
|
2013-06-25 15:26:31 +00:00
|
|
|
free(source);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-25 22:52:14 +00:00
|
|
|
client_source_accept(struct weston_data_source *source,
|
2013-04-18 19:07:39 +00:00
|
|
|
uint32_t time, const char *mime_type)
|
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_source_send_target(source->resource, mime_type);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-25 22:52:14 +00:00
|
|
|
client_source_send(struct weston_data_source *source,
|
2013-04-18 19:07:39 +00:00
|
|
|
const char *mime_type, int32_t fd)
|
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_source_send_send(source->resource, mime_type, fd);
|
2013-04-18 19:07:39 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-25 22:52:14 +00:00
|
|
|
client_source_cancel(struct weston_data_source *source)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_data_source_send_cancelled(source->resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_data_source(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t id)
|
|
|
|
{
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
source = malloc(sizeof *source);
|
|
|
|
if (source == NULL) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_signal_init(&source->destroy_signal);
|
2013-04-18 19:07:39 +00:00
|
|
|
source->accept = client_source_accept;
|
|
|
|
source->send = client_source_send;
|
|
|
|
source->cancel = client_source_cancel;
|
|
|
|
|
|
|
|
wl_array_init(&source->mime_types);
|
2013-06-14 15:07:55 +00:00
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
source->resource =
|
|
|
|
wl_resource_create(client, &wl_data_source_interface, 1, id);
|
|
|
|
wl_resource_set_implementation(source->resource, &data_source_interface,
|
|
|
|
source, destroy_data_source);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unbind_data_device(struct wl_resource *resource)
|
|
|
|
{
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_data_device(struct wl_client *client,
|
|
|
|
struct wl_resource *manager_resource,
|
|
|
|
uint32_t id, struct wl_resource *seat_resource)
|
|
|
|
{
|
2013-06-14 15:08:01 +00:00
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
|
2013-04-18 19:07:39 +00:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-06-28 01:17:02 +00:00
|
|
|
resource = wl_resource_create(client,
|
|
|
|
&wl_data_device_interface, 1, id);
|
2013-04-18 19:07:39 +00:00
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
wl_list_insert(&seat->drag_resource_list, wl_resource_get_link(resource));
|
2013-06-28 01:17:02 +00:00
|
|
|
wl_resource_set_implementation(resource, &data_device_interface,
|
|
|
|
seat, unbind_data_device);
|
2013-04-18 19:07:39 +00: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, uint32_t version, uint32_t id)
|
|
|
|
{
|
2013-06-28 01:17:02 +00:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource =
|
|
|
|
wl_resource_create(client,
|
|
|
|
&wl_data_device_manager_interface, 1, id);
|
|
|
|
if (resource)
|
|
|
|
wl_resource_set_implementation(resource, &manager_interface,
|
|
|
|
NULL, NULL);
|
2013-04-18 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2013-05-07 03:19:49 +00:00
|
|
|
wl_data_device_set_keyboard_focus(struct weston_seat *seat)
|
2013-04-18 19:07:39 +00:00
|
|
|
{
|
|
|
|
struct wl_resource *data_device, *focus, *offer;
|
2013-07-25 22:52:14 +00:00
|
|
|
struct weston_data_source *source;
|
2013-04-18 19:07:39 +00:00
|
|
|
|
|
|
|
if (!seat->keyboard)
|
|
|
|
return;
|
|
|
|
|
|
|
|
focus = seat->keyboard->focus_resource;
|
|
|
|
if (!focus)
|
|
|
|
return;
|
|
|
|
|
2013-06-14 15:07:55 +00:00
|
|
|
data_device = wl_resource_find_for_client(&seat->drag_resource_list,
|
|
|
|
wl_resource_get_client(focus));
|
2013-04-18 19:07:39 +00:00
|
|
|
if (!data_device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
source = seat->selection_data_source;
|
|
|
|
if (source) {
|
2013-07-25 22:52:14 +00:00
|
|
|
offer = weston_data_source_send_offer(source, data_device);
|
2013-04-18 19:07:39 +00:00
|
|
|
wl_data_device_send_selection(data_device, offer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT int
|
|
|
|
wl_data_device_manager_init(struct wl_display *display)
|
|
|
|
{
|
2013-07-08 23:03:57 +00:00
|
|
|
if (wl_global_create(display,
|
|
|
|
&wl_data_device_manager_interface, 1,
|
|
|
|
NULL, bind_manager) == NULL)
|
2013-04-18 19:07:39 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|