diff options
author | wil <william.barsse@gmail.com> | 2016-12-29 20:26:35 +0100 |
---|---|---|
committer | wil <william.barsse@gmail.com> | 2016-12-29 20:31:30 +0100 |
commit | a0aa8d9780c6c8b0138800e3b2c2c0053174a2c5 (patch) | |
tree | c82dec85d4f5c9dbe0b93131f56614bccaa3a227 /sway/commands/layout.c | |
parent | [fix] move next/prev behavior for vert/horiz layout (diff) | |
download | sway-a0aa8d9780c6c8b0138800e3b2c2c0053174a2c5.tar.gz sway-a0aa8d9780c6c8b0138800e3b2c2c0053174a2c5.tar.zst sway-a0aa8d9780c6c8b0138800e3b2c2c0053174a2c5.zip |
cleanup in auto layouts
- added L_AUTO_FIRST/LAST instead of using explicit layouts.
- when switching between auto layout that don't share the same major axis, invert the
width/height of their child views to preserve their relative proportions.
Diffstat (limited to 'sway/commands/layout.c')
-rw-r--r-- | sway/commands/layout.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/sway/commands/layout.c b/sway/commands/layout.c index 9e468c21..5426186e 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c | |||
@@ -56,24 +56,12 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
56 | swayc_change_layout(parent, L_HORIZ); | 56 | swayc_change_layout(parent, L_HORIZ); |
57 | } | 57 | } |
58 | } else if (strcasecmp(argv[0], "auto_left") == 0) { | 58 | } else if (strcasecmp(argv[0], "auto_left") == 0) { |
59 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
60 | parent = new_container(parent, L_AUTO_LEFT); | ||
61 | } | ||
62 | swayc_change_layout(parent, L_AUTO_LEFT); | 59 | swayc_change_layout(parent, L_AUTO_LEFT); |
63 | } else if (strcasecmp(argv[0], "auto_right") == 0) { | 60 | } else if (strcasecmp(argv[0], "auto_right") == 0) { |
64 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
65 | parent = new_container(parent, L_AUTO_RIGHT); | ||
66 | } | ||
67 | swayc_change_layout(parent, L_AUTO_RIGHT); | 61 | swayc_change_layout(parent, L_AUTO_RIGHT); |
68 | } else if (strcasecmp(argv[0], "auto_top") == 0) { | 62 | } else if (strcasecmp(argv[0], "auto_top") == 0) { |
69 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
70 | parent = new_container(parent, L_AUTO_TOP); | ||
71 | } | ||
72 | swayc_change_layout(parent, L_AUTO_TOP); | 63 | swayc_change_layout(parent, L_AUTO_TOP); |
73 | } else if (strcasecmp(argv[0], "auto_bot") == 0) { | 64 | } else if (strcasecmp(argv[0], "auto_bot") == 0) { |
74 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
75 | parent = new_container(parent, L_AUTO_BOTTOM); | ||
76 | } | ||
77 | swayc_change_layout(parent, L_AUTO_BOTTOM); | 65 | swayc_change_layout(parent, L_AUTO_BOTTOM); |
78 | } else if (strcasecmp(argv[0], "incnmaster") == 0) { | 66 | } else if (strcasecmp(argv[0], "incnmaster") == 0) { |
79 | if ((error = checkarg(argc, "layout incnmaster", | 67 | if ((error = checkarg(argc, "layout incnmaster", |
@@ -105,6 +93,42 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
105 | ((int)container->parent->nb_slave_groups + inc >= 1)) { | 93 | ((int)container->parent->nb_slave_groups + inc >= 1)) { |
106 | container->parent->nb_slave_groups += inc; | 94 | container->parent->nb_slave_groups += inc; |
107 | } | 95 | } |
96 | } else if (strcasecmp(argv[0], "auto") == 0) { | ||
97 | if ((error = checkarg(argc, "auto", EXPECTED_EQUAL_TO, 2))) { | ||
98 | return error; | ||
99 | } | ||
100 | swayc_t *container = get_focused_view(swayc_active_workspace()); | ||
101 | swayc_t *parent = container->parent; | ||
102 | enum swayc_layouts layout; | ||
103 | if (strcasecmp(argv[1], "next") == 0) { | ||
104 | if (is_auto_layout(parent->layout) && parent->layout < L_AUTO_LAST) { | ||
105 | layout = parent->layout + 1; | ||
106 | } else { | ||
107 | layout = L_AUTO_FIRST; | ||
108 | } | ||
109 | } else if (strcasecmp(argv[1], "prev") == 0) { | ||
110 | if (is_auto_layout(parent->layout) && parent->layout > L_AUTO_FIRST) { | ||
111 | layout = parent->layout - 1; | ||
112 | } else { | ||
113 | layout = L_AUTO_FIRST; | ||
114 | } | ||
115 | } else { | ||
116 | return cmd_results_new(CMD_FAILURE, "layout auto", | ||
117 | "Must be one of <prev|next>."); | ||
118 | } | ||
119 | swayc_change_layout(parent, layout); | ||
120 | } else if (strcasecmp(argv[0], "promote") == 0) { | ||
121 | // swap first child in auto layout with currently focused child | ||
122 | swayc_t *container = get_focused_view(swayc_active_workspace()); | ||
123 | swayc_t *parent = container->parent; | ||
124 | if (is_auto_layout(parent->layout)) { | ||
125 | int focused_idx = index_child(container); | ||
126 | swayc_t *first = parent->children->items[0]; | ||
127 | if (focused_idx > 0) { | ||
128 | list_swap(parent->children, 0, focused_idx); | ||
129 | swap_geometry(first, container); | ||
130 | } | ||
131 | } | ||
108 | } | 132 | } |
109 | } | 133 | } |
110 | 134 | ||