From 1fedb1a1ee96c4299f7f3bb4223ff0e98730cf8b Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:12:50 +0100 Subject: [PATCH] Reset swipe on other cursor rebase --- include/sway/output.h | 4 ++++ sway/desktop/output.c | 18 +++++++++++++++++- sway/input/seatop_default.c | 17 +++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/sway/output.h b/include/sway/output.h index 22033a76..cb6889ae 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -217,6 +217,8 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener, struct workspace_scroll workspace_scroll_get_default(); +bool workspace_scroll_equal(struct workspace_scroll *a, struct workspace_scroll *b); + void workspace_scroll_begin(struct sway_seat *seat, enum swipe_gesture_direction direction); @@ -225,6 +227,8 @@ void workspace_scroll_update(struct sway_seat *seat, double delta_sum, void workspace_scroll_end(struct sway_seat *seat); +void workspace_scroll_reset(struct sway_seat *seat, struct sway_workspace *ws); + struct sway_output_non_desktop *output_non_desktop_create(struct wlr_output *wlr_output); #endif diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 196fd906..3247a0e6 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -1126,6 +1126,13 @@ struct workspace_scroll workspace_scroll_get_default() { }; } +bool workspace_scroll_equal(struct workspace_scroll *a, struct workspace_scroll *b) { + return a->avg_velocity == b->avg_velocity && + a->direction == b->direction && + a->num_updates == b->num_updates && + a->percent == b->percent; +} + void workspace_scroll_begin(struct sway_seat *seat, enum swipe_gesture_direction direction) { struct sway_workspace *focused_ws = seat_get_focused_workspace(seat); @@ -1232,7 +1239,16 @@ void workspace_scroll_end(struct sway_seat *seat) { sway_log(SWAY_DEBUG, "Switched to workspace: %s\n", focused_ws->name); reset_state: - workspace_switch(focused_ws); + workspace_scroll_reset(seat, focused_ws); +} + +void workspace_scroll_reset(struct sway_seat *seat, struct sway_workspace *ws) { + if (!ws) { + ws = seat_get_focused_workspace(seat); + } + struct sway_output *output = ws->output; + + workspace_switch(ws); seat_consider_warp_to_focus(seat); // Reset the state diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c index 6d861318..d6a3b749 100644 --- a/sway/input/seatop_default.c +++ b/sway/input/seatop_default.c @@ -1131,6 +1131,23 @@ static void handle_rebase(struct sway_seat *seat, uint32_t time_msec) { e->previous_node = node_at_coords(seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + // Reset the swipe if any other button is pressed during the swipe + struct sway_workspace *focused_ws = seat_get_focused_workspace(seat); + if (focused_ws) { + switch (e->gestures.type) { + default: + break; + case GESTURE_TYPE_WORKSPACE_SWIPE_HORIZONTAL:; + case GESTURE_TYPE_WORKSPACE_SWIPE_VERTICAL:; + struct sway_output *output = focused_ws->output; + struct workspace_scroll workspace_scroll_default = workspace_scroll_get_default(); + if (!workspace_scroll_equal(&output->workspace_scroll, &workspace_scroll_default)) { + workspace_scroll_reset(seat, NULL); + } + break; + } + } + if (surface) { if (seat_is_input_allowed(seat, surface)) { wlr_seat_pointer_notify_enter(seat->wlr_seat, surface, sx, sy);