diff options
author | Zandr Martin <zandrmartin@gmail.com> | 2016-09-01 21:39:08 -0500 |
---|---|---|
committer | Zandr Martin <zandrmartin@gmail.com> | 2016-09-01 21:39:08 -0500 |
commit | b374c35758777f98e5ddbe4b0dc43bd7c80f36d7 (patch) | |
tree | 04bb4cfc3da7d2e0de7fbc38db42f65c66d2df4c /sway/commands/new_float.c | |
parent | Merge pull request #874 from yohanesu75/ipc-client-fix (diff) | |
download | sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.gz sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.zst sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.zip |
refactor commands.c
Diffstat (limited to 'sway/commands/new_float.c')
-rw-r--r-- | sway/commands/new_float.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/sway/commands/new_float.c b/sway/commands/new_float.c new file mode 100644 index 00000000..f847492a --- /dev/null +++ b/sway/commands/new_float.c | |||
@@ -0,0 +1,43 @@ | |||
1 | #include <errno.h> | ||
2 | #include <string.h> | ||
3 | #include "commands.h" | ||
4 | #include "container.h" | ||
5 | |||
6 | struct cmd_results *cmd_new_float(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "new_float", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (argc > 2) { | ||
13 | return cmd_results_new(CMD_INVALID, "new_float", | ||
14 | "Expected 'new_float <normal|none|pixel> [<n>]"); | ||
15 | } | ||
16 | |||
17 | enum swayc_border_types border = config->floating_border; | ||
18 | int thickness = config->floating_border_thickness; | ||
19 | |||
20 | if (strcasecmp(argv[0], "none") == 0) { | ||
21 | border = B_NONE; | ||
22 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
23 | border = B_NORMAL; | ||
24 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
25 | border = B_PIXEL; | ||
26 | } else { | ||
27 | return cmd_results_new(CMD_INVALID, "new_float", | ||
28 | "Expected 'border <normal|none|pixel>"); | ||
29 | } | ||
30 | |||
31 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
32 | thickness = (int)strtol(argv[1], NULL, 10); | ||
33 | if (errno == ERANGE || thickness < 0) { | ||
34 | errno = 0; | ||
35 | return cmd_results_new(CMD_INVALID, "new_float", "Number is out out of range."); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | config->floating_border = border; | ||
40 | config->floating_border_thickness = thickness; | ||
41 | |||
42 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
43 | } | ||