diff options
Diffstat (limited to 'sway/commands/input/scroll_button.c')
-rw-r--r-- | sway/commands/input/scroll_button.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/sway/commands/input/scroll_button.c b/sway/commands/input/scroll_button.c new file mode 100644 index 00000000..350fcca2 --- /dev/null +++ b/sway/commands/input/scroll_button.c | |||
@@ -0,0 +1,44 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include <errno.h> | ||
4 | #include "sway/config.h" | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/input/input-manager.h" | ||
7 | |||
8 | struct cmd_results *input_cmd_scroll_button(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | struct input_config *current_input_config = | ||
14 | config->handler_context.input_config; | ||
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "scroll_button", | ||
17 | "No input device defined."); | ||
18 | } | ||
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | |||
22 | errno = 0; | ||
23 | char *endptr; | ||
24 | int scroll_button = strtol(*argv, &endptr, 10); | ||
25 | if (endptr == *argv && scroll_button == 0) { | ||
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "scroll_button", | ||
28 | "Scroll button identifier must be an integer."); | ||
29 | } | ||
30 | if (errno == ERANGE) { | ||
31 | free_input_config(new_config); | ||
32 | return cmd_results_new(CMD_INVALID, "scroll_button", | ||
33 | "Scroll button identifier out of range."); | ||
34 | } | ||
35 | if (scroll_button < 0) { | ||
36 | free_input_config(new_config); | ||
37 | return cmd_results_new(CMD_INVALID, "scroll_button", | ||
38 | "Scroll button identifier cannot be negative."); | ||
39 | } | ||
40 | new_config->scroll_button = scroll_button; | ||
41 | |||
42 | apply_input_config(new_config); | ||
43 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
44 | } | ||