aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-07-10 21:25:10 -0400
committerDrew DeVault <sir@cmpwn.com>2019-07-11 10:46:56 -0400
commitc312a10cc7ace29fde9105204787c9853745a57d (patch)
treeb16a3055aef48a903b1b4d5227c243f64f3a82d1
parent5ffcea4c28103ecac3d4970412e8b44dbccfcb22 (diff)
cmd_split: fix toggle split for non-split layouts
Previously, `layout toggle` and `layout toggle split` would set L_VERT when layout was L_HORIZ, otherwise it would set L_HORIZ. This meant that when the layout was L_TABBED or L_STACKED, it would always be L_HORIZ. This extends #4315 (which corrects the handling when multiple layouts are given) to try prev_split_layout, config->default_orientation, and then falling back to L_VERT when the output is taller than wide and L_HORIZ when wider than tall.
-rw-r--r--sway/commands/layout.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
index c1828263..4b31b442 100644
--- a/sway/commands/layout.c
+++ b/sway/commands/layout.c
@@ -26,19 +26,37 @@ static const char expected_syntax[] =
"'layout toggle [split|all]' or "
"'layout toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...'";
+static enum sway_container_layout toggle_split_layout(
+ enum sway_container_layout layout,
+ enum sway_container_layout prev_split_layout,
+ struct sway_output *output) {
+ if (layout == L_HORIZ) {
+ return L_VERT;
+ } else if (layout == L_VERT) {
+ return L_HORIZ;
+ } else if (prev_split_layout != L_NONE) {
+ return prev_split_layout;
+ } else if (config->default_orientation != L_NONE) {
+ return config->default_orientation;
+ } else if (output->height > output->width) {
+ return L_VERT;
+ }
+ return L_HORIZ;
+}
+
static enum sway_container_layout get_layout_toggle(int argc, char **argv,
enum sway_container_layout layout,
enum sway_container_layout prev_split_layout,
struct sway_output *output) {
// "layout toggle"
if (argc == 1) {
- return layout == L_HORIZ ? L_VERT : L_HORIZ;
+ return toggle_split_layout(layout, prev_split_layout, output);
}
if (argc == 2) {
// "layout toggle split" (same as "layout toggle")
if (strcasecmp(argv[1], "split") == 0) {
- return layout == L_HORIZ ? L_VERT : L_HORIZ;
+ return toggle_split_layout(layout, prev_split_layout, output);
}
// "layout toggle all"
if (strcasecmp(argv[1], "all") == 0) {
@@ -68,18 +86,7 @@ static enum sway_container_layout get_layout_toggle(int argc, char **argv,
return parsed;
}
if (strcmp(argv[i], "split") == 0) {
- if (layout == L_HORIZ) {
- return L_VERT;
- } else if (layout == L_VERT) {
- return L_HORIZ;
- } else if (prev_split_layout != L_NONE) {
- return prev_split_layout;
- } else if (config->default_orientation != L_NONE) {
- return config->default_orientation;
- } else if (output->height > output->width) {
- return L_VERT;
- }
- return L_HORIZ;
+ return toggle_split_layout(layout, prev_split_layout, output);
}
// invalid layout strings are silently ignored
}