2012-01-04 21:40:21 -05: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>
|
|
|
|
|
|
2012-10-19 23:06:53 -04:00
|
|
|
#include "wayland-private.h"
|
2012-01-04 21:40:21 -05:00
|
|
|
#include "wayland-server.h"
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
data_offer_accept(struct wl_client *client, struct wl_resource *resource,
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
uint32_t serial, const char *mime_type)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
|
|
|
|
struct wl_data_offer *offer = resource->data;
|
|
|
|
|
|
|
|
|
|
/* 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)
|
2012-06-03 17:30:12 -04:00
|
|
|
offer->source->accept(offer->source, serial, mime_type);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
data_offer_receive(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
const char *mime_type, int32_t fd)
|
|
|
|
|
{
|
|
|
|
|
struct wl_data_offer *offer = resource->data;
|
|
|
|
|
|
|
|
|
|
if (offer->source)
|
2012-06-03 17:30:12 -04:00
|
|
|
offer->source->send(offer->source, mime_type, fd);
|
|
|
|
|
else
|
|
|
|
|
close(fd);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
data_offer_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
wl_resource_destroy(resource);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
2012-06-03 17:30:12 -04:00
|
|
|
static const struct wl_data_offer_interface data_offer_interface = {
|
|
|
|
|
data_offer_accept,
|
|
|
|
|
data_offer_receive,
|
|
|
|
|
data_offer_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-04 21:40:21 -05:00
|
|
|
static void
|
|
|
|
|
destroy_data_offer(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
struct wl_data_offer *offer = resource->data;
|
|
|
|
|
|
2012-06-18 12:09:47 -04:00
|
|
|
if (offer->source)
|
|
|
|
|
wl_list_remove(&offer->source_destroy_listener.link);
|
2012-01-04 21:40:21 -05:00
|
|
|
free(offer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-04-12 15:29:48 -04:00
|
|
|
destroy_offer_data_source(struct wl_listener *listener, void *data)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-03-01 14:09:41 +02:00
|
|
|
struct wl_data_offer *offer;
|
|
|
|
|
|
|
|
|
|
offer = container_of(listener, struct wl_data_offer,
|
|
|
|
|
source_destroy_listener);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
|
|
|
|
offer->source = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wl_resource *
|
|
|
|
|
wl_data_source_send_offer(struct wl_data_source *source,
|
|
|
|
|
struct wl_resource *target)
|
|
|
|
|
{
|
|
|
|
|
struct wl_data_offer *offer;
|
2012-03-04 13:40:49 -05:00
|
|
|
char **p;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
|
|
|
|
offer = malloc(sizeof *offer);
|
|
|
|
|
if (offer == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
offer->resource.destroy = destroy_data_offer;
|
|
|
|
|
offer->resource.object.id = 0;
|
|
|
|
|
offer->resource.object.interface = &wl_data_offer_interface;
|
|
|
|
|
offer->resource.object.implementation =
|
2012-06-03 17:30:12 -04:00
|
|
|
(void (**)(void)) &data_offer_interface;
|
2012-01-04 21:40:21 -05:00
|
|
|
offer->resource.data = offer;
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_init(&offer->resource.destroy_signal);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
|
|
|
|
offer->source = source;
|
2012-04-12 15:29:48 -04:00
|
|
|
offer->source_destroy_listener.notify = destroy_offer_data_source;
|
|
|
|
|
wl_signal_add(&source->resource.destroy_signal,
|
|
|
|
|
&offer->source_destroy_listener);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
|
|
|
|
wl_client_add_resource(target->client, &offer->resource);
|
|
|
|
|
|
2012-03-02 17:08:59 +02:00
|
|
|
wl_data_device_send_data_offer(target, &offer->resource);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-03-04 13:40:49 -05:00
|
|
|
wl_array_for_each(p, &source->mime_types)
|
2012-03-02 17:08:59 +02:00
|
|
|
wl_data_offer_send_offer(&offer->resource, *p);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
|
|
|
|
return &offer->resource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
data_source_offer(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
const char *type)
|
|
|
|
|
{
|
|
|
|
|
struct wl_data_source *source = resource->data;
|
|
|
|
|
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)
|
|
|
|
|
{
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
wl_resource_destroy(resource);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wl_data_source_interface data_source_interface = {
|
|
|
|
|
data_source_offer,
|
|
|
|
|
data_source_destroy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct wl_resource *
|
|
|
|
|
find_resource(struct wl_list *list, struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *r;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(r, list, link) {
|
|
|
|
|
if (r->client == client)
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-04-12 15:29:48 -04:00
|
|
|
destroy_drag_focus(struct wl_listener *listener, void *data)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat =
|
|
|
|
|
container_of(listener, struct wl_seat, drag_focus_listener);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->drag_focus_resource = NULL;
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
drag_grab_focus(struct wl_pointer_grab *grab,
|
2012-05-08 17:17:26 +01:00
|
|
|
struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
|
2012-05-29 10:58:26 +03:00
|
|
|
struct wl_resource *resource, *offer = NULL;
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
struct wl_display *display;
|
|
|
|
|
uint32_t serial;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->drag_focus_resource) {
|
|
|
|
|
wl_data_device_send_leave(seat->drag_focus_resource);
|
|
|
|
|
wl_list_remove(&seat->drag_focus_listener.link);
|
|
|
|
|
seat->drag_focus_resource = NULL;
|
|
|
|
|
seat->drag_focus = NULL;
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
2012-05-29 10:58:26 +03:00
|
|
|
if (!surface)
|
|
|
|
|
return;
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
|
2012-05-29 10:58:26 +03:00
|
|
|
if (!seat->drag_data_source &&
|
|
|
|
|
surface->resource.client != seat->drag_client)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
resource = find_resource(&seat->drag_resource_list,
|
|
|
|
|
surface->resource.client);
|
|
|
|
|
if (!resource)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
display = wl_client_get_display(resource->client);
|
|
|
|
|
serial = wl_display_next_serial(display);
|
|
|
|
|
|
|
|
|
|
if (seat->drag_data_source)
|
2012-05-16 18:44:40 +01:00
|
|
|
offer = wl_data_source_send_offer(seat->drag_data_source,
|
2012-01-04 21:40:21 -05:00
|
|
|
resource);
|
|
|
|
|
|
2012-05-29 10:58:26 +03:00
|
|
|
wl_data_device_send_enter(resource, serial, &surface->resource,
|
|
|
|
|
x, y, offer);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-29 10:58:26 +03:00
|
|
|
seat->drag_focus = surface;
|
|
|
|
|
seat->drag_focus_listener.notify = destroy_drag_focus;
|
|
|
|
|
wl_signal_add(&resource->destroy_signal,
|
|
|
|
|
&seat->drag_focus_listener);
|
|
|
|
|
seat->drag_focus_resource = resource;
|
|
|
|
|
grab->focus = surface;
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-02-18 05:05:27 -07:00
|
|
|
drag_grab_motion(struct wl_pointer_grab *grab,
|
2012-05-08 17:17:26 +01:00
|
|
|
uint32_t time, wl_fixed_t x, wl_fixed_t y)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->drag_focus_resource)
|
|
|
|
|
wl_data_device_send_motion(seat->drag_focus_resource,
|
2012-03-02 17:08:59 +02:00
|
|
|
time, x, y);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
2012-03-02 15:45:56 +02:00
|
|
|
static void
|
2012-05-16 18:44:40 +01:00
|
|
|
data_device_end_drag_grab(struct wl_seat *seat)
|
2012-03-02 15:45:56 +02:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->drag_surface) {
|
2012-10-11 14:05:37 +03:00
|
|
|
seat->drag_surface = NULL;
|
|
|
|
|
wl_signal_emit(&seat->drag_icon_signal, NULL);
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_list_remove(&seat->drag_icon_listener.link);
|
2012-03-02 15:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
drag_grab_focus(&seat->drag_grab, NULL,
|
2012-05-08 17:17:26 +01:00
|
|
|
wl_fixed_from_int(0), wl_fixed_from_int(0));
|
2012-04-13 10:39:24 -04:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_end_grab(seat->pointer);
|
2012-03-02 15:45:56 +02:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->drag_data_source = NULL;
|
2012-05-29 10:58:26 +03:00
|
|
|
seat->drag_client = NULL;
|
2012-03-02 15:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-04 21:40:21 -05:00
|
|
|
static void
|
2012-02-18 05:05:27 -07:00
|
|
|
drag_grab_button(struct wl_pointer_grab *grab,
|
2012-05-30 16:31:48 +01:00
|
|
|
uint32_t time, uint32_t button, uint32_t state_w)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
|
2012-05-30 16:31:48 +01:00
|
|
|
enum wl_pointer_button_state state = state_w;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->drag_focus_resource &&
|
2012-05-30 16:31:48 +01:00
|
|
|
seat->pointer->grab_button == button &&
|
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_data_device_send_drop(seat->drag_focus_resource);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-30 16:31:48 +01:00
|
|
|
if (seat->pointer->button_count == 0 &&
|
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
2012-05-29 10:58:26 +03:00
|
|
|
if (seat->drag_data_source)
|
|
|
|
|
wl_list_remove(&seat->drag_data_source_listener.link);
|
2012-07-17 18:56:03 +04:00
|
|
|
data_device_end_drag_grab(seat);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-18 05:05:27 -07:00
|
|
|
static const struct wl_pointer_grab_interface drag_grab_interface = {
|
2012-01-04 21:40:21 -05:00
|
|
|
drag_grab_focus,
|
|
|
|
|
drag_grab_motion,
|
|
|
|
|
drag_grab_button,
|
|
|
|
|
};
|
|
|
|
|
|
2012-03-02 15:45:56 +02:00
|
|
|
static void
|
2012-04-12 15:29:48 -04:00
|
|
|
destroy_data_device_source(struct wl_listener *listener, void *data)
|
2012-03-02 15:45:56 +02:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = container_of(listener, struct wl_seat,
|
|
|
|
|
drag_data_source_listener);
|
2012-03-02 15:45:56 +02:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
data_device_end_drag_grab(seat);
|
2012-03-02 15:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-03-01 14:09:42 +02:00
|
|
|
static void
|
2012-04-12 15:29:48 -04:00
|
|
|
destroy_data_device_icon(struct wl_listener *listener, void *data)
|
2012-03-01 14:09:42 +02:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = container_of(listener, struct wl_seat,
|
2012-05-25 10:40:28 +03:00
|
|
|
drag_icon_listener);
|
2012-03-01 14:09:42 +02:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->drag_surface = NULL;
|
2012-03-01 14:09:42 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-04 21:40:21 -05:00
|
|
|
static void
|
|
|
|
|
data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
struct wl_resource *source_resource,
|
2012-02-15 17:02:52 +02:00
|
|
|
struct wl_resource *origin_resource,
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
struct wl_resource *icon_resource, uint32_t serial)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = resource->data;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-02-15 17:02:52 +02:00
|
|
|
/* FIXME: Check that client has implicit grab on the origin
|
|
|
|
|
* surface that matches the given time. */
|
2012-01-04 21:40:21 -05:00
|
|
|
|
|
|
|
|
/* FIXME: Check that the data source type array isn't empty. */
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->drag_grab.interface = &drag_grab_interface;
|
2012-03-02 15:45:56 +02:00
|
|
|
|
2012-05-29 10:58:26 +03:00
|
|
|
seat->drag_client = client;
|
|
|
|
|
seat->drag_data_source = NULL;
|
|
|
|
|
|
|
|
|
|
if (source_resource) {
|
|
|
|
|
seat->drag_data_source = source_resource->data;
|
|
|
|
|
seat->drag_data_source_listener.notify =
|
|
|
|
|
destroy_data_device_source;
|
|
|
|
|
wl_signal_add(&source_resource->destroy_signal,
|
|
|
|
|
&seat->drag_data_source_listener);
|
|
|
|
|
}
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-03-01 14:09:42 +02:00
|
|
|
if (icon_resource) {
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->drag_surface = icon_resource->data;
|
|
|
|
|
seat->drag_icon_listener.notify = destroy_data_device_icon;
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_add(&icon_resource->destroy_signal,
|
2012-05-16 18:44:40 +01:00
|
|
|
&seat->drag_icon_listener);
|
|
|
|
|
wl_signal_emit(&seat->drag_icon_signal, icon_resource);
|
2012-03-01 14:09:42 +02:00
|
|
|
}
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_set_focus(seat->pointer, NULL,
|
|
|
|
|
wl_fixed_from_int(0), wl_fixed_from_int(0));
|
|
|
|
|
wl_pointer_start_grab(seat->pointer, &seat->drag_grab);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-04-12 15:29:48 -04:00
|
|
|
destroy_selection_data_source(struct wl_listener *listener, void *data)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = container_of(listener, struct wl_seat,
|
|
|
|
|
selection_data_source_listener);
|
|
|
|
|
struct wl_resource *data_device;
|
|
|
|
|
struct wl_resource *focus = NULL;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->selection_data_source = NULL;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->keyboard)
|
|
|
|
|
focus = seat->keyboard->focus_resource;
|
2012-01-04 21:40:21 -05:00
|
|
|
if (focus) {
|
2012-05-16 18:44:40 +01:00
|
|
|
data_device = find_resource(&seat->drag_resource_list,
|
2012-01-04 21:40:21 -05:00
|
|
|
focus->client);
|
2012-05-31 23:26:50 -04:00
|
|
|
if (data_device)
|
|
|
|
|
wl_data_device_send_selection(data_device, NULL);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
2012-05-31 23:28:31 -04:00
|
|
|
|
|
|
|
|
wl_signal_emit(&seat->selection_signal, seat);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_seat_set_selection(struct wl_seat *seat, struct wl_data_source *source,
|
|
|
|
|
uint32_t serial)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_resource *data_device, *offer;
|
|
|
|
|
struct wl_resource *focus = NULL;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->selection_data_source &&
|
|
|
|
|
seat->selection_serial - serial < UINT32_MAX / 2)
|
2012-04-13 12:48:38 -04:00
|
|
|
return;
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
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;
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->selection_data_source = source;
|
|
|
|
|
seat->selection_serial = serial;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->keyboard)
|
|
|
|
|
focus = seat->keyboard->focus_resource;
|
2012-01-04 21:40:21 -05:00
|
|
|
if (focus) {
|
2012-05-16 18:44:40 +01:00
|
|
|
data_device = find_resource(&seat->drag_resource_list,
|
2012-01-04 21:40:21 -05:00
|
|
|
focus->client);
|
2012-05-31 23:29:08 -04:00
|
|
|
if (data_device && source) {
|
2012-05-16 18:44:40 +01:00
|
|
|
offer = wl_data_source_send_offer(seat->selection_data_source,
|
2012-01-04 21:40:21 -05:00
|
|
|
data_device);
|
2012-03-02 17:08:59 +02:00
|
|
|
wl_data_device_send_selection(data_device, offer);
|
2012-05-31 23:29:08 -04:00
|
|
|
} else if (data_device) {
|
|
|
|
|
wl_data_device_send_selection(data_device, NULL);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_signal_emit(&seat->selection_signal, seat);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-05-31 23:29:08 -04:00
|
|
|
if (source) {
|
|
|
|
|
seat->selection_data_source_listener.notify =
|
|
|
|
|
destroy_selection_data_source;
|
|
|
|
|
wl_signal_add(&source->resource.destroy_signal,
|
|
|
|
|
&seat->selection_data_source_listener);
|
|
|
|
|
}
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
data_device_set_selection(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
struct wl_resource *source_resource, uint32_t serial)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
|
|
|
|
if (!source_resource)
|
|
|
|
|
return;
|
|
|
|
|
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
/* FIXME: Store serial and check against incoming serial here. */
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_seat_set_selection(resource->data, source_resource->data,
|
|
|
|
|
serial);
|
2012-01-04 21:40:21 -05: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)
|
|
|
|
|
{
|
|
|
|
|
struct wl_data_source *source =
|
|
|
|
|
container_of(resource, struct wl_data_source, resource);
|
2012-03-04 13:40:49 -05:00
|
|
|
char **p;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-03-04 13:40:49 -05:00
|
|
|
wl_array_for_each(p, &source->mime_types)
|
2012-01-04 21:40:21 -05:00
|
|
|
free(*p);
|
|
|
|
|
|
|
|
|
|
wl_array_release(&source->mime_types);
|
|
|
|
|
|
|
|
|
|
source->resource.object.id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-03 17:30:12 -04:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-04 21:40:21 -05:00
|
|
|
static void
|
|
|
|
|
create_data_source(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct wl_data_source *source;
|
|
|
|
|
|
|
|
|
|
source = malloc(sizeof *source);
|
|
|
|
|
if (source == NULL) {
|
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source->resource.destroy = destroy_data_source;
|
|
|
|
|
source->resource.object.id = id;
|
|
|
|
|
source->resource.object.interface = &wl_data_source_interface;
|
|
|
|
|
source->resource.object.implementation =
|
|
|
|
|
(void (**)(void)) &data_source_interface;
|
|
|
|
|
source->resource.data = source;
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_init(&source->resource.destroy_signal);
|
2012-01-04 21:40:21 -05:00
|
|
|
|
2012-06-03 17:30:12 -04:00
|
|
|
source->accept = client_source_accept;
|
|
|
|
|
source->send = client_source_send;
|
|
|
|
|
source->cancel = client_source_cancel;
|
2012-01-04 21:40:21 -05:00
|
|
|
|
|
|
|
|
wl_array_init(&source->mime_types);
|
|
|
|
|
wl_client_add_resource(client, &source->resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void unbind_data_device(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_list_remove(&resource->link);
|
|
|
|
|
free(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_data_device(struct wl_client *client,
|
|
|
|
|
struct wl_resource *manager_resource,
|
2012-05-16 18:44:40 +01:00
|
|
|
uint32_t id, struct wl_resource *seat_resource)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_seat *seat = seat_resource->data;
|
2012-01-04 21:40:21 -05:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = wl_client_add_object(client, &wl_data_device_interface,
|
|
|
|
|
&data_device_interface, id,
|
|
|
|
|
seat);
|
|
|
|
|
|
|
|
|
|
wl_list_insert(&seat->drag_resource_list, &resource->link);
|
2012-01-04 21:40:21 -05:00
|
|
|
resource->destroy = unbind_data_device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
wl_client_add_object(client, &wl_data_device_manager_interface,
|
|
|
|
|
&manager_interface, id, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_data_device_set_keyboard_focus(struct wl_seat *seat)
|
2012-01-04 21:40:21 -05:00
|
|
|
{
|
|
|
|
|
struct wl_resource *data_device, *focus, *offer;
|
|
|
|
|
struct wl_data_source *source;
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (!seat->keyboard)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
focus = seat->keyboard->focus_resource;
|
2012-01-04 21:40:21 -05:00
|
|
|
if (!focus)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
data_device = find_resource(&seat->drag_resource_list,
|
2012-01-04 21:40:21 -05:00
|
|
|
focus->client);
|
|
|
|
|
if (!data_device)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
source = seat->selection_data_source;
|
2012-01-04 21:40:21 -05:00
|
|
|
if (source) {
|
|
|
|
|
offer = wl_data_source_send_offer(source, data_device);
|
2012-03-02 17:08:59 +02:00
|
|
|
wl_data_device_send_selection(data_device, offer);
|
2012-01-04 21:40:21 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_data_device_manager_init(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
if (wl_display_add_global(display,
|
|
|
|
|
&wl_data_device_manager_interface,
|
|
|
|
|
NULL, bind_manager) == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|