From c9292de59d8f2ac3ea06eb34e5810883ea5265f1 Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 22 Jul 2023 18:30:27 +0200 Subject: [PATCH] Add scrolldistance option, allowing scroll distance to be configured in the config file --- docs/spmenu.conf | 5 ++++- libs/conf/config.c | 1 + libs/options.h | 3 +++ libs/wl/wayland.c | 13 +++++++++---- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 8729582..e71d9da 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -269,7 +269,10 @@ spmenu = { { click = "None"; button = "Scroll Up"; function = "moveprev"; argument = "0"; }, // Scroll Up: Move to the previous page { click = "None"; button = "Scroll Down"; function = "movenext"; argument = "0"; }, // Scroll Down: Move to the next page - { ignoreglobalmouse = 1; } ); // Ignore hardcoded mouse binds (0/1) + { + scrolldistance = 512; // Distance to scroll for a scroll action to count (num) + ignoreglobalmouse = 1; // Ignore hardcoded mouse binds (0/1) + } ); /* Keys * diff --git a/libs/conf/config.c b/libs/conf/config.c index adac70e..8961d91 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -968,6 +968,7 @@ void conf_init(void) { } config_setting_lookup_int(conf, "ignoreglobalmouse", &sp.ignoreglobalmouse); + config_setting_lookup_int(conf, "scrolldistance", &scrolldistance); } } diff --git a/libs/options.h b/libs/options.h index cb6f883..eb91193 100644 --- a/libs/options.h +++ b/libs/options.h @@ -11,6 +11,9 @@ static int loadtheme = 1; /* Load theme (~/.config/spmenu/them static int loadbinds = 1; /* Load keybind file (~/.config/spmenu/binds.conf) on runtime */ static int mon = -1; /* Monitor to run spmenu on */ +/* Wayland options */ +static int scrolldistance = 512; /* Distance to scroll for a scroll action to count */ + /* Config file options */ #if USECONFIG static char *configfile = NULL; /* Config file path. Default is ~/.config/spmenu/spmenu.conf */ diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index cd7164a..5331ceb 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -382,14 +382,19 @@ void pointer_motion_handler(void *data, struct wl_pointer *pointer, uint32_t tim } void pointer_axis_handler(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) { - mouse_scroll = 1; - - if (value > 0) { + if (value > scrolldistance) { mouse_scroll_direction = 0; - } else { + } else if (value < -scrolldistance) { mouse_scroll_direction = 1; + } else { + mouse_scroll = 0; + mouse_scroll_direction = -1; + + return; } + mouse_scroll = 1; + buttonpress_wl(mouse_scroll_direction, mouse_x, mouse_y); mouse_scroll = 0;