diff options
author | Spencer Michaels <spencer@smichaels.net> | 2018-11-17 14:31:33 -0500 |
---|---|---|
committer | Spencer Michaels <spencer@smichaels.net> | 2018-11-18 13:49:30 -0500 |
commit | 70bc4c3ab6c408850543d827f788ef310fdb269c (patch) | |
tree | 265d4ea923f1329d1e7661c0f92a242337318d58 /sway | |
parent | b87250425fe13149e41b346f15c5cf808f376438 (diff) |
Add scroll factor config option.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/input.c | 1 | ||||
-rw-r--r-- | sway/commands/input/pointer_accel.c | 9 | ||||
-rw-r--r-- | sway/commands/input/scroll_factor.c | 32 | ||||
-rw-r--r-- | sway/config/input.c | 4 | ||||
-rw-r--r-- | sway/input/cursor.c | 10 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway-input.5.scd | 10 |
7 files changed, 60 insertions, 7 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c index c50926a8..b5765c38 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -22,6 +22,7 @@ static struct cmd_handler input_handlers[] = { { "repeat_delay", input_cmd_repeat_delay }, { "repeat_rate", input_cmd_repeat_rate }, { "scroll_button", input_cmd_scroll_button }, + { "scroll_factor", input_cmd_scroll_factor }, { "scroll_method", input_cmd_scroll_method }, { "tap", input_cmd_tap }, { "tap_button_map", input_cmd_tap_button_map }, diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c index df487b1c..efd81ee6 100644 --- a/sway/commands/input/pointer_accel.c +++ b/sway/commands/input/pointer_accel.c @@ -1,8 +1,10 @@ +#include <math.h> #include <stdlib.h> #include <string.h> #include "sway/config.h" #include "sway/commands.h" #include "sway/input/input-manager.h" +#include "util.h" struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { struct cmd_results *error = NULL; @@ -15,8 +17,11 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { "pointer_accel", "No input device defined."); } - float pointer_accel = atof(argv[0]); - if (pointer_accel < -1 || pointer_accel > 1) { + float pointer_accel = parse_float(argv[0]); + if (isnan(pointer_accel)) { + return cmd_results_new(CMD_INVALID, "pointer_accel", + "Invalid pointer accel; expected float."); + } if (pointer_accel < -1 || pointer_accel > 1) { return cmd_results_new(CMD_INVALID, "pointer_accel", "Input out of range [-1, 1]"); } diff --git a/sway/commands/input/scroll_factor.c b/sway/commands/input/scroll_factor.c new file mode 100644 index 00000000..52d943b0 --- /dev/null +++ b/sway/commands/input/scroll_factor.c @@ -0,0 +1,32 @@ +#include <errno.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input/input-manager.h" +#include "util.h" + +struct cmd_results *input_cmd_scroll_factor(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "scroll_factor", EXPECTED_AT_LEAST, 1))) { + return error; + } + struct input_config *ic = config->handler_context.input_config; + if (!ic) { + return cmd_results_new(CMD_FAILURE, + "scroll_factor", "No input device defined."); + } + + float scroll_factor = parse_float(argv[0]); + if (isnan(scroll_factor)) { + return cmd_results_new(CMD_INVALID, "scroll_factor", + "Invalid scroll factor; expected float."); + } else if (scroll_factor < 0) { + return cmd_results_new(CMD_INVALID, "scroll_factor", + "Scroll factor cannot be negative."); + } + ic->scroll_factor = scroll_factor; + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config/input.c b/sway/config/input.c index 794d5194..d5d2d90b 100644 --- a/sway/config/input.c +++ b/sway/config/input.c @@ -29,6 +29,7 @@ struct input_config *new_input_config(const char* identifier) { input->natural_scroll = INT_MIN; input->accel_profile = INT_MIN; input->pointer_accel = FLT_MIN; + input->scroll_factor = FLT_MIN; input->scroll_button = INT_MIN; input->scroll_method = INT_MIN; input->left_handed = INT_MIN; @@ -68,6 +69,9 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { if (src->pointer_accel != FLT_MIN) { dst->pointer_accel = src->pointer_accel; } + if (src->scroll_factor != FLT_MIN) { + dst->scroll_factor = src->scroll_factor; + } if (src->repeat_delay != INT_MIN) { dst->repeat_delay = src->repeat_delay; } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index c6b7414c..d89f64d8 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -5,6 +5,7 @@ #elif __FreeBSD__ #include <dev/evdev/input-event-codes.h> #endif +#include <float.h> #include <limits.h> #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_xcursor_manager.h> @@ -979,6 +980,8 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { static void dispatch_cursor_axis(struct sway_cursor *cursor, struct wlr_event_pointer_axis *event) { struct sway_seat *seat = cursor->seat; + struct sway_input_device *input_device = event->device->data; + struct input_config *ic = input_device_get_config(input_device); // Determine what's under the cursor struct wlr_surface *surface = NULL; @@ -990,6 +993,8 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor, enum wlr_edges edge = cont ? find_edge(cont, cursor) : WLR_EDGE_NONE; bool on_border = edge != WLR_EDGE_NONE; bool on_titlebar = cont && !on_border && !surface; + float scroll_factor = + (ic == NULL || ic->scroll_factor == FLT_MIN) ? 1.0f : ic->scroll_factor; // Scrolling on a tabbed or stacked title bar if (on_titlebar) { @@ -1000,7 +1005,7 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor, seat_get_active_tiling_child(seat, tabcontainer); list_t *siblings = container_get_siblings(cont); int desired = list_find(siblings, active->sway_container) + - event->delta_discrete; + round(scroll_factor * event->delta_discrete); if (desired < 0) { desired = 0; } else if (desired >= siblings->length) { @@ -1024,7 +1029,8 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor, } wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, - event->orientation, event->delta, event->delta_discrete, event->source); + event->orientation, scroll_factor * event->delta, + round(scroll_factor * event->delta_discrete), event->source); } static void handle_cursor_axis(struct wl_listener *listener, void *data) { diff --git a/sway/meson.build b/sway/meson.build index cde09a02..d9bc08f3 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -135,6 +135,7 @@ sway_sources = files( 'commands/input/repeat_delay.c', 'commands/input/repeat_rate.c', 'commands/input/scroll_button.c', + 'commands/input/scroll_factor.c', 'commands/input/scroll_method.c', 'commands/input/tap.c', 'commands/input/tap_button_map.c', diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index 82273ef3..45994644 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -105,14 +105,18 @@ The following commands may only be used in the configuration file. *input* <identifier> repeat\_rate <characters per second> Sets the frequency of key repeats once the repeat\_delay has passed. -*input* <identifier> scroll\_method none|two\_finger|edge|on\_button\_down - Changes the scroll method for the specified input device. - *input* <identifier> scroll\_button <button\_identifier> Sets button used for scroll\_method on\_button\_down. The button identifier can be obtained from `libinput debug-events`. If set to 0, it disables the scroll\_button on\_button\_down. +*input* <identifier> scroll\_factor <floating point value> + Changes the scroll factor for the specified input device. Scroll speed will + be scaled by the given value, which must be non-negative. + +*input* <identifier> scroll\_method none|two\_finger|edge|on\_button\_down + Changes the scroll method for the specified input device. + *input* <identifier> tap enabled|disabled Enables or disables tap for specified input device. |