diff --git a/include/sway/commands.h b/include/sway/commands.h index 2746ef28f..e4c39b0b6 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -258,6 +258,7 @@ sway_cmd input_cmd_map_to_region; sway_cmd input_cmd_middle_emulation; sway_cmd input_cmd_natural_scroll; sway_cmd input_cmd_pointer_accel; +sway_cmd input_cmd_sensitivity; sway_cmd input_cmd_scroll_factor; sway_cmd input_cmd_repeat_delay; sway_cmd input_cmd_repeat_rate; diff --git a/include/sway/config.h b/include/sway/config.h index 538930f22..f3f5ee117 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -147,6 +147,7 @@ struct input_config { int middle_emulation; int natural_scroll; float pointer_accel; + float sensitivity; float scroll_factor; int repeat_delay; int repeat_rate; diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index c9bd08f0d..a5b167189 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -73,4 +73,6 @@ char *input_device_get_identifier(struct wlr_input_device *device); const char *input_device_get_type(struct sway_input_device *device); +struct sway_input_device *input_sway_device_from_wlr(struct wlr_input_device *device); + #endif diff --git a/sway/commands/input.c b/sway/commands/input.c index 77acb671b..f27f94285 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -27,6 +27,7 @@ static const struct cmd_handler input_handlers[] = { { "scroll_button", input_cmd_scroll_button }, { "scroll_factor", input_cmd_scroll_factor }, { "scroll_method", input_cmd_scroll_method }, + { "sensitivity", input_cmd_sensitivity }, { "tap", input_cmd_tap }, { "tap_button_map", input_cmd_tap_button_map }, { "tool_mode", input_cmd_tool_mode }, diff --git a/sway/commands/input/sensitivity.c b/sway/commands/input/sensitivity.c new file mode 100644 index 000000000..d57bcff05 --- /dev/null +++ b/sway/commands/input/sensitivity.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input/input-manager.h" +#include "util.h" + +struct cmd_results *input_cmd_sensitivity(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "sensitivity", EXPECTED_AT_LEAST, 1))) { + return error; + } + struct input_config *ic = config->handler_context.input_config; + if (!ic) { + return cmd_results_new(CMD_FAILURE, "No input device defined."); + } + + float sensitivity = parse_float(argv[0]); + if (isnan(sensitivity)) { + return cmd_results_new(CMD_INVALID, + "Invalid sensitivity; expected float."); + } else if (sensitivity < 0) { + return cmd_results_new(CMD_INVALID, + "Sensitivity cannot be negative."); + } + ic->sensitivity = sensitivity; + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/config/input.c b/sway/config/input.c index a998e1704..348df673d 100644 --- a/sway/config/input.c +++ b/sway/config/input.c @@ -31,6 +31,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->sensitivity = FLT_MIN; input->scroll_factor = FLT_MIN; input->scroll_button = INT_MIN; input->scroll_method = INT_MIN; @@ -73,6 +74,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->sensitivity != FLT_MIN) { + dst->sensitivity = src->sensitivity; + } if (src->scroll_factor != FLT_MIN) { dst->scroll_factor = src->scroll_factor; } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index f0be27937..f48e41bad 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 200809L #include #include +#include #include #include #include @@ -21,6 +22,7 @@ #include "sway/commands.h" #include "sway/desktop.h" #include "sway/input/cursor.h" +#include "sway/input/input-manager.h" #include "sway/input/keyboard.h" #include "sway/input/tablet.h" #include "sway/layers.h" @@ -29,7 +31,8 @@ #include "sway/tree/root.h" #include "sway/tree/view.h" #include "sway/tree/workspace.h" -#include "wlr-layer-shell-unstable-v1-protocol.h" +#include "sway/commands.h" +#include "sway/config.h" static uint32_t get_current_time_msec(void) { struct timespec now; @@ -374,7 +377,7 @@ static void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, return; } - dx = sx_confined - sx; + dx = sx_confined - sx; dy = sy_confined - sy; } @@ -387,9 +390,14 @@ static void handle_pointer_motion_relative( struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, motion); struct wlr_event_pointer_motion *e = data; + + struct sway_input_device *sid = input_sway_device_from_wlr(e->device); + struct input_config *ic = sid ? input_device_get_config(sid) : NULL; + float sensitivity = (ic && ic->sensitivity != FLT_MIN) ? ic->sensitivity : 1.0f; + cursor_handle_activity_from_device(cursor, e->device); - pointer_motion(cursor, e->time_msec, e->device, e->delta_x, e->delta_y, + pointer_motion(cursor, e->time_msec, e->device, e->delta_x * sensitivity, e->delta_y * sensitivity, e->unaccel_dx, e->unaccel_dy); } diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 8538d97ca..88e199b3c 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -154,7 +154,7 @@ static void apply_input_type_config(struct sway_input_device *input_device) { } } -static struct sway_input_device *input_sway_device_from_wlr( +struct sway_input_device *input_sway_device_from_wlr( struct wlr_input_device *device) { struct sway_input_device *input_device = NULL; wl_list_for_each(input_device, &server.input->devices, link) { diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 8357ae04e..cd5bd5525 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -1010,12 +1010,21 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) { if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { struct input_config *ic = input_device_get_config(device); float scroll_factor = 1.0f; - if (ic != NULL && !isnan(ic->scroll_factor) && - ic->scroll_factor != FLT_MIN) { - scroll_factor = ic->scroll_factor; + float sensitivity = 1.0f; + if (ic != NULL) { + if (!isnan(ic->scroll_factor) && ic->scroll_factor != FLT_MIN) { + scroll_factor = ic->scroll_factor; + } + + if (!isnan(ic->sensitivity) && ic->sensitivity != FLT_MIN) { + sensitivity = ic->sensitivity; + } } + json_object_object_add(object, "scroll_factor", json_object_new_double(scroll_factor)); + json_object_object_add(object, "sensitivity", + json_object_new_double(sensitivity)); } if (wlr_input_device_is_libinput(device->wlr_device)) { diff --git a/sway/meson.build b/sway/meson.build index 5f34ce6b0..71c74817a 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -162,6 +162,7 @@ sway_sources = files( 'commands/input/middle_emulation.c', 'commands/input/natural_scroll.c', 'commands/input/pointer_accel.c', + 'commands/input/sensitivity.c', 'commands/input/repeat_delay.c', 'commands/input/repeat_rate.c', 'commands/input/scroll_button.c', diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index 8b702b778..f387edc8c 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -171,6 +171,10 @@ The following commands may only be used in the configuration file. *input* pointer_accel [<-1|1>] Changes the pointer acceleration for the specified input device. +*input* sensitivity + Multiplies the sensitivity of a relative pointing input device. Has no + effect on absolute pointing devices. + *input* scroll_button disable|button[1-3,8,9]| Sets the button used for scroll_method on_button_down. The button can be given as an event name or code, which can be obtained from *libinput diff --git a/sway/sway-ipc.7.scd b/sway/sway-ipc.7.scd index d90fe97ae..c1a330c68 100644 --- a/sway/sway-ipc.7.scd +++ b/sway/sway-ipc.7.scd @@ -1134,6 +1134,9 @@ following properties: |- scroll_factor : floating : (Only pointers) Multiplier applied on scroll event values. +|- sensitivity +: floating +: (Only pointers) Multiplier applied on relative pointer movements. |- libinput : object : (Only libinput devices) An object describing the current device settings.