|
|
@ -28,6 +28,20 @@ static void drag_set_focus(struct wlr_drag *drag,
|
|
|
|
if (drag->focus_client) {
|
|
|
|
if (drag->focus_client) {
|
|
|
|
wl_list_remove(&drag->seat_client_destroy.link);
|
|
|
|
wl_list_remove(&drag->seat_client_destroy.link);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If we're switching focus to another client, we want to destroy all
|
|
|
|
|
|
|
|
// offers without destroying the source. If the drag operation ends, we
|
|
|
|
|
|
|
|
// want to keep the offer around for the data transfer.
|
|
|
|
|
|
|
|
struct wlr_data_offer *offer, *tmp;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(offer, tmp,
|
|
|
|
|
|
|
|
&drag->focus_client->seat->drag_offers, link) {
|
|
|
|
|
|
|
|
struct wl_client *client = wl_resource_get_client(offer->resource);
|
|
|
|
|
|
|
|
if (!drag->dropped && offer->source == drag->source &&
|
|
|
|
|
|
|
|
client == drag->focus_client->client) {
|
|
|
|
|
|
|
|
offer->source = NULL;
|
|
|
|
|
|
|
|
data_offer_destroy(offer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &drag->focus_client->data_devices) {
|
|
|
|
wl_resource_for_each(resource, &drag->focus_client->data_devices) {
|
|
|
|
wl_data_device_send_leave(resource);
|
|
|
|
wl_data_device_send_leave(resource);
|
|
|
@ -37,20 +51,20 @@ static void drag_set_focus(struct wlr_drag *drag,
|
|
|
|
drag->focus = NULL;
|
|
|
|
drag->focus = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!surface || !surface->resource) {
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!drag->source &&
|
|
|
|
if (!drag->source &&
|
|
|
|
wl_resource_get_client(surface->resource) !=
|
|
|
|
wl_resource_get_client(surface->resource) !=
|
|
|
|
drag->seat_client->client) {
|
|
|
|
drag->seat_client->client) {
|
|
|
|
return;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_seat_client *focus_client = wlr_seat_client_for_wl_client(
|
|
|
|
struct wlr_seat_client *focus_client = wlr_seat_client_for_wl_client(
|
|
|
|
drag->seat_client->seat, wl_resource_get_client(surface->resource));
|
|
|
|
drag->seat_client->seat, wl_resource_get_client(surface->resource));
|
|
|
|
if (!focus_client) {
|
|
|
|
if (!focus_client) {
|
|
|
|
return;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (drag->source != NULL) {
|
|
|
|
if (drag->source != NULL) {
|
|
|
@ -88,6 +102,7 @@ static void drag_set_focus(struct wlr_drag *drag,
|
|
|
|
drag->seat_client_destroy.notify = drag_handle_seat_client_destroy;
|
|
|
|
drag->seat_client_destroy.notify = drag_handle_seat_client_destroy;
|
|
|
|
wl_signal_add(&focus_client->events.destroy, &drag->seat_client_destroy);
|
|
|
|
wl_signal_add(&focus_client->events.destroy, &drag->seat_client_destroy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
wlr_signal_emit_safe(&drag->events.focus, drag);
|
|
|
|
wlr_signal_emit_safe(&drag->events.focus, drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -101,33 +116,41 @@ static void drag_icon_set_mapped(struct wlr_drag_icon *icon, bool mapped) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_end(struct wlr_drag *drag) {
|
|
|
|
static void drag_icon_destroy(struct wlr_drag_icon *icon);
|
|
|
|
if (!drag->cancelling) {
|
|
|
|
|
|
|
|
drag->cancelling = true;
|
|
|
|
static void drag_destroy(struct wlr_drag *drag) {
|
|
|
|
if (drag->is_pointer_grab) {
|
|
|
|
if (drag->cancelling) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
drag->cancelling = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&drag->events.destroy, drag);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (drag->started) {
|
|
|
|
|
|
|
|
wlr_seat_keyboard_end_grab(drag->seat);
|
|
|
|
|
|
|
|
switch (drag->grab_type) {
|
|
|
|
|
|
|
|
case WLR_DRAG_GRAB_KEYBOARD:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WLR_DRAG_GRAB_KEYBOARD_POINTER:
|
|
|
|
wlr_seat_pointer_end_grab(drag->seat);
|
|
|
|
wlr_seat_pointer_end_grab(drag->seat);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WLR_DRAG_GRAB_KEYBOARD_TOUCH:
|
|
|
|
wlr_seat_touch_end_grab(drag->seat);
|
|
|
|
wlr_seat_touch_end_grab(drag->seat);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
wlr_seat_keyboard_end_grab(drag->seat);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (drag->source) {
|
|
|
|
|
|
|
|
wl_list_remove(&drag->source_destroy.link);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drag_set_focus(drag, NULL, 0, 0);
|
|
|
|
drag_set_focus(drag, NULL, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (drag->icon) {
|
|
|
|
|
|
|
|
wl_list_remove(&drag->icon_destroy.link);
|
|
|
|
|
|
|
|
drag_icon_set_mapped(drag->icon, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(drag->seat->drag == drag);
|
|
|
|
assert(drag->seat->drag == drag);
|
|
|
|
drag->seat->drag = NULL;
|
|
|
|
drag->seat->drag = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&drag->events.destroy, drag);
|
|
|
|
if (drag->source) {
|
|
|
|
free(drag);
|
|
|
|
wl_list_remove(&drag->source_destroy.link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drag_icon_destroy(drag->icon);
|
|
|
|
|
|
|
|
free(drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_handle_pointer_enter(struct wlr_seat_pointer_grab *grab,
|
|
|
|
static void drag_handle_pointer_enter(struct wlr_seat_pointer_grab *grab,
|
|
|
@ -156,6 +179,26 @@ static void drag_handle_pointer_motion(struct wlr_seat_pointer_grab *grab,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_drop(struct wlr_drag *drag, uint32_t time) {
|
|
|
|
|
|
|
|
assert(drag->focus_client);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drag->dropped = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &drag->focus_client->data_devices) {
|
|
|
|
|
|
|
|
wl_data_device_send_drop(resource);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drag->source) {
|
|
|
|
|
|
|
|
wlr_data_source_dnd_drop(drag->source);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drag_drop_event event = {
|
|
|
|
|
|
|
|
.drag = drag,
|
|
|
|
|
|
|
|
.time = time,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&drag->events.drop, &event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t drag_handle_pointer_button(struct wlr_seat_pointer_grab *grab,
|
|
|
|
static uint32_t drag_handle_pointer_button(struct wlr_seat_pointer_grab *grab,
|
|
|
|
uint32_t time, uint32_t button, uint32_t state) {
|
|
|
|
uint32_t time, uint32_t button, uint32_t state) {
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
@ -165,17 +208,7 @@ static uint32_t drag_handle_pointer_button(struct wlr_seat_pointer_grab *grab,
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
|
|
|
if (drag->focus_client && drag->source->current_dnd_action &&
|
|
|
|
if (drag->focus_client && drag->source->current_dnd_action &&
|
|
|
|
drag->source->accepted) {
|
|
|
|
drag->source->accepted) {
|
|
|
|
struct wl_resource *resource;
|
|
|
|
drag_drop(drag, time);
|
|
|
|
wl_resource_for_each(resource, &drag->focus_client->data_devices) {
|
|
|
|
|
|
|
|
wl_data_device_send_drop(resource);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_data_source_dnd_drop(drag->source);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drag_drop_event event = {
|
|
|
|
|
|
|
|
.drag = drag,
|
|
|
|
|
|
|
|
.time = time,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&drag->events.drop, &event);
|
|
|
|
|
|
|
|
} else if (drag->source->impl->dnd_finish) {
|
|
|
|
} else if (drag->source->impl->dnd_finish) {
|
|
|
|
// This will end the grab and free `drag`
|
|
|
|
// This will end the grab and free `drag`
|
|
|
|
wlr_data_source_destroy(drag->source);
|
|
|
|
wlr_data_source_destroy(drag->source);
|
|
|
@ -185,7 +218,7 @@ static uint32_t drag_handle_pointer_button(struct wlr_seat_pointer_grab *grab,
|
|
|
|
|
|
|
|
|
|
|
|
if (grab->seat->pointer_state.button_count == 0 &&
|
|
|
|
if (grab->seat->pointer_state.button_count == 0 &&
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
|
|
|
drag_end(drag);
|
|
|
|
drag_destroy(drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -199,7 +232,7 @@ static void drag_handle_pointer_axis(struct wlr_seat_pointer_grab *grab,
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_handle_pointer_cancel(struct wlr_seat_pointer_grab *grab) {
|
|
|
|
static void drag_handle_pointer_cancel(struct wlr_seat_pointer_grab *grab) {
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
drag_end(drag);
|
|
|
|
drag_destroy(drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wlr_pointer_grab_interface
|
|
|
|
static const struct wlr_pointer_grab_interface
|
|
|
@ -225,13 +258,10 @@ static void drag_handle_touch_up(struct wlr_seat_touch_grab *grab,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (drag->focus_client) {
|
|
|
|
if (drag->focus_client) {
|
|
|
|
struct wl_resource *resource;
|
|
|
|
drag_drop(drag, time);
|
|
|
|
wl_resource_for_each(resource, &drag->focus_client->data_devices) {
|
|
|
|
|
|
|
|
wl_data_device_send_drop(resource);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drag_end(drag);
|
|
|
|
drag_destroy(drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_handle_touch_motion(struct wlr_seat_touch_grab *grab,
|
|
|
|
static void drag_handle_touch_motion(struct wlr_seat_touch_grab *grab,
|
|
|
@ -255,7 +285,7 @@ static void drag_handle_touch_enter(struct wlr_seat_touch_grab *grab,
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_handle_touch_cancel(struct wlr_seat_touch_grab *grab) {
|
|
|
|
static void drag_handle_touch_cancel(struct wlr_seat_touch_grab *grab) {
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
drag_end(drag);
|
|
|
|
drag_destroy(drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wlr_touch_grab_interface
|
|
|
|
static const struct wlr_touch_grab_interface
|
|
|
@ -287,7 +317,7 @@ static void drag_handle_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab,
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_handle_keyboard_cancel(struct wlr_seat_keyboard_grab *grab) {
|
|
|
|
static void drag_handle_keyboard_cancel(struct wlr_seat_keyboard_grab *grab) {
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
drag_end(drag);
|
|
|
|
drag_destroy(drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wlr_keyboard_grab_interface
|
|
|
|
static const struct wlr_keyboard_grab_interface
|
|
|
@ -306,7 +336,7 @@ static void drag_handle_icon_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
static void drag_handle_drag_source_destroy(struct wl_listener *listener,
|
|
|
|
static void drag_handle_drag_source_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
void *data) {
|
|
|
|
struct wlr_drag *drag = wl_container_of(listener, drag, source_destroy);
|
|
|
|
struct wlr_drag *drag = wl_container_of(listener, drag, source_destroy);
|
|
|
|
drag_end(drag);
|
|
|
|
drag_destroy(drag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -318,8 +348,6 @@ static void drag_icon_destroy(struct wlr_drag_icon *icon) {
|
|
|
|
wlr_signal_emit_safe(&icon->events.destroy, icon);
|
|
|
|
wlr_signal_emit_safe(&icon->events.destroy, icon);
|
|
|
|
icon->surface->role_data = NULL;
|
|
|
|
icon->surface->role_data = NULL;
|
|
|
|
wl_list_remove(&icon->surface_destroy.link);
|
|
|
|
wl_list_remove(&icon->surface_destroy.link);
|
|
|
|
wl_list_remove(&icon->seat_client_destroy.link);
|
|
|
|
|
|
|
|
wl_list_remove(&icon->link);
|
|
|
|
|
|
|
|
free(icon);
|
|
|
|
free(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -345,26 +373,15 @@ const struct wlr_surface_role drag_icon_surface_role = {
|
|
|
|
.commit = drag_icon_surface_role_commit,
|
|
|
|
.commit = drag_icon_surface_role_commit,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_icon_handle_seat_client_destroy(struct wl_listener *listener,
|
|
|
|
static struct wlr_drag_icon *drag_icon_create(struct wlr_drag *drag,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_surface *surface) {
|
|
|
|
struct wlr_drag_icon *icon =
|
|
|
|
|
|
|
|
wl_container_of(listener, icon, seat_client_destroy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drag_icon_destroy(icon);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct wlr_drag_icon *drag_icon_create(
|
|
|
|
|
|
|
|
struct wlr_surface *icon_surface, struct wlr_seat_client *client,
|
|
|
|
|
|
|
|
bool is_pointer, int32_t touch_id) {
|
|
|
|
|
|
|
|
struct wlr_drag_icon *icon = calloc(1, sizeof(struct wlr_drag_icon));
|
|
|
|
struct wlr_drag_icon *icon = calloc(1, sizeof(struct wlr_drag_icon));
|
|
|
|
if (!icon) {
|
|
|
|
if (!icon) {
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
icon->surface = icon_surface;
|
|
|
|
icon->drag = drag;
|
|
|
|
icon->client = client;
|
|
|
|
icon->surface = surface;
|
|
|
|
icon->is_pointer = is_pointer;
|
|
|
|
|
|
|
|
icon->touch_id = touch_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_init(&icon->events.map);
|
|
|
|
wl_signal_init(&icon->events.map);
|
|
|
|
wl_signal_init(&icon->events.unmap);
|
|
|
|
wl_signal_init(&icon->events.unmap);
|
|
|
@ -373,15 +390,9 @@ static struct wlr_drag_icon *drag_icon_create(
|
|
|
|
wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
|
|
|
|
wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
|
|
|
|
icon->surface_destroy.notify = drag_icon_handle_surface_destroy;
|
|
|
|
icon->surface_destroy.notify = drag_icon_handle_surface_destroy;
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_add(&client->events.destroy, &icon->seat_client_destroy);
|
|
|
|
|
|
|
|
icon->seat_client_destroy.notify = drag_icon_handle_seat_client_destroy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
icon->surface->role_data = icon;
|
|
|
|
icon->surface->role_data = icon;
|
|
|
|
|
|
|
|
|
|
|
|
wl_list_insert(&client->seat->drag_icons, &icon->link);
|
|
|
|
if (wlr_surface_has_buffer(surface)) {
|
|
|
|
wlr_signal_emit_safe(&client->seat->events.new_drag_icon, icon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wlr_surface_has_buffer(icon_surface)) {
|
|
|
|
|
|
|
|
drag_icon_set_mapped(icon, true);
|
|
|
|
drag_icon_set_mapped(icon, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -389,20 +400,11 @@ static struct wlr_drag_icon *drag_icon_create(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void seat_handle_drag_source_destroy(struct wl_listener *listener,
|
|
|
|
struct wlr_drag *wlr_drag_create(struct wlr_seat_client *seat_client,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_data_source *source, struct wlr_surface *icon_surface) {
|
|
|
|
struct wlr_seat *seat =
|
|
|
|
|
|
|
|
wl_container_of(listener, seat, drag_source_destroy);
|
|
|
|
|
|
|
|
wl_list_remove(&seat->drag_source_destroy.link);
|
|
|
|
|
|
|
|
seat->drag_source = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool seat_client_start_drag(struct wlr_seat_client *client,
|
|
|
|
|
|
|
|
struct wlr_data_source *source, struct wlr_surface *icon_surface,
|
|
|
|
|
|
|
|
struct wlr_surface *origin, uint32_t serial) {
|
|
|
|
|
|
|
|
struct wlr_drag *drag = calloc(1, sizeof(struct wlr_drag));
|
|
|
|
struct wlr_drag *drag = calloc(1, sizeof(struct wlr_drag));
|
|
|
|
if (drag == NULL) {
|
|
|
|
if (drag == NULL) {
|
|
|
|
return false;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_init(&drag->events.focus);
|
|
|
|
wl_signal_init(&drag->events.focus);
|
|
|
@ -410,51 +412,18 @@ bool seat_client_start_drag(struct wlr_seat_client *client,
|
|
|
|
wl_signal_init(&drag->events.drop);
|
|
|
|
wl_signal_init(&drag->events.drop);
|
|
|
|
wl_signal_init(&drag->events.destroy);
|
|
|
|
wl_signal_init(&drag->events.destroy);
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_seat *seat = client->seat;
|
|
|
|
drag->seat = seat_client->seat;
|
|
|
|
drag->seat = seat;
|
|
|
|
drag->seat_client = seat_client;
|
|
|
|
|
|
|
|
|
|
|
|
drag->is_pointer_grab = !wl_list_empty(&client->pointers) &&
|
|
|
|
|
|
|
|
seat->pointer_state.button_count == 1 &&
|
|
|
|
|
|
|
|
seat->pointer_state.grab_serial == serial &&
|
|
|
|
|
|
|
|
seat->pointer_state.focused_surface &&
|
|
|
|
|
|
|
|
seat->pointer_state.focused_surface == origin;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool is_touch_grab = !wl_list_empty(&client->touches) &&
|
|
|
|
|
|
|
|
wlr_seat_touch_num_points(seat) == 1 &&
|
|
|
|
|
|
|
|
seat->touch_state.grab_serial == serial;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set in the iteration
|
|
|
|
|
|
|
|
struct wlr_touch_point *point = NULL;
|
|
|
|
|
|
|
|
if (is_touch_grab) {
|
|
|
|
|
|
|
|
wl_list_for_each(point, &seat->touch_state.touch_points, link) {
|
|
|
|
|
|
|
|
is_touch_grab = point->surface && point->surface == origin;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!drag->is_pointer_grab && !is_touch_grab) {
|
|
|
|
|
|
|
|
free(drag);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (seat->drag != NULL) {
|
|
|
|
|
|
|
|
wlr_log(WLR_DEBUG, "Refusing to start drag, "
|
|
|
|
|
|
|
|
"another drag is already in progress");
|
|
|
|
|
|
|
|
free(drag);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (icon_surface) {
|
|
|
|
if (icon_surface) {
|
|
|
|
int32_t touch_id = (point ? point->touch_id : 0);
|
|
|
|
struct wlr_drag_icon *icon = drag_icon_create(drag, icon_surface);
|
|
|
|
struct wlr_drag_icon *icon =
|
|
|
|
if (icon == NULL) {
|
|
|
|
drag_icon_create(icon_surface, client, drag->is_pointer_grab,
|
|
|
|
|
|
|
|
touch_id);
|
|
|
|
|
|
|
|
if (!icon) {
|
|
|
|
|
|
|
|
free(drag);
|
|
|
|
free(drag);
|
|
|
|
return false;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drag->icon = icon;
|
|
|
|
drag->icon = icon;
|
|
|
|
|
|
|
|
|
|
|
|
drag->icon_destroy.notify = drag_handle_icon_destroy;
|
|
|
|
drag->icon_destroy.notify = drag_handle_icon_destroy;
|
|
|
|
wl_signal_add(&icon->events.destroy, &drag->icon_destroy);
|
|
|
|
wl_signal_add(&icon->events.destroy, &drag->icon_destroy);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -465,41 +434,85 @@ bool seat_client_start_drag(struct wlr_seat_client *client,
|
|
|
|
wl_signal_add(&source->events.destroy, &drag->source_destroy);
|
|
|
|
wl_signal_add(&source->events.destroy, &drag->source_destroy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drag->seat_client = client;
|
|
|
|
|
|
|
|
drag->pointer_grab.data = drag;
|
|
|
|
drag->pointer_grab.data = drag;
|
|
|
|
drag->pointer_grab.interface = &data_device_pointer_drag_interface;
|
|
|
|
drag->pointer_grab.interface = &data_device_pointer_drag_interface;
|
|
|
|
|
|
|
|
|
|
|
|
drag->touch_grab.data = drag;
|
|
|
|
drag->touch_grab.data = drag;
|
|
|
|
drag->touch_grab.interface = &data_device_touch_drag_interface;
|
|
|
|
drag->touch_grab.interface = &data_device_touch_drag_interface;
|
|
|
|
drag->grab_touch_id = seat->touch_state.grab_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drag->keyboard_grab.data = drag;
|
|
|
|
drag->keyboard_grab.data = drag;
|
|
|
|
drag->keyboard_grab.interface = &data_device_keyboard_drag_interface;
|
|
|
|
drag->keyboard_grab.interface = &data_device_keyboard_drag_interface;
|
|
|
|
|
|
|
|
|
|
|
|
wlr_seat_keyboard_start_grab(seat, &drag->keyboard_grab);
|
|
|
|
return drag;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_seat_request_start_drag(struct wlr_seat *seat, struct wlr_drag *drag,
|
|
|
|
|
|
|
|
struct wlr_surface *origin, uint32_t serial) {
|
|
|
|
|
|
|
|
assert(drag->seat == seat);
|
|
|
|
|
|
|
|
|
|
|
|
if (drag->is_pointer_grab) {
|
|
|
|
if (seat->drag != NULL) {
|
|
|
|
wlr_seat_pointer_clear_focus(seat);
|
|
|
|
wlr_log(WLR_DEBUG, "Rejecting start_drag request, "
|
|
|
|
wlr_seat_pointer_start_grab(seat, &drag->pointer_grab);
|
|
|
|
"another drag-and-drop operation is already in progress");
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
assert(point);
|
|
|
|
|
|
|
|
wlr_seat_touch_start_grab(seat, &drag->touch_grab);
|
|
|
|
|
|
|
|
drag_set_focus(drag, point->surface, point->sx, point->sy);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_seat_request_start_drag_event event = {
|
|
|
|
|
|
|
|
.drag = drag,
|
|
|
|
|
|
|
|
.origin = origin,
|
|
|
|
|
|
|
|
.serial = serial,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&seat->events.request_start_drag, &event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void seat_handle_drag_source_destroy(struct wl_listener *listener,
|
|
|
|
|
|
|
|
void *data) {
|
|
|
|
|
|
|
|
struct wlr_seat *seat =
|
|
|
|
|
|
|
|
wl_container_of(listener, seat, drag_source_destroy);
|
|
|
|
|
|
|
|
wl_list_remove(&seat->drag_source_destroy.link);
|
|
|
|
|
|
|
|
seat->drag_source = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_seat_start_drag(struct wlr_seat *seat, struct wlr_drag *drag,
|
|
|
|
|
|
|
|
uint32_t serial) {
|
|
|
|
|
|
|
|
assert(drag->seat == seat);
|
|
|
|
|
|
|
|
assert(!drag->started);
|
|
|
|
|
|
|
|
drag->started = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_seat_keyboard_start_grab(seat, &drag->keyboard_grab);
|
|
|
|
|
|
|
|
|
|
|
|
seat->drag = drag;
|
|
|
|
seat->drag = drag;
|
|
|
|
seat->drag_serial = serial;
|
|
|
|
seat->drag_serial = serial;
|
|
|
|
|
|
|
|
|
|
|
|
// We need to destroy the previous source, because listeners only expect one
|
|
|
|
// We need to destroy the previous source, because listeners only expect one
|
|
|
|
// active drag source at a time.
|
|
|
|
// active drag source at a time.
|
|
|
|
wlr_data_source_destroy(seat->drag_source);
|
|
|
|
wlr_data_source_destroy(seat->drag_source);
|
|
|
|
seat->drag_source = source;
|
|
|
|
seat->drag_source = drag->source;
|
|
|
|
if (source != NULL) {
|
|
|
|
if (drag->source != NULL) {
|
|
|
|
seat->drag_source_destroy.notify = seat_handle_drag_source_destroy;
|
|
|
|
seat->drag_source_destroy.notify = seat_handle_drag_source_destroy;
|
|
|
|
wl_signal_add(&source->events.destroy, &seat->drag_source_destroy);
|
|
|
|
wl_signal_add(&drag->source->events.destroy, &seat->drag_source_destroy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&seat->events.start_drag, drag);
|
|
|
|
wlr_signal_emit_safe(&seat->events.start_drag, drag);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_seat_start_pointer_drag(struct wlr_seat *seat, struct wlr_drag *drag,
|
|
|
|
|
|
|
|
uint32_t serial) {
|
|
|
|
|
|
|
|
drag->grab_type = WLR_DRAG_GRAB_KEYBOARD_POINTER;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_seat_pointer_clear_focus(seat);
|
|
|
|
|
|
|
|
wlr_seat_pointer_start_grab(seat, &drag->pointer_grab);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_seat_start_drag(seat, drag, serial);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_seat_start_touch_drag(struct wlr_seat *seat, struct wlr_drag *drag,
|
|
|
|
|
|
|
|
uint32_t serial, struct wlr_touch_point *point) {
|
|
|
|
|
|
|
|
drag->grab_type = WLR_DRAG_GRAB_KEYBOARD_TOUCH;
|
|
|
|
|
|
|
|
drag->grab_touch_id = seat->touch_state.grab_id;
|
|
|
|
|
|
|
|
drag->touch_id = point->touch_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_seat_touch_start_grab(seat, &drag->touch_grab);
|
|
|
|
|
|
|
|
drag_set_focus(drag, point->surface, point->sx, point->sy);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
wlr_seat_start_drag(seat, drag, serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|