From e5a31ae87054dacfbdea6ebf4ceba92dbd067e36 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 12 Nov 2017 11:43:50 -0500 Subject: wlr-seat: basic touch --- include/rootston/cursor.h | 1 - include/rootston/seat.h | 7 ------- 2 files changed, 8 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index f49b6439..b5af7de3 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -39,7 +39,6 @@ struct roots_cursor { uint32_t resize_edges; // Ring buffer of input events that could trigger move/resize/rotate int input_events_idx; - struct wl_list touch_points; struct roots_input_event input_events[16]; struct wl_listener motion; diff --git a/include/rootston/seat.h b/include/rootston/seat.h index bef515a4..5fb2f196 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -43,13 +43,6 @@ struct roots_touch { struct wl_list link; }; -struct roots_touch_point { - struct roots_touch *device; - int32_t slot; - double x, y; - struct wl_list link; -}; - struct roots_tablet_tool { struct roots_seat *seat; struct wlr_input_device *device; -- cgit v1.2.3 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 --- include/rootston/cursor.h | 9 ++++ include/rootston/seat.h | 3 ++ include/wlr/types/wlr_data_device.h | 7 +++ include/wlr/types/wlr_seat.h | 1 + rootston/cursor.c | 98 ++++++++++++++++++++++++++----------- rootston/output.c | 17 +++++-- rootston/seat.c | 24 +++++++++ types/wlr_data_device.c | 83 ++++++++++++++++++------------- types/wlr_seat.c | 44 ++++++++++++----- 9 files changed, 209 insertions(+), 77 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index b5af7de3..f0c9be89 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -56,6 +56,9 @@ struct roots_cursor { struct wl_listener pointer_grab_begin; struct wl_listener pointer_grab_end; + struct wl_listener touch_grab_begin; + struct wl_listener touch_grab_end; + struct wl_listener request_set_cursor; }; @@ -99,4 +102,10 @@ void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor, void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor, struct wlr_seat_pointer_grab *grab); +void roots_cursor_handle_touch_grab_begin(struct roots_cursor *cursor, + struct wlr_seat_touch_grab *grab); + +void roots_cursor_handle_touch_grab_end(struct roots_cursor *cursor, + struct wlr_seat_touch_grab *grab); + #endif diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 5fb2f196..e5a1dc71 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -9,6 +9,9 @@ struct roots_drag_icon { struct wl_list link; // roots_seat::drag_icons bool mapped; + bool is_pointer; + bool touch_id; + int32_t sx; int32_t sy; diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 6e8d0a73..b21e53bc 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -10,6 +10,9 @@ wlr_pointer_grab_interface wlr_data_device_pointer_drag_interface; extern const struct wlr_keyboard_grab_interface wlr_data_device_keyboard_drag_interface; +extern const struct +wlr_touch_grab_interface wlr_data_device_touch_drag_interface; + struct wlr_data_device_manager { struct wl_global *global; }; @@ -55,14 +58,18 @@ struct wlr_drag { struct wlr_seat_keyboard_grab keyboard_grab; struct wlr_seat_touch_grab touch_grab; + struct wlr_seat *seat; struct wlr_seat_client *seat_client; struct wlr_seat_client *focus_client; + bool is_pointer_grab; + struct wlr_surface *icon; struct wlr_surface *focus; struct wlr_data_source *source; bool cancelling; + int32_t grab_touch_id; struct wl_listener icon_destroy; struct wl_listener source_destroy; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 8950722f..79c592aa 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -144,6 +144,7 @@ struct wlr_seat_touch_state { struct wl_list touch_points; // wlr_touch_point::link uint32_t grab_serial; + uint32_t grab_id; struct wlr_seat_touch_grab *grab; struct wlr_seat_touch_grab *default_grab; 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) { diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index ca18a4d6..3eeb1cce 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -437,8 +437,12 @@ static void wlr_drag_set_focus(struct wlr_drag *drag, static void wlr_drag_end(struct wlr_drag *drag) { if (!drag->cancelling) { drag->cancelling = true; - wlr_seat_pointer_end_grab(drag->pointer_grab.seat); - wlr_seat_keyboard_end_grab(drag->keyboard_grab.seat); + if (drag->is_pointer_grab) { + wlr_seat_pointer_end_grab(drag->seat); + } else { + wlr_seat_touch_end_grab(drag->seat); + } + wlr_seat_keyboard_end_grab(drag->seat); if (drag->source) { wl_list_remove(&drag->source_destroy.link); @@ -523,20 +527,34 @@ wlr_pointer_grab_interface wlr_data_device_pointer_drag_interface = { static void touch_drag_down(struct wlr_seat_touch_grab *grab, struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, double sy) { - // TODO + // eat the event } static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t touch_id) { - // TODO + struct wlr_drag *drag = grab->data; + if (drag->grab_touch_id != touch_id) { + return; + } + + if (drag->focus_client && drag->focus_client->data_device) { + wl_data_device_send_drop(drag->focus_client->data_device); + } + + wlr_drag_end(drag); } static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t touch_id, double sx, double sy) { - // TODO + struct wlr_drag *drag = grab->data; + if (drag->focus && drag->focus_client && drag->focus_client->data_device) { + wl_data_device_send_motion(drag->focus_client->data_device, time, + wl_fixed_from_double(sx), wl_fixed_from_double(sy)); + } } static void touch_drag_cancel(struct wlr_seat_touch_grab *grab) { - // TODO + struct wlr_drag *drag = grab->data; + wlr_drag_end(drag); } const struct wlr_touch_grab_interface wlr_data_device_touch_drag_interface = { @@ -594,25 +612,32 @@ static bool seat_client_start_drag(struct wlr_seat_client *client, return false; } - struct wlr_seat_pointer_state pointer_state = client->seat->pointer_state; - struct wlr_seat_touch_state touch_state = client->seat->touch_state; + drag->seat = client->seat; - bool is_pointer_grab = client->pointer && - pointer_state.button_count == 1 && - pointer_state.grab_serial == serial && - pointer_state.focused_surface && - pointer_state.focused_surface == origin; + drag->is_pointer_grab = client->pointer != NULL && + client->seat->pointer_state.button_count == 1 && + client->seat->pointer_state.grab_serial == serial && + client->seat->pointer_state.focused_surface && + client->seat->pointer_state.focused_surface == origin; bool is_touch_grab = client->touch && - wl_list_length(&touch_state.touch_points) == 1 && - touch_state.grab_serial == serial; + wl_list_length(&client->seat->touch_state.touch_points) == 1 && + client->seat->touch_state.grab_serial == serial; + + struct wlr_touch_point *point = NULL; + if (is_touch_grab) { + wl_list_for_each(point, &client->seat->touch_state.touch_points, link) { + if (point->surface && point->surface == origin) { + is_touch_grab = true; + } + break; + } + } - if (!is_pointer_grab || !is_touch_grab) { + if (!drag->is_pointer_grab && !is_touch_grab) { return true; } - struct wlr_seat *seat = client->seat; - if (icon) { drag->icon = icon; drag->icon_destroy.notify = drag_handle_icon_destroy; @@ -632,17 +657,19 @@ static bool seat_client_start_drag(struct wlr_seat_client *client, drag->touch_grab.data = drag; drag->touch_grab.interface = &wlr_data_device_touch_drag_interface; + drag->grab_touch_id = drag->seat->touch_state.grab_id; drag->keyboard_grab.data = drag; drag->keyboard_grab.interface = &wlr_data_device_keyboard_drag_interface; - wlr_seat_keyboard_start_grab(seat, &drag->keyboard_grab); + wlr_seat_keyboard_start_grab(drag->seat, &drag->keyboard_grab); - if (is_pointer_grab) { - wlr_seat_pointer_clear_focus(seat); - wlr_seat_pointer_start_grab(seat, &drag->pointer_grab); + if (drag->is_pointer_grab) { + wlr_seat_pointer_clear_focus(drag->seat); + wlr_seat_pointer_start_grab(drag->seat, &drag->pointer_grab); } else { - wlr_seat_touch_start_grab(seat, &drag->touch_grab); + wlr_seat_touch_start_grab(drag->seat, &drag->touch_grab); + wlr_drag_set_focus(drag, point->surface, point->sx, point->sy); } return true; @@ -654,20 +681,10 @@ static void data_device_start_drag(struct wl_client *client, struct wl_resource *origin_resource, struct wl_resource *icon_resource, uint32_t serial) { struct wlr_seat_client *seat_client = wl_resource_get_user_data(device_resource); - struct wlr_seat *seat = seat_client->seat; struct wlr_surface *origin = wl_resource_get_user_data(origin_resource); struct wlr_data_source *source = NULL; struct wlr_surface *icon = NULL; - bool is_pointer_grab = seat->pointer_state.button_count == 1 && - seat->pointer_state.grab_serial == serial && - seat->pointer_state.focused_surface && - seat->pointer_state.focused_surface == origin; - - if (!is_pointer_grab) { - return; - } - if (source_resource) { source = wl_resource_get_user_data(source_resource); } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 212373df..d2b9cfb6 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -378,6 +378,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { return NULL; } touch_grab->interface = &default_touch_grab_impl; + touch_grab->seat = wlr_seat; wlr_seat->touch_state.default_grab = touch_grab; wlr_seat->touch_state.grab = touch_grab; @@ -600,7 +601,9 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time, void wlr_seat_pointer_start_grab(struct wlr_seat *wlr_seat, struct wlr_seat_pointer_grab *grab) { + assert(wlr_seat); grab->seat = wlr_seat; + assert(grab->seat); wlr_seat->pointer_state.grab = grab; wl_signal_emit(&wlr_seat->events.pointer_grab_begin, grab); @@ -959,37 +962,58 @@ struct wlr_touch_point *wlr_seat_touch_get_point( void wlr_seat_touch_notify_down(struct wlr_seat *seat, struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, double sy) { + clock_gettime(CLOCK_MONOTONIC, &seat->last_event); struct wlr_seat_touch_grab *grab = seat->touch_state.grab; + struct wlr_touch_point *point = + touch_point_create(seat, touch_id, surface, sx, sy); + if (!point) { + wlr_log(L_ERROR, "could not create touch point"); + return; + } + grab->interface->down(grab, surface, time, touch_id, sx, sy); if (wl_list_length(&seat->touch_state.touch_points) == 1) { seat->touch_state.grab_serial = wl_display_get_serial(seat->display); + seat->touch_state.grab_id = touch_id; } } void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id) { + clock_gettime(CLOCK_MONOTONIC, &seat->last_event); struct wlr_seat_touch_grab *grab = seat->touch_state.grab; + struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); + if (!point) { + wlr_log(L_ERROR, "got touch up for unknown touch point"); + return; + } + grab->interface->up(grab, time, touch_id); + touch_point_destroy(point); } void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, double sx, double sy) { + clock_gettime(CLOCK_MONOTONIC, &seat->last_event); struct wlr_seat_touch_grab *grab = seat->touch_state.grab; + struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); + if (!point) { + wlr_log(L_ERROR, "got touch motion for unknown touch point"); + return; + } + + point->sx = sx; + point->sy = sy; + grab->interface->motion(grab, time, touch_id, sx, sy); } void wlr_seat_touch_send_down(struct wlr_seat *seat, struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, double sy) { - if (wlr_seat_touch_get_point(seat, touch_id)) { - wlr_log(L_ERROR, "got touch down for a touch point that's already down"); - return; - } - - struct wlr_touch_point *point = - touch_point_create(seat, touch_id, surface, sx, sy); + struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); if (!point) { - wlr_log(L_ERROR, "could not create touch point"); + wlr_log(L_ERROR, "got touch down for unknown touch point"); return; } @@ -1009,7 +1033,6 @@ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, int32_t touch_ uint32_t serial = wl_display_next_serial(seat->display); wl_touch_send_up(point->client->touch, serial, time, touch_id); wl_touch_send_frame(point->client->touch); - touch_point_destroy(point); } void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, @@ -1020,9 +1043,6 @@ void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t to return; } - point->sx = sx; - point->sy = sy; - wl_touch_send_motion(point->client->touch, time, touch_id, wl_fixed_from_double(sx), wl_fixed_from_double(sy)); wl_touch_send_frame(point->client->touch); -- 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 'include/rootston') 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 'include/rootston') 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 cd566ccd8e1c41af6b1d5f03fabdbdeaca2625ab Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 09:47:53 +0100 Subject: Add cursor theme to rootston config --- include/rootston/config.h | 1 + rootston/config.c | 3 +++ rootston/desktop.c | 5 +++-- rootston/rootston.ini.example | 2 ++ types/wlr_xcursor_manager.c | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/config.h b/include/rootston/config.h index 71ee61c7..1fb2911d 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -48,6 +48,7 @@ struct roots_config { struct { char *mapped_output; struct wlr_box *mapped_box; + char *theme; } cursor; struct wl_list outputs; diff --git a/rootston/config.c b/rootston/config.c index 727b52d0..638d6e73 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -276,6 +276,9 @@ static int config_ini_handler(void *user, const char *section, const char *name, } else if (strcmp(name, "geometry") == 0) { free(config->cursor.mapped_box); config->cursor.mapped_box = parse_geometry(value); + } else if (strcmp(name, "theme") == 0) { + free(config->cursor.theme); + config->cursor.theme = strdup(value); } else { wlr_log(L_ERROR, "got unknown cursor config: %s", name); } diff --git a/rootston/desktop.c b/rootston/desktop.c index 1695d007..a2af5e95 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -338,10 +338,11 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->server = server; desktop->config = config; - desktop->xcursor_manager = wlr_xcursor_manager_create(NULL, + desktop->xcursor_manager = wlr_xcursor_manager_create(config->cursor.theme, ROOTS_XCURSOR_SIZE); if (desktop->xcursor_manager == NULL) { - wlr_log(L_ERROR, "Cannot create XCursor manager"); + wlr_log(L_ERROR, "Cannot create XCursor manager for theme %s", + config->cursor.theme); wlr_list_free(desktop->views); free(desktop); return NULL; diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example index c33b0f04..17467100 100644 --- a/rootston/rootston.ini.example +++ b/rootston/rootston.ini.example @@ -21,6 +21,8 @@ rotate = 90 map-to-output = VGA-1 # Restrict cursor movements to concrete rectangle geometry = 2500x800 +# Load a custom XCursor theme +theme = default # Single device configuration. String after semicolon must match device's name. [device:PixArt Dell MS116 USB Optical Mouse] diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index 6c12d04b..f32a96bc 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -46,7 +46,7 @@ int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager, return 1; } theme->scale = scale; - theme->theme = wlr_xcursor_theme_load(NULL, manager->size * scale); + theme->theme = wlr_xcursor_theme_load(manager->name, manager->size * scale); if (theme->theme == NULL) { free(theme); return 1; -- cgit v1.2.3 From 5b13f51dfc72493beb1ee0e95ae1eea9e53b8681 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 17:34:24 +0100 Subject: Add per-seat cursor configuration --- include/rootston/config.h | 29 +++++++++++----- rootston/config.c | 87 ++++++++++++++++++++++++++++++++++++++--------- rootston/desktop.c | 11 ++++-- rootston/input.c | 2 +- rootston/seat.c | 37 +++++++++++++++----- 5 files changed, 130 insertions(+), 36 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/config.h b/include/rootston/config.h index 1fb2911d..de20fb8e 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -3,6 +3,8 @@ #include #include +#define ROOTS_CONFIG_DEFAULT_SEAT_NAME "seat0" + struct roots_output_config { char *name; enum wl_output_transform transform; @@ -17,9 +19,9 @@ struct roots_output_config { struct roots_device_config { char *name; + char *seat; char *mapped_output; struct wlr_box *mapped_box; - char *seat; struct wl_list link; }; @@ -33,6 +35,7 @@ struct roots_binding_config { struct roots_keyboard_config { char *name; + char *seat; uint32_t meta_key; char *rules; char *model; @@ -42,19 +45,22 @@ struct roots_keyboard_config { struct wl_list link; }; +struct roots_cursor_config { + char *seat; + char *mapped_output; + struct wlr_box *mapped_box; + char *theme; + struct wl_list link; +}; + struct roots_config { bool xwayland; - struct { - char *mapped_output; - struct wlr_box *mapped_box; - char *theme; - } cursor; - struct wl_list outputs; struct wl_list devices; struct wl_list bindings; struct wl_list keyboards; + struct wl_list cursors; char *config_path; char *startup_cmd; }; @@ -90,6 +96,13 @@ struct roots_device_config *roots_config_get_device(struct roots_config *config, * returns NULL. A NULL device returns the default config for keyboards. */ struct roots_keyboard_config *roots_config_get_keyboard( - struct roots_config *config, struct wlr_input_device *device); + struct roots_config *config, struct wlr_input_device *device); + +/** + * Get configuration for the cursor. If the cursor is not configured, returns + * NULL. A NULL seat_name returns the default config for cursors. + */ +struct roots_cursor_config *roots_config_get_cursor(struct roots_config *config, + const char *seat_name); #endif diff --git a/rootston/config.c b/rootston/config.c index 638d6e73..466ad16a 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -150,6 +150,37 @@ void add_binding_config(struct wl_list *bindings, const char* combination, } } +static void config_handle_cursor(struct roots_config *config, + const char *seat_name, const char *name, const char *value) { + struct roots_cursor_config *cc; + bool found = false; + wl_list_for_each(cc, &config->cursors, link) { + if (strcmp(cc->seat, seat_name) == 0) { + found = true; + break; + } + } + + if (!found) { + cc = calloc(1, sizeof(struct roots_cursor_config)); + cc->seat = strdup(seat_name); + wl_list_insert(&config->cursors, &cc->link); + } + + if (strcmp(name, "map-to-output") == 0) { + free(cc->mapped_output); + cc->mapped_output = strdup(value); + } else if (strcmp(name, "geometry") == 0) { + free(cc->mapped_box); + cc->mapped_box = parse_geometry(value); + } else if (strcmp(name, "theme") == 0) { + free(cc->theme); + cc->theme = strdup(value); + } else { + wlr_log(L_ERROR, "got unknown cursor config: %s", name); + } +} + static void config_handle_keyboard(struct roots_config *config, const char *device_name, const char *name, const char *value) { struct roots_keyboard_config *kc; @@ -190,6 +221,7 @@ static void config_handle_keyboard(struct roots_config *config, static const char *output_prefix = "output:"; static const char *device_prefix = "device:"; static const char *keyboard_prefix = "keyboard:"; +static const char *cursor_prefix = "cursor:"; static int config_ini_handler(void *user, const char *section, const char *name, const char *value) { @@ -269,19 +301,12 @@ static int config_ini_handler(void *user, const char *section, const char *name, oc->name, oc->mode.width, oc->mode.height, oc->mode.refresh_rate); } + } else if (strncmp(cursor_prefix, section, strlen(cursor_prefix)) == 0) { + const char *seat_name = section + strlen(cursor_prefix); + config_handle_cursor(config, seat_name, name, value); } else if (strcmp(section, "cursor") == 0) { - if (strcmp(name, "map-to-output") == 0) { - free(config->cursor.mapped_output); - config->cursor.mapped_output = strdup(value); - } else if (strcmp(name, "geometry") == 0) { - free(config->cursor.mapped_box); - config->cursor.mapped_box = parse_geometry(value); - } else if (strcmp(name, "theme") == 0) { - free(config->cursor.theme); - config->cursor.theme = strdup(value); - } else { - wlr_log(L_ERROR, "got unknown cursor config: %s", name); - } + config_handle_cursor(config, ROOTS_CONFIG_DEFAULT_SEAT_NAME, name, + value); } else if (strncmp(device_prefix, section, strlen(device_prefix)) == 0) { const char *device_name = section + strlen(device_prefix); @@ -297,7 +322,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, if (!found) { dc = calloc(1, sizeof(struct roots_device_config)); dc->name = strdup(device_name); - dc->seat = strdup("seat0"); + dc->seat = strdup(ROOTS_CONFIG_DEFAULT_SEAT_NAME); wl_list_insert(&config->devices, &dc->link); } @@ -338,6 +363,7 @@ struct roots_config *roots_config_create_from_args(int argc, char *argv[]) { wl_list_init(&config->outputs); wl_list_init(&config->devices); wl_list_init(&config->keyboards); + wl_list_init(&config->cursors); wl_list_init(&config->bindings); int c; @@ -418,6 +444,15 @@ void roots_config_destroy(struct roots_config *config) { free(kc); } + struct roots_cursor_config *cc, *ctmp = NULL; + wl_list_for_each_safe(cc, ctmp, &config->cursors, link) { + free(cc->seat); + free(cc->mapped_output); + free(cc->mapped_box); + free(cc->theme); + free(cc); + } + struct roots_binding_config *bc, *btmp = NULL; wl_list_for_each_safe(bc, btmp, &config->bindings, link) { free(bc->keysyms); @@ -426,8 +461,6 @@ void roots_config_destroy(struct roots_config *config) { } free(config->config_path); - free(config->cursor.mapped_output); - free(config->cursor.mapped_box); free(config); } @@ -457,13 +490,33 @@ struct roots_device_config *roots_config_get_device(struct roots_config *config, struct roots_keyboard_config *roots_config_get_keyboard( struct roots_config *config, struct wlr_input_device *device) { + const char *device_name = ""; + if (device != NULL) { + device_name = device->name; + } + struct roots_keyboard_config *kc; wl_list_for_each(kc, &config->keyboards, link) { - if ((device != NULL && strcmp(kc->name, device->name) == 0) || - (device == NULL && strcmp(kc->name, "") == 0)) { + if (strcmp(kc->name, device_name) == 0) { return kc; } } return NULL; } + +struct roots_cursor_config *roots_config_get_cursor(struct roots_config *config, + const char *seat_name) { + if (seat_name == NULL) { + seat_name = ROOTS_CONFIG_DEFAULT_SEAT_NAME; + } + + struct roots_cursor_config *cc; + wl_list_for_each(cc, &config->cursors, link) { + if (strcmp(cc->seat, seat_name) == 0) { + return cc; + } + } + + return NULL; +} diff --git a/rootston/desktop.c b/rootston/desktop.c index a2af5e95..3bc5e748 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -338,11 +338,18 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->server = server; desktop->config = config; - desktop->xcursor_manager = wlr_xcursor_manager_create(config->cursor.theme, + const char *cursor_theme = NULL; + struct roots_cursor_config *cc = + roots_config_get_cursor(config, ROOTS_CONFIG_DEFAULT_SEAT_NAME); + if (cc != NULL) { + cursor_theme = cc->theme; + } + + desktop->xcursor_manager = wlr_xcursor_manager_create(cursor_theme, ROOTS_XCURSOR_SIZE); if (desktop->xcursor_manager == NULL) { wlr_log(L_ERROR, "Cannot create XCursor manager for theme %s", - config->cursor.theme); + cursor_theme); wlr_list_free(desktop->views); free(desktop); return NULL; diff --git a/rootston/input.c b/rootston/input.c index 35a5af97..a5d710c4 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -43,7 +43,7 @@ static void input_add_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; struct roots_input *input = wl_container_of(listener, input, input_add); - char *seat_name = "seat0"; + char *seat_name = ROOTS_CONFIG_DEFAULT_SEAT_NAME; struct roots_device_config *dc = roots_config_get_device(input->config, device); if (dc) { diff --git a/rootston/seat.c b/rootston/seat.c index 1fa37c44..2abc542b 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -157,20 +157,29 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { } // configure device to output mappings - const char *mapped_output = config->cursor.mapped_output; + const char *mapped_output = NULL; + struct roots_cursor_config *cc = + roots_config_get_cursor(config, seat->seat->name); + if (cc != NULL) { + mapped_output = cc->mapped_output; + } wl_list_for_each(output, &desktop->outputs, link) { - if (mapped_output && strcmp(mapped_output, output->wlr_output->name) == 0) { + if (mapped_output && + strcmp(mapped_output, output->wlr_output->name) == 0) { wlr_cursor_map_to_output(cursor, output->wlr_output); } wl_list_for_each(pointer, &seat->pointers, link) { - seat_set_device_output_mappings(seat, pointer->device, output->wlr_output); + seat_set_device_output_mappings(seat, pointer->device, + output->wlr_output); } wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { - seat_set_device_output_mappings(seat, tablet_tool->device, output->wlr_output); + seat_set_device_output_mappings(seat, tablet_tool->device, + output->wlr_output); } wl_list_for_each(touch, &seat->touch, link) { - seat_set_device_output_mappings(seat, touch->device, output->wlr_output); + seat_set_device_output_mappings(seat, touch->device, + output->wlr_output); } } } @@ -185,9 +194,6 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { struct roots_desktop *desktop = seat->input->server->desktop; wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout); - // TODO: be able to configure per-seat cursor themes - seat->cursor->xcursor_manager = desktop->xcursor_manager; - wl_list_init(&seat->cursor->touch_points); roots_seat_configure_cursor(seat); @@ -446,6 +452,21 @@ void roots_seat_remove_device(struct roots_seat *seat, } void roots_seat_configure_xcursor(struct roots_seat *seat) { + const char *cursor_theme = NULL; + struct roots_cursor_config *cc = + roots_config_get_cursor(seat->input->config, seat->seat->name); + if (cc != NULL) { + cursor_theme = cc->theme; + } + + seat->cursor->xcursor_manager = + wlr_xcursor_manager_create(cursor_theme, ROOTS_XCURSOR_SIZE); + if (seat->cursor->xcursor_manager == NULL) { + wlr_log(L_ERROR, "Cannot create XCursor manager for theme %s", + cursor_theme); + return; + } + struct roots_output *output; wl_list_for_each(output, &seat->input->server->desktop->outputs, link) { if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager, -- 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 'include/rootston') 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 From 90d2eca218be2beff2465433f0d2937a3d4de267 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 19 Nov 2017 10:07:30 -0500 Subject: rootston: xwayland ready listener --- include/rootston/desktop.h | 1 + rootston/main.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index b809db43..10e5bbc6 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -50,6 +50,7 @@ struct roots_desktop { #ifdef HAS_XWAYLAND struct wlr_xwayland *xwayland; struct wl_listener xwayland_surface; + struct wl_listener xwayland_ready; #endif }; diff --git a/rootston/main.c b/rootston/main.c index 814d3aef..46548094 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -59,8 +59,9 @@ int main(int argc, char **argv) { ready(NULL, NULL); #else if (server.desktop->xwayland != NULL) { - struct wl_listener xwayland_ready = { .notify = ready }; - wl_signal_add(&server.desktop->xwayland->events.ready, &xwayland_ready); + wl_signal_add(&server.desktop->xwayland->events.ready, + &server.desktop->xwayland_ready); + server.desktop->xwayland_ready.notify = ready; } else { ready(NULL, NULL); } -- cgit v1.2.3 From bd8cdf1e9ff0ba6a0e8f7c36fec7f7540c94fded Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 19 Nov 2017 10:20:32 -0500 Subject: rootston: remove grab listeners --- include/rootston/cursor.h | 18 ------------------ rootston/cursor.c | 16 ---------------- rootston/seat.c | 48 ----------------------------------------------- 3 files changed, 82 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index f0c9be89..e2a371bf 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -53,12 +53,6 @@ struct roots_cursor { struct wl_listener tool_axis; struct wl_listener tool_tip; - struct wl_listener pointer_grab_begin; - struct wl_listener pointer_grab_end; - - struct wl_listener touch_grab_begin; - struct wl_listener touch_grab_end; - struct wl_listener request_set_cursor; }; @@ -96,16 +90,4 @@ void roots_cursor_handle_tool_tip(struct roots_cursor *cursor, void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, struct wlr_seat_pointer_request_set_cursor_event *event); -void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor, - struct wlr_seat_pointer_grab *grab); - -void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor, - struct wlr_seat_pointer_grab *grab); - -void roots_cursor_handle_touch_grab_begin(struct roots_cursor *cursor, - struct wlr_seat_touch_grab *grab); - -void roots_cursor_handle_touch_grab_end(struct roots_cursor *cursor, - struct wlr_seat_touch_grab *grab); - #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index d0b40876..e2615bec 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -354,19 +354,3 @@ void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, event->hotspot_y); cursor->cursor_client = event->seat_client->client; } - -void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor, - struct wlr_seat_pointer_grab *grab) { -} - -void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor, - struct wlr_seat_pointer_grab *grab) { -} - -void roots_cursor_handle_touch_grab_begin(struct roots_cursor *cursor, - struct wlr_seat_touch_grab *grab) { -} - -void roots_cursor_handle_touch_grab_end(struct roots_cursor *cursor, - struct wlr_seat_touch_grab *grab) { -} diff --git a/rootston/seat.c b/rootston/seat.c index 96c6fb0d..c24ee787 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -96,38 +96,6 @@ static void handle_request_set_cursor(struct wl_listener *listener, roots_cursor_handle_request_set_cursor(cursor, event); } -static void handle_pointer_grab_begin(struct wl_listener *listener, - void *data) { - struct roots_cursor *cursor = - wl_container_of(listener, cursor, pointer_grab_begin); - struct wlr_seat_pointer_grab *grab = data; - roots_cursor_handle_pointer_grab_begin(cursor, grab); -} - -static void handle_pointer_grab_end(struct wl_listener *listener, - void *data) { - struct roots_cursor *cursor = - wl_container_of(listener, cursor, pointer_grab_end); - struct wlr_seat_pointer_grab *grab = data; - 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; @@ -249,22 +217,6 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wl_signal_add(&seat->seat->events.request_set_cursor, &seat->cursor->request_set_cursor); seat->cursor->request_set_cursor.notify = handle_request_set_cursor; - - wl_signal_add(&seat->seat->events.pointer_grab_begin, - &seat->cursor->pointer_grab_begin); - seat->cursor->pointer_grab_begin.notify = handle_pointer_grab_begin; - - 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