From b374c35758777f98e5ddbe4b0dc43bd7c80f36d7 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Thu, 1 Sep 2016 21:39:08 -0500 Subject: refactor commands.c --- sway/commands/new_float.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 sway/commands/new_float.c (limited to 'sway/commands/new_float.c') 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 @@ +#include +#include +#include "commands.h" +#include "container.h" + +struct cmd_results *cmd_new_float(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "new_float", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (argc > 2) { + return cmd_results_new(CMD_INVALID, "new_float", + "Expected 'new_float []"); + } + + enum swayc_border_types border = config->floating_border; + int thickness = config->floating_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 { + return cmd_results_new(CMD_INVALID, "new_float", + "Expected 'border "); + } + + 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, "new_float", "Number is out out of range."); + } + } + + config->floating_border = border; + config->floating_border_thickness = thickness; + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} -- cgit v1.2.3-54-g00ecf