summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-04-18 23:19:23 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-04-18 23:19:23 +1000
commit5b30391383be7e31ae1b213f2a6095bd7a95defc (patch)
tree96ad3f77bf2538401d5538e0e0ba9c12c99f32b6
parentMerge pull request #1819 from emersion/destroy-display (diff)
downloadsway-5b30391383be7e31ae1b213f2a6095bd7a95defc.tar.gz
sway-5b30391383be7e31ae1b213f2a6095bd7a95defc.tar.zst
sway-5b30391383be7e31ae1b213f2a6095bd7a95defc.zip
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 }
-rw-r--r--include/sway/commands.h2
-rw-r--r--include/sway/config.h2
-rw-r--r--sway/commands.c2
-rw-r--r--sway/commands/input.c4
-rw-r--r--sway/commands/input/repeat.c55
-rw-r--r--sway/config/input.c8
-rw-r--r--sway/input/keyboard.c9
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-input.5.txt6
9 files changed, 88 insertions, 1 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index dbebaa49..7b8c949b 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -196,6 +196,8 @@ sway_cmd input_cmd_map_to_output;
196sway_cmd input_cmd_middle_emulation; 196sway_cmd input_cmd_middle_emulation;
197sway_cmd input_cmd_natural_scroll; 197sway_cmd input_cmd_natural_scroll;
198sway_cmd input_cmd_pointer_accel; 198sway_cmd input_cmd_pointer_accel;
199sway_cmd input_cmd_repeat_delay;
200sway_cmd input_cmd_repeat_rate;
199sway_cmd input_cmd_scroll_method; 201sway_cmd input_cmd_scroll_method;
200sway_cmd input_cmd_tap; 202sway_cmd input_cmd_tap;
201sway_cmd input_cmd_xkb_layout; 203sway_cmd input_cmd_xkb_layout;
diff --git a/include/sway/config.h b/include/sway/config.h
index ed49fbbd..085f7b92 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -65,6 +65,8 @@ struct input_config {
65 int middle_emulation; 65 int middle_emulation;
66 int natural_scroll; 66 int natural_scroll;
67 float pointer_accel; 67 float pointer_accel;
68 int repeat_delay;
69 int repeat_rate;
68 int scroll_method; 70 int scroll_method;
69 int send_events; 71 int send_events;
70 int tap; 72 int tap;
diff --git a/sway/commands.c b/sway/commands.c
index 99f42524..fb3eaa75 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -191,6 +191,8 @@ static struct cmd_handler input_handlers[] = {
191 { "middle_emulation", input_cmd_middle_emulation }, 191 { "middle_emulation", input_cmd_middle_emulation },
192 { "natural_scroll", input_cmd_natural_scroll }, 192 { "natural_scroll", input_cmd_natural_scroll },
193 { "pointer_accel", input_cmd_pointer_accel }, 193 { "pointer_accel", input_cmd_pointer_accel },
194 { "repeat_delay", input_cmd_repeat_delay },
195 { "repeat_rate", input_cmd_repeat_rate },
194 { "scroll_method", input_cmd_scroll_method }, 196 { "scroll_method", input_cmd_scroll_method },
195 { "tap", input_cmd_tap }, 197 { "tap", input_cmd_tap },
196 { "xkb_layout", input_cmd_xkb_layout }, 198 { "xkb_layout", input_cmd_xkb_layout },
diff --git a/sway/commands/input.c b/sway/commands/input.c
index fa9cf05a..eeb4ee75 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -55,6 +55,10 @@ struct cmd_results *cmd_input(int argc, char **argv) {
55 res = input_cmd_natural_scroll(argc_new, argv_new); 55 res = input_cmd_natural_scroll(argc_new, argv_new);
56 } else if (strcasecmp("pointer_accel", argv[1]) == 0) { 56 } else if (strcasecmp("pointer_accel", argv[1]) == 0) {
57 res = input_cmd_pointer_accel(argc_new, argv_new); 57 res = input_cmd_pointer_accel(argc_new, argv_new);
58 } else if (strcasecmp("repeat_delay", argv[1]) == 0) {
59 res = input_cmd_repeat_delay(argc_new, argv_new);
60 } else if (strcasecmp("repeat_rate", argv[1]) == 0) {
61 res = input_cmd_repeat_rate(argc_new, argv_new);
58 } else if (strcasecmp("scroll_method", argv[1]) == 0) { 62 } else if (strcasecmp("scroll_method", argv[1]) == 0) {
59 res = input_cmd_scroll_method(argc_new, argv_new); 63 res = input_cmd_scroll_method(argc_new, argv_new);
60 } else if (strcasecmp("tap", argv[1]) == 0) { 64 } 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 00000000..b2f6fa46
--- /dev/null
+++ b/sway/commands/input/repeat.c
@@ -0,0 +1,55 @@
1#include <stdlib.h>
2#include <string.h>
3#include "sway/config.h"
4#include "sway/commands.h"
5#include "sway/input/input-manager.h"
6
7struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) {
8 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "repeat_delay", EXPECTED_EQUAL_TO, 1))) {
10 return error;
11 }
12 struct input_config *current_input_config =
13 config->handler_context.input_config;
14 if (!current_input_config) {
15 return cmd_results_new(CMD_FAILURE,
16 "repeat_delay", "No input device defined.");
17 }
18 struct input_config *new_config =
19 new_input_config(current_input_config->identifier);
20
21 int repeat_delay = atoi(argv[0]);
22 if (repeat_delay < 0) {
23 return cmd_results_new(CMD_INVALID, "repeat_delay",
24 "Repeat delay cannot be negative");
25 }
26 new_config->repeat_delay = repeat_delay;
27
28 apply_input_config(new_config);
29 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
30}
31
32struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) {
33 struct cmd_results *error = NULL;
34 if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) {
35 return error;
36 }
37 struct input_config *current_input_config =
38 config->handler_context.input_config;
39 if (!current_input_config) {
40 return cmd_results_new(CMD_FAILURE,
41 "repeat_rate", "No input device defined.");
42 }
43 struct input_config *new_config =
44 new_input_config(current_input_config->identifier);
45
46 int repeat_rate = atoi(argv[0]);
47 if (repeat_rate < 0) {
48 return cmd_results_new(CMD_INVALID, "repeat_rate",
49 "Repeat rate cannot be negative");
50 }
51 new_config->repeat_rate = repeat_rate;
52
53 apply_input_config(new_config);
54 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
55}
diff --git a/sway/config/input.c b/sway/config/input.c
index 5e657c43..a9f20723 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -29,6 +29,8 @@ struct input_config *new_input_config(const char* identifier) {
29 input->pointer_accel = FLT_MIN; 29 input->pointer_accel = FLT_MIN;
30 input->scroll_method = INT_MIN; 30 input->scroll_method = INT_MIN;
31 input->left_handed = INT_MIN; 31 input->left_handed = INT_MIN;
32 input->repeat_delay = INT_MIN;
33 input->repeat_rate = INT_MIN;
32 34
33 return input; 35 return input;
34} 36}
@@ -59,6 +61,12 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
59 if (src->pointer_accel != FLT_MIN) { 61 if (src->pointer_accel != FLT_MIN) {
60 dst->pointer_accel = src->pointer_accel; 62 dst->pointer_accel = src->pointer_accel;
61 } 63 }
64 if (src->repeat_delay != INT_MIN) {
65 dst->repeat_delay = src->repeat_delay;
66 }
67 if (src->repeat_rate != INT_MIN) {
68 dst->repeat_rate = src->repeat_rate;
69 }
62 if (src->scroll_method != INT_MIN) { 70 if (src->scroll_method != INT_MIN) {
63 dst->scroll_method = src->scroll_method; 71 dst->scroll_method = src->scroll_method;
64 } 72 }
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index dbb0c359..dbf2ce01 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -1,4 +1,5 @@
1#include <assert.h> 1#include <assert.h>
2#include <limits.h>
2#include <wlr/backend/multi.h> 3#include <wlr/backend/multi.h>
3#include <wlr/backend/session.h> 4#include <wlr/backend/session.h>
4#include "sway/input/seat.h" 5#include "sway/input/seat.h"
@@ -479,7 +480,13 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
479 keyboard->keymap = keymap; 480 keyboard->keymap = keymap;
480 wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap); 481 wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap);
481 482
482 wlr_keyboard_set_repeat_info(wlr_device->keyboard, 25, 600); 483 if (input_config && input_config->repeat_delay != INT_MIN
484 && input_config->repeat_rate != INT_MIN) {
485 wlr_keyboard_set_repeat_info(wlr_device->keyboard,
486 input_config->repeat_rate, input_config->repeat_delay);
487 } else {
488 wlr_keyboard_set_repeat_info(wlr_device->keyboard, 25, 600);
489 }
483 xkb_context_unref(context); 490 xkb_context_unref(context);
484 struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat; 491 struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat;
485 wlr_seat_set_keyboard(seat, wlr_device); 492 wlr_seat_set_keyboard(seat, wlr_device);
diff --git a/sway/meson.build b/sway/meson.build
index 9e55e335..7dfda254 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -90,6 +90,7 @@ sway_sources = files(
90 'commands/input/middle_emulation.c', 90 'commands/input/middle_emulation.c',
91 'commands/input/natural_scroll.c', 91 'commands/input/natural_scroll.c',
92 'commands/input/pointer_accel.c', 92 'commands/input/pointer_accel.c',
93 'commands/input/repeat.c',
93 'commands/input/scroll_method.c', 94 'commands/input/scroll_method.c',
94 'commands/input/tap.c', 95 'commands/input/tap.c',
95 'commands/input/xkb_layout.c', 96 'commands/input/xkb_layout.c',
diff --git a/sway/sway-input.5.txt b/sway/sway-input.5.txt
index 05725360..c3380f54 100644
--- a/sway/sway-input.5.txt
+++ b/sway/sway-input.5.txt
@@ -92,6 +92,12 @@ Libinput Configuration
92**input** <identifier> pointer_accel <[-1,1]>:: 92**input** <identifier> pointer_accel <[-1,1]>::
93 Changes the pointer acceleration for the specified input device. 93 Changes the pointer acceleration for the specified input device.
94 94
95**input** <identifier> repeat_delay <milliseconds>::
96 Sets the amount of time a key must be held before it starts repeating.
97
98**input** <identifier> repeat_rate <milliseconds>::
99 Sets the frequency of key repeats once the repeat_delay has passed.
100
95**input** <identifier> scroll_method <none|two_finger|edge|on_button_down>:: 101**input** <identifier> scroll_method <none|two_finger|edge|on_button_down>::
96 Changes the scroll method for the specified input device. 102 Changes the scroll method for the specified input device.
97 103