diff options
Diffstat (limited to 'sway/old/commands/border.c')
-rw-r--r-- | sway/old/commands/border.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/sway/old/commands/border.c b/sway/old/commands/border.c new file mode 100644 index 00000000..c888622e --- /dev/null +++ b/sway/old/commands/border.c | |||
@@ -0,0 +1,65 @@ | |||
1 | #include <errno.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <strings.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/focus.h" | ||
8 | |||
9 | struct cmd_results *cmd_border(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if (!config->active) { | ||
12 | return cmd_results_new(CMD_FAILURE, "border", "Can only be used when sway is running."); | ||
13 | } | ||
14 | if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) { | ||
15 | return error; | ||
16 | } | ||
17 | |||
18 | if (argc > 2) { | ||
19 | return cmd_results_new(CMD_INVALID, "border", | ||
20 | "Expected 'border <normal|pixel|none|toggle> [<n>]"); | ||
21 | } | ||
22 | |||
23 | swayc_t *view = current_container; | ||
24 | enum swayc_border_types border = view->border_type; | ||
25 | int thickness = view->border_thickness; | ||
26 | |||
27 | if (strcasecmp(argv[0], "none") == 0) { | ||
28 | border = B_NONE; | ||
29 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
30 | border = B_NORMAL; | ||
31 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
32 | border = B_PIXEL; | ||
33 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
34 | switch (border) { | ||
35 | case B_NONE: | ||
36 | border = B_PIXEL; | ||
37 | break; | ||
38 | case B_NORMAL: | ||
39 | border = B_NONE; | ||
40 | break; | ||
41 | case B_PIXEL: | ||
42 | border = B_NORMAL; | ||
43 | break; | ||
44 | } | ||
45 | } else { | ||
46 | return cmd_results_new(CMD_INVALID, "border", | ||
47 | "Expected 'border <normal|pixel|none|toggle>"); | ||
48 | } | ||
49 | |||
50 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
51 | thickness = (int)strtol(argv[1], NULL, 10); | ||
52 | if (errno == ERANGE || thickness < 0) { | ||
53 | errno = 0; | ||
54 | return cmd_results_new(CMD_INVALID, "border", "Number is out of range."); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | if (view) { | ||
59 | view->border_type = border; | ||
60 | view->border_thickness = thickness; | ||
61 | update_geometry(view); | ||
62 | } | ||
63 | |||
64 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
65 | } | ||