Skip to content

input/seatop_default: handle continuous scroll events #8678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/sway/input/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "sway/input/seat.h"
#include "config.h"

#define SWAY_CONTINUOUS_SCROLL_TIMEOUT 1000
#define SWAY_CURSOR_PRESSED_BUTTONS_CAP 32

#define SWAY_SCROLL_UP KEY_MAX + 1
Expand Down
6 changes: 6 additions & 0 deletions include/sway/input/seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ struct sway_drag {
struct wl_listener destroy;
};

struct sway_scroll_axis {
double value;
uint32_t time_msec;
};

struct sway_seat {
struct wlr_seat *wlr_seat;
struct sway_cursor *cursor;
struct sway_scroll_axis axis[2];

// Seat scene tree structure
// - scene_tree
Expand Down
32 changes: 31 additions & 1 deletion sway/input/seatop_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,35 @@ static uint32_t wl_axis_to_button(struct wlr_pointer_axis_event *event) {
}
}

static int calc_scroll_steps(struct sway_seat *seat,
struct wlr_pointer_axis_event *event, float scroll_factor) {
if (event->delta_discrete) {
return roundf(scroll_factor * event->delta_discrete /
WLR_POINTER_AXIS_DISCRETE_STEP);
}
if (!sway_assert(event->orientation < 2, "axis out of range")) {
return 0;
}

struct sway_scroll_axis *axis = &seat->axis[event->orientation];
if (event->time_msec - axis->time_msec > SWAY_CONTINUOUS_SCROLL_TIMEOUT) {
axis->value = 0;
}

axis->value += scroll_factor * event->delta;
axis->time_msec = event->time_msec;
if (axis->value > WLR_POINTER_AXIS_DISCRETE_STEP) {
axis->value -= WLR_POINTER_AXIS_DISCRETE_STEP;
return 1;
}
if (axis->value < -WLR_POINTER_AXIS_DISCRETE_STEP) {
axis->value += WLR_POINTER_AXIS_DISCRETE_STEP;
return -1;
}

return 0;
}

static void handle_pointer_axis(struct sway_seat *seat,
struct wlr_pointer_axis_event *event) {
struct sway_input_device *input_device =
Expand Down Expand Up @@ -758,8 +787,9 @@ 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 desired = list_find(siblings, active->sway_container) +
roundf(scroll_factor * event->delta_discrete / WLR_POINTER_AXIS_DISCRETE_STEP);
calc_scroll_steps(seat, event, scroll_factor);
if (desired < 0) {
desired = 0;
} else if (desired >= siblings->length) {
Expand Down