From 1141a97c8db56be9c91730091e3516c6129bede4 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Fri, 29 Dec 2023 00:16:52 -0700 Subject: [PATCH] fix: Ignore release without matching press Fixes: #146 --- main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 135c98a..dacbd87 100644 --- a/main.c +++ b/main.c @@ -242,6 +242,8 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) { struct slurp_seat *seat = data; + enum wl_pointer_button_state prev_state = seat->button_state; + if (seat->touch_selection.has_selection) { return; } @@ -253,7 +255,11 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, handle_selection_start(seat, &seat->pointer_selection); break; case WL_POINTER_BUTTON_STATE_RELEASED: - handle_selection_end(seat, &seat->pointer_selection); + // Ignore a release event, if we didn't get the pressed event. + // That probably means the press happened before slurp started. + if (prev_state == WL_POINTER_BUTTON_STATE_PRESSED) { + handle_selection_end(seat, &seat->pointer_selection); + } break; } }