swayfx/sway/commands/split.c

81 lines
2.2 KiB
C
Raw Normal View History

2018-03-31 15:44:17 +11:00
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
#include "sway/tree/arrange.h"
2018-03-31 15:44:17 +11:00
#include "sway/tree/container.h"
#include "sway/tree/view.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "log.h"
2018-04-03 10:12:18 +10:00
static struct cmd_results *do_split(int layout) {
struct sway_container *con = config->handler_context.current_container;
2018-05-25 17:10:58 +10:00
if (container_is_floating(con)) {
return cmd_results_new(CMD_FAILURE, "split",
"Can't split a floating view");
}
2018-04-03 10:12:18 +10:00
struct sway_container *parent = container_split(con, layout);
2018-04-08 08:01:18 +10:00
container_create_notify(parent);
arrange_and_commit(parent);
2018-03-31 15:44:17 +11:00
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
struct cmd_results *cmd_split(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) {
return error;
}
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
2018-05-25 17:10:58 +10:00
return do_split(L_VERT);
2018-03-31 15:44:17 +11:00
} else if (strcasecmp(argv[0], "h") == 0 ||
strcasecmp(argv[0], "horizontal") == 0) {
2018-05-25 17:10:58 +10:00
return do_split(L_HORIZ);
2018-03-31 15:44:17 +11:00
} else if (strcasecmp(argv[0], "t") == 0 ||
strcasecmp(argv[0], "toggle") == 0) {
struct sway_container *focused =
config->handler_context.current_container;
2018-04-03 04:15:40 +10:00
2018-03-31 15:44:17 +11:00
if (focused->parent->layout == L_VERT) {
2018-05-25 17:10:58 +10:00
return do_split(L_HORIZ);
2018-03-31 15:44:17 +11:00
} else {
2018-05-25 17:10:58 +10:00
return do_split(L_VERT);
2018-03-31 15:44:17 +11:00
}
} else {
2018-05-25 17:10:58 +10:00
return cmd_results_new(CMD_FAILURE, "split",
2018-03-31 15:44:17 +11:00
"Invalid split command (expected either horizontal or vertical).");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
struct cmd_results *cmd_splitv(int argc, char **argv) {
2018-04-03 10:12:18 +10:00
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
return error;
}
return do_split(L_VERT);
2018-03-31 15:44:17 +11:00
}
struct cmd_results *cmd_splith(int argc, char **argv) {
2018-04-03 10:12:18 +10:00
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
return error;
}
return do_split(L_HORIZ);
2018-03-31 15:44:17 +11:00
}
struct cmd_results *cmd_splitt(int argc, char **argv) {
2018-04-03 10:12:18 +10:00
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);
2018-03-31 15:44:17 +11:00
} else {
2018-04-03 10:12:18 +10:00
return do_split(L_VERT);
2018-03-31 15:44:17 +11:00
}
}