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/output.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'rootston/output.c') 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); + } + } } } -- cgit v1.2.3 From ac4841ba37aee8c0d661c44f2de2fd6ed5d38086 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 15 Nov 2017 06:43:30 -0500 Subject: put dnd icon in the right place --- include/rootston/seat.h | 3 +++ include/wlr/types/wlr_seat.h | 15 +++++++++++++++ rootston/cursor.c | 5 +++++ rootston/output.c | 4 ++-- types/wlr_seat.c | 12 ++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) (limited to 'rootston/output.c') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index e5a1dc71..c9dc883c 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -26,6 +26,9 @@ struct roots_seat { struct wl_list link; struct wl_list drag_icons; + // coordinates of the touch grab if one exists + double touch_grab_x, touch_grab_y; + struct roots_view *focus; struct wl_list keyboards; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index ee13f99d..716e37c5 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -321,6 +321,11 @@ uint32_t wlr_seat_pointer_notify_button(struct wlr_seat *wlr_seat, void wlr_seat_pointer_notify_axis(struct wlr_seat *wlr_seat, uint32_t time, enum wlr_axis_orientation orientation, double value); +/** + * Whether or not the pointer has a grab other than the default grab. + */ +bool wlr_seat_pointer_has_grab(struct wlr_seat *seat); + /** * Set this keyboard as the active keyboard for the seat. */ @@ -388,6 +393,11 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, */ void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat); +/** + * Whether or not the keyboard has a grab other than the default grab + */ +bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat); + /** * Start a grab of the touch device of this seat. The grabber is responsible for * handling all touch events until the grab ends. @@ -477,4 +487,9 @@ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, double sx, double sy); +/** + * Whether or not the seat has a touch grab other than the default grab. + */ +bool wlr_seat_touch_has_grab(struct wlr_seat *seat); + #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 16441f4b..7e261234 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -270,6 +270,11 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, wlr_seat_touch_point_clear_focus(cursor->seat->seat, event->time_msec, event->slot); } + + if (wlr_seat_touch_has_grab(cursor->seat->seat)) { + cursor->seat->touch_grab_x = lx; + cursor->seat->touch_grab_y = ly; + } } void roots_cursor_handle_tool_axis(struct roots_cursor *cursor, diff --git a/rootston/output.c b/rootston/output.c index 82760632..0b13a959 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -209,8 +209,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { 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 + icon_x = seat->touch_grab_x + drag_icon->sx; + icon_y = seat->touch_grab_y + drag_icon->sy; render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); } } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index eb73b174..8d9201bb 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -672,6 +672,10 @@ void wlr_seat_pointer_notify_axis(struct wlr_seat *wlr_seat, uint32_t time, grab->interface->axis(grab, time, orientation, value); } +bool wlr_seat_pointer_has_grab(struct wlr_seat *seat) { + return seat->pointer_state.grab->interface != &default_pointer_grab_impl; +} + void wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time, uint32_t key, uint32_t state) { struct wlr_seat_client *client = wlr_seat->keyboard_state.focused_client; @@ -869,6 +873,10 @@ void wlr_seat_keyboard_clear_focus(struct wlr_seat *seat) { wlr_seat_keyboard_enter(seat, NULL); } +bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat) { + return seat->keyboard_state.grab->interface != &default_keyboard_grab_impl; +} + void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat) { clock_gettime(CLOCK_MONOTONIC, &seat->last_event); struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab; @@ -1129,3 +1137,7 @@ void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t to wl_fixed_from_double(sx), wl_fixed_from_double(sy)); wl_touch_send_frame(point->client->touch); } + +bool wlr_seat_touch_has_grab(struct wlr_seat *seat) { + return seat->touch_state.grab->interface != &default_touch_grab_impl; +} -- cgit v1.2.3 From 12758a00a2d388b050386f017a3a273c1302e648 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 15 Nov 2017 08:34:35 -0500 Subject: rootston: touch to focus --- include/rootston/seat.h | 7 ++++--- include/wlr/types/wlr_seat.h | 5 +++++ rootston/cursor.c | 49 +++++++++++++++++++++++++++++++++----------- rootston/output.c | 4 ++-- types/wlr_seat.c | 4 ++++ 5 files changed, 52 insertions(+), 17 deletions(-) (limited to 'rootston/output.c') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index c9dc883c..aebd4399 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -10,7 +10,7 @@ struct roots_drag_icon { bool mapped; bool is_pointer; - bool touch_id; + int32_t touch_id; int32_t sx; int32_t sy; @@ -26,8 +26,9 @@ struct roots_seat { struct wl_list link; struct wl_list drag_icons; - // coordinates of the touch grab if one exists - double touch_grab_x, touch_grab_y; + // coordinates of the first touch point if it exists + int32_t touch_id; + double touch_x, touch_y; struct roots_view *focus; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 716e37c5..109e9be9 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -487,6 +487,11 @@ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, double sx, double sy); +/** + * How many touch points are currently down for the seat. + */ +int wlr_seat_touch_num_points(struct wlr_seat *seat); + /** * Whether or not the seat has a touch grab other than the default grab. */ diff --git a/rootston/cursor.c b/rootston/cursor.c index 7e261234..b6325fdc 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -128,13 +128,14 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t static void roots_cursor_press_button(struct roots_cursor *cursor, struct wlr_input_device *device, uint32_t time, uint32_t button, - uint32_t state) { + uint32_t state, double lx, double ly) { struct roots_seat *seat = cursor->seat; struct roots_desktop *desktop = seat->input->server->desktop; + bool is_touch = device->type == WLR_INPUT_DEVICE_TOUCH; + struct wlr_surface *surface; double sx, sy; - struct roots_view *view = view_at(desktop, - cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + struct roots_view *view = view_at(desktop, lx, ly, &surface, &sx, &sy); if (state == WLR_BUTTON_PRESSED && view && roots_seat_has_meta_pressed(seat)) { roots_seat_focus_view(seat, view); @@ -165,14 +166,20 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, return; } - uint32_t serial = - wlr_seat_pointer_notify_button(seat->seat, time, button, state); + uint32_t serial; + if (is_touch) { + serial = wl_display_get_serial(desktop->server->wl_display); + } else { + serial = wlr_seat_pointer_notify_button(seat->seat, time, button, state); + } int i; switch (state) { case WLR_BUTTON_RELEASED: seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH; - roots_cursor_update_position(cursor, time); + if (!is_touch) { + roots_cursor_update_position(cursor, time); + } break; case WLR_BUTTON_PRESSED: i = cursor->input_events_idx; @@ -203,7 +210,7 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, void roots_cursor_handle_button(struct roots_cursor *cursor, struct wlr_event_pointer_button *event) { roots_cursor_press_button(cursor, event->device, event->time_msec, - event->button, event->state); + event->button, event->state, cursor->cursor->x, cursor->cursor->y); } void roots_cursor_handle_axis(struct roots_cursor *cursor, @@ -231,12 +238,29 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, wlr_seat_touch_notify_down(cursor->seat->seat, surface, event->time_msec, event->slot, sx, sy); } + + if (wlr_seat_touch_num_points(cursor->seat->seat) == 1) { + cursor->seat->touch_id = event->slot; + cursor->seat->touch_x = lx; + cursor->seat->touch_y = ly; + roots_cursor_press_button(cursor, event->device, event->time_msec, + BTN_LEFT, 1, lx, ly); + } } void roots_cursor_handle_touch_up(struct roots_cursor *cursor, struct wlr_event_touch_up *event) { + struct wlr_touch_point *point = wlr_seat_touch_get_point(cursor->seat->seat, event->slot); + if (!point) { + return; + } + + if (wlr_seat_touch_num_points(cursor->seat->seat) == 1) { + roots_cursor_press_button(cursor, event->device, event->time_msec, + BTN_LEFT, 0, cursor->seat->touch_x, cursor->seat->touch_y); + } + wlr_seat_touch_notify_up(cursor->seat->seat, event->time_msec, event->slot); - //roots_cursor_press_button(cursor, event->device, event->time_msec, BTN_LEFT, 0); } void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, @@ -271,9 +295,9 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, event->slot); } - if (wlr_seat_touch_has_grab(cursor->seat->seat)) { - cursor->seat->touch_grab_x = lx; - cursor->seat->touch_grab_y = ly; + if (event->slot == cursor->seat->touch_id) { + cursor->seat->touch_x = lx; + cursor->seat->touch_y = ly; } } @@ -298,7 +322,8 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor, void roots_cursor_handle_tool_tip(struct roots_cursor *cursor, struct wlr_event_tablet_tool_tip *event) { roots_cursor_press_button(cursor, event->device, - event->time_msec, BTN_LEFT, event->state); + event->time_msec, BTN_LEFT, event->state, cursor->cursor->x, + cursor->cursor->y); } void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, diff --git a/rootston/output.c b/rootston/output.c index 0b13a959..6c8f2519 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -209,8 +209,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { struct wlr_touch_point *point = wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id); if (point) { - icon_x = seat->touch_grab_x + drag_icon->sx; - icon_y = seat->touch_grab_y + drag_icon->sy; + icon_x = seat->touch_x + drag_icon->sx; + icon_y = seat->touch_y + drag_icon->sy; render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); } } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 8d9201bb..c37611b3 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -1138,6 +1138,10 @@ void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t to wl_touch_send_frame(point->client->touch); } +int wlr_seat_touch_num_points(struct wlr_seat *seat) { + return wl_list_length(&seat->touch_state.touch_points); +} + bool wlr_seat_touch_has_grab(struct wlr_seat *seat) { return seat->touch_state.grab->interface != &default_touch_grab_impl; } -- cgit v1.2.3 From 3b74db467b7f628ad45ee319424448a02dc052ec Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 19 Nov 2017 09:33:55 -0500 Subject: data-device: wlr-drag-icon --- include/rootston/seat.h | 16 ------- include/wlr/types/wlr_data_device.h | 25 ++++++++++- include/wlr/types/wlr_seat.h | 2 + rootston/cursor.c | 86 ------------------------------------- rootston/output.c | 4 +- rootston/seat.c | 1 - types/wlr_data_device.c | 84 +++++++++++++++++++++++++++++++++--- types/wlr_seat.c | 1 + 8 files changed, 107 insertions(+), 112 deletions(-) (limited to 'rootston/output.c') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index aebd4399..dad8bbc4 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -4,27 +4,11 @@ #include "rootston/input.h" #include "rootston/keyboard.h" -struct roots_drag_icon { - struct wlr_surface *surface; - struct wl_list link; // roots_seat::drag_icons - bool mapped; - - bool is_pointer; - int32_t touch_id; - - int32_t sx; - int32_t sy; - - struct wl_listener surface_destroy; - struct wl_listener surface_commit; -}; - struct roots_seat { struct roots_input *input; struct wlr_seat *seat; struct roots_cursor *cursor; struct wl_list link; - struct wl_list drag_icons; // coordinates of the first touch point if it exists int32_t touch_id; diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 189ab59b..7ee6cec1 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -53,6 +53,27 @@ struct wlr_data_source { } events; }; +struct wlr_drag_icon { + struct wlr_surface *surface; + struct wlr_seat_client *client; + struct wl_list link; // wlr_seat::drag_icons + bool mapped; + + bool is_pointer; + int32_t touch_id; + + int32_t sx; + int32_t sy; + + struct { + struct wl_signal destroy; + } events; + + struct wl_listener surface_destroy; + struct wl_listener surface_commit; + struct wl_listener seat_client_unbound; +}; + struct wlr_drag { struct wlr_seat_pointer_grab pointer_grab; struct wlr_seat_keyboard_grab keyboard_grab; @@ -64,7 +85,7 @@ struct wlr_drag { bool is_pointer_grab; - struct wlr_surface *icon; + struct wlr_drag_icon *icon; struct wlr_surface *focus; struct wlr_data_source *source; @@ -72,9 +93,9 @@ struct wlr_drag { int32_t grab_touch_id; struct wl_listener point_destroy; - struct wl_listener icon_destroy; struct wl_listener source_destroy; struct wl_listener seat_client_unbound; + struct wl_listener icon_destroy; }; /** diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index dbd03401..b5c06718 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -165,6 +165,8 @@ struct wlr_seat { struct wl_global *wl_global; struct wl_display *display; struct wl_list clients; + struct wl_list drag_icons; // wlr_drag_icon::link + char *name; uint32_t capabilities; struct timespec last_event; diff --git a/rootston/cursor.c b/rootston/cursor.c index 10bb4dd3..d0b40876 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -355,104 +355,18 @@ void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, cursor->cursor_client = event->seat_client->client; } -static void handle_drag_icon_commit(struct wl_listener *listener, void *data) { - struct roots_drag_icon *drag_icon = - wl_container_of(listener, drag_icon, surface_commit); - drag_icon->sx += drag_icon->surface->current->sx; - drag_icon->sy += drag_icon->surface->current->sy; -} - -static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) { - struct roots_drag_icon *drag_icon = - wl_container_of(listener, drag_icon, surface_destroy); - wl_list_remove(&drag_icon->link); - wl_list_remove(&drag_icon->surface_destroy.link); - wl_list_remove(&drag_icon->surface_commit.link); - 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) { - if (grab->interface == &wlr_data_device_pointer_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 = true; - } - } } 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; - 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; - } - } } 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 6c8f2519..b551dcf4 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -191,10 +191,10 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { render_view(view, desktop, wlr_output, &now); } - struct roots_drag_icon *drag_icon = NULL; + struct wlr_drag_icon *drag_icon = NULL; struct roots_seat *seat = NULL; wl_list_for_each(seat, &server->input->seats, link) { - wl_list_for_each(drag_icon, &seat->drag_icons, link) { + wl_list_for_each(drag_icon, &seat->seat->drag_icons, link) { if (!drag_icon->mapped) { continue; } diff --git a/rootston/seat.c b/rootston/seat.c index 1855ca49..96c6fb0d 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -277,7 +277,6 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_init(&seat->pointers); wl_list_init(&seat->touch); wl_list_init(&seat->tablet_tools); - wl_list_init(&seat->drag_icons); seat->input = input; diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 6328fd09..ab10bb2e 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -452,6 +452,7 @@ static void wlr_drag_end(struct wlr_drag *drag) { wlr_drag_set_focus(drag, NULL, 0, 0); if (drag->icon) { + drag->icon->mapped = false; wl_list_remove(&drag->icon_destroy.link); } @@ -614,8 +615,74 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener, wlr_drag_end(drag); } +static void wlr_drag_icon_destroy(struct wlr_drag_icon *icon) { + if (!icon) { + return; + } + wl_signal_emit(&icon->events.destroy, icon); + wl_list_remove(&icon->surface_commit.link); + wl_list_remove(&icon->surface_destroy.link); + wl_list_remove(&icon->seat_client_unbound.link); + wl_list_remove(&icon->link); + free(icon); +} + +static void handle_drag_icon_surface_destroy(struct wl_listener *listener, + void *data) { + struct wlr_drag_icon *icon = + wl_container_of(listener, icon, surface_destroy); + wlr_drag_icon_destroy(icon); +} + +static void handle_drag_icon_surface_commit(struct wl_listener *listener, + void *data) { + struct wlr_drag_icon *icon = + wl_container_of(listener, icon, surface_commit); + icon->sx += icon->surface->current->sx; + icon->sy += icon->surface->current->sy; +} + +static void handle_drag_icon_seat_client_unbound(struct wl_listener *listener, + void *data) { + struct wlr_drag_icon *icon = + wl_container_of(listener, icon, seat_client_unbound); + struct wlr_seat_client *client = data; + + if (client == icon->client) { + wlr_drag_icon_destroy(icon); + } +} + +static struct wlr_drag_icon *wlr_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)); + if (!icon) { + return NULL; + } + + icon->surface = icon_surface; + icon->client = client; + icon->is_pointer = is_pointer; + icon->touch_id = touch_id; + wl_list_insert(&client->seat->drag_icons, &icon->link); + + wl_signal_init(&icon->events.destroy); + + wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy); + icon->surface_destroy.notify = handle_drag_icon_surface_destroy; + + wl_signal_add(&icon->surface->events.commit, &icon->surface_commit); + icon->surface_commit.notify = handle_drag_icon_surface_commit; + + wl_signal_add(&client->seat->events.client_unbound, &icon->seat_client_unbound); + icon->seat_client_unbound.notify = handle_drag_icon_seat_client_unbound; + + return icon; +} + static bool seat_client_start_drag(struct wlr_seat_client *client, - struct wlr_data_source *source, struct wlr_surface *icon, + 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)); if (drag == NULL) { @@ -649,11 +716,20 @@ static bool seat_client_start_drag(struct wlr_seat_client *client, return true; } - if (icon) { + if (icon_surface) { + int32_t touch_id = (point ? point->touch_id : 0); + struct wlr_drag_icon *icon = + wlr_drag_icon_create(icon_surface, client, drag->is_pointer_grab, + touch_id); + + if (!icon) { + free(drag); + return false; + } + drag->icon = icon; drag->icon_destroy.notify = drag_handle_icon_destroy; wl_signal_add(&icon->events.destroy, &drag->icon_destroy); - drag->icon = icon; } if (source) { @@ -712,8 +788,6 @@ static void data_device_start_drag(struct wl_client *client, } } - // TODO touch grab - if (!seat_client_start_drag(seat_client, source, icon, origin, serial)) { wl_resource_post_no_memory(device_resource); return; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 4438f5cc..3bdd11ef 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -404,6 +404,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { wlr_seat->display = display; wlr_seat->name = strdup(name); wl_list_init(&wlr_seat->clients); + wl_list_init(&wlr_seat->drag_icons); wl_signal_init(&wlr_seat->events.client_bound); wl_signal_init(&wlr_seat->events.client_unbound); -- cgit v1.2.3