From acb3fbdfb559e461aaac6d357146f43c4e9c3d38 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 27 Aug 2015 21:52:59 -0500 Subject: [PATCH] Added in default_orientation handling --- include/config.h | 3 +++ sway/commands.c | 14 ++++++++++++++ sway/config.c | 2 ++ sway/container.c | 11 ++++++++++- sway/handlers.c | 7 +++++++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index 6d36eb41..d1a6d0ac 100644 --- a/include/config.h +++ b/include/config.h @@ -5,6 +5,7 @@ #include #include #include "list.h" +#include "layout.h" struct sway_variable { char *name; @@ -42,6 +43,8 @@ struct sway_config { list_t *output_configs; struct sway_mode *current_mode; uint32_t floating_mod; + enum swayc_layouts default_orientation; + enum swayc_layouts default_layout; // Flags bool focus_follows_mouse; diff --git a/sway/commands.c b/sway/commands.c index df48724a..1d88e724 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -388,6 +388,19 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { return true; } +static bool cmd_orientation(struct sway_config *config, int argc, char **argv) { + if (strcasecmp(argv[0],"horizontal") == 0) { + config->default_orientation = L_HORIZ; + } else if (strcasecmp(argv[0], "vertical") == 0) { + config->default_orientation = L_VERT; + } else if (strcasecmp(argv[0], "auto") == 0) { + // Do nothing + } else { + return false; + } + return true; +} + static bool cmd_output(struct sway_config *config, int argc, char **argv) { if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) { return false; @@ -713,6 +726,7 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { /* Keep alphabetized */ static struct cmd_handler handlers[] = { { "bindsym", cmd_bindsym }, + { "default_orientation", cmd_orientation }, { "exec", cmd_exec }, { "exec_always", cmd_exec_always }, { "exit", cmd_exit }, diff --git a/sway/config.c b/sway/config.c index 53fc860a..08b14f84 100644 --- a/sway/config.c +++ b/sway/config.c @@ -27,6 +27,8 @@ void config_defaults(struct sway_config *config) { config->current_mode->name = NULL; config->current_mode->bindings = create_list(); list_add(config->modes, config->current_mode); + config->default_layout = L_NONE; + config->default_orientation = L_NONE; // Flags config->focus_follows_mouse = true; config->mouse_warping = true; diff --git a/sway/container.c b/sway/container.c index 05bb6abb..abbd5504 100644 --- a/sway/container.c +++ b/sway/container.c @@ -146,7 +146,16 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); swayc_t *workspace = new_swayc(C_WORKSPACE); - workspace->layout = L_HORIZ; // TODO: default layout + // TODO: default_layout + if (config->default_layout != L_NONE) { + workspace->layout = config->default_layout; + } else if (config->default_orientation != L_NONE) { + workspace->layout = config->default_orientation; + } else if (output->width >= output->height) { + workspace->layout = L_HORIZ; + } else { + workspace->layout = L_VERT; + } workspace->x = output->x; workspace->y = output->y; workspace->width = output->width; diff --git a/sway/handlers.c b/sway/handlers.c index 2223a98c..aa336e8d 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -130,6 +130,13 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_ if (!c) return; c->width = to->w; c->height = to->h; + if (config->default_layout == L_NONE && config->default_orientation == L_NONE) { + if (c->width >= c->height) { + ((swayc_t*)c->children->items[0])->layout = L_HORIZ; + } else { + ((swayc_t*)c->children->items[0])->layout = L_VERT; + } + } arrange_windows(&root_container, -1, -1); }