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