data-device: Move all drag-related fields out of weston_seat
We can now allocate a temporary weston_drag structure that we keep all this drag-and-drop related state in.
This commit is contained in:
+1
-12
@@ -444,24 +444,13 @@ struct weston_seat {
|
|||||||
enum weston_keyboard_modifier modifier_state;
|
enum weston_keyboard_modifier modifier_state;
|
||||||
struct weston_surface *saved_kbd_focus;
|
struct weston_surface *saved_kbd_focus;
|
||||||
struct wl_listener saved_kbd_focus_listener;
|
struct wl_listener saved_kbd_focus_listener;
|
||||||
|
struct wl_list drag_resource_list;
|
||||||
|
|
||||||
uint32_t selection_serial;
|
uint32_t selection_serial;
|
||||||
struct wl_data_source *selection_data_source;
|
struct wl_data_source *selection_data_source;
|
||||||
struct wl_listener selection_data_source_listener;
|
struct wl_listener selection_data_source_listener;
|
||||||
struct wl_signal selection_signal;
|
struct wl_signal selection_signal;
|
||||||
|
|
||||||
struct wl_list drag_resource_list;
|
|
||||||
struct wl_client *drag_client;
|
|
||||||
struct wl_data_source *drag_data_source;
|
|
||||||
struct wl_listener drag_data_source_listener;
|
|
||||||
struct weston_surface *drag_focus;
|
|
||||||
struct wl_resource *drag_focus_resource;
|
|
||||||
struct wl_listener drag_focus_listener;
|
|
||||||
struct weston_pointer_grab drag_grab;
|
|
||||||
struct weston_surface *drag_surface;
|
|
||||||
struct wl_listener drag_surface_destroy_listener;
|
|
||||||
int32_t drag_dx, drag_dy;
|
|
||||||
|
|
||||||
uint32_t num_tp;
|
uint32_t num_tp;
|
||||||
|
|
||||||
void (*led_update)(struct weston_seat *ws, enum weston_led leds);
|
void (*led_update)(struct weston_seat *ws, enum weston_led leds);
|
||||||
|
|||||||
+98
-86
@@ -27,6 +27,19 @@
|
|||||||
|
|
||||||
#include "compositor.h"
|
#include "compositor.h"
|
||||||
|
|
||||||
|
struct weston_drag {
|
||||||
|
struct wl_client *client;
|
||||||
|
struct wl_data_source *data_source;
|
||||||
|
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;
|
||||||
|
struct weston_surface *surface;
|
||||||
|
struct wl_listener surface_destroy_listener;
|
||||||
|
int32_t dx, dy;
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
empty_region(pixman_region32_t *region)
|
empty_region(pixman_region32_t *region)
|
||||||
{
|
{
|
||||||
@@ -165,8 +178,8 @@ find_resource(struct wl_list *list, struct wl_client *client)
|
|||||||
static void
|
static void
|
||||||
drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
|
drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat = es->configure_private;
|
struct weston_drag *drag = es->configure_private;
|
||||||
struct weston_pointer *pointer = seat->pointer;
|
struct weston_pointer *pointer = drag->grab.pointer;
|
||||||
struct wl_list *list;
|
struct wl_list *list;
|
||||||
float fx, fy;
|
float fx, fy;
|
||||||
|
|
||||||
@@ -174,23 +187,23 @@ drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_
|
|||||||
if (pointer->sprite && weston_surface_is_mapped(pointer->sprite))
|
if (pointer->sprite && weston_surface_is_mapped(pointer->sprite))
|
||||||
list = &pointer->sprite->layer_link;
|
list = &pointer->sprite->layer_link;
|
||||||
else
|
else
|
||||||
list = &seat->compositor->cursor_layer.surface_list;
|
list = &es->compositor->cursor_layer.surface_list;
|
||||||
|
|
||||||
wl_list_insert(list, &es->layer_link);
|
wl_list_insert(list, &es->layer_link);
|
||||||
weston_surface_update_transform(es);
|
weston_surface_update_transform(es);
|
||||||
empty_region(&es->pending.input);
|
empty_region(&es->pending.input);
|
||||||
}
|
}
|
||||||
|
|
||||||
seat->drag_dx += sx;
|
drag->dx += sx;
|
||||||
seat->drag_dy += sy;
|
drag->dy += sy;
|
||||||
|
|
||||||
fx = wl_fixed_to_double(seat->pointer->x) + seat->drag_dx;
|
fx = wl_fixed_to_double(pointer->x) + drag->dx;
|
||||||
fy = wl_fixed_to_double(seat->pointer->y) + seat->drag_dy;
|
fy = wl_fixed_to_double(pointer->y) + drag->dy;
|
||||||
weston_surface_configure(es, fx, fy, width, height);
|
weston_surface_configure(es, fx, fy, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
device_setup_new_drag_surface(struct weston_seat *seat,
|
device_setup_new_drag_surface(struct weston_drag *drag,
|
||||||
struct weston_surface *surface)
|
struct weston_surface *surface)
|
||||||
{
|
{
|
||||||
if (surface->configure) {
|
if (surface->configure) {
|
||||||
@@ -200,65 +213,64 @@ device_setup_new_drag_surface(struct weston_seat *seat,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
seat->drag_surface = surface;
|
drag->surface = surface;
|
||||||
seat->drag_dx = 0;
|
drag->dx = 0;
|
||||||
seat->drag_dy = 0;
|
drag->dy = 0;
|
||||||
|
|
||||||
surface->configure = drag_surface_configure;
|
surface->configure = drag_surface_configure;
|
||||||
surface->configure_private = seat;
|
surface->configure_private = drag;
|
||||||
|
|
||||||
wl_signal_add(&surface->resource.destroy_signal,
|
wl_signal_add(&surface->resource.destroy_signal,
|
||||||
&seat->drag_surface_destroy_listener);
|
&drag->surface_destroy_listener);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
device_release_drag_surface(struct weston_seat *seat)
|
device_release_drag_surface(struct weston_drag *drag)
|
||||||
{
|
{
|
||||||
if (weston_surface_is_mapped(seat->drag_surface))
|
if (weston_surface_is_mapped(drag->surface))
|
||||||
weston_surface_unmap(seat->drag_surface);
|
weston_surface_unmap(drag->surface);
|
||||||
|
|
||||||
seat->drag_surface->configure = NULL;
|
drag->surface->configure = NULL;
|
||||||
empty_region(&seat->drag_surface->pending.input);
|
empty_region(&drag->surface->pending.input);
|
||||||
wl_list_remove(&seat->drag_surface_destroy_listener.link);
|
wl_list_remove(&drag->surface_destroy_listener.link);
|
||||||
seat->drag_surface = NULL;
|
drag->surface = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_drag_focus(struct wl_listener *listener, void *data)
|
destroy_drag_focus(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat =
|
struct weston_drag *drag =
|
||||||
container_of(listener, struct weston_seat, drag_focus_listener);
|
container_of(listener, struct weston_drag, focus_listener);
|
||||||
|
|
||||||
seat->drag_focus_resource = NULL;
|
drag->focus_resource = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drag_grab_focus(struct weston_pointer_grab *grab,
|
drag_grab_focus(struct weston_pointer_grab *grab,
|
||||||
struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y)
|
struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat =
|
struct weston_drag *drag =
|
||||||
container_of(grab, struct weston_seat, drag_grab);
|
container_of(grab, struct weston_drag, grab);
|
||||||
struct wl_resource *resource, *offer = NULL;
|
struct wl_resource *resource, *offer = NULL;
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
|
|
||||||
if (seat->drag_focus_resource) {
|
if (drag->focus_resource) {
|
||||||
wl_data_device_send_leave(seat->drag_focus_resource);
|
wl_data_device_send_leave(drag->focus_resource);
|
||||||
wl_list_remove(&seat->drag_focus_listener.link);
|
wl_list_remove(&drag->focus_listener.link);
|
||||||
seat->drag_focus_resource = NULL;
|
drag->focus_resource = NULL;
|
||||||
seat->drag_focus = NULL;
|
drag->focus = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!surface)
|
if (!surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!seat->drag_data_source &&
|
if (!drag->data_source && surface->resource.client != drag->client)
|
||||||
surface->resource.client != seat->drag_client)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
resource = find_resource(&seat->drag_resource_list,
|
resource = find_resource(&drag->grab.pointer->seat->drag_resource_list,
|
||||||
surface->resource.client);
|
surface->resource.client);
|
||||||
if (!resource)
|
if (!resource)
|
||||||
return;
|
return;
|
||||||
@@ -266,18 +278,16 @@ drag_grab_focus(struct weston_pointer_grab *grab,
|
|||||||
display = wl_client_get_display(resource->client);
|
display = wl_client_get_display(resource->client);
|
||||||
serial = wl_display_next_serial(display);
|
serial = wl_display_next_serial(display);
|
||||||
|
|
||||||
if (seat->drag_data_source)
|
if (drag->data_source)
|
||||||
offer = wl_data_source_send_offer(seat->drag_data_source,
|
offer = wl_data_source_send_offer(drag->data_source, resource);
|
||||||
resource);
|
|
||||||
|
|
||||||
wl_data_device_send_enter(resource, serial, &surface->resource,
|
wl_data_device_send_enter(resource, serial, &surface->resource,
|
||||||
x, y, offer);
|
x, y, offer);
|
||||||
|
|
||||||
seat->drag_focus = surface;
|
drag->focus = surface;
|
||||||
seat->drag_focus_listener.notify = destroy_drag_focus;
|
drag->focus_listener.notify = destroy_drag_focus;
|
||||||
wl_signal_add(&resource->destroy_signal,
|
wl_signal_add(&resource->destroy_signal, &drag->focus_listener);
|
||||||
&seat->drag_focus_listener);
|
drag->focus_resource = resource;
|
||||||
seat->drag_focus_resource = resource;
|
|
||||||
grab->focus = surface;
|
grab->focus = surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,55 +295,55 @@ static void
|
|||||||
drag_grab_motion(struct weston_pointer_grab *grab,
|
drag_grab_motion(struct weston_pointer_grab *grab,
|
||||||
uint32_t time, wl_fixed_t x, wl_fixed_t y)
|
uint32_t time, wl_fixed_t x, wl_fixed_t y)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat =
|
struct weston_drag *drag =
|
||||||
container_of(grab, struct weston_seat, drag_grab);
|
container_of(grab, struct weston_drag, grab);
|
||||||
|
struct weston_pointer *pointer = drag->grab.pointer;
|
||||||
float fx, fy;
|
float fx, fy;
|
||||||
|
|
||||||
if (seat->drag_surface) {
|
if (drag->surface) {
|
||||||
fx = wl_fixed_to_double(seat->pointer->x) + seat->drag_dx;
|
fx = wl_fixed_to_double(pointer->x) + drag->dx;
|
||||||
fy = wl_fixed_to_double(seat->pointer->y) + seat->drag_dy;
|
fy = wl_fixed_to_double(pointer->y) + drag->dy;
|
||||||
weston_surface_set_position(seat->drag_surface, fx, fy);
|
weston_surface_set_position(drag->surface, fx, fy);
|
||||||
weston_surface_schedule_repaint(seat->drag_surface);
|
weston_surface_schedule_repaint(drag->surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seat->drag_focus_resource)
|
if (drag->focus_resource)
|
||||||
wl_data_device_send_motion(seat->drag_focus_resource,
|
wl_data_device_send_motion(drag->focus_resource, time, x, y);
|
||||||
time, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
data_device_end_drag_grab(struct weston_seat *seat)
|
data_device_end_drag_grab(struct weston_drag *drag)
|
||||||
{
|
{
|
||||||
if (seat->drag_surface)
|
if (drag->surface)
|
||||||
device_release_drag_surface(seat);
|
device_release_drag_surface(drag);
|
||||||
|
|
||||||
drag_grab_focus(&seat->drag_grab, NULL,
|
drag_grab_focus(&drag->grab, NULL,
|
||||||
wl_fixed_from_int(0), wl_fixed_from_int(0));
|
wl_fixed_from_int(0), wl_fixed_from_int(0));
|
||||||
|
|
||||||
weston_pointer_end_grab(seat->pointer);
|
weston_pointer_end_grab(drag->grab.pointer);
|
||||||
|
|
||||||
seat->drag_data_source = NULL;
|
free(drag);
|
||||||
seat->drag_client = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drag_grab_button(struct weston_pointer_grab *grab,
|
drag_grab_button(struct weston_pointer_grab *grab,
|
||||||
uint32_t time, uint32_t button, uint32_t state_w)
|
uint32_t time, uint32_t button, uint32_t state_w)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat =
|
struct weston_drag *drag =
|
||||||
container_of(grab, struct weston_seat, drag_grab);
|
container_of(grab, struct weston_drag, grab);
|
||||||
|
struct weston_pointer *pointer = drag->grab.pointer;
|
||||||
enum wl_pointer_button_state state = state_w;
|
enum wl_pointer_button_state state = state_w;
|
||||||
|
|
||||||
if (seat->drag_focus_resource &&
|
if (drag->focus_resource &&
|
||||||
seat->pointer->grab_button == button &&
|
pointer->grab_button == button &&
|
||||||
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
||||||
wl_data_device_send_drop(seat->drag_focus_resource);
|
wl_data_device_send_drop(drag->focus_resource);
|
||||||
|
|
||||||
if (seat->pointer->button_count == 0 &&
|
if (pointer->button_count == 0 &&
|
||||||
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
||||||
if (seat->drag_data_source)
|
if (drag->data_source)
|
||||||
wl_list_remove(&seat->drag_data_source_listener.link);
|
wl_list_remove(&drag->data_source_listener.link);
|
||||||
data_device_end_drag_grab(seat);
|
data_device_end_drag_grab(drag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,21 +356,19 @@ static const struct weston_pointer_grab_interface drag_grab_interface = {
|
|||||||
static void
|
static void
|
||||||
destroy_data_device_source(struct wl_listener *listener, void *data)
|
destroy_data_device_source(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat = container_of(listener, struct weston_seat,
|
struct weston_drag *drag = container_of(listener, struct weston_drag,
|
||||||
drag_data_source_listener);
|
data_source_listener);
|
||||||
|
|
||||||
data_device_end_drag_grab(seat);
|
data_device_end_drag_grab(drag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_drag_surface_destroy(struct wl_listener *listener, void *data)
|
handle_drag_surface_destroy(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat;
|
struct weston_drag *drag = container_of(listener, struct weston_drag,
|
||||||
|
surface_destroy_listener);
|
||||||
|
|
||||||
seat = container_of(listener, struct weston_seat,
|
drag->surface = NULL;
|
||||||
drag_surface_destroy_listener);
|
|
||||||
|
|
||||||
seat->drag_surface = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -370,35 +378,39 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
|
|||||||
struct wl_resource *icon_resource, uint32_t serial)
|
struct wl_resource *icon_resource, uint32_t serial)
|
||||||
{
|
{
|
||||||
struct weston_seat *seat = resource->data;
|
struct weston_seat *seat = resource->data;
|
||||||
|
struct weston_drag *drag = resource->data;
|
||||||
|
|
||||||
/* FIXME: Check that client has implicit grab on the origin
|
/* FIXME: Check that client has implicit grab on the origin
|
||||||
* surface that matches the given time. */
|
* surface that matches the given time. */
|
||||||
|
|
||||||
/* FIXME: Check that the data source type array isn't empty. */
|
/* FIXME: Check that the data source type array isn't empty. */
|
||||||
|
|
||||||
seat->drag_grab.interface = &drag_grab_interface;
|
drag = malloc(sizeof *drag);
|
||||||
|
if (drag == NULL) {
|
||||||
|
wl_resource_post_no_memory(resource);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
seat->drag_client = client;
|
memset(drag, 0, sizeof *drag);
|
||||||
seat->drag_data_source = NULL;
|
drag->grab.interface = &drag_grab_interface;
|
||||||
seat->drag_surface_destroy_listener.notify =
|
drag->client = client;
|
||||||
handle_drag_surface_destroy;
|
drag->surface_destroy_listener.notify = handle_drag_surface_destroy;
|
||||||
|
|
||||||
if (source_resource) {
|
if (source_resource) {
|
||||||
seat->drag_data_source = source_resource->data;
|
drag->data_source = source_resource->data;
|
||||||
seat->drag_data_source_listener.notify =
|
drag->data_source_listener.notify = destroy_data_device_source;
|
||||||
destroy_data_device_source;
|
|
||||||
wl_signal_add(&source_resource->destroy_signal,
|
wl_signal_add(&source_resource->destroy_signal,
|
||||||
&seat->drag_data_source_listener);
|
&drag->data_source_listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon_resource) {
|
if (icon_resource) {
|
||||||
if (!device_setup_new_drag_surface(seat, icon_resource->data))
|
if (!device_setup_new_drag_surface(drag, icon_resource->data))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
weston_pointer_set_focus(seat->pointer, NULL,
|
weston_pointer_set_focus(seat->pointer, NULL,
|
||||||
wl_fixed_from_int(0), wl_fixed_from_int(0));
|
wl_fixed_from_int(0), wl_fixed_from_int(0));
|
||||||
weston_pointer_start_grab(seat->pointer, &seat->drag_grab);
|
weston_pointer_start_grab(seat->pointer, &drag->grab);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user