Reset swipe on other cursor rebase

This commit is contained in:
Erik Reider 2024-01-24 11:12:50 +01:00
parent 0da822151d
commit 1fedb1a1ee
3 changed files with 38 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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);