Add scroll factor config option.

master
Spencer Michaels 6 years ago
parent b87250425f
commit 70bc4c3ab6

@ -3,6 +3,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <float.h>
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -140,6 +141,17 @@ bool parse_boolean(const char *boolean, bool current) {
return false; return false;
} }
float parse_float(const char *value) {
errno = 0;
char *end;
float flt = strtof(value, &end);
if (*end || errno) {
wlr_log(WLR_DEBUG, "Invalid float value '%s', defaulting to NAN", value);
return NAN;
}
return flt;
}
enum wlr_direction opposite_direction(enum wlr_direction d) { enum wlr_direction opposite_direction(enum wlr_direction d) {
switch (d) { switch (d) {
case WLR_DIRECTION_UP: case WLR_DIRECTION_UP:

@ -229,6 +229,7 @@ sway_cmd input_cmd_map_to_output;
sway_cmd input_cmd_middle_emulation; sway_cmd input_cmd_middle_emulation;
sway_cmd input_cmd_natural_scroll; sway_cmd input_cmd_natural_scroll;
sway_cmd input_cmd_pointer_accel; sway_cmd input_cmd_pointer_accel;
sway_cmd input_cmd_scroll_factor;
sway_cmd input_cmd_repeat_delay; sway_cmd input_cmd_repeat_delay;
sway_cmd input_cmd_repeat_rate; sway_cmd input_cmd_repeat_rate;
sway_cmd input_cmd_scroll_button; sway_cmd input_cmd_scroll_button;

@ -100,6 +100,7 @@ struct input_config {
int middle_emulation; int middle_emulation;
int natural_scroll; int natural_scroll;
float pointer_accel; float pointer_accel;
float scroll_factor;
int repeat_delay; int repeat_delay;
int repeat_rate; int repeat_rate;
int scroll_button; int scroll_button;

@ -59,6 +59,12 @@ uint32_t parse_color(const char *color);
*/ */
bool parse_boolean(const char *boolean, bool current); bool parse_boolean(const char *boolean, bool current);
/**
* Given a string that represents a floating point value, return a float.
* Returns NAN on error.
*/
float parse_float(const char *value);
enum wlr_direction opposite_direction(enum wlr_direction d); enum wlr_direction opposite_direction(enum wlr_direction d);
#endif #endif

@ -22,6 +22,7 @@ static struct cmd_handler input_handlers[] = {
{ "repeat_delay", input_cmd_repeat_delay }, { "repeat_delay", input_cmd_repeat_delay },
{ "repeat_rate", input_cmd_repeat_rate }, { "repeat_rate", input_cmd_repeat_rate },
{ "scroll_button", input_cmd_scroll_button }, { "scroll_button", input_cmd_scroll_button },
{ "scroll_factor", input_cmd_scroll_factor },
{ "scroll_method", input_cmd_scroll_method }, { "scroll_method", input_cmd_scroll_method },
{ "tap", input_cmd_tap }, { "tap", input_cmd_tap },
{ "tap_button_map", input_cmd_tap_button_map }, { "tap_button_map", input_cmd_tap_button_map },

@ -1,8 +1,10 @@
#include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "sway/config.h" #include "sway/config.h"
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "util.h"
struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) {
struct cmd_results *error = NULL; 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."); "pointer_accel", "No input device defined.");
} }
float pointer_accel = atof(argv[0]); float pointer_accel = parse_float(argv[0]);
if (pointer_accel < -1 || pointer_accel > 1) { 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", return cmd_results_new(CMD_INVALID, "pointer_accel",
"Input out of range [-1, 1]"); "Input out of range [-1, 1]");
} }

@ -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);
}

@ -29,6 +29,7 @@ struct input_config *new_input_config(const char* identifier) {
input->natural_scroll = INT_MIN; input->natural_scroll = INT_MIN;
input->accel_profile = INT_MIN; input->accel_profile = INT_MIN;
input->pointer_accel = FLT_MIN; input->pointer_accel = FLT_MIN;
input->scroll_factor = FLT_MIN;
input->scroll_button = INT_MIN; input->scroll_button = INT_MIN;
input->scroll_method = INT_MIN; input->scroll_method = INT_MIN;
input->left_handed = 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) { if (src->pointer_accel != FLT_MIN) {
dst->pointer_accel = src->pointer_accel; dst->pointer_accel = src->pointer_accel;
} }
if (src->scroll_factor != FLT_MIN) {
dst->scroll_factor = src->scroll_factor;
}
if (src->repeat_delay != INT_MIN) { if (src->repeat_delay != INT_MIN) {
dst->repeat_delay = src->repeat_delay; dst->repeat_delay = src->repeat_delay;
} }

@ -5,6 +5,7 @@
#elif __FreeBSD__ #elif __FreeBSD__
#include <dev/evdev/input-event-codes.h> #include <dev/evdev/input-event-codes.h>
#endif #endif
#include <float.h>
#include <limits.h> #include <limits.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_xcursor_manager.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, static void dispatch_cursor_axis(struct sway_cursor *cursor,
struct wlr_event_pointer_axis *event) { struct wlr_event_pointer_axis *event) {
struct sway_seat *seat = cursor->seat; 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 // Determine what's under the cursor
struct wlr_surface *surface = NULL; 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; enum wlr_edges edge = cont ? find_edge(cont, cursor) : WLR_EDGE_NONE;
bool on_border = edge != WLR_EDGE_NONE; bool on_border = edge != WLR_EDGE_NONE;
bool on_titlebar = cont && !on_border && !surface; 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 // Scrolling on a tabbed or stacked title bar
if (on_titlebar) { if (on_titlebar) {
@ -1000,7 +1005,7 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
seat_get_active_tiling_child(seat, tabcontainer); seat_get_active_tiling_child(seat, tabcontainer);
list_t *siblings = container_get_siblings(cont); list_t *siblings = container_get_siblings(cont);
int desired = list_find(siblings, active->sway_container) + int desired = list_find(siblings, active->sway_container) +
event->delta_discrete; round(scroll_factor * event->delta_discrete);
if (desired < 0) { if (desired < 0) {
desired = 0; desired = 0;
} else if (desired >= siblings->length) { } 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, 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) { static void handle_cursor_axis(struct wl_listener *listener, void *data) {

@ -135,6 +135,7 @@ sway_sources = files(
'commands/input/repeat_delay.c', 'commands/input/repeat_delay.c',
'commands/input/repeat_rate.c', 'commands/input/repeat_rate.c',
'commands/input/scroll_button.c', 'commands/input/scroll_button.c',
'commands/input/scroll_factor.c',
'commands/input/scroll_method.c', 'commands/input/scroll_method.c',
'commands/input/tap.c', 'commands/input/tap.c',
'commands/input/tap_button_map.c', 'commands/input/tap_button_map.c',

@ -105,14 +105,18 @@ The following commands may only be used in the configuration file.
*input* <identifier> repeat\_rate <characters per second> *input* <identifier> repeat\_rate <characters per second>
Sets the frequency of key repeats once the repeat\_delay has passed. 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> *input* <identifier> scroll\_button <button\_identifier>
Sets button used for scroll\_method on\_button\_down. The button identifier Sets button used for scroll\_method on\_button\_down. The button identifier
can be obtained from `libinput debug-events`. can be obtained from `libinput debug-events`.
If set to 0, it disables the scroll\_button on\_button\_down. 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 *input* <identifier> tap enabled|disabled
Enables or disables tap for specified input device. Enables or disables tap for specified input device.

Loading…
Cancel
Save