From ec2fedf6d0d4d101351bfa03a60beb02c90573fc Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 9 Aug 2015 14:35:59 -0400 Subject: [PATCH] Implement layout [splith|splitv|toggle split] --- sway/commands.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sway/commands.c b/sway/commands.c index 8030712e0..33a5e4856 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -7,6 +7,7 @@ #include #include #include "stringop.h" +#include "layout.h" #include "log.h" #include "commands.h" @@ -106,6 +107,31 @@ int cmd_focus_follows_mouse(struct sway_config *config, int argc, char **argv) { return 0; } +int cmd_layout(struct sway_config *config, int argc, char **argv) { + if (argc < 1) { + sway_log(L_ERROR, "Invalid layout command (expected at least 1 argument, got %d)", argc); + return 1; + } + swayc_t *parent = get_focused_container(&root_container); + while (parent->type == C_VIEW) { + parent = parent->parent; + } + if (strcasecmp(argv[0], "splith") == 0) { + parent->layout = L_HORIZ; + } else if (strcasecmp(argv[0], "splitv") == 0) { + parent->layout = L_VERT; + } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { + if (parent->layout == L_VERT) { + parent->layout = L_HORIZ; + } else { + parent->layout = L_VERT; + } + } + arrange_windows(parent, parent->width, parent->height); + + return 0; +} + int cmd_set(struct sway_config *config, int argc, char **argv) { if (argc != 2) { sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); @@ -126,6 +152,7 @@ struct cmd_handler handlers[] = { { "exec", cmd_exec }, { "exit", cmd_exit }, { "focus_follows_mouse", cmd_focus_follows_mouse }, + { "layout", cmd_layout }, { "set", cmd_set }, };