aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/kill.c27
-rw-r--r--sway/commands/split.c76
2 files changed, 93 insertions, 10 deletions
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index f6774767..46d6e98e 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -3,21 +3,28 @@
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/tree/view.h"
+#include "sway/tree/container.h"
#include "sway/commands.h"
struct cmd_results *cmd_kill(int argc, char **argv) {
- enum sway_container_type type = config->handler_context.current_container->type;
- if (type != C_VIEW && type != C_CONTAINER) {
+ struct sway_container *con =
+ config->handler_context.current_container;
+
+ switch (con->type) {
+ case C_ROOT:
+ case C_OUTPUT:
+ case C_WORKSPACE:
+ case C_TYPES:
return cmd_results_new(CMD_INVALID, NULL,
"Can only kill views and containers with this command");
- }
-
- // TODO close arbitrary containers without a view
- struct sway_view *view =
- config->handler_context.current_container->sway_view;
-
- if (view) {
- view_close(view);
+ break;
+ case C_CONTAINER:
+ con = container_destroy(con);
+ arrange_windows(con, -1, -1);
+ break;
+ case C_VIEW:
+ view_close(con->sway_view);
+ break;
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/commands/split.c b/sway/commands/split.c
new file mode 100644
index 00000000..ab8565a9
--- /dev/null
+++ b/sway/commands/split.c
@@ -0,0 +1,76 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "sway/tree/container.h"
+#include "sway/tree/layout.h"
+#include "sway/tree/view.h"
+#include "sway/input/input-manager.h"
+#include "sway/input/seat.h"
+#include "log.h"
+
+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);
+
+ 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) {
+ do_split(L_VERT);
+ } else if (strcasecmp(argv[0], "h") == 0 ||
+ strcasecmp(argv[0], "horizontal") == 0) {
+ 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(L_HORIZ);
+ } else {
+ do_split(L_VERT);
+ }
+ } else {
+ error = cmd_results_new(CMD_FAILURE, "split",
+ "Invalid split command (expected either horizontal or vertical).");
+ return error;
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+struct cmd_results *cmd_splitv(int argc, char **argv) {
+ 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) {
+ 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 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(L_VERT);
+ }
+}