diff --git a/common/util.c b/common/util.c index 5ea94f48..f8cc9c37 100644 --- a/common/util.c +++ b/common/util.c @@ -142,3 +142,16 @@ bool sway_set_cloexec(int fd, bool cloexec) { } return true; } + +float _distance_scrolled = 0; +void scroll_distance_add(float delta) { + _distance_scrolled += delta; +} + +void scroll_distance_reset() { + _distance_scrolled = 0; +} + +float scroll_distance_get() { + return _distance_scrolled; +} diff --git a/include/util.h b/include/util.h index c80da1cb..7c38ba48 100644 --- a/include/util.h +++ b/include/util.h @@ -67,4 +67,8 @@ const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel); bool sway_set_cloexec(int fd, bool cloexec); +void scroll_distance_add(float delta); +void scroll_distance_reset(); +float scroll_distance_get(); + #endif diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c index f9eb8c8a..4e51e692 100644 --- a/sway/input/seatop_default.c +++ b/sway/input/seatop_default.c @@ -12,6 +12,7 @@ #include "sway/tree/view.h" #include "sway/tree/workspace.h" #include "log.h" +#include "util.h" #if HAVE_XWAYLAND #include "sway/xwayland.h" #endif @@ -709,8 +710,17 @@ static void handle_pointer_axis(struct sway_seat *seat, struct sway_node *active = seat_get_active_tiling_child(seat, tabcontainer); list_t *siblings = container_get_siblings(cont); + int delta_discrete = event->delta_discrete; + if (delta_discrete == 0) { + scroll_distance_add(event->delta); + float dist = scroll_distance_get(); + delta_discrete = round(dist / 10.); + if (abs(delta_discrete) > 0) { + scroll_distance_reset(); + } + } int desired = list_find(siblings, active->sway_container) + - round(scroll_factor * event->delta_discrete); + round(scroll_factor * delta_discrete); if (desired < 0) { desired = 0; } else if (desired >= siblings->length) {