aboutsummaryrefslogtreecommitdiff
path: root/rootston/seat.c
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2019-01-30 18:36:19 +0100
committeremersion <contact@emersion.fr>2019-02-20 18:42:29 +0100
commit6291e8453247053d2a706da7e1a5d7271e1774d2 (patch)
treea7151bfb81f6ce4f7d4faf839528cae37c6c5f17 /rootston/seat.c
parent18600f457be7a538e39914c37b72fee1a933ebe1 (diff)
data-device: refactor wlr_drag
Diffstat (limited to 'rootston/seat.c')
-rw-r--r--rootston/seat.c57
1 files changed, 47 insertions, 10 deletions
diff --git a/rootston/seat.c b/rootston/seat.c
index cd95472d..428787ef 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -603,10 +603,37 @@ static void roots_drag_icon_handle_destroy(struct wl_listener *listener,
free(icon);
}
-static void roots_seat_handle_new_drag_icon(struct wl_listener *listener,
+static void roots_seat_handle_request_start_drag(struct wl_listener *listener,
void *data) {
- struct roots_seat *seat = wl_container_of(listener, seat, new_drag_icon);
- struct wlr_drag_icon *wlr_drag_icon = data;
+ struct roots_seat *seat =
+ wl_container_of(listener, seat, request_start_drag);
+ struct wlr_seat_request_start_drag_event *event = data;
+
+ if (wlr_seat_validate_pointer_grab_serial(seat->seat,
+ event->origin, event->serial)) {
+ wlr_seat_start_pointer_drag(seat->seat, event->drag, event->serial);
+ return;
+ }
+
+ struct wlr_touch_point *point;
+ if (wlr_seat_validate_touch_grab_serial(seat->seat,
+ event->origin, event->serial, &point)) {
+ wlr_seat_start_touch_drag(seat->seat, event->drag, event->serial, point);
+ return;
+ }
+
+ wlr_log(WLR_DEBUG, "Ignoring start_drag request: "
+ "could not validate pointer or touch serial %" PRIu32, event->serial);
+}
+
+static void roots_seat_handle_start_drag(struct wl_listener *listener,
+ void *data) {
+ struct roots_seat *seat = wl_container_of(listener, seat, start_drag);
+ struct wlr_drag *wlr_drag = data;
+ struct wlr_drag_icon *wlr_drag_icon = wlr_drag->icon;
+ if (wlr_drag_icon == NULL) {
+ return;
+ }
struct roots_drag_icon *icon = calloc(1, sizeof(struct roots_drag_icon));
if (icon == NULL) {
@@ -649,20 +676,27 @@ static void roots_seat_handle_request_set_primary_selection(
void roots_drag_icon_update_position(struct roots_drag_icon *icon) {
roots_drag_icon_damage_whole(icon);
- struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
struct roots_seat *seat = icon->seat;
- struct wlr_cursor *cursor = seat->cursor->cursor;
- if (wlr_icon->is_pointer) {
+ struct wlr_drag *wlr_drag = icon->wlr_drag_icon->drag;
+ assert(wlr_drag != NULL);
+
+ switch (seat->seat->drag->grab_type) {
+ case WLR_DRAG_GRAB_KEYBOARD:
+ assert(false);
+ case WLR_DRAG_GRAB_KEYBOARD_POINTER:;
+ struct wlr_cursor *cursor = seat->cursor->cursor;
icon->x = cursor->x;
icon->y = cursor->y;
- } else {
+ break;
+ case WLR_DRAG_GRAB_KEYBOARD_TOUCH:;
struct wlr_touch_point *point =
- wlr_seat_touch_get_point(seat->seat, wlr_icon->touch_id);
+ wlr_seat_touch_get_point(seat->seat, wlr_drag->touch_id);
if (point == NULL) {
return;
}
icon->x = seat->touch_x;
icon->y = seat->touch_y;
+ break;
}
roots_drag_icon_damage_whole(icon);
@@ -738,8 +772,11 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
roots_seat_handle_request_set_primary_selection;
wl_signal_add(&seat->seat->events.request_set_primary_selection,
&seat->request_set_primary_selection);
- seat->new_drag_icon.notify = roots_seat_handle_new_drag_icon;
- wl_signal_add(&seat->seat->events.new_drag_icon, &seat->new_drag_icon);
+ seat->request_start_drag.notify = roots_seat_handle_request_start_drag;
+ wl_signal_add(&seat->seat->events.request_start_drag,
+ &seat->request_start_drag);
+ seat->start_drag.notify = roots_seat_handle_start_drag;
+ wl_signal_add(&seat->seat->events.start_drag, &seat->start_drag);
seat->destroy.notify = roots_seat_handle_destroy;
wl_signal_add(&seat->seat->events.destroy, &seat->destroy);