diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-07-10 21:25:10 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-11 10:46:56 -0400 |
commit | c312a10cc7ace29fde9105204787c9853745a57d (patch) | |
tree | b16a3055aef48a903b1b4d5227c243f64f3a82d1 /sway | |
parent | cmd_layout: toggle split for tabbed/stack default (diff) | |
download | sway-c312a10cc7ace29fde9105204787c9853745a57d.tar.gz sway-c312a10cc7ace29fde9105204787c9853745a57d.tar.zst sway-c312a10cc7ace29fde9105204787c9853745a57d.zip |
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.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/layout.c | 35 |
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[] = | |||
26 | "'layout toggle [split|all]' or " | 26 | "'layout toggle [split|all]' or " |
27 | "'layout toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...'"; | 27 | "'layout toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...'"; |
28 | 28 | ||
29 | static enum sway_container_layout toggle_split_layout( | ||
30 | enum sway_container_layout layout, | ||
31 | enum sway_container_layout prev_split_layout, | ||
32 | struct sway_output *output) { | ||
33 | if (layout == L_HORIZ) { | ||
34 | return L_VERT; | ||
35 | } else if (layout == L_VERT) { | ||
36 | return L_HORIZ; | ||
37 | } else if (prev_split_layout != L_NONE) { | ||
38 | return prev_split_layout; | ||
39 | } else if (config->default_orientation != L_NONE) { | ||
40 | return config->default_orientation; | ||
41 | } else if (output->height > output->width) { | ||
42 | return L_VERT; | ||
43 | } | ||
44 | return L_HORIZ; | ||
45 | } | ||
46 | |||
29 | static enum sway_container_layout get_layout_toggle(int argc, char **argv, | 47 | static enum sway_container_layout get_layout_toggle(int argc, char **argv, |
30 | enum sway_container_layout layout, | 48 | enum sway_container_layout layout, |
31 | enum sway_container_layout prev_split_layout, | 49 | enum sway_container_layout prev_split_layout, |
32 | struct sway_output *output) { | 50 | struct sway_output *output) { |
33 | // "layout toggle" | 51 | // "layout toggle" |
34 | if (argc == 1) { | 52 | if (argc == 1) { |
35 | return layout == L_HORIZ ? L_VERT : L_HORIZ; | 53 | return toggle_split_layout(layout, prev_split_layout, output); |
36 | } | 54 | } |
37 | 55 | ||
38 | if (argc == 2) { | 56 | if (argc == 2) { |
39 | // "layout toggle split" (same as "layout toggle") | 57 | // "layout toggle split" (same as "layout toggle") |
40 | if (strcasecmp(argv[1], "split") == 0) { | 58 | if (strcasecmp(argv[1], "split") == 0) { |
41 | return layout == L_HORIZ ? L_VERT : L_HORIZ; | 59 | return toggle_split_layout(layout, prev_split_layout, output); |
42 | } | 60 | } |
43 | // "layout toggle all" | 61 | // "layout toggle all" |
44 | if (strcasecmp(argv[1], "all") == 0) { | 62 | if (strcasecmp(argv[1], "all") == 0) { |
@@ -68,18 +86,7 @@ static enum sway_container_layout get_layout_toggle(int argc, char **argv, | |||
68 | return parsed; | 86 | return parsed; |
69 | } | 87 | } |
70 | if (strcmp(argv[i], "split") == 0) { | 88 | if (strcmp(argv[i], "split") == 0) { |
71 | if (layout == L_HORIZ) { | 89 | return toggle_split_layout(layout, prev_split_layout, output); |
72 | return L_VERT; | ||
73 | } else if (layout == L_VERT) { | ||
74 | return L_HORIZ; | ||
75 | } else if (prev_split_layout != L_NONE) { | ||
76 | return prev_split_layout; | ||
77 | } else if (config->default_orientation != L_NONE) { | ||
78 | return config->default_orientation; | ||
79 | } else if (output->height > output->width) { | ||
80 | return L_VERT; | ||
81 | } | ||
82 | return L_HORIZ; | ||
83 | } | 90 | } |
84 | // invalid layout strings are silently ignored | 91 | // invalid layout strings are silently ignored |
85 | } | 92 | } |