mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 16:01:27 +00:00
Merge pull request #3700 from emersion/refactor-dnd
Update for swaywm/wlroots#1517
This commit is contained in:
commit
512619a9a1
|
@ -75,7 +75,8 @@ struct sway_seat {
|
||||||
|
|
||||||
struct wl_listener focus_destroy;
|
struct wl_listener focus_destroy;
|
||||||
struct wl_listener new_node;
|
struct wl_listener new_node;
|
||||||
struct wl_listener new_drag_icon;
|
struct wl_listener request_start_drag;
|
||||||
|
struct wl_listener start_drag;
|
||||||
struct wl_listener request_set_selection;
|
struct wl_listener request_set_selection;
|
||||||
struct wl_listener request_set_primary_selection;
|
struct wl_listener request_set_primary_selection;
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,6 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sway_seat *seat = cursor->seat;
|
struct sway_seat *seat = cursor->seat;
|
||||||
struct wlr_seat *wlr_seat = seat->wlr_seat;
|
|
||||||
|
|
||||||
if (seat_doing_seatop(seat)) {
|
if (seat_doing_seatop(seat)) {
|
||||||
seatop_motion(seat, time_msec);
|
seatop_motion(seat, time_msec);
|
||||||
|
@ -404,10 +403,11 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
|
||||||
|
|
||||||
cursor_do_rebase(cursor, time_msec, node, surface, sx, sy);
|
cursor_do_rebase(cursor, time_msec, node, surface, sx, sy);
|
||||||
|
|
||||||
struct wlr_drag_icon *wlr_drag_icon;
|
struct sway_drag_icon *drag_icon;
|
||||||
wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) {
|
wl_list_for_each(drag_icon, &root->drag_icons, link) {
|
||||||
struct sway_drag_icon *drag_icon = wlr_drag_icon->data;
|
if (drag_icon->seat == seat) {
|
||||||
drag_icon_update_position(drag_icon);
|
drag_icon_update_position(drag_icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,10 +991,11 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||||
seat->touch_x = lx;
|
seat->touch_x = lx;
|
||||||
seat->touch_y = ly;
|
seat->touch_y = ly;
|
||||||
|
|
||||||
struct wlr_drag_icon *wlr_drag_icon;
|
struct sway_drag_icon *drag_icon;
|
||||||
wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) {
|
wl_list_for_each(drag_icon, &root->drag_icons, link) {
|
||||||
struct sway_drag_icon *drag_icon = wlr_drag_icon->data;
|
if (drag_icon->seat == seat) {
|
||||||
drag_icon_update_position(drag_icon);
|
drag_icon_update_position(drag_icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ void seat_destroy(struct sway_seat *seat) {
|
||||||
}
|
}
|
||||||
sway_cursor_destroy(seat->cursor);
|
sway_cursor_destroy(seat->cursor);
|
||||||
wl_list_remove(&seat->new_node.link);
|
wl_list_remove(&seat->new_node.link);
|
||||||
wl_list_remove(&seat->new_drag_icon.link);
|
wl_list_remove(&seat->request_start_drag.link);
|
||||||
|
wl_list_remove(&seat->start_drag.link);
|
||||||
wl_list_remove(&seat->request_set_selection.link);
|
wl_list_remove(&seat->request_set_selection.link);
|
||||||
wl_list_remove(&seat->request_set_primary_selection.link);
|
wl_list_remove(&seat->request_set_primary_selection.link);
|
||||||
wl_list_remove(&seat->link);
|
wl_list_remove(&seat->link);
|
||||||
|
@ -261,12 +262,16 @@ void drag_icon_update_position(struct sway_drag_icon *icon) {
|
||||||
struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
|
struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
|
||||||
struct sway_seat *seat = icon->seat;
|
struct sway_seat *seat = icon->seat;
|
||||||
struct wlr_cursor *cursor = seat->cursor->cursor;
|
struct wlr_cursor *cursor = seat->cursor->cursor;
|
||||||
if (wlr_icon->is_pointer) {
|
switch (wlr_icon->drag->grab_type) {
|
||||||
|
case WLR_DRAG_GRAB_KEYBOARD:
|
||||||
|
return;
|
||||||
|
case WLR_DRAG_GRAB_KEYBOARD_POINTER:
|
||||||
icon->x = cursor->x;
|
icon->x = cursor->x;
|
||||||
icon->y = cursor->y;
|
icon->y = cursor->y;
|
||||||
} else {
|
break;
|
||||||
|
case WLR_DRAG_GRAB_KEYBOARD_TOUCH:;
|
||||||
struct wlr_touch_point *point =
|
struct wlr_touch_point *point =
|
||||||
wlr_seat_touch_get_point(seat->wlr_seat, wlr_icon->touch_id);
|
wlr_seat_touch_get_point(seat->wlr_seat, wlr_icon->drag->touch_id);
|
||||||
if (point == NULL) {
|
if (point == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -305,9 +310,39 @@ static void drag_icon_handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
free(icon);
|
free(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_new_drag_icon(struct wl_listener *listener, void *data) {
|
static void handle_request_start_drag(struct wl_listener *listener,
|
||||||
struct sway_seat *seat = wl_container_of(listener, seat, new_drag_icon);
|
void *data) {
|
||||||
struct wlr_drag_icon *wlr_drag_icon = data;
|
struct sway_seat *seat = wl_container_of(listener, seat, request_start_drag);
|
||||||
|
struct wlr_seat_request_start_drag_event *event = data;
|
||||||
|
|
||||||
|
if (wlr_seat_validate_pointer_grab_serial(seat->wlr_seat,
|
||||||
|
event->origin, event->serial)) {
|
||||||
|
wlr_seat_start_pointer_drag(seat->wlr_seat, event->drag, event->serial);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_touch_point *point;
|
||||||
|
if (wlr_seat_validate_touch_grab_serial(seat->wlr_seat,
|
||||||
|
event->origin, event->serial, &point)) {
|
||||||
|
wlr_seat_start_touch_drag(seat->wlr_seat,
|
||||||
|
event->drag, event->serial, point);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: tablet grabs
|
||||||
|
|
||||||
|
sway_log(SWAY_DEBUG, "Ignoring start_drag request: "
|
||||||
|
"could not validate pointer or touch serial %" PRIu32, event->serial);
|
||||||
|
wlr_data_source_destroy(event->drag->source);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_start_drag(struct wl_listener *listener, void *data) {
|
||||||
|
struct sway_seat *seat = wl_container_of(listener, seat, start_drag);
|
||||||
|
struct wlr_drag *wlr_drag = data;
|
||||||
|
struct wlr_drag_icon *wlr_drag_icon = wlr_drag->icon;
|
||||||
|
if (wlr_drag_icon == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct sway_drag_icon *icon = calloc(1, sizeof(struct sway_drag_icon));
|
struct sway_drag_icon *icon = calloc(1, sizeof(struct sway_drag_icon));
|
||||||
if (icon == NULL) {
|
if (icon == NULL) {
|
||||||
|
@ -406,8 +441,12 @@ struct sway_seat *seat_create(const char *seat_name) {
|
||||||
wl_signal_add(&root->events.new_node, &seat->new_node);
|
wl_signal_add(&root->events.new_node, &seat->new_node);
|
||||||
seat->new_node.notify = handle_new_node;
|
seat->new_node.notify = handle_new_node;
|
||||||
|
|
||||||
wl_signal_add(&seat->wlr_seat->events.new_drag_icon, &seat->new_drag_icon);
|
wl_signal_add(&seat->wlr_seat->events.request_start_drag,
|
||||||
seat->new_drag_icon.notify = handle_new_drag_icon;
|
&seat->request_start_drag);
|
||||||
|
seat->request_start_drag.notify = handle_request_start_drag;
|
||||||
|
|
||||||
|
wl_signal_add(&seat->wlr_seat->events.start_drag, &seat->start_drag);
|
||||||
|
seat->start_drag.notify = handle_start_drag;
|
||||||
|
|
||||||
wl_signal_add(&seat->wlr_seat->events.request_set_selection,
|
wl_signal_add(&seat->wlr_seat->events.request_set_selection,
|
||||||
&seat->request_set_selection);
|
&seat->request_set_selection);
|
||||||
|
|
Loading…
Reference in a new issue