From e5a31ae87054dacfbdea6ebf4ceba92dbd067e36 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 12 Nov 2017 11:43:50 -0500 Subject: [PATCH 01/20] wlr-seat: basic touch --- include/rootston/cursor.h | 1 - include/rootston/seat.h | 7 -- include/wlr/types/wlr_cursor.h | 7 ++ include/wlr/types/wlr_seat.h | 31 +++++++++ rootston/cursor.c | 73 +++++++++++--------- rootston/seat.c | 2 - types/wlr_cursor.c | 18 +++++ types/wlr_seat.c | 121 +++++++++++++++++++++++++++++++++ 8 files changed, 217 insertions(+), 43 deletions(-) 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; diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index 0db32eb2..c73a4c8d 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -126,4 +126,11 @@ void wlr_cursor_map_to_region(struct wlr_cursor *cur, struct wlr_box *box); void wlr_cursor_map_input_to_region(struct wlr_cursor *cur, struct wlr_input_device *dev, struct wlr_box *box); +/** + * Convert absolute coordinates to layout coordinates for the device. + */ +bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur, + struct wlr_input_device *device, double x_mm, double y_mm, + double width_mm, double height_mm, double *lx, double *ly); + #endif diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index a5f00402..e8477b18 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -103,6 +103,23 @@ struct wlr_seat_keyboard_state { struct wlr_seat_keyboard_grab *default_grab; }; +struct wlr_touch_point { + int32_t touch_id; + struct wlr_surface *surface; + struct wlr_seat_client *client; + double sx, sy; + + struct wl_listener surface_destroy; + struct wl_listener resource_destroy; + + struct wl_list link; +}; + +struct wlr_seat_touch_state { + struct wlr_seat *seat; + struct wl_list touch_points; // wlr_touch_point::link +}; + struct wlr_seat { struct wl_global *wl_global; struct wl_display *display; @@ -117,6 +134,7 @@ struct wlr_seat { struct wlr_seat_pointer_state pointer_state; struct wlr_seat_keyboard_state keyboard_state; + struct wlr_seat_touch_state touch_state; struct wl_listener selection_data_source_destroy; @@ -328,4 +346,17 @@ void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat); // TODO: May be useful to be able to simulate keyboard input events +struct wlr_touch_point *wlr_seat_touch_get_point(struct wlr_seat *seat, + int32_t touch_id); + +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); + +void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, + int32_t touch_id); + +void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, + int32_t touch_id, double sx, double sy); + #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index ecd5e9a0..417bdaf5 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -214,50 +214,57 @@ void roots_cursor_handle_axis(struct roots_cursor *cursor, void roots_cursor_handle_touch_down(struct roots_cursor *cursor, struct wlr_event_touch_down *event) { - struct roots_touch_point *point = - calloc(1, sizeof(struct roots_touch_point)); - if (!point) { - wlr_log(L_ERROR, "could not allocate memory for touch point"); + struct roots_desktop *desktop = cursor->seat->input->server->desktop; + struct wlr_surface *surface = NULL; + double lx, ly; + bool result = + wlr_cursor_absolute_to_layout_coords(cursor->cursor, + event->device, event->x_mm, event->y_mm, event->width_mm, + event->height_mm, &lx, &ly); + if (!result) { return; } + double sx, sy; + view_at(desktop, lx, ly, &surface, &sx, &sy); - point->device = event->device->data; - point->slot = event->slot; - point->x = event->x_mm / event->width_mm; - point->y = event->y_mm / event->height_mm; - wlr_cursor_warp_absolute(cursor->cursor, event->device, point->x, point->y); - roots_cursor_update_position(cursor, event->time_msec); - wl_list_insert(&cursor->touch_points, &point->link); - roots_cursor_press_button(cursor, event->device, - event->time_msec, BTN_LEFT, 1); + if (surface) { + wlr_seat_touch_notify_down(cursor->seat->seat, surface, + event->time_msec, event->slot, sx, sy); + } } void roots_cursor_handle_touch_up(struct roots_cursor *cursor, struct wlr_event_touch_up *event) { - struct roots_touch_point *point; - wl_list_for_each(point, &cursor->touch_points, link) { - if (point->slot == event->slot) { - wl_list_remove(&point->link); - free(point); - break; - } - } - roots_cursor_press_button(cursor, event->device, - event->time_msec, BTN_LEFT, 0); + // TODO + 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, struct wlr_event_touch_motion *event) { - struct roots_touch_point *point; - wl_list_for_each(point, &cursor->touch_points, link) { - if (point->slot == event->slot) { - point->x = event->x_mm / event->width_mm; - point->y = event->y_mm / event->height_mm; - wlr_cursor_warp_absolute(cursor->cursor, event->device, - point->x, point->y); - roots_cursor_update_position(cursor, event->time_msec); - break; - } + struct roots_desktop *desktop = cursor->seat->input->server->desktop; + struct wlr_touch_point *point = + wlr_seat_touch_get_point(cursor->seat->seat, event->slot); + if (!point) { + return; + } + + struct wlr_surface *surface = NULL; + double lx, ly; + bool result = + wlr_cursor_absolute_to_layout_coords(cursor->cursor, + event->device, event->x_mm, event->y_mm, event->width_mm, + event->height_mm, &lx, &ly); + if (!result) { + return; + } + + double sx, sy; + view_at(desktop, lx, ly, &surface, &sx, &sy); + + if (surface == point->surface) { + wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec, + event->slot, sx, sy); } } diff --git a/rootston/seat.c b/rootston/seat.c index 6d8dc749..a99e2310 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -188,8 +188,6 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { // 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); roots_seat_configure_xcursor(seat); diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index e8965b68..ec66f7c7 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -637,3 +637,21 @@ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur, c_device->mapped_box = box; } + +bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur, + struct wlr_input_device *device, double x_mm, double y_mm, + double width_mm, double height_mm, double *lx, double *ly) { + if (width_mm <= 0 || height_mm <= 0) { + return false; + } + + struct wlr_box *mapping = get_mapping(cur, device); + if (!mapping) { + mapping = wlr_output_layout_get_box(cur->state->layout, NULL); + } + + *lx = x_mm > 0 ? mapping->width * (x_mm / width_mm) + mapping->x : cur->x; + *ly = y_mm > 0 ? mapping->height * (y_mm / height_mm) + mapping->y : cur->y; + + return true; +} diff --git a/types/wlr_seat.c b/types/wlr_seat.c index dad88354..d52a4bdc 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -338,6 +338,10 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { wl_list_init( &wlr_seat->keyboard_state.surface_destroy.link); + // touch state + wlr_seat->touch_state.seat = wlr_seat; + wl_list_init(&wlr_seat->touch_state.touch_points); + struct wl_global *wl_global = wl_global_create(display, &wl_seat_interface, 6, wlr_seat, wl_seat_bind); if (!wl_global) { @@ -819,3 +823,120 @@ void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time, struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab; grab->interface->key(grab, time, key, state); } + +static void touch_point_destroy(struct wlr_touch_point *point) { + wl_list_remove(&point->surface_destroy.link); + wl_list_remove(&point->resource_destroy.link); + wl_list_remove(&point->link); + free(point); +} + +static void handle_touch_point_resource_destroy(struct wl_listener *listener, + void *data) { + struct wlr_touch_point *point = + wl_container_of(listener, point, resource_destroy); + touch_point_destroy(point); +} + +static void handle_touch_point_surface_destroy(struct wl_listener *listener, + void *data) { + struct wlr_touch_point *point = + wl_container_of(listener, point, surface_destroy); + touch_point_destroy(point); +} + +static struct wlr_touch_point *touch_point_create( + struct wlr_seat *seat, int32_t touch_id, + struct wlr_surface *surface, double sx, double sy) { + struct wl_client *wl_client = wl_resource_get_client(surface->resource); + struct wlr_seat_client *client = wlr_seat_client_for_wl_client(seat, wl_client); + + if (!client || !client->touch) { + // touch points are not valid without a connected client with touch + return NULL; + } + + struct wlr_touch_point *point = calloc(1, sizeof(struct wlr_touch_point)); + if (!point) { + return NULL; + } + + point->touch_id = touch_id; + point->surface = surface; + point->client = client; + + point->sx = sx; + point->sy = sy; + + wl_signal_add(&surface->events.destroy, &point->surface_destroy); + point->surface_destroy.notify = handle_touch_point_surface_destroy; + wl_resource_add_destroy_listener(surface->resource, + &point->resource_destroy); + point->resource_destroy.notify = handle_touch_point_resource_destroy; + + wl_list_insert(&seat->touch_state.touch_points, &point->link); + + return point; +} + +struct wlr_touch_point *wlr_seat_touch_get_point( + struct wlr_seat *seat, int32_t touch_id) { + struct wlr_touch_point *point = NULL; + wl_list_for_each(point, &seat->touch_state.touch_points, link) { + if (point->touch_id == touch_id) { + return point; + } + } + + return NULL; +} + +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) { + 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); + if (!point) { + wlr_log(L_ERROR, "could not create touch point"); + return; + } + + uint32_t serial = wl_display_next_serial(seat->display); + wl_touch_send_down(point->client->touch, serial, time, surface->resource, + touch_id, wl_fixed_from_double(sx), wl_fixed_from_double(sy)); + wl_touch_send_frame(point->client->touch); +} + +void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id) { + struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); + if (!point) { + wlr_log(L_ERROR, "got touch notify up for unknown touch point"); + return; + } + + 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_notify_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, + double sx, double sy) { + struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); + if (!point) { + wlr_log(L_ERROR, "got touch motion notify for unknown touch point"); + 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); +} From 4240096b83989c4820aad33f9a866148e6b9e250 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 12 Nov 2017 17:04:56 -0500 Subject: [PATCH 02/20] wlr-seat: default touch grab --- include/wlr/types/wlr_seat.h | 36 ++++++++++++++++++ rootston/cursor.c | 1 - types/wlr_seat.c | 71 +++++++++++++++++++++++++++++++++--- 3 files changed, 102 insertions(+), 6 deletions(-) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index e8477b18..81013e5b 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -49,6 +49,29 @@ struct wlr_keyboard_grab_interface { void (*cancel)(struct wlr_seat_keyboard_grab *grab); }; +struct wlr_seat_touch_grab; + +struct wlr_touch_grab_interface { + void (*down)(struct wlr_seat_touch_grab *grab, struct wlr_surface *surface, + uint32_t time, int32_t touch_id, double sx, double sy); + void (*up)(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t touch_id); + void (*motion)(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t + touch_id, double sx, double sy); + // XXX this will conflict with the actual touch cancel which is different so + // we need to rename this + void (*cancel)(struct wlr_seat_touch_grab *grab); +}; + +/** + * Passed to `wlr_seat_touch_start_grab()` to start a grab of the touch device. + * The grabber is responsible for handling touch events for the seat. + */ +struct wlr_seat_touch_grab { + const struct wlr_touch_grab_interface *interface; + struct wlr_seat *seat; + void *data; +}; + /** * Passed to `wlr_seat_keyboard_start_grab()` to start a grab of the keyboard. * The grabber is responsible for handling keyboard events for the seat. @@ -118,6 +141,9 @@ struct wlr_touch_point { struct wlr_seat_touch_state { struct wlr_seat *seat; struct wl_list touch_points; // wlr_touch_point::link + + struct wlr_seat_touch_grab *grab; + struct wlr_seat_touch_grab *default_grab; }; struct wlr_seat { @@ -359,4 +385,14 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, double sx, double 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); + +void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, + int32_t touch_id); + +void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, + int32_t touch_id, double sx, double sy); + #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 417bdaf5..632966d4 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -235,7 +235,6 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, void roots_cursor_handle_touch_up(struct roots_cursor *cursor, struct wlr_event_touch_up *event) { - // TODO 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); } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index d52a4bdc..a33e19df 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -300,12 +300,41 @@ static const struct wlr_keyboard_grab_interface default_keyboard_grab_impl = { .cancel = default_keyboard_cancel, }; +static void default_touch_down(struct wlr_seat_touch_grab *grab, + struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, + double sy) { + wlr_seat_touch_send_down(grab->seat, surface, time, touch_id, sx, sy); +} + +static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time, + int32_t touch_id) { + wlr_seat_touch_send_up(grab->seat, time, touch_id); +} + +static void default_touch_motion(struct wlr_seat_touch_grab *grab, + uint32_t time, int32_t touch_id, double sx, double sy) { + wlr_seat_touch_send_motion(grab->seat, time, touch_id, sx, sy); +} + +static void default_touch_cancel(struct wlr_seat_touch_grab *grab) { + // cannot be cancelled +} + +static const struct wlr_touch_grab_interface default_touch_grab_impl = { + .down = default_touch_down, + .up = default_touch_up, + .motion = default_touch_motion, + .cancel = default_touch_cancel, +}; + + struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { struct wlr_seat *wlr_seat = calloc(1, sizeof(struct wlr_seat)); if (!wlr_seat) { return NULL; } + // pointer state wlr_seat->pointer_state.seat = wlr_seat; wl_list_init(&wlr_seat->pointer_state.surface_destroy.link); wl_list_init(&wlr_seat->pointer_state.resource_destroy.link); @@ -321,6 +350,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { wlr_seat->pointer_state.default_grab = pointer_grab; wlr_seat->pointer_state.grab = pointer_grab; + // keyboard state struct wlr_seat_keyboard_grab *keyboard_grab = calloc(1, sizeof(struct wlr_seat_keyboard_grab)); if (!keyboard_grab) { @@ -339,6 +369,18 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { &wlr_seat->keyboard_state.surface_destroy.link); // touch state + struct wlr_seat_touch_grab *touch_grab = + calloc(1, sizeof(struct wlr_seat_touch_grab)); + if (!touch_grab) { + free(pointer_grab); + free(keyboard_grab); + free(wlr_seat); + return NULL; + } + touch_grab->interface = &default_touch_grab_impl; + wlr_seat->touch_state.default_grab = touch_grab; + wlr_seat->touch_state.grab = touch_grab; + wlr_seat->touch_state.seat = wlr_seat; wl_list_init(&wlr_seat->touch_state.touch_points); @@ -382,6 +424,7 @@ void wlr_seat_destroy(struct wlr_seat *wlr_seat) { wl_global_destroy(wlr_seat->wl_global); free(wlr_seat->pointer_state.default_grab); free(wlr_seat->keyboard_state.default_grab); + free(wlr_seat->touch_state.default_grab); free(wlr_seat->data_device); free(wlr_seat->name); free(wlr_seat); @@ -830,7 +873,6 @@ static void touch_point_destroy(struct wlr_touch_point *point) { wl_list_remove(&point->link); free(point); } - static void handle_touch_point_resource_destroy(struct wl_listener *listener, void *data) { struct wlr_touch_point *point = @@ -894,6 +936,25 @@ 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) { + struct wlr_seat_touch_grab *grab = seat->touch_state.grab; + grab->interface->down(grab, surface, time, touch_id, sx, sy); +} + +void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, + int32_t touch_id) { + struct wlr_seat_touch_grab *grab = seat->touch_state.grab; + grab->interface->up(grab, time, touch_id); +} + +void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, + int32_t touch_id, double sx, double sy) { + struct wlr_seat_touch_grab *grab = seat->touch_state.grab; + 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; @@ -912,10 +973,10 @@ void wlr_seat_touch_notify_down(struct wlr_seat *seat, wl_touch_send_frame(point->client->touch); } -void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id) { +void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id) { struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); if (!point) { - wlr_log(L_ERROR, "got touch notify up for unknown touch point"); + wlr_log(L_ERROR, "got touch up for unknown touch point"); return; } @@ -925,11 +986,11 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, int32_t touc touch_point_destroy(point); } -void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, +void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, double sx, double sy) { struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); if (!point) { - wlr_log(L_ERROR, "got touch motion notify for unknown touch point"); + wlr_log(L_ERROR, "got touch motion for unknown touch point"); return; } From 469729d3af214ebe3bce5f924d1aee9bf4c130f1 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 12 Nov 2017 17:25:10 -0500 Subject: [PATCH 03/20] wlr-seat: document seat touch functions --- include/wlr/types/wlr_seat.h | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 81013e5b..afa460ec 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -109,6 +109,7 @@ struct wlr_seat_pointer_state { struct wl_listener resource_destroy; }; +// TODO: May be useful to be able to simulate keyboard input events struct wlr_seat_keyboard_state { struct wlr_seat *seat; struct wlr_keyboard *keyboard; @@ -370,28 +371,62 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, */ void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat); -// TODO: May be useful to be able to simulate keyboard input events - +/** + * Get the active touch point with the given `touch_id`. If the touch point does + * not exist or is no longer active, returns NULL. + */ struct wlr_touch_point *wlr_seat_touch_get_point(struct wlr_seat *seat, int32_t touch_id); +/** + * Notify the seat of a touch down on the given surface. Defers to any grab of + * the touch device. + */ 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); +/** + * Notify the seat that the touch point given by `touch_id` is up. Defers to any + * grab of the touch device. + */ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id); +/** + * Notify the seat that the touch point given by `touch_id` has moved. Defers to + * any grab of the touch device. + */ void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, double sx, double sy); +/** + * Send a touch down event to the client of the given surface. All future touch + * events for this point will go to this surface. If the touch down is valid, + * this will add a new touch point with the given `touch_id`. The touch down may + * not be valid if the surface seat client does not accept touch input. + * Coordinates are surface-local. Compositors should use + * `wlr_seat_touch_notify_down()` to respect any grabs of the touch device. + */ 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); +/** + * Send a touch up event for the touch point given by the `touch_id`. The event + * will go to the client for the surface given in the cooresponding touch down + * event. This will remove the touch point. Compositors should use + * `wlr_seat_touch_notify_up()` to respect any grabs of the touch device. + */ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id); +/** + * Send a touch motion event for the touch point given by the `touch_id`. The + * event will go to the cleint for the surface given in the corresponding touch + * down event. Compositors should use `wlr_seat_touch_notify_motion()` to + * respect any grabs of the touch device. + */ void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id, double sx, double sy); From cbb6fd7352ea98d60d380ce376da4b76fe7f4740 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 12 Nov 2017 17:34:32 -0500 Subject: [PATCH 04/20] wlr-seat: touch grab begin and end --- include/wlr/types/wlr_seat.h | 16 ++++++++++++++++ types/wlr_seat.c | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index afa460ec..f429fb8e 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -175,6 +175,9 @@ struct wlr_seat { struct wl_signal keyboard_grab_begin; struct wl_signal keyboard_grab_end; + struct wl_signal touch_grab_begin; + struct wl_signal touch_grab_end; + struct wl_signal request_set_cursor; struct wl_signal selection; @@ -371,6 +374,19 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, */ void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat); +/** + * Start a grab of the touch device of this seat. The grabber is responsible for + * handling all touch events until the grab ends. + */ +void wlr_seat_touch_start_grab(struct wlr_seat *wlr_seat, + struct wlr_seat_touch_grab *grab); + +/** + * End the grab of the touch device of this seat. This reverts the grab back to + * the default grab for the touch device. + */ +void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat); + /** * Get the active touch point with the given `touch_id`. If the touch point does * not exist or is no longer active, returns NULL. diff --git a/types/wlr_seat.c b/types/wlr_seat.c index a33e19df..2d6d800f 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -407,6 +407,9 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { wl_signal_init(&wlr_seat->events.keyboard_grab_begin); wl_signal_init(&wlr_seat->events.keyboard_grab_end); + wl_signal_init(&wlr_seat->events.touch_grab_begin); + wl_signal_init(&wlr_seat->events.touch_grab_end); + return wlr_seat; } @@ -867,6 +870,26 @@ void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time, grab->interface->key(grab, time, key, state); } +void wlr_seat_touch_start_grab(struct wlr_seat *wlr_seat, + struct wlr_seat_touch_grab *grab) { + grab->seat = wlr_seat; + wlr_seat->touch_state.grab = grab; + + wl_signal_emit(&wlr_seat->events.touch_grab_begin, grab); +} + +void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) { + struct wlr_seat_touch_grab *grab = wlr_seat->touch_state.grab; + + if (grab != wlr_seat->touch_state.default_grab) { + wlr_seat->touch_state.grab = wlr_seat->touch_state.default_grab; + wl_signal_emit(&wlr_seat->events.touch_grab_end, grab); + if (grab->interface->cancel) { + grab->interface->cancel(grab); + } + } +} + static void touch_point_destroy(struct wlr_touch_point *point) { wl_list_remove(&point->surface_destroy.link); wl_list_remove(&point->resource_destroy.link); From 94e7dc8a3e4df444ef9aeb46b866dd9c8c658855 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 13 Nov 2017 08:22:04 -0500 Subject: [PATCH 05/20] data-device: touch grab stubs --- include/wlr/types/wlr_data_device.h | 1 + include/wlr/types/wlr_seat.h | 2 + types/wlr_data_device.c | 60 ++++++++++++++++++++++++++--- types/wlr_seat.c | 3 ++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index f45c15a2..6e8d0a73 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -53,6 +53,7 @@ struct wlr_data_source { struct wlr_drag { struct wlr_seat_pointer_grab pointer_grab; struct wlr_seat_keyboard_grab keyboard_grab; + struct wlr_seat_touch_grab touch_grab; struct wlr_seat_client *seat_client; struct wlr_seat_client *focus_client; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index f429fb8e..8950722f 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -143,6 +143,8 @@ struct wlr_seat_touch_state { struct wlr_seat *seat; struct wl_list touch_points; // wlr_touch_point::link + uint32_t grab_serial; + struct wlr_seat_touch_grab *grab; struct wlr_seat_touch_grab *default_grab; }; diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index df18317b..ca18a4d6 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -521,6 +521,31 @@ wlr_pointer_grab_interface wlr_data_device_pointer_drag_interface = { .cancel = pointer_drag_cancel, }; +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 +} + +static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t touch_id) { + // TODO +} + +static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t + touch_id, double sx, double sy) { + // TODO +} + +static void touch_drag_cancel(struct wlr_seat_touch_grab *grab) { + // TODO +} + +const struct wlr_touch_grab_interface wlr_data_device_touch_drag_interface = { + .down = touch_drag_down, + .up = touch_drag_up, + .motion = touch_drag_motion, + .cancel = touch_drag_cancel, +}; + static void keyboard_drag_enter(struct wlr_seat_keyboard_grab *grab, struct wlr_surface *surface) { // nothing has keyboard focus during drags @@ -562,12 +587,30 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener, } 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, + struct wlr_surface *origin, uint32_t serial) { struct wlr_drag *drag = calloc(1, sizeof(struct wlr_drag)); if (drag == NULL) { return false; } + struct wlr_seat_pointer_state pointer_state = client->seat->pointer_state; + struct wlr_seat_touch_state touch_state = client->seat->touch_state; + + 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; + + bool is_touch_grab = client->touch && + wl_list_length(&touch_state.touch_points) == 1 && + touch_state.grab_serial == serial; + + if (!is_pointer_grab || !is_touch_grab) { + return true; + } + struct wlr_seat *seat = client->seat; if (icon) { @@ -587,13 +630,20 @@ static bool seat_client_start_drag(struct wlr_seat_client *client, drag->pointer_grab.data = drag; drag->pointer_grab.interface = &wlr_data_device_pointer_drag_interface; + drag->touch_grab.data = drag; + drag->touch_grab.interface = &wlr_data_device_touch_drag_interface; + drag->keyboard_grab.data = drag; drag->keyboard_grab.interface = &wlr_data_device_keyboard_drag_interface; - wlr_seat_pointer_clear_focus(seat); - wlr_seat_keyboard_start_grab(seat, &drag->keyboard_grab); - wlr_seat_pointer_start_grab(seat, &drag->pointer_grab); + + if (is_pointer_grab) { + wlr_seat_pointer_clear_focus(seat); + wlr_seat_pointer_start_grab(seat, &drag->pointer_grab); + } else { + wlr_seat_touch_start_grab(seat, &drag->touch_grab); + } return true; } @@ -634,7 +684,7 @@ static void data_device_start_drag(struct wl_client *client, // TODO touch grab - if (!seat_client_start_drag(seat_client, source, icon)) { + if (!seat_client_start_drag(seat_client, source, icon, origin, serial)) { wl_resource_post_no_memory(device_resource); } else { source->seat_client = seat_client; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 2d6d800f..212373df 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -961,6 +961,9 @@ void wlr_seat_touch_notify_down(struct wlr_seat *seat, double sy) { struct wlr_seat_touch_grab *grab = seat->touch_state.grab; 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); + } } void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, From 6a516f7c417c96b6e5a5526c73e6f52ccb9c55d9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 13 Nov 2017 15:41:48 -0500 Subject: [PATCH 06/20] 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 | 100 +++++++++++++++++++--------- rootston/output.c | 17 ++++- rootston/seat.c | 24 +++++++ types/wlr_data_device.c | 83 ++++++++++++++--------- types/wlr_seat.c | 44 ++++++++---- 9 files changed, 210 insertions(+), 78 deletions(-) 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,24 +612,31 @@ 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; - if (!is_pointer_grab || !is_touch_grab) { - return true; + 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; + } } - struct wlr_seat *seat = client->seat; + if (!drag->is_pointer_grab && !is_touch_grab) { + return true; + } if (icon) { drag->icon = icon; @@ -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); From b310fdac823f9e9233099eb3288a1d308cef6680 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 13 Nov 2017 18:08:10 -0500 Subject: [PATCH 07/20] wlr-data-device: cleanup --- types/wlr_data_device.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 3eeb1cce..741ed556 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -275,7 +275,8 @@ void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) { struct wlr_data_offer *offer = wlr_data_source_send_offer(seat_client->seat->selection_source, seat_client->data_device); - wl_data_device_send_selection(seat_client->data_device, offer->resource); + wl_data_device_send_selection(seat_client->data_device, + offer->resource); } else { wl_data_device_send_selection(seat_client->data_device, NULL); } @@ -525,12 +526,14 @@ wlr_pointer_grab_interface wlr_data_device_pointer_drag_interface = { .cancel = pointer_drag_cancel, }; -static void touch_drag_down(struct wlr_seat_touch_grab *grab, struct wlr_surface *surface, +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) { // eat the event } -static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t touch_id) { +static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, + int32_t touch_id) { struct wlr_drag *drag = grab->data; if (drag->grab_touch_id != touch_id) { return; @@ -543,8 +546,8 @@ static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, int32 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) { +static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time, + int32_t touch_id, double sx, double sy) { 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, @@ -680,7 +683,8 @@ static void data_device_start_drag(struct wl_client *client, struct wl_resource *source_resource, 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_client *seat_client = + wl_resource_get_user_data(device_resource); struct wlr_surface *origin = wl_resource_get_user_data(origin_resource); struct wlr_data_source *source = NULL; struct wlr_surface *icon = NULL; @@ -717,7 +721,8 @@ static const struct wl_data_device_interface data_device_impl = { void data_device_manager_get_data_device(struct wl_client *client, struct wl_resource *manager_resource, uint32_t id, struct wl_resource *seat_resource) { - struct wlr_seat_client *seat_client = wl_resource_get_user_data(seat_resource); + struct wlr_seat_client *seat_client = + wl_resource_get_user_data(seat_resource); struct wl_resource *resource = wl_resource_create(client, @@ -884,9 +889,9 @@ struct wlr_data_device_manager *wlr_data_device_manager_create( } void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) { - if (!manager) { - return; - } - wl_global_destroy(manager->global); - free(manager); + if (!manager) { + return; + } + wl_global_destroy(manager->global); + free(manager); } From 4eab61f86f22f902a02f23f57cd318c2400d2729 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 13 Nov 2017 19:16:34 -0500 Subject: [PATCH 08/20] wlr-seat: refactor touch grab interface --- include/wlr/types/wlr_seat.h | 50 +++++++++++++++++++++--------------- rootston/cursor.c | 4 +-- types/wlr_data_device.c | 11 ++++---- types/wlr_seat.c | 33 ++++++++++++++---------- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 79c592aa..e05bea47 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -24,6 +24,22 @@ struct wlr_seat_client { struct wl_list link; }; +struct wlr_touch_point { + int32_t touch_id; + struct wlr_surface *surface; + struct wlr_seat_client *client; + double sx, sy; + + struct wl_listener surface_destroy; + struct wl_listener resource_destroy; + + struct { + struct wl_signal destroy; + } events; + + struct wl_list link; +}; + struct wlr_seat_pointer_grab; struct wlr_pointer_grab_interface { @@ -52,11 +68,12 @@ struct wlr_keyboard_grab_interface { struct wlr_seat_touch_grab; struct wlr_touch_grab_interface { - void (*down)(struct wlr_seat_touch_grab *grab, struct wlr_surface *surface, - uint32_t time, int32_t touch_id, double sx, double sy); - void (*up)(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t touch_id); - void (*motion)(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t - touch_id, double sx, double sy); + void (*down)(struct wlr_seat_touch_grab *grab, uint32_t time, + struct wlr_touch_point *point); + void (*up)(struct wlr_seat_touch_grab *grab, uint32_t time, + struct wlr_touch_point *point); + void (*motion)(struct wlr_seat_touch_grab *grab, uint32_t time, + struct wlr_touch_point *point); // XXX this will conflict with the actual touch cancel which is different so // we need to rename this void (*cancel)(struct wlr_seat_touch_grab *grab); @@ -127,18 +144,6 @@ struct wlr_seat_keyboard_state { struct wlr_seat_keyboard_grab *default_grab; }; -struct wlr_touch_point { - int32_t touch_id; - struct wlr_surface *surface; - struct wlr_seat_client *client; - double sx, sy; - - struct wl_listener surface_destroy; - struct wl_listener resource_destroy; - - struct wl_list link; -}; - struct wlr_seat_touch_state { struct wlr_seat *seat; struct wl_list touch_points; // wlr_touch_point::link @@ -414,10 +419,13 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, /** * Notify the seat that the touch point given by `touch_id` has moved. Defers to - * any grab of the touch device. + * any grab of the touch device. The seat should be notified of touch motion + * even if the surface is not the owner of the touch point for processing by + * grabs. */ -void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, - int32_t touch_id, double sx, double sy); +void wlr_seat_touch_notify_motion(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, + double sy); /** * Send a touch down event to the client of the given surface. All future touch @@ -442,7 +450,7 @@ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, /** * Send a touch motion event for the touch point given by the `touch_id`. The - * event will go to the cleint for the surface given in the corresponding touch + * event will go to the client for the surface given in the corresponding touch * down event. Compositors should use `wlr_seat_touch_notify_motion()` to * respect any grabs of the touch device. */ diff --git a/rootston/cursor.c b/rootston/cursor.c index 863267b6..eff81104 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -261,8 +261,8 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, double sx, sy; view_at(desktop, lx, ly, &surface, &sx, &sy); - if (surface == point->surface) { - wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec, + if (surface) { + wlr_seat_touch_notify_motion(cursor->seat->seat, surface, event->time_msec, event->slot, sx, sy); } } diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 741ed556..462320e0 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -527,15 +527,14 @@ 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) { + uint32_t time, struct wlr_touch_point *point) { // eat the event } static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, - int32_t touch_id) { + struct wlr_touch_point *point) { struct wlr_drag *drag = grab->data; - if (drag->grab_touch_id != touch_id) { + if (drag->grab_touch_id != point->touch_id) { return; } @@ -547,11 +546,11 @@ static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, } static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time, - int32_t touch_id, double sx, double sy) { + struct wlr_touch_point *point) { 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)); + wl_fixed_from_double(point->sx), wl_fixed_from_double(point->sy)); } } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index d2b9cfb6..80b9a7c3 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -300,20 +300,21 @@ static const struct wlr_keyboard_grab_interface default_keyboard_grab_impl = { .cancel = default_keyboard_cancel, }; -static void default_touch_down(struct wlr_seat_touch_grab *grab, - struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, - double sy) { - wlr_seat_touch_send_down(grab->seat, surface, time, touch_id, sx, sy); +static void default_touch_down(struct wlr_seat_touch_grab *grab, uint32_t time, + struct wlr_touch_point *point) { + wlr_seat_touch_send_down(grab->seat, point->surface, time, point->touch_id, + point->sx, point->sy); } static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time, - int32_t touch_id) { - wlr_seat_touch_send_up(grab->seat, time, touch_id); + struct wlr_touch_point *point) { + wlr_seat_touch_send_up(grab->seat, time, point->touch_id); } static void default_touch_motion(struct wlr_seat_touch_grab *grab, - uint32_t time, int32_t touch_id, double sx, double sy) { - wlr_seat_touch_send_motion(grab->seat, time, touch_id, sx, sy); + uint32_t time, struct wlr_touch_point *point) { + wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx, + point->sy); } static void default_touch_cancel(struct wlr_seat_touch_grab *grab) { @@ -894,6 +895,7 @@ void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) { } static void touch_point_destroy(struct wlr_touch_point *point) { + wl_signal_emit(&point->events.destroy, point); wl_list_remove(&point->surface_destroy.link); wl_list_remove(&point->resource_destroy.link); wl_list_remove(&point->link); @@ -936,6 +938,8 @@ static struct wlr_touch_point *touch_point_create( point->sx = sx; point->sy = sy; + wl_signal_init(&point->events.destroy); + wl_signal_add(&surface->events.destroy, &point->surface_destroy); point->surface_destroy.notify = handle_touch_point_surface_destroy; wl_resource_add_destroy_listener(surface->resource, @@ -971,7 +975,8 @@ void wlr_seat_touch_notify_down(struct wlr_seat *seat, return; } - grab->interface->down(grab, surface, time, touch_id, sx, sy); + grab->interface->down(grab, time, point); + 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; @@ -988,12 +993,14 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, return; } - grab->interface->up(grab, time, touch_id); + grab->interface->up(grab, time, point); + 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) { +void wlr_seat_touch_notify_motion(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 = wlr_seat_touch_get_point(seat, touch_id); @@ -1005,7 +1012,7 @@ void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, point->sx = sx; point->sy = sy; - grab->interface->motion(grab, time, touch_id, sx, sy); + grab->interface->motion(grab, time, point); } void wlr_seat_touch_send_down(struct wlr_seat *seat, From a337e9550587aea885779fe93340f1b90376682c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 14 Nov 2017 08:51:37 -0500 Subject: [PATCH 09/20] wlr-touch: make dnd work --- include/wlr/types/wlr_data_device.h | 1 + include/wlr/types/wlr_seat.h | 22 +++++++- rootston/cursor.c | 7 ++- types/wlr_data_device.c | 7 +++ types/wlr_seat.c | 85 +++++++++++++++++++++++++++-- 5 files changed, 115 insertions(+), 7 deletions(-) diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index b21e53bc..189ab59b 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -71,6 +71,7 @@ struct wlr_drag { bool cancelling; 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; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index e05bea47..ee13f99d 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -28,9 +28,13 @@ struct wlr_touch_point { int32_t touch_id; struct wlr_surface *surface; struct wlr_seat_client *client; + + struct wlr_surface *focus_surface; + struct wlr_seat_client *focus_client; double sx, sy; struct wl_listener surface_destroy; + struct wl_listener focus_surface_destroy; struct wl_listener resource_destroy; struct { @@ -74,6 +78,8 @@ struct wlr_touch_grab_interface { struct wlr_touch_point *point); void (*motion)(struct wlr_seat_touch_grab *grab, uint32_t time, struct wlr_touch_point *point); + void (*enter)(struct wlr_seat_touch_grab *grab, uint32_t time, + struct wlr_touch_point *point); // XXX this will conflict with the actual touch cancel which is different so // we need to rename this void (*cancel)(struct wlr_seat_touch_grab *grab); @@ -423,10 +429,24 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, * even if the surface is not the owner of the touch point for processing by * grabs. */ -void wlr_seat_touch_notify_motion(struct wlr_seat *seat, +void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, + int32_t touch_id, double sx, double sy); + +/** + * Notify the seat that the touch point given by `touch_id` has entered a new + * surface. The surface is required. To clear focus, use + * `wlr_seat_touch_point_clear_focus()`. + */ +void wlr_seat_touch_point_focus(struct wlr_seat *seat, struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, double sy); +/** + * Clear the focused surface for the touch point given by `touch_id`. + */ +void wlr_seat_touch_point_clear_focus(struct wlr_seat *seat, uint32_t time, + int32_t touch_id); + /** * Send a touch down event to the client of the given surface. All future touch * events for this point will go to this surface. If the touch down is valid, diff --git a/rootston/cursor.c b/rootston/cursor.c index eff81104..16441f4b 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -262,8 +262,13 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, view_at(desktop, lx, ly, &surface, &sx, &sy); if (surface) { - wlr_seat_touch_notify_motion(cursor->seat->seat, surface, event->time_msec, + wlr_seat_touch_point_focus(cursor->seat->seat, surface, + event->time_msec, event->slot, sx, sy); + wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec, event->slot, sx, sy); + } else { + wlr_seat_touch_point_clear_focus(cursor->seat->seat, event->time_msec, + event->slot); } } diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 462320e0..57122818 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -554,6 +554,12 @@ static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time, } } +static void touch_drag_enter(struct wlr_seat_touch_grab *grab, uint32_t time, + struct wlr_touch_point *point) { + struct wlr_drag *drag = grab->data; + wlr_drag_set_focus(drag, point->focus_surface, point->sx, point->sy); +} + static void touch_drag_cancel(struct wlr_seat_touch_grab *grab) { struct wlr_drag *drag = grab->data; wlr_drag_end(drag); @@ -563,6 +569,7 @@ const struct wlr_touch_grab_interface wlr_data_device_touch_drag_interface = { .down = touch_drag_down, .up = touch_drag_up, .motion = touch_drag_motion, + .enter = touch_drag_enter, .cancel = touch_drag_cancel, }; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 80b9a7c3..eb73b174 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -313,8 +313,15 @@ static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time, static void default_touch_motion(struct wlr_seat_touch_grab *grab, uint32_t time, struct wlr_touch_point *point) { - wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx, - point->sy); + if (!point->focus_surface || point->focus_surface == point->surface) { + wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx, + point->sy); + } +} + +static void default_touch_enter(struct wlr_seat_touch_grab *grab, + uint32_t time, struct wlr_touch_point *point) { + // not handled by default } static void default_touch_cancel(struct wlr_seat_touch_grab *grab) { @@ -325,6 +332,7 @@ static const struct wlr_touch_grab_interface default_touch_grab_impl = { .down = default_touch_down, .up = default_touch_up, .motion = default_touch_motion, + .enter = default_touch_enter, .cancel = default_touch_cancel, }; @@ -998,9 +1006,8 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, touch_point_destroy(point); } -void wlr_seat_touch_notify_motion(struct wlr_seat *seat, - struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, - double sy) { +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); @@ -1015,6 +1022,74 @@ void wlr_seat_touch_notify_motion(struct wlr_seat *seat, grab->interface->motion(grab, time, point); } +static void touch_point_clear_focus(struct wlr_touch_point *point) { + if (point->focus_surface) { + wl_list_remove(&point->focus_surface_destroy.link); + point->focus_client = NULL; + point->focus_surface = NULL; + } +} + +static void handle_point_focus_destroy(struct wl_listener *listener, + void *data) { + struct wlr_touch_point *point = + wl_container_of(listener, point, focus_surface_destroy); + touch_point_clear_focus(point); +} + +static void touch_point_set_focus(struct wlr_touch_point *point, + struct wlr_surface *surface, double sx, double sy) { + if (point->focus_surface == surface) { + return; + } + + touch_point_clear_focus(point); + + if (surface && surface->resource) { + struct wlr_seat_client *client = + wlr_seat_client_for_wl_client(point->client->seat, + wl_resource_get_client(surface->resource)); + + if (client && client->touch) { + wl_signal_add(&surface->events.destroy, &point->focus_surface_destroy); + point->focus_surface_destroy.notify = handle_point_focus_destroy; + point->focus_surface = surface; + point->focus_client = client; + point->sx = sx; + point->sy = sy; + } + } +} + +void wlr_seat_touch_point_focus(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, + double sy) { + assert(surface); + struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); + if (!point) { + wlr_log(L_ERROR, "got touch point focus for unknown touch point"); + return; + } + struct wlr_surface *focus = point->focus_surface; + touch_point_set_focus(point, surface, sx, sy); + + if (focus != point->focus_surface) { + struct wlr_seat_touch_grab *grab = seat->touch_state.grab; + grab->interface->enter(grab, time, point); + } +} + +void wlr_seat_touch_point_clear_focus(struct wlr_seat *seat, uint32_t time, + int32_t touch_id) { + struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); + if (!point) { + wlr_log(L_ERROR, "got touch point focus for unknown touch point"); + return; + } + + touch_point_set_focus(point, NULL, 0, 0); +} + 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) { From ac4841ba37aee8c0d661c44f2de2fd6ed5d38086 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 15 Nov 2017 06:43:30 -0500 Subject: [PATCH 10/20] 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(-) 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; +} From 12758a00a2d388b050386f017a3a273c1302e648 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 15 Nov 2017 08:34:35 -0500 Subject: [PATCH 11/20] 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(-) 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; } From ae7d8870e776deca116d2a5099eaba5c3fc9c33a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 16 Nov 2017 16:45:56 -0500 Subject: [PATCH 12/20] data-device: bug: fix touch detection --- types/wlr_data_device.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 999faa22..bac8dbf3 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -630,15 +630,15 @@ static bool seat_client_start_drag(struct wlr_seat_client *client, client->seat->pointer_state.focused_surface == origin; bool is_touch_grab = client->touch && - wl_list_length(&client->seat->touch_state.touch_points) == 1 && + wlr_seat_touch_num_points(client->seat) == 1 && client->seat->touch_state.grab_serial == serial; + // set in the iteration struct wlr_touch_point *point = NULL; + if (is_touch_grab) { wl_list_for_each(point, &client->seat->touch_state.touch_points, link) { - if (point->surface && point->surface == origin) { - is_touch_grab = true; - } + is_touch_grab = point->surface && point->surface == origin; break; } } @@ -677,6 +677,7 @@ static bool seat_client_start_drag(struct wlr_seat_client *client, wlr_seat_pointer_clear_focus(drag->seat); wlr_seat_pointer_start_grab(drag->seat, &drag->pointer_grab); } else { + assert(point); wlr_seat_touch_start_grab(drag->seat, &drag->touch_grab); wlr_drag_set_focus(drag, point->surface, point->sx, point->sy); } From 4434be835d6aaf6314f2596181295fabd883eac9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 16 Nov 2017 17:20:55 -0500 Subject: [PATCH 13/20] wlr-seat: clear touch focus on touch point destroy --- types/wlr_seat.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/types/wlr_seat.c b/types/wlr_seat.c index c37611b3..6566d397 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -910,8 +910,18 @@ void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) { } } +static void touch_point_clear_focus(struct wlr_touch_point *point) { + if (point->focus_surface) { + wl_list_remove(&point->focus_surface_destroy.link); + point->focus_client = NULL; + point->focus_surface = NULL; + } +} + static void touch_point_destroy(struct wlr_touch_point *point) { wl_signal_emit(&point->events.destroy, point); + + touch_point_clear_focus(point); wl_list_remove(&point->surface_destroy.link); wl_list_remove(&point->resource_destroy.link); wl_list_remove(&point->link); @@ -1030,14 +1040,6 @@ void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, grab->interface->motion(grab, time, point); } -static void touch_point_clear_focus(struct wlr_touch_point *point) { - if (point->focus_surface) { - wl_list_remove(&point->focus_surface_destroy.link); - point->focus_client = NULL; - point->focus_surface = NULL; - } -} - static void handle_point_focus_destroy(struct wl_listener *listener, void *data) { struct wlr_touch_point *point = @@ -1095,7 +1097,7 @@ void wlr_seat_touch_point_clear_focus(struct wlr_seat *seat, uint32_t time, return; } - touch_point_set_focus(point, NULL, 0, 0); + touch_point_clear_focus(point); } void wlr_seat_touch_send_down(struct wlr_seat *seat, From fb18e345a6e4546fe87729962b54cce61759bc71 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 16 Nov 2017 17:34:38 -0500 Subject: [PATCH 14/20] wlr-seat: return serial from touch down interface --- include/wlr/types/wlr_seat.h | 6 +++--- rootston/cursor.c | 5 +++-- types/wlr_data_device.c | 3 ++- types/wlr_seat.c | 26 +++++++++++++++----------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 109e9be9..dbd03401 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -72,7 +72,7 @@ struct wlr_keyboard_grab_interface { struct wlr_seat_touch_grab; struct wlr_touch_grab_interface { - void (*down)(struct wlr_seat_touch_grab *grab, uint32_t time, + uint32_t (*down)(struct wlr_seat_touch_grab *grab, uint32_t time, struct wlr_touch_point *point); void (*up)(struct wlr_seat_touch_grab *grab, uint32_t time, struct wlr_touch_point *point); @@ -422,7 +422,7 @@ struct wlr_touch_point *wlr_seat_touch_get_point(struct wlr_seat *seat, * Notify the seat of a touch down on the given surface. Defers to any grab of * the touch device. */ -void wlr_seat_touch_notify_down(struct wlr_seat *seat, +uint32_t wlr_seat_touch_notify_down(struct wlr_seat *seat, struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, double sy); @@ -465,7 +465,7 @@ void wlr_seat_touch_point_clear_focus(struct wlr_seat *seat, uint32_t time, * Coordinates are surface-local. Compositors should use * `wlr_seat_touch_notify_down()` to respect any grabs of the touch device. */ -void wlr_seat_touch_send_down(struct wlr_seat *seat, +uint32_t wlr_seat_touch_send_down(struct wlr_seat *seat, struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, double sy); diff --git a/rootston/cursor.c b/rootston/cursor.c index 35fe9c25..40618fe7 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -234,12 +234,13 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, double sx, sy; view_at(desktop, lx, ly, &surface, &sx, &sy); + uint32_t serial = 0; if (surface) { - wlr_seat_touch_notify_down(cursor->seat->seat, surface, + serial = 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) { + if (serial && 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; diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index bac8dbf3..eb8a3503 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -526,9 +526,10 @@ wlr_pointer_grab_interface wlr_data_device_pointer_drag_interface = { .cancel = pointer_drag_cancel, }; -static void touch_drag_down(struct wlr_seat_touch_grab *grab, +uint32_t touch_drag_down(struct wlr_seat_touch_grab *grab, uint32_t time, struct wlr_touch_point *point) { // eat the event + return 0; } static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 6566d397..4438f5cc 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -300,10 +300,10 @@ static const struct wlr_keyboard_grab_interface default_keyboard_grab_impl = { .cancel = default_keyboard_cancel, }; -static void default_touch_down(struct wlr_seat_touch_grab *grab, uint32_t time, +static uint32_t default_touch_down(struct wlr_seat_touch_grab *grab, uint32_t time, struct wlr_touch_point *point) { - wlr_seat_touch_send_down(grab->seat, point->surface, time, point->touch_id, - point->sx, point->sy); + return wlr_seat_touch_send_down(grab->seat, point->surface, time, + point->touch_id, point->sx, point->sy); } static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time, @@ -658,7 +658,7 @@ uint32_t wlr_seat_pointer_notify_button(struct wlr_seat *wlr_seat, struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab; uint32_t serial = grab->interface->button(grab, time, button, state); - if (wlr_seat->pointer_state.button_count == 1) { + if (serial && wlr_seat->pointer_state.button_count == 1) { wlr_seat->pointer_state.grab_serial = serial; } @@ -989,7 +989,7 @@ struct wlr_touch_point *wlr_seat_touch_get_point( return NULL; } -void wlr_seat_touch_notify_down(struct wlr_seat *seat, +uint32_t 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); @@ -998,15 +998,17 @@ void wlr_seat_touch_notify_down(struct wlr_seat *seat, touch_point_create(seat, touch_id, surface, sx, sy); if (!point) { wlr_log(L_ERROR, "could not create touch point"); - return; + return 0; } - grab->interface->down(grab, time, point); + uint32_t serial = grab->interface->down(grab, time, point); - if (wl_list_length(&seat->touch_state.touch_points) == 1) { - seat->touch_state.grab_serial = wl_display_get_serial(seat->display); + if (serial && wlr_seat_touch_num_points(seat) == 1) { + seat->touch_state.grab_serial = serial; seat->touch_state.grab_id = touch_id; } + + return serial; } void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, @@ -1100,19 +1102,21 @@ void wlr_seat_touch_point_clear_focus(struct wlr_seat *seat, uint32_t time, touch_point_clear_focus(point); } -void wlr_seat_touch_send_down(struct wlr_seat *seat, +uint32_t wlr_seat_touch_send_down(struct wlr_seat *seat, struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, double sy) { struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); if (!point) { wlr_log(L_ERROR, "got touch down for unknown touch point"); - return; + return 0; } uint32_t serial = wl_display_next_serial(seat->display); wl_touch_send_down(point->client->touch, serial, time, surface->resource, touch_id, wl_fixed_from_double(sx), wl_fixed_from_double(sy)); wl_touch_send_frame(point->client->touch); + + return serial; } void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id) { From f61986e8dbadf1be3f3d850356d939ef57f942a0 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 16 Nov 2017 17:53:52 -0500 Subject: [PATCH 15/20] rename touch slot to touch id --- backend/libinput/touch.c | 8 ++++---- examples/pointer.c | 8 ++++---- examples/support/shared.c | 8 ++++---- examples/support/shared.h | 8 ++++---- examples/touch.c | 14 +++++++------- include/wlr/types/wlr_touch.h | 8 ++++---- rootston/cursor.c | 18 +++++++++--------- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index f133b678..0ba6ec86 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -33,7 +33,7 @@ void handle_touch_down(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); - wlr_event.slot = libinput_event_touch_get_slot(tevent); + wlr_event.touch_id = libinput_event_touch_get_slot(tevent); wlr_event.x_mm = libinput_event_touch_get_x(tevent); wlr_event.y_mm = libinput_event_touch_get_y(tevent); libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); @@ -54,7 +54,7 @@ void handle_touch_up(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); - wlr_event.slot = libinput_event_touch_get_slot(tevent); + wlr_event.touch_id = libinput_event_touch_get_slot(tevent); wl_signal_emit(&wlr_dev->touch->events.up, &wlr_event); } @@ -72,7 +72,7 @@ void handle_touch_motion(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); - wlr_event.slot = libinput_event_touch_get_slot(tevent); + wlr_event.touch_id = libinput_event_touch_get_slot(tevent); wlr_event.x_mm = libinput_event_touch_get_x(tevent); wlr_event.y_mm = libinput_event_touch_get_y(tevent); libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); @@ -93,6 +93,6 @@ void handle_touch_cancel(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); - wlr_event.slot = libinput_event_touch_get_slot(tevent); + wlr_event.touch_id = libinput_event_touch_get_slot(tevent); wl_signal_emit(&wlr_dev->touch->events.cancel, &wlr_event); } diff --git a/examples/pointer.c b/examples/pointer.c index 476cc617..8fafb3d6 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -55,7 +55,7 @@ struct sample_state { }; struct touch_point { - int32_t slot; + int32_t touch_id; double x, y; }; @@ -199,7 +199,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { struct wlr_event_touch_up *event = data; for (size_t i = 0; i < sample->touch_points->length; ++i) { struct touch_point *point = sample->touch_points->items[i]; - if (point->slot == event->slot) { + if (point->touch_id == event->touch_id) { wlr_list_del(sample->touch_points, i); break; } @@ -212,7 +212,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { struct sample_state *sample = wl_container_of(listener, sample, touch_down); struct wlr_event_touch_down *event = data; struct touch_point *point = calloc(1, sizeof(struct touch_point)); - point->slot = event->slot; + point->touch_id = event->touch_id; point->x = event->x_mm / event->width_mm; point->y = event->y_mm / event->height_mm; if (wlr_list_add(sample->touch_points, point) == -1) { @@ -228,7 +228,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { struct wlr_event_touch_motion *event = data; for (size_t i = 0; i < sample->touch_points->length; ++i) { struct touch_point *point = sample->touch_points->items[i]; - if (point->slot == event->slot) { + if (point->touch_id == event->touch_id) { point->x = event->x_mm / event->width_mm; point->y = event->y_mm / event->height_mm; break; diff --git a/examples/support/shared.c b/examples/support/shared.c index 07614d86..811c09a6 100644 --- a/examples/support/shared.c +++ b/examples/support/shared.c @@ -136,7 +136,7 @@ static void touch_down_notify(struct wl_listener *listener, void *data) { struct wlr_event_touch_down *event = data; struct touch_state *tstate = wl_container_of(listener, tstate, down); if (tstate->compositor->touch_down_cb) { - tstate->compositor->touch_down_cb(tstate, event->slot, + tstate->compositor->touch_down_cb(tstate, event->touch_id, event->x_mm, event->y_mm, event->width_mm, event->height_mm); } } @@ -145,7 +145,7 @@ static void touch_motion_notify(struct wl_listener *listener, void *data) { struct wlr_event_touch_motion *event = data; struct touch_state *tstate = wl_container_of(listener, tstate, motion); if (tstate->compositor->touch_motion_cb) { - tstate->compositor->touch_motion_cb(tstate, event->slot, + tstate->compositor->touch_motion_cb(tstate, event->touch_id, event->x_mm, event->y_mm, event->width_mm, event->height_mm); } } @@ -154,7 +154,7 @@ static void touch_up_notify(struct wl_listener *listener, void *data) { struct wlr_event_touch_up *event = data; struct touch_state *tstate = wl_container_of(listener, tstate, up); if (tstate->compositor->touch_up_cb) { - tstate->compositor->touch_up_cb(tstate, event->slot); + tstate->compositor->touch_up_cb(tstate, event->touch_id); } } @@ -162,7 +162,7 @@ static void touch_cancel_notify(struct wl_listener *listener, void *data) { struct wlr_event_touch_cancel *event = data; struct touch_state *tstate = wl_container_of(listener, tstate, cancel); if (tstate->compositor->touch_cancel_cb) { - tstate->compositor->touch_cancel_cb(tstate, event->slot); + tstate->compositor->touch_cancel_cb(tstate, event->touch_id); } } diff --git a/examples/support/shared.h b/examples/support/shared.h index cf75f5fe..014b709e 100644 --- a/examples/support/shared.h +++ b/examples/support/shared.h @@ -95,12 +95,12 @@ struct compositor_state { enum wlr_axis_source source, enum wlr_axis_orientation orientation, double delta); - void (*touch_down_cb)(struct touch_state *s, int32_t slot, + void (*touch_down_cb)(struct touch_state *s, int32_t touch_id, double x, double y, double width, double height); - void (*touch_motion_cb)(struct touch_state *s, int32_t slot, + void (*touch_motion_cb)(struct touch_state *s, int32_t touch_id, double x, double y, double width, double height); - void (*touch_up_cb)(struct touch_state *s, int32_t slot); - void (*touch_cancel_cb)(struct touch_state *s, int32_t slot); + void (*touch_up_cb)(struct touch_state *s, int32_t touch_id); + void (*touch_cancel_cb)(struct touch_state *s, int32_t touch_id); void (*tool_axis_cb)(struct tablet_tool_state *s, struct wlr_event_tablet_tool_axis *event); void (*tool_proximity_cb)(struct tablet_tool_state *s, diff --git a/examples/touch.c b/examples/touch.c index df6c6c48..d1891525 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -28,7 +28,7 @@ struct sample_state { }; struct touch_point { - int32_t slot; + int32_t touch_id; double x, y; }; @@ -58,11 +58,11 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_swap_buffers(wlr_output); } -static void handle_touch_down(struct touch_state *tstate, int32_t slot, +static void handle_touch_down(struct touch_state *tstate, int32_t touch_id, double x, double y, double width, double height) { struct sample_state *sample = tstate->compositor->data; struct touch_point *point = calloc(1, sizeof(struct touch_point)); - point->slot = slot; + point->touch_id = touch_id; point->x = x / width; point->y = y / height; if (wlr_list_add(sample->touch_points, point) == -1) { @@ -70,23 +70,23 @@ static void handle_touch_down(struct touch_state *tstate, int32_t slot, } } -static void handle_touch_up(struct touch_state *tstate, int32_t slot) { +static void handle_touch_up(struct touch_state *tstate, int32_t touch_id) { struct sample_state *sample = tstate->compositor->data; for (size_t i = 0; i < sample->touch_points->length; ++i) { struct touch_point *point = sample->touch_points->items[i]; - if (point->slot == slot) { + if (point->touch_id == touch_id) { wlr_list_del(sample->touch_points, i); break; } } } -static void handle_touch_motion(struct touch_state *tstate, int32_t slot, +static void handle_touch_motion(struct touch_state *tstate, int32_t touch_id, double x, double y, double width, double height) { struct sample_state *sample = tstate->compositor->data; for (size_t i = 0; i < sample->touch_points->length; ++i) { struct touch_point *point = sample->touch_points->items[i]; - if (point->slot == slot) { + if (point->touch_id == touch_id) { point->x = x / width; point->y = y / height; break; diff --git a/include/wlr/types/wlr_touch.h b/include/wlr/types/wlr_touch.h index 072e25fd..2925fd01 100644 --- a/include/wlr/types/wlr_touch.h +++ b/include/wlr/types/wlr_touch.h @@ -22,7 +22,7 @@ struct wlr_touch { struct wlr_event_touch_down { struct wlr_input_device *device; uint32_t time_msec; - int32_t slot; + int32_t touch_id; double x_mm, y_mm; double width_mm, height_mm; }; @@ -30,13 +30,13 @@ struct wlr_event_touch_down { struct wlr_event_touch_up { struct wlr_input_device *device; uint32_t time_msec; - int32_t slot; + int32_t touch_id; }; struct wlr_event_touch_motion { struct wlr_input_device *device; uint32_t time_msec; - int32_t slot; + int32_t touch_id; double x_mm, y_mm; double width_mm, height_mm; }; @@ -44,7 +44,7 @@ struct wlr_event_touch_motion { struct wlr_event_touch_cancel { struct wlr_input_device *device; uint32_t time_msec; - int32_t slot; + int32_t touch_id; }; #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 40618fe7..2a0550d6 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -237,11 +237,11 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, uint32_t serial = 0; if (surface) { serial = wlr_seat_touch_notify_down(cursor->seat->seat, surface, - event->time_msec, event->slot, sx, sy); + event->time_msec, event->touch_id, sx, sy); } if (serial && wlr_seat_touch_num_points(cursor->seat->seat) == 1) { - cursor->seat->touch_id = event->slot; + cursor->seat->touch_id = event->touch_id; cursor->seat->touch_x = lx; cursor->seat->touch_y = ly; roots_cursor_press_button(cursor, event->device, event->time_msec, @@ -251,7 +251,7 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, 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); + struct wlr_touch_point *point = wlr_seat_touch_get_point(cursor->seat->seat, event->touch_id); if (!point) { return; } @@ -261,14 +261,14 @@ void roots_cursor_handle_touch_up(struct roots_cursor *cursor, BTN_LEFT, 0, cursor->seat->touch_x, cursor->seat->touch_y); } - wlr_seat_touch_notify_up(cursor->seat->seat, event->time_msec, event->slot); + wlr_seat_touch_notify_up(cursor->seat->seat, event->time_msec, event->touch_id); } void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, struct wlr_event_touch_motion *event) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct wlr_touch_point *point = - wlr_seat_touch_get_point(cursor->seat->seat, event->slot); + wlr_seat_touch_get_point(cursor->seat->seat, event->touch_id); if (!point) { return; } @@ -288,15 +288,15 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, if (surface) { wlr_seat_touch_point_focus(cursor->seat->seat, surface, - event->time_msec, event->slot, sx, sy); + event->time_msec, event->touch_id, sx, sy); wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec, - event->slot, sx, sy); + event->touch_id, sx, sy); } else { wlr_seat_touch_point_clear_focus(cursor->seat->seat, event->time_msec, - event->slot); + event->touch_id); } - if (event->slot == cursor->seat->touch_id) { + if (event->touch_id == cursor->seat->touch_id) { cursor->seat->touch_x = lx; cursor->seat->touch_y = ly; } From 632759a49988e545ae9aff636c2095f295492293 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 17 Nov 2017 15:28:22 +0100 Subject: [PATCH 16/20] Fix segfault when xwayland is disabled --- rootston/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rootston/main.c b/rootston/main.c index 365ff6e0..814d3aef 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -58,8 +58,12 @@ int main(int argc, char **argv) { #ifndef HAS_XWAYLAND ready(NULL, NULL); #else - struct wl_listener xwayland_ready = { .notify = ready }; - wl_signal_add(&server.desktop->xwayland->events.ready, &xwayland_ready); + if (server.desktop->xwayland != NULL) { + struct wl_listener xwayland_ready = { .notify = ready }; + wl_signal_add(&server.desktop->xwayland->events.ready, &xwayland_ready); + } else { + ready(NULL, NULL); + } #endif wl_display_run(server.wl_display); From cd566ccd8e1c41af6b1d5f03fabdbdeaca2625ab Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 09:47:53 +0100 Subject: [PATCH 17/20] 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(-) 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; From 5b13f51dfc72493beb1ee0e95ae1eea9e53b8681 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 17:34:24 +0100 Subject: [PATCH 18/20] 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(-) 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, From f17c3947eafca8a1d73a937a30ed8794d23d14d4 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 18 Nov 2017 14:03:31 -0500 Subject: [PATCH 19/20] rootston: seat/cursor 80col cleanup --- rootston/cursor.c | 19 +++++++++++++------ rootston/seat.c | 33 ++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index 2a0550d6..10bb4dd3 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -28,7 +28,8 @@ void roots_cursor_destroy(struct roots_cursor *cursor) { // TODO } -static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) { +static void roots_cursor_update_position(struct roots_cursor *cursor, + uint32_t time) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct roots_seat *seat = cursor->seat; struct roots_view *view; @@ -137,7 +138,9 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, double 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)) { + if (state == WLR_BUTTON_PRESSED && + view && + roots_seat_has_meta_pressed(seat)) { roots_seat_focus_view(seat, view); uint32_t edges; @@ -170,7 +173,8 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, if (is_touch) { serial = wl_display_get_serial(desktop->server->wl_display); } else { - serial = wlr_seat_pointer_notify_button(seat->seat, time, button, state); + serial = + wlr_seat_pointer_notify_button(seat->seat, time, button, state); } int i; @@ -251,7 +255,8 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, 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->touch_id); + struct wlr_touch_point *point = + wlr_seat_touch_get_point(cursor->seat->seat, event->touch_id); if (!point) { return; } @@ -261,7 +266,8 @@ void roots_cursor_handle_touch_up(struct roots_cursor *cursor, BTN_LEFT, 0, cursor->seat->touch_x, cursor->seat->touch_y); } - wlr_seat_touch_notify_up(cursor->seat->seat, event->time_msec, event->touch_id); + wlr_seat_touch_notify_up(cursor->seat->seat, event->time_msec, + event->touch_id); } void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, @@ -331,7 +337,8 @@ void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, struct wlr_seat_pointer_request_set_cursor_event *event) { struct wlr_surface *focused_surface = event->seat_client->seat->pointer_state.focused_surface; - bool has_focused = focused_surface != NULL && focused_surface->resource != NULL; + bool has_focused = + focused_surface != NULL && focused_surface->resource != NULL; struct wl_client *focused_client = NULL; if (has_focused) { focused_client = wl_resource_get_client(focused_surface->resource); diff --git a/rootston/seat.c b/rootston/seat.c index 9412ff0c..1855ca49 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -31,7 +31,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { roots_cursor_handle_motion(cursor, event); } -static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) { +static void handle_cursor_motion_absolute(struct wl_listener *listener, + void *data) { struct roots_cursor *cursor = wl_container_of(listener, cursor, motion_absolute); struct wlr_event_pointer_motion_absolute *event = data; @@ -127,7 +128,8 @@ static void handle_touch_grab_end(struct wl_listener *listener, roots_cursor_handle_touch_grab_end(cursor, grab); } -static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) { +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; @@ -233,10 +235,12 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wl_signal_add(&wlr_cursor->events.touch_up, &seat->cursor->touch_up); seat->cursor->touch_up.notify = handle_touch_up; - wl_signal_add(&wlr_cursor->events.touch_motion, &seat->cursor->touch_motion); + wl_signal_add(&wlr_cursor->events.touch_motion, + &seat->cursor->touch_motion); seat->cursor->touch_motion.notify = handle_touch_motion; - wl_signal_add(&wlr_cursor->events.tablet_tool_axis, &seat->cursor->tool_axis); + wl_signal_add(&wlr_cursor->events.tablet_tool_axis, + &seat->cursor->tool_axis); seat->cursor->tool_axis.notify = handle_tool_axis; wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &seat->cursor->tool_tip); @@ -304,9 +308,11 @@ void roots_seat_destroy(struct roots_seat *seat) { // TODO } -static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) { +static void seat_add_keyboard(struct roots_seat *seat, + struct wlr_input_device *device) { assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); - struct roots_keyboard *keyboard = roots_keyboard_create(device, seat->input); + struct roots_keyboard *keyboard = + roots_keyboard_create(device, seat->input); if (keyboard == NULL) { wlr_log(L_ERROR, "could not allocate keyboard for seat"); return; @@ -327,7 +333,8 @@ static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device * wlr_seat_set_keyboard(seat->seat, device); } -static void seat_add_pointer(struct roots_seat *seat, struct wlr_input_device *device) { +static void seat_add_pointer(struct roots_seat *seat, + struct wlr_input_device *device) { struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1); if (!pointer) { wlr_log(L_ERROR, "could not allocate pointer for seat"); @@ -342,7 +349,8 @@ static void seat_add_pointer(struct roots_seat *seat, struct wlr_input_device *d roots_seat_configure_cursor(seat); } -static void seat_add_touch(struct roots_seat *seat, struct wlr_input_device *device) { +static void seat_add_touch(struct roots_seat *seat, + struct wlr_input_device *device) { struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1); if (!touch) { wlr_log(L_ERROR, "could not allocate touch for seat"); @@ -357,12 +365,15 @@ static void seat_add_touch(struct roots_seat *seat, struct wlr_input_device *dev roots_seat_configure_cursor(seat); } -static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) { +static void seat_add_tablet_pad(struct roots_seat *seat, + struct wlr_input_device *device) { // TODO } -static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) { - struct roots_tablet_tool *tablet_tool = calloc(sizeof(struct roots_tablet_tool), 1); +static void seat_add_tablet_tool(struct roots_seat *seat, + struct wlr_input_device *device) { + struct roots_tablet_tool *tablet_tool = + calloc(sizeof(struct roots_tablet_tool), 1); if (!tablet_tool) { wlr_log(L_ERROR, "could not allocate tablet_tool for seat"); return; From 458fe633df7827f5b74c034026b6b67045c1e610 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 18 Nov 2017 14:04:20 -0500 Subject: [PATCH 20/20] data-device: fix memory leak --- types/wlr_data_device.c | 1 + 1 file changed, 1 insertion(+) diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index eb8a3503..6328fd09 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -645,6 +645,7 @@ static bool seat_client_start_drag(struct wlr_seat_client *client, } if (!drag->is_pointer_grab && !is_touch_grab) { + free(drag); return true; }