diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-11-12 17:04:56 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-11-15 08:34:48 -0500 |
commit | 4240096b83989c4820aad33f9a866148e6b9e250 (patch) | |
tree | 65616f14621276958c1b6c4a2ab422ac873cdeba | |
parent | e5a31ae87054dacfbdea6ebf4ceba92dbd067e36 (diff) |
wlr-seat: default touch grab
-rw-r--r-- | include/wlr/types/wlr_seat.h | 36 | ||||
-rw-r--r-- | rootston/cursor.c | 1 | ||||
-rw-r--r-- | 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; } |