aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/input
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-04-24 19:39:29 +0100
committerLibravatar emersion <contact@emersion.fr>2018-04-26 10:53:47 +0100
commitff61df17ffd358b03663a35fe7140e51e1ee98fc (patch)
tree3736887591d8464f577d2ad4a753a404d38d77ae /sway/commands/input
parentMerge pull request #1863 from RyanDwyer/remove-workspace-layout (diff)
downloadsway-ff61df17ffd358b03663a35fe7140e51e1ee98fc.tar.gz
sway-ff61df17ffd358b03663a35fe7140e51e1ee98fc.tar.zst
sway-ff61df17ffd358b03663a35fe7140e51e1ee98fc.zip
Add map_from_region command
Diffstat (limited to 'sway/commands/input')
-rw-r--r--sway/commands/input/map_from_region.c79
-rw-r--r--sway/commands/input/map_to_output.c2
2 files changed, 80 insertions, 1 deletions
diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c
new file mode 100644
index 00000000..80bb856d
--- /dev/null
+++ b/sway/commands/input/map_from_region.c
@@ -0,0 +1,79 @@
1#define _POSIX_C_SOURCE 200809L
2#include <stdbool.h>
3#include <string.h>
4#include <strings.h>
5#include "log.h"
6#include "sway/commands.h"
7#include "sway/config.h"
8#include "sway/input/input-manager.h"
9
10static bool parse_coords(const char *str, double *x, double *y, bool *mm) {
11 *mm = false;
12
13 char *end;
14 *x = strtod(str, &end);
15 if (end[0] != 'x') {
16 return false;
17 }
18 ++end;
19
20 *y = strtod(end, &end);
21 if (end[0] == 'm') {
22 // Expect mm
23 if (end[1] != 'm') {
24 return false;
25 }
26 *mm = true;
27 end = &end[2];
28 }
29 if (end[0] != '\0') {
30 return false;
31 }
32
33 return true;
34}
35
36struct cmd_results *input_cmd_map_from_region(int argc, char **argv) {
37 struct cmd_results *error = NULL;
38 if ((error = checkarg(argc, "map_from_region", EXPECTED_EQUAL_TO, 2))) {
39 return error;
40 }
41 struct input_config *current_input_config =
42 config->handler_context.input_config;
43 if (!current_input_config) {
44 return cmd_results_new(CMD_FAILURE, "map_from_region",
45 "No input device defined");
46 }
47
48 struct input_config *new_config =
49 new_input_config(current_input_config->identifier);
50
51 new_config->mapped_from_region =
52 calloc(1, sizeof(struct input_config_mapped_from_region));
53
54 bool mm1, mm2;
55 if (!parse_coords(argv[0], &new_config->mapped_from_region->x1,
56 &new_config->mapped_from_region->y1, &mm1)) {
57 return cmd_results_new(CMD_FAILURE, "map_from_region",
58 "Invalid top-left coordinates");
59 }
60 if (!parse_coords(argv[1], &new_config->mapped_from_region->x2,
61 &new_config->mapped_from_region->y2, &mm2)) {
62 return cmd_results_new(CMD_FAILURE, "map_from_region",
63 "Invalid bottom-right coordinates");
64 }
65 if (new_config->mapped_from_region->x1 > new_config->mapped_from_region->x2 ||
66 new_config->mapped_from_region->y1 > new_config->mapped_from_region->y2) {
67 return cmd_results_new(CMD_FAILURE, "map_from_region",
68 "Invalid rectangle");
69 }
70 if (mm1 != mm2) {
71 return cmd_results_new(CMD_FAILURE, "map_from_region",
72 "Both coordinates must be in the same unit");
73 }
74 new_config->mapped_from_region->mm = mm1;
75
76 apply_input_config(new_config);
77
78 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
79}
diff --git a/sway/commands/input/map_to_output.c b/sway/commands/input/map_to_output.c
index 60e4608e..68439bec 100644
--- a/sway/commands/input/map_to_output.c
+++ b/sway/commands/input/map_to_output.c
@@ -20,7 +20,7 @@ struct cmd_results *input_cmd_map_to_output(int argc, char **argv) {
20 struct input_config *new_config = 20 struct input_config *new_config =
21 new_input_config(current_input_config->identifier); 21 new_input_config(current_input_config->identifier);
22 22
23 new_config->mapped_output = strdup(argv[0]); 23 new_config->mapped_to_output = strdup(argv[0]);
24 apply_input_config(new_config); 24 apply_input_config(new_config);
25 25
26 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 26 return cmd_results_new(CMD_SUCCESS, NULL, NULL);