From 6a516f7c417c96b6e5a5526c73e6f52ccb9c55d9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 13 Nov 2017 15:41:48 -0500 Subject: basic touch dnd --- rootston/cursor.c | 98 +++++++++++++++++++++++++++++++++++++++---------------- rootston/output.c | 17 ++++++++-- rootston/seat.c | 24 ++++++++++++++ 3 files changed, 107 insertions(+), 32 deletions(-) (limited to 'rootston') diff --git a/rootston/cursor.c b/rootston/cursor.c index 632966d4..863267b6 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -328,33 +328,59 @@ static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) { free(drag_icon); } +static struct roots_drag_icon *seat_add_drag_icon(struct roots_seat *seat, + struct wlr_surface *icon_surface) { + if (!icon_surface) { + return NULL; + } + + struct roots_drag_icon *iter_icon; + wl_list_for_each(iter_icon, &seat->drag_icons, link) { + if (iter_icon->surface == icon_surface) { + // already in the list + return iter_icon; + } + } + + struct roots_drag_icon *drag_icon = + calloc(1, sizeof(struct roots_drag_icon)); + drag_icon->mapped = true; + drag_icon->surface = icon_surface; + wl_list_insert(&seat->drag_icons, &drag_icon->link); + + wl_signal_add(&icon_surface->events.destroy, + &drag_icon->surface_destroy); + drag_icon->surface_destroy.notify = handle_drag_icon_destroy; + + wl_signal_add(&icon_surface->events.commit, + &drag_icon->surface_commit); + drag_icon->surface_commit.notify = handle_drag_icon_commit; + + return drag_icon; +} + +static void seat_unmap_drag_icon(struct roots_seat *seat, + struct wlr_surface *icon_surface) { + if (!icon_surface) { + return; + } + + struct roots_drag_icon *icon; + wl_list_for_each(icon, &seat->drag_icons, link) { + if (icon->surface == icon_surface) { + icon->mapped = false; + } + } +} + void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor, struct wlr_seat_pointer_grab *grab) { - struct roots_seat *seat = cursor->seat; if (grab->interface == &wlr_data_device_pointer_drag_interface) { struct wlr_drag *drag = grab->data; - if (drag->icon) { - struct roots_drag_icon *iter_icon; - wl_list_for_each(iter_icon, &seat->drag_icons, link) { - if (iter_icon->surface == drag->icon) { - // already in the list - return; - } - } - - struct roots_drag_icon *drag_icon = - calloc(1, sizeof(struct roots_drag_icon)); - drag_icon->mapped = true; - drag_icon->surface = drag->icon; - wl_list_insert(&seat->drag_icons, &drag_icon->link); - - wl_signal_add(&drag->icon->events.destroy, - &drag_icon->surface_destroy); - drag_icon->surface_destroy.notify = handle_drag_icon_destroy; - - wl_signal_add(&drag->icon->events.commit, - &drag_icon->surface_commit); - drag_icon->surface_commit.notify = handle_drag_icon_commit; + struct roots_drag_icon *icon = + seat_add_drag_icon(cursor->seat, drag->icon); + if (icon) { + icon->is_pointer = true; } } } @@ -363,13 +389,27 @@ void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor, struct wlr_seat_pointer_grab *grab) { if (grab->interface == &wlr_data_device_pointer_drag_interface) { struct wlr_drag *drag = grab->data; - struct roots_drag_icon *icon; - wl_list_for_each(icon, &cursor->seat->drag_icons, link) { - if (icon->surface == drag->icon) { - icon->mapped = false; - } + seat_unmap_drag_icon(cursor->seat, drag->icon); + } +} + +void roots_cursor_handle_touch_grab_begin(struct roots_cursor *cursor, + struct wlr_seat_touch_grab *grab) { + if (grab->interface == &wlr_data_device_touch_drag_interface) { + struct wlr_drag *drag = grab->data; + struct roots_drag_icon *icon = + seat_add_drag_icon(cursor->seat, drag->icon); + if (icon) { + icon->is_pointer = false; + icon->touch_id = drag->grab_touch_id; } } +} - roots_cursor_update_position(cursor, 0); +void roots_cursor_handle_touch_grab_end(struct roots_cursor *cursor, + struct wlr_seat_touch_grab *grab) { + if (grab->interface == &wlr_data_device_touch_drag_interface) { + struct wlr_drag *drag = grab->data; + seat_unmap_drag_icon(cursor->seat, drag->icon); + } } diff --git a/rootston/output.c b/rootston/output.c index 28312c2c..82760632 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -200,9 +200,20 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { } struct wlr_surface *icon = drag_icon->surface; struct wlr_cursor *cursor = seat->cursor->cursor; - double icon_x = cursor->x + drag_icon->sx; - double icon_y = cursor->y + drag_icon->sy; - render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); + double icon_x = 0, icon_y = 0; + if (drag_icon->is_pointer) { + icon_x = cursor->x + drag_icon->sx; + icon_y = cursor->y + drag_icon->sy; + render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); + } else { + struct wlr_touch_point *point = + wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id); + if (point) { + icon_x = point->sx + drag_icon->sx; // TODO plus view x + icon_y = point->sy + drag_icon->sy; // TODO plus view y + render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); + } + } } } diff --git a/rootston/seat.c b/rootston/seat.c index a99e2310..38dfc49d 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -111,6 +111,22 @@ static void handle_pointer_grab_end(struct wl_listener *listener, roots_cursor_handle_pointer_grab_end(cursor, grab); } +static void handle_touch_grab_begin(struct wl_listener *listener, + void *data) { + struct roots_cursor *cursor = + wl_container_of(listener, cursor, touch_grab_begin); + struct wlr_seat_touch_grab *grab = data; + roots_cursor_handle_touch_grab_begin(cursor, grab); +} + +static void handle_touch_grab_end(struct wl_listener *listener, + void *data) { + struct roots_cursor *cursor = + wl_container_of(listener, cursor, touch_grab_end); + struct wlr_seat_touch_grab *grab = data; + roots_cursor_handle_touch_grab_end(cursor, grab); +} + static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) { struct wlr_cursor *cursor = seat->cursor->cursor; struct roots_config *config = seat->input->config; @@ -231,6 +247,14 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wl_signal_add(&seat->seat->events.pointer_grab_end, &seat->cursor->pointer_grab_end); seat->cursor->pointer_grab_end.notify = handle_pointer_grab_end; + + wl_signal_add(&seat->seat->events.touch_grab_begin, + &seat->cursor->touch_grab_begin); + seat->cursor->touch_grab_begin.notify = handle_touch_grab_begin; + + wl_signal_add(&seat->seat->events.touch_grab_end, + &seat->cursor->touch_grab_end); + seat->cursor->touch_grab_end.notify = handle_touch_grab_end; } struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { -- cgit v1.2.3