Skip to content

Commit

Permalink
Fixed tracker value being updated even if percent isn't
Browse files Browse the repository at this point in the history
Fixes long swipes still updating the tracker value even if the percent wasn't changed
  • Loading branch information
ErikReider committed Jan 25, 2024
1 parent b491ac4 commit 4f9ac2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions include/sway/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ bool workspace_scroll_equal(struct workspace_scroll *a, struct workspace_scroll
void workspace_scroll_begin(struct sway_seat *seat,
enum swipe_gesture_direction direction);

void workspace_scroll_update(struct sway_seat *seat, double delta_sum,
enum swipe_gesture_direction direction);
void workspace_scroll_update(struct sway_seat *seat, struct gesture_tracker *tracker,
struct wlr_pointer_swipe_update_event *event, int invert);

void workspace_scroll_end(struct sway_seat *seat);

Expand Down
26 changes: 24 additions & 2 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,23 @@ void workspace_scroll_begin(struct sway_seat *seat,
seat_set_focus_workspace(seat, NULL);
}

void workspace_scroll_update(struct sway_seat *seat, double delta_sum,
enum swipe_gesture_direction direction) {
void workspace_scroll_update(struct sway_seat *seat, struct gesture_tracker *tracker,
struct wlr_pointer_swipe_update_event *event, int invert) {
double delta_sum;
enum swipe_gesture_direction direction;
switch (tracker->type) {
case GESTURE_TYPE_WORKSPACE_SWIPE_HORIZONTAL:
direction = SWIPE_GESTURE_DIRECTION_HORIZONTAL;
delta_sum = tracker->dx + event->dx * invert;
break;
case GESTURE_TYPE_WORKSPACE_SWIPE_VERTICAL:
direction = SWIPE_GESTURE_DIRECTION_VERTICAL;
delta_sum = tracker->dy + event->dy * invert;
break;
default:
return;
}

struct sway_workspace *focused_ws = seat_get_focused_workspace(seat);
struct sway_output *output = focused_ws->output;
struct workspace_scroll *ws_scroll = &output->workspace_scroll;
Expand Down Expand Up @@ -1197,6 +1212,13 @@ void workspace_scroll_update(struct sway_seat *seat, double delta_sum,
}
}
}

// Update the tracker data if we aren't exceeding the max swipe limit
if (percent < max && percent > min) {
tracker->dx += event->dx * invert;
tracker->dy += event->dy * invert;
}

ws_scroll->percent = CLAMP(percent, min, max);
ws_scroll->direction = direction;

Expand Down
15 changes: 1 addition & 14 deletions sway/input/seatop_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,20 +1057,7 @@ static void handle_swipe_update(struct sway_seat *seat,

if (binding) {
int invert = binding->flags & BINDING_INVERTED ? 1 : -1;
tracker->dx += event->dx * invert;
tracker->dy += event->dy * invert;
switch (binding->gesture.type) {
case GESTURE_TYPE_WORKSPACE_SWIPE_HORIZONTAL:
workspace_scroll_update(seat, tracker->dx,
SWIPE_GESTURE_DIRECTION_HORIZONTAL);
break;
case GESTURE_TYPE_WORKSPACE_SWIPE_VERTICAL:
workspace_scroll_update(seat, tracker->dy,
SWIPE_GESTURE_DIRECTION_VERTICAL);
break;
default:
break;
}
workspace_scroll_update(seat, tracker, event, invert);
}
} else {
// ... otherwise forward to client
Expand Down

0 comments on commit 4f9ac2d

Please sign in to comment.