From 585646d2ad2a322da034b52fa494d697584ed144 Mon Sep 17 00:00:00 2001 From: Some Chinese Guy Date: Tue, 7 Apr 2020 11:59:27 +0300 Subject: [PATCH] fixed logic for keeping track of touch points --- include/slurp.h | 6 ++++-- main.c | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/slurp.h b/include/slurp.h index 3be3c1c..8d411bb 100644 --- a/include/slurp.h +++ b/include/slurp.h @@ -9,6 +9,8 @@ #include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h" +#define TOUCH_ID_EMPTY -1 + struct slurp_box { int32_t x, y; int32_t width, height; @@ -82,8 +84,8 @@ struct slurp_seat { int32_t anchor_x, anchor_y; struct slurp_box selection; bool has_selection; - bool already_touched; - + int32_t touch_id; + // pointer: struct wl_pointer *wl_pointer; enum wl_pointer_button_state button_state; diff --git a/main.c b/main.c index 152ad87..641e93d 100644 --- a/main.c +++ b/main.c @@ -236,8 +236,8 @@ static void touch_handle_down(void *data, struct wl_touch *touch, struct wl_surface *surface, int32_t id, wl_fixed_t x, wl_fixed_t y) { struct slurp_seat *seat = data; - if (!seat->already_touched) { - seat->already_touched = true; + if (seat->touch_id == TOUCH_ID_EMPTY) { + seat->touch_id = id; seat->current_output = output_from_surface(seat->state, surface); move_seat(seat, x, y); @@ -246,7 +246,7 @@ static void touch_handle_down(void *data, struct wl_touch *touch, } static void touch_clear_state(struct slurp_seat *seat) { - seat->already_touched = false; + seat->touch_id = TOUCH_ID_EMPTY; seat->current_output = NULL; } @@ -261,9 +261,11 @@ static void touch_handle_motion(void *data, struct wl_touch *touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y) { struct slurp_seat *seat = data; - move_seat(seat, x, y); - handle_active_selection_motion(seat); - seat_set_outputs_dirty(seat); + if (seat->touch_id == id) { + move_seat(seat, x, y); + handle_active_selection_motion(seat); + seat_set_outputs_dirty(seat); + } } static void touch_handle_cancel(void *data, struct wl_touch *touch) { @@ -311,6 +313,7 @@ static void create_seat(struct slurp_state *state, struct wl_seat *wl_seat) { } seat->state = state; seat->wl_seat = wl_seat; + seat->touch_id = TOUCH_ID_EMPTY; wl_list_insert(&state->seats, &seat->link); wl_seat_add_listener(wl_seat, &seat_listener, seat); }