aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/split.c
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2018-04-02 20:12:18 -0400
committerTony Crisci <tony@dubstepdish.com>2018-04-02 20:12:18 -0400
commit32ef182f474dbb40c4bedb69256ca6ec8bd31039 (patch)
tree6c0d05d8605ff5bec4d87a2064e46e6e8cb25385 /sway/commands/split.c
parenta89096278b3dee599d75b7e91810a354b90a0ecb (diff)
cleanup split command handlers
Diffstat (limited to 'sway/commands/split.c')
-rw-r--r--sway/commands/split.c65
1 files changed, 27 insertions, 38 deletions
diff --git a/sway/commands/split.c b/sway/commands/split.c
index ca116aef..ab8565a9 100644
--- a/sway/commands/split.c
+++ b/sway/commands/split.c
@@ -8,58 +8,33 @@
#include "sway/input/seat.h"
#include "log.h"
-static struct cmd_results *_do_split(int argc, char **argv, int layout) {
- char *name = layout == L_VERT ? "splitv" :
- layout == L_HORIZ ? "splith" : "split";
- struct cmd_results *error = NULL;
- if (config->reading) {
- return cmd_results_new(CMD_FAILURE, name,
- "Can't be used in config file.");
- }
- if (!config->active) {
- return cmd_results_new(CMD_FAILURE, name,
- "Can only be used when sway is running.");
- }
- if ((error = checkarg(argc, name, EXPECTED_EQUAL_TO, 0))) {
- return error;
- }
-
- struct sway_container *focused = config->handler_context.current_container;
- struct sway_container *parent = container_split(focused, layout);
+static struct cmd_results *do_split(int layout) {
+ struct sway_container *con = config->handler_context.current_container;
+ struct sway_container *parent = container_split(con, layout);
arrange_windows(parent, -1, -1);
- // TODO borders: update borders
-
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
struct cmd_results *cmd_split(int argc, char **argv) {
struct cmd_results *error = NULL;
- if (config->reading) {
- return cmd_results_new(CMD_FAILURE, "split",
- "Can't be used in config file.");
- }
- if (!config->active) {
- return cmd_results_new(CMD_FAILURE, "split",
- "Can only be used when sway is running.");
- }
if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) {
return error;
}
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
- _do_split(argc - 1, argv + 1, L_VERT);
+ do_split(L_VERT);
} else if (strcasecmp(argv[0], "h") == 0 ||
strcasecmp(argv[0], "horizontal") == 0) {
- _do_split(argc - 1, argv + 1, L_HORIZ);
+ do_split(L_HORIZ);
} else if (strcasecmp(argv[0], "t") == 0 ||
strcasecmp(argv[0], "toggle") == 0) {
struct sway_container *focused =
config->handler_context.current_container;
if (focused->parent->layout == L_VERT) {
- _do_split(argc - 1, argv + 1, L_HORIZ);
+ do_split(L_HORIZ);
} else {
- _do_split(argc - 1, argv + 1, L_VERT);
+ do_split(L_VERT);
}
} else {
error = cmd_results_new(CMD_FAILURE, "split",
@@ -70,18 +45,32 @@ struct cmd_results *cmd_split(int argc, char **argv) {
}
struct cmd_results *cmd_splitv(int argc, char **argv) {
- return _do_split(argc, argv, L_VERT);
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
+ return error;
+ }
+ return do_split(L_VERT);
}
struct cmd_results *cmd_splith(int argc, char **argv) {
- return _do_split(argc, argv, L_HORIZ);
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
+ return error;
+ }
+ return do_split(L_HORIZ);
}
struct cmd_results *cmd_splitt(int argc, char **argv) {
- struct sway_container *focused = config->handler_context.current_container;
- if (focused->parent->layout == L_VERT) {
- return _do_split(argc, argv, L_HORIZ);
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
+ return error;
+ }
+
+ struct sway_container *con = config->handler_context.current_container;
+
+ if (con->parent->layout == L_VERT) {
+ return do_split(L_HORIZ);
} else {
- return _do_split(argc, argv, L_VERT);
+ return do_split(L_VERT);
}
}