aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/new_window.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-09-02 19:47:37 -0400
committerGitHub <noreply@github.com>2016-09-02 19:47:37 -0400
commit29820ff826013b595e8c15d9e933767b0c965beb (patch)
treee5bae8ecc19c438091478ad878a8297252c72a81 /sway/commands/new_window.c
parent4e6d7b125895955e3a84583c6d61f3eb2f8a4fe9 (diff)
parent65ace5dec5c24695501056376e227fb9b1f84a3a (diff)
Merge pull request #879 from zandrmartin/commands-refactor
refactor commands.c
Diffstat (limited to 'sway/commands/new_window.c')
-rw-r--r--sway/commands/new_window.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/sway/commands/new_window.c b/sway/commands/new_window.c
new file mode 100644
index 00000000..423b5af0
--- /dev/null
+++ b/sway/commands/new_window.c
@@ -0,0 +1,43 @@
+#include <errno.h>
+#include <string.h>
+#include "sway/commands.h"
+#include "sway/container.h"
+
+struct cmd_results *cmd_new_window(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "new_window", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+
+ if (argc > 2) {
+ return cmd_results_new(CMD_INVALID, "new_window",
+ "Expected 'new_window <normal|none|pixel> [<n>]");
+ }
+
+ enum swayc_border_types border = config->border;
+ int thickness = config->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_window",
+ "Expected 'border <normal|none|pixel>");
+ }
+
+ 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_window", "Number is out out of range.");
+ }
+ }
+
+ config->border = border;
+ config->border_thickness = thickness;
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}