diff options
Diffstat (limited to 'sway/commands/output/mode.c')
-rw-r--r-- | sway/commands/output/mode.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/sway/commands/output/mode.c b/sway/commands/output/mode.c new file mode 100644 index 00000000..daec6d44 --- /dev/null +++ b/sway/commands/output/mode.c | |||
@@ -0,0 +1,55 @@ | |||
1 | #include <strings.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/config.h" | ||
4 | |||
5 | struct cmd_results *output_cmd_mode(int argc, char **argv) { | ||
6 | if (!config->handler_context.output_config) { | ||
7 | return cmd_results_new(CMD_FAILURE, "output", "Missing output config"); | ||
8 | } | ||
9 | if (!argc) { | ||
10 | return cmd_results_new(CMD_INVALID, "output", "Missing mode argument."); | ||
11 | } | ||
12 | |||
13 | struct output_config *output = config->handler_context.output_config; | ||
14 | |||
15 | char *end; | ||
16 | output->width = strtol(*argv, &end, 10); | ||
17 | if (*end) { | ||
18 | // Format is 1234x4321 | ||
19 | if (*end != 'x') { | ||
20 | return cmd_results_new(CMD_INVALID, "output", | ||
21 | "Invalid mode width."); | ||
22 | } | ||
23 | ++end; | ||
24 | output->height = strtol(end, &end, 10); | ||
25 | if (*end) { | ||
26 | if (*end != '@') { | ||
27 | return cmd_results_new(CMD_INVALID, "output", | ||
28 | "Invalid mode height."); | ||
29 | } | ||
30 | ++end; | ||
31 | output->refresh_rate = strtof(end, &end); | ||
32 | if (strcasecmp("Hz", end) != 0) { | ||
33 | return cmd_results_new(CMD_INVALID, "output", | ||
34 | "Invalid mode refresh rate."); | ||
35 | } | ||
36 | } | ||
37 | } else { | ||
38 | // Format is 1234 4321 | ||
39 | if (!argc) { | ||
40 | return cmd_results_new(CMD_INVALID, "output", | ||
41 | "Missing mode argument (height)."); | ||
42 | } | ||
43 | argc--; argv++; | ||
44 | output->height = strtol(*argv, &end, 10); | ||
45 | if (*end) { | ||
46 | return cmd_results_new(CMD_INVALID, "output", | ||
47 | "Invalid mode height."); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | config->handler_context.leftovers.argc = argc - 1; | ||
52 | config->handler_context.leftovers.argv = argv + 1; | ||
53 | return NULL; | ||
54 | } | ||
55 | |||