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 | df1a0468756b4a6d68cc5904313c4630edf14dd1 (diff) |
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 @@ +#define _POSIX_C_SOURCE 200809L +#include <stdlib.h> +#include <string.h> +#include <wlr/types/wlr_box.h> +#include "sway/commands.h" +#include "sway/config.h" + +struct cmd_results *input_cmd_map_to_region(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "map_to_region", EXPECTED_EQUAL_TO, 4))) { + return error; + } + struct input_config *ic = config->handler_context.input_config; + if (!ic) { + return cmd_results_new(CMD_FAILURE, "No input device defined"); + } + + // This is used to clear the current output mapping. + ic->mapped_to_output = strdup(""); + + ic->mapped_to_region = calloc(1, sizeof(struct wlr_box)); + + const char *errstr; + char *end; + + ic->mapped_to_region->x = strtol(argv[0], &end, 10); + if (end[0] != '\0') { + errstr = "Invalid X coordinate"; + goto error; + } + + ic->mapped_to_region->y = strtol(argv[1], &end, 10); + if (end[0] != '\0') { + errstr = "Invalid Y coordinate"; + goto error; + } + + ic->mapped_to_region->width = strtol(argv[2], &end, 10); + if (end[0] != '\0' || ic->mapped_to_region->width < 1) { + errstr = "Invalid width"; + goto error; + } + + ic->mapped_to_region->height = strtol(argv[3], &end, 10); + if (end[0] != '\0' || ic->mapped_to_region->height < 1) { + errstr = "Invalid height"; + goto error; + } + + return cmd_results_new(CMD_SUCCESS, NULL); + +error: + free(ic->mapped_to_region); + ic->mapped_to_region = NULL; + return cmd_results_new(CMD_FAILURE, errstr); +} |