diff options
author | Tadeo Kondrak <me@tadeo.ca> | 2019-10-28 18:26:00 -0600 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-11-17 13:34:24 +0100 |
commit | 4829f1c26a521a4ef6659d91505112cc0be8d237 (patch) | |
tree | 4e0987c668241600401755630afe40c3879ca06a /sway/commands/input | |
parent | xwayland: get_constraints using size hints (diff) | |
download | sway-4829f1c26a521a4ef6659d91505112cc0be8d237.tar.gz sway-4829f1c26a521a4ef6659d91505112cc0be8d237.tar.zst sway-4829f1c26a521a4ef6659d91505112cc0be8d237.zip |
Implement input map_to_region command
Diffstat (limited to 'sway/commands/input')
-rw-r--r-- | sway/commands/input/map_to_region.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sway/commands/input/map_to_region.c b/sway/commands/input/map_to_region.c new file mode 100644 index 00000000..e0b69ed5 --- /dev/null +++ b/sway/commands/input/map_to_region.c | |||
@@ -0,0 +1,56 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <wlr/types/wlr_box.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/config.h" | ||
7 | |||
8 | struct cmd_results *input_cmd_map_to_region(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "map_to_region", EXPECTED_EQUAL_TO, 4))) { | ||
11 | return error; | ||
12 | } | ||
13 | struct input_config *ic = config->handler_context.input_config; | ||
14 | if (!ic) { | ||
15 | return cmd_results_new(CMD_FAILURE, "No input device defined"); | ||
16 | } | ||
17 | |||
18 | // This is used to clear the current output mapping. | ||
19 | ic->mapped_to_output = strdup(""); | ||
20 | |||
21 | ic->mapped_to_region = calloc(1, sizeof(struct wlr_box)); | ||
22 | |||
23 | const char *errstr; | ||
24 | char *end; | ||
25 | |||
26 | ic->mapped_to_region->x = strtol(argv[0], &end, 10); | ||
27 | if (end[0] != '\0') { | ||
28 | errstr = "Invalid X coordinate"; | ||
29 | goto error; | ||
30 | } | ||
31 | |||
32 | ic->mapped_to_region->y = strtol(argv[1], &end, 10); | ||
33 | if (end[0] != '\0') { | ||
34 | errstr = "Invalid Y coordinate"; | ||
35 | goto error; | ||
36 | } | ||
37 | |||
38 | ic->mapped_to_region->width = strtol(argv[2], &end, 10); | ||
39 | if (end[0] != '\0' || ic->mapped_to_region->width < 1) { | ||
40 | errstr = "Invalid width"; | ||
41 | goto error; | ||
42 | } | ||
43 | |||
44 | ic->mapped_to_region->height = strtol(argv[3], &end, 10); | ||
45 | if (end[0] != '\0' || ic->mapped_to_region->height < 1) { | ||
46 | errstr = "Invalid height"; | ||
47 | goto error; | ||
48 | } | ||
49 | |||
50 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
51 | |||
52 | error: | ||
53 | free(ic->mapped_to_region); | ||
54 | ic->mapped_to_region = NULL; | ||
55 | return cmd_results_new(CMD_FAILURE, errstr); | ||
56 | } | ||