diff options
-rw-r--r-- | sway/commands/resize.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index e657864c..8cf4591e 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -133,12 +133,29 @@ static enum resize_axis parse_resize_axis(const char *axis) { | |||
133 | return RESIZE_AXIS_INVALID; | 133 | return RESIZE_AXIS_INVALID; |
134 | } | 134 | } |
135 | 135 | ||
136 | static enum resize_axis normalize_axis(enum resize_axis axis) { | ||
137 | switch (axis) { | ||
138 | case RESIZE_AXIS_HORIZONTAL: | ||
139 | case RESIZE_AXIS_LEFT: | ||
140 | case RESIZE_AXIS_RIGHT: | ||
141 | return RESIZE_AXIS_HORIZONTAL; | ||
142 | case RESIZE_AXIS_VERTICAL: | ||
143 | case RESIZE_AXIS_UP: | ||
144 | case RESIZE_AXIS_DOWN: | ||
145 | return RESIZE_AXIS_VERTICAL; | ||
146 | case RESIZE_AXIS_INVALID: | ||
147 | sway_assert(false, "Never reached"); | ||
148 | } | ||
149 | sway_assert(false, "Never reached"); | ||
150 | return RESIZE_AXIS_INVALID; | ||
151 | } | ||
152 | |||
136 | static int parallel_coord(struct sway_container *c, enum resize_axis a) { | 153 | static int parallel_coord(struct sway_container *c, enum resize_axis a) { |
137 | return a == RESIZE_AXIS_HORIZONTAL ? c->x : c->y; | 154 | return normalize_axis(a) == RESIZE_AXIS_HORIZONTAL ? c->x : c->y; |
138 | } | 155 | } |
139 | 156 | ||
140 | static int parallel_size(struct sway_container *c, enum resize_axis a) { | 157 | static int parallel_size(struct sway_container *c, enum resize_axis a) { |
141 | return a == RESIZE_AXIS_HORIZONTAL ? c->width : c->height; | 158 | return normalize_axis(a) == RESIZE_AXIS_HORIZONTAL ? c->width : c->height; |
142 | } | 159 | } |
143 | 160 | ||
144 | static void resize_tiled(int amount, enum resize_axis axis) { | 161 | static void resize_tiled(int amount, enum resize_axis axis) { |
@@ -149,7 +166,7 @@ static void resize_tiled(int amount, enum resize_axis axis) { | |||
149 | } | 166 | } |
150 | 167 | ||
151 | enum sway_container_layout parallel_layout = | 168 | enum sway_container_layout parallel_layout = |
152 | axis == RESIZE_AXIS_HORIZONTAL ? L_HORIZ : L_VERT; | 169 | normalize_axis(axis) == RESIZE_AXIS_HORIZONTAL ? L_HORIZ : L_VERT; |
153 | int minor_weight = 0; | 170 | int minor_weight = 0; |
154 | int major_weight = 0; | 171 | int major_weight = 0; |
155 | while (parent->parent) { | 172 | while (parent->parent) { |
@@ -185,6 +202,15 @@ static void resize_tiled(int amount, enum resize_axis axis) { | |||
185 | "Found the proper parent: %p. It has %d l conts, and %d r conts", | 202 | "Found the proper parent: %p. It has %d l conts, and %d r conts", |
186 | parent->parent, minor_weight, major_weight); | 203 | parent->parent, minor_weight, major_weight); |
187 | 204 | ||
205 | // Implement up/down/left/right direction by zeroing one of the weights, | ||
206 | // then setting the axis to be horizontal or vertical | ||
207 | if (axis == RESIZE_AXIS_UP || axis == RESIZE_AXIS_LEFT) { | ||
208 | major_weight = 0; | ||
209 | } else if (axis == RESIZE_AXIS_RIGHT || axis == RESIZE_AXIS_DOWN) { | ||
210 | minor_weight = 0; | ||
211 | } | ||
212 | axis = normalize_axis(axis); | ||
213 | |||
188 | int min_sane = axis == RESIZE_AXIS_HORIZONTAL ? MIN_SANE_W : MIN_SANE_H; | 214 | int min_sane = axis == RESIZE_AXIS_HORIZONTAL ? MIN_SANE_W : MIN_SANE_H; |
189 | 215 | ||
190 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks | 216 | //TODO: Ensure rounding is done in such a way that there are NO pixel leaks |
@@ -201,14 +227,14 @@ static void resize_tiled(int amount, enum resize_axis axis) { | |||
201 | int parent_size = parallel_size(parent, axis); | 227 | int parent_size = parallel_size(parent, axis); |
202 | 228 | ||
203 | if (sibling_pos != focused_pos) { | 229 | if (sibling_pos != focused_pos) { |
204 | if (sibling_pos < parent_pos) { | 230 | if (sibling_pos < parent_pos && minor_weight) { |
205 | double pixels = -amount / minor_weight; | 231 | double pixels = -amount / minor_weight; |
206 | if (major_weight && (sibling_size + pixels / 2) < min_sane) { | 232 | if (major_weight && (sibling_size + pixels / 2) < min_sane) { |
207 | return; // Too small | 233 | return; // Too small |
208 | } else if ((sibling_size + pixels) < min_sane) { | 234 | } else if ((sibling_size + pixels) < min_sane) { |
209 | return; // Too small | 235 | return; // Too small |
210 | } | 236 | } |
211 | } else if (sibling_pos > parent_pos) { | 237 | } else if (sibling_pos > parent_pos && major_weight) { |
212 | double pixels = -amount / major_weight; | 238 | double pixels = -amount / major_weight; |
213 | if (minor_weight && (sibling_size + pixels / 2) < min_sane) { | 239 | if (minor_weight && (sibling_size + pixels / 2) < min_sane) { |
214 | return; // Too small | 240 | return; // Too small |
@@ -237,7 +263,7 @@ static void resize_tiled(int amount, enum resize_axis axis) { | |||
237 | int parent_pos = parallel_coord(parent, axis); | 263 | int parent_pos = parallel_coord(parent, axis); |
238 | 264 | ||
239 | if (sibling_pos != focused_pos) { | 265 | if (sibling_pos != focused_pos) { |
240 | if (sibling_pos < parent_pos) { | 266 | if (sibling_pos < parent_pos && minor_weight) { |
241 | double pixels = -1 * amount; | 267 | double pixels = -1 * amount; |
242 | pixels /= minor_weight; | 268 | pixels /= minor_weight; |
243 | if (major_weight) { | 269 | if (major_weight) { |
@@ -245,7 +271,7 @@ static void resize_tiled(int amount, enum resize_axis axis) { | |||
245 | } else { | 271 | } else { |
246 | container_recursive_resize(sibling, pixels, major_edge); | 272 | container_recursive_resize(sibling, pixels, major_edge); |
247 | } | 273 | } |
248 | } else if (sibling_pos > parent_pos) { | 274 | } else if (sibling_pos > parent_pos && major_weight) { |
249 | double pixels = -1 * amount; | 275 | double pixels = -1 * amount; |
250 | pixels /= major_weight; | 276 | pixels /= major_weight; |
251 | if (minor_weight) { | 277 | if (minor_weight) { |
@@ -355,7 +381,6 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, | |||
355 | } | 381 | } |
356 | if (amount->unit == RESIZE_UNIT_PPT) { | 382 | if (amount->unit == RESIZE_UNIT_PPT) { |
357 | float pct = amount->amount / 100.0f; | 383 | float pct = amount->amount / 100.0f; |
358 | // TODO: Make left/right/up/down resize in that direction? | ||
359 | switch (axis) { | 384 | switch (axis) { |
360 | case RESIZE_AXIS_LEFT: | 385 | case RESIZE_AXIS_LEFT: |
361 | case RESIZE_AXIS_RIGHT: | 386 | case RESIZE_AXIS_RIGHT: |