From 5b30391383be7e31ae1b213f2a6095bd7a95defc Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 18 Apr 2018 23:19:23 +1000 Subject: [PATCH 1/3] Make key repeat configurable This creates two input commands for configuring the repeat delay and rate. Example config: input "myidentifier" { repeat_delay 250 repeat_rate 25 } --- include/sway/commands.h | 2 ++ include/sway/config.h | 2 ++ sway/commands.c | 2 ++ sway/commands/input.c | 4 +++ sway/commands/input/repeat.c | 55 ++++++++++++++++++++++++++++++++++++ sway/config/input.c | 8 ++++++ sway/input/keyboard.c | 9 +++++- sway/meson.build | 1 + sway/sway-input.5.txt | 6 ++++ 9 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 sway/commands/input/repeat.c diff --git a/include/sway/commands.h b/include/sway/commands.h index dbebaa491..7b8c949b1 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -196,6 +196,8 @@ sway_cmd input_cmd_map_to_output; sway_cmd input_cmd_middle_emulation; sway_cmd input_cmd_natural_scroll; sway_cmd input_cmd_pointer_accel; +sway_cmd input_cmd_repeat_delay; +sway_cmd input_cmd_repeat_rate; sway_cmd input_cmd_scroll_method; sway_cmd input_cmd_tap; sway_cmd input_cmd_xkb_layout; diff --git a/include/sway/config.h b/include/sway/config.h index ed49fbbd2..085f7b922 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -65,6 +65,8 @@ struct input_config { int middle_emulation; int natural_scroll; float pointer_accel; + int repeat_delay; + int repeat_rate; int scroll_method; int send_events; int tap; diff --git a/sway/commands.c b/sway/commands.c index 99f425245..fb3eaa750 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -191,6 +191,8 @@ static struct cmd_handler input_handlers[] = { { "middle_emulation", input_cmd_middle_emulation }, { "natural_scroll", input_cmd_natural_scroll }, { "pointer_accel", input_cmd_pointer_accel }, + { "repeat_delay", input_cmd_repeat_delay }, + { "repeat_rate", input_cmd_repeat_rate }, { "scroll_method", input_cmd_scroll_method }, { "tap", input_cmd_tap }, { "xkb_layout", input_cmd_xkb_layout }, diff --git a/sway/commands/input.c b/sway/commands/input.c index fa9cf05a6..eeb4ee75c 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -55,6 +55,10 @@ struct cmd_results *cmd_input(int argc, char **argv) { res = input_cmd_natural_scroll(argc_new, argv_new); } else if (strcasecmp("pointer_accel", argv[1]) == 0) { res = input_cmd_pointer_accel(argc_new, argv_new); + } else if (strcasecmp("repeat_delay", argv[1]) == 0) { + res = input_cmd_repeat_delay(argc_new, argv_new); + } else if (strcasecmp("repeat_rate", argv[1]) == 0) { + res = input_cmd_repeat_rate(argc_new, argv_new); } else if (strcasecmp("scroll_method", argv[1]) == 0) { res = input_cmd_scroll_method(argc_new, argv_new); } else if (strcasecmp("tap", argv[1]) == 0) { diff --git a/sway/commands/input/repeat.c b/sway/commands/input/repeat.c new file mode 100644 index 000000000..b2f6fa46c --- /dev/null +++ b/sway/commands/input/repeat.c @@ -0,0 +1,55 @@ +#include +#include +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input/input-manager.h" + +struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "repeat_delay", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct input_config *current_input_config = + config->handler_context.input_config; + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, + "repeat_delay", "No input device defined."); + } + struct input_config *new_config = + new_input_config(current_input_config->identifier); + + int repeat_delay = atoi(argv[0]); + if (repeat_delay < 0) { + return cmd_results_new(CMD_INVALID, "repeat_delay", + "Repeat delay cannot be negative"); + } + new_config->repeat_delay = repeat_delay; + + apply_input_config(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + +struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct input_config *current_input_config = + config->handler_context.input_config; + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, + "repeat_rate", "No input device defined."); + } + struct input_config *new_config = + new_input_config(current_input_config->identifier); + + int repeat_rate = atoi(argv[0]); + if (repeat_rate < 0) { + return cmd_results_new(CMD_INVALID, "repeat_rate", + "Repeat rate cannot be negative"); + } + new_config->repeat_rate = repeat_rate; + + apply_input_config(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config/input.c b/sway/config/input.c index 5e657c439..a9f207238 100644 --- a/sway/config/input.c +++ b/sway/config/input.c @@ -29,6 +29,8 @@ struct input_config *new_input_config(const char* identifier) { input->pointer_accel = FLT_MIN; input->scroll_method = INT_MIN; input->left_handed = INT_MIN; + input->repeat_delay = INT_MIN; + input->repeat_rate = INT_MIN; return input; } @@ -59,6 +61,12 @@ 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->repeat_delay != INT_MIN) { + dst->repeat_delay = src->repeat_delay; + } + if (src->repeat_rate != INT_MIN) { + dst->repeat_rate = src->repeat_rate; + } if (src->scroll_method != INT_MIN) { dst->scroll_method = src->scroll_method; } diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index dbb0c3596..dbf2ce013 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -1,4 +1,5 @@ #include +#include #include #include #include "sway/input/seat.h" @@ -479,7 +480,13 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) { keyboard->keymap = keymap; wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap); - wlr_keyboard_set_repeat_info(wlr_device->keyboard, 25, 600); + if (input_config && input_config->repeat_delay != INT_MIN + && input_config->repeat_rate != INT_MIN) { + wlr_keyboard_set_repeat_info(wlr_device->keyboard, + input_config->repeat_rate, input_config->repeat_delay); + } else { + wlr_keyboard_set_repeat_info(wlr_device->keyboard, 25, 600); + } xkb_context_unref(context); struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat; wlr_seat_set_keyboard(seat, wlr_device); diff --git a/sway/meson.build b/sway/meson.build index 9e55e335f..7dfda254d 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -90,6 +90,7 @@ sway_sources = files( 'commands/input/middle_emulation.c', 'commands/input/natural_scroll.c', 'commands/input/pointer_accel.c', + 'commands/input/repeat.c', 'commands/input/scroll_method.c', 'commands/input/tap.c', 'commands/input/xkb_layout.c', diff --git a/sway/sway-input.5.txt b/sway/sway-input.5.txt index 057253606..c3380f54f 100644 --- a/sway/sway-input.5.txt +++ b/sway/sway-input.5.txt @@ -92,6 +92,12 @@ Libinput Configuration **input** pointer_accel <[-1,1]>:: Changes the pointer acceleration for the specified input device. +**input** repeat_delay :: + Sets the amount of time a key must be held before it starts repeating. + +**input** repeat_rate :: + Sets the frequency of key repeats once the repeat_delay has passed. + **input** scroll_method :: Changes the scroll method for the specified input device. From 9d3739a6f787edee185baa5e0746e72c07f9314f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 19 Apr 2018 13:47:29 +1000 Subject: [PATCH 2/3] Split repeat commands into separate files. --- .../input/{repeat.c => repeat_delay.c} | 25 ---------------- sway/commands/input/repeat_rate.c | 30 +++++++++++++++++++ sway/meson.build | 3 +- 3 files changed, 32 insertions(+), 26 deletions(-) rename sway/commands/input/{repeat.c => repeat_delay.c} (54%) create mode 100644 sway/commands/input/repeat_rate.c diff --git a/sway/commands/input/repeat.c b/sway/commands/input/repeat_delay.c similarity index 54% rename from sway/commands/input/repeat.c rename to sway/commands/input/repeat_delay.c index b2f6fa46c..ce2658415 100644 --- a/sway/commands/input/repeat.c +++ b/sway/commands/input/repeat_delay.c @@ -28,28 +28,3 @@ struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) { apply_input_config(new_config); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } - -struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) { - struct cmd_results *error = NULL; - if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) { - return error; - } - struct input_config *current_input_config = - config->handler_context.input_config; - if (!current_input_config) { - return cmd_results_new(CMD_FAILURE, - "repeat_rate", "No input device defined."); - } - struct input_config *new_config = - new_input_config(current_input_config->identifier); - - int repeat_rate = atoi(argv[0]); - if (repeat_rate < 0) { - return cmd_results_new(CMD_INVALID, "repeat_rate", - "Repeat rate cannot be negative"); - } - new_config->repeat_rate = repeat_rate; - - apply_input_config(new_config); - return cmd_results_new(CMD_SUCCESS, NULL, NULL); -} diff --git a/sway/commands/input/repeat_rate.c b/sway/commands/input/repeat_rate.c new file mode 100644 index 000000000..f2ea2e692 --- /dev/null +++ b/sway/commands/input/repeat_rate.c @@ -0,0 +1,30 @@ +#include +#include +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input/input-manager.h" + +struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct input_config *current_input_config = + config->handler_context.input_config; + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, + "repeat_rate", "No input device defined."); + } + struct input_config *new_config = + new_input_config(current_input_config->identifier); + + int repeat_rate = atoi(argv[0]); + if (repeat_rate < 0) { + return cmd_results_new(CMD_INVALID, "repeat_rate", + "Repeat rate cannot be negative"); + } + new_config->repeat_rate = repeat_rate; + + apply_input_config(new_config); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/meson.build b/sway/meson.build index 7dfda254d..4ceb07b40 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -90,7 +90,8 @@ sway_sources = files( 'commands/input/middle_emulation.c', 'commands/input/natural_scroll.c', 'commands/input/pointer_accel.c', - 'commands/input/repeat.c', + 'commands/input/repeat_delay.c', + 'commands/input/repeat_rate.c', 'commands/input/scroll_method.c', 'commands/input/tap.c', 'commands/input/xkb_layout.c', From 9ab61716b5017fc2aec3ed03bd4687dfb8c5fe9f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 19 Apr 2018 13:48:20 +1000 Subject: [PATCH 3/3] Correct the repeat_rate documentation. --- sway/sway-input.5.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/sway-input.5.txt b/sway/sway-input.5.txt index c3380f54f..948b4b6f5 100644 --- a/sway/sway-input.5.txt +++ b/sway/sway-input.5.txt @@ -95,7 +95,7 @@ Libinput Configuration **input** repeat_delay :: Sets the amount of time a key must be held before it starts repeating. -**input** repeat_rate :: +**input** repeat_rate :: Sets the frequency of key repeats once the repeat_delay has passed. **input** scroll_method ::