summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <RedSoxFan@users.noreply.github.com>2018-08-09 20:04:33 -0400
committerLibravatar GitHub <noreply@github.com>2018-08-09 20:04:33 -0400
commitdf1aeed6c2eb74050de9cced3917500c801855a7 (patch)
tree0d697c0f097e8a24949fdf7a52bf5a6c3ca5c6ba
parentRemove obsolete security sanity check (diff)
parentUpdate resize documentation (diff)
downloadsway-df1aeed6c2eb74050de9cced3917500c801855a7.tar.gz
sway-df1aeed6c2eb74050de9cced3917500c801855a7.tar.zst
sway-df1aeed6c2eb74050de9cced3917500c801855a7.zip
Merge pull request #2441 from RyanDwyer/finish-resize-commands
Finish resize commands
-rw-r--r--sway/commands/resize.c84
-rw-r--r--sway/sway.5.scd18
2 files changed, 81 insertions, 21 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index e657864c..c3560985 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
136static 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
136static int parallel_coord(struct sway_container *c, enum resize_axis a) { 153static 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
140static int parallel_size(struct sway_container *c, enum resize_axis a) { 157static 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
144static void resize_tiled(int amount, enum resize_axis axis) { 161static 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,18 +227,18 @@ 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 (!major_weight && 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
215 } else if ((sibling_size + pixels) < min_sane) { 241 } else if (!minor_weight && sibling_size + pixels < min_sane) {
216 return; // Too small 242 return; // Too small
217 } 243 }
218 } 244 }
@@ -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:
@@ -382,8 +407,43 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis,
382 */ 407 */
383static struct cmd_results *resize_set_tiled(struct sway_container *con, 408static struct cmd_results *resize_set_tiled(struct sway_container *con,
384 struct resize_amount *width, struct resize_amount *height) { 409 struct resize_amount *width, struct resize_amount *height) {
385 return cmd_results_new(CMD_INVALID, "resize", 410 if (width->amount) {
386 "'resize set' is not implemented for tiled views"); 411 if (width->unit == RESIZE_UNIT_PPT ||
412 width->unit == RESIZE_UNIT_DEFAULT) {
413 // Convert to px
414 struct sway_container *parent = con->parent;
415 while (parent->type >= C_WORKSPACE && parent->layout != L_HORIZ) {
416 parent = parent->parent;
417 }
418 if (parent->type >= C_WORKSPACE) {
419 width->amount = parent->width * width->amount / 100;
420 width->unit = RESIZE_UNIT_PX;
421 }
422 }
423 if (width->unit == RESIZE_UNIT_PX) {
424 resize_tiled(width->amount - con->width, RESIZE_AXIS_HORIZONTAL);
425 }
426 }
427
428 if (height->amount) {
429 if (height->unit == RESIZE_UNIT_PPT ||
430 height->unit == RESIZE_UNIT_DEFAULT) {
431 // Convert to px
432 struct sway_container *parent = con->parent;
433 while (parent->type >= C_WORKSPACE && parent->layout != L_VERT) {
434 parent = parent->parent;
435 }
436 if (parent->type >= C_WORKSPACE) {
437 height->amount = parent->height * height->amount / 100;
438 height->unit = RESIZE_UNIT_PX;
439 }
440 }
441 if (height->unit == RESIZE_UNIT_PX) {
442 resize_tiled(height->amount - con->height, RESIZE_AXIS_VERTICAL);
443 }
444 }
445
446 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
387} 447}
388 448
389/** 449/**
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 31ab281b..a09d06c2 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -170,16 +170,16 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1).
170*reload* 170*reload*
171 Reloads the sway config file and applies any changes. 171 Reloads the sway config file and applies any changes.
172 172
173*resize* shrink|grow width|height [<amount>] [px|ppt] 173*resize* shrink|grow width|height [<amount> [px|ppt]]
174 Resizes the currently focused container by _amount_, specified in pixels or 174 Resizes the currently focused container by _amount_, specified in pixels or
175 percentage points. If omitted, floating containers are resized in px and 175 percentage points. If the units are omitted, floating containers are resized
176 tiled containers by ppt. If omitted, the default _amount_ is 10. 176 in px and tiled containers by ppt. _amount_ will default to 10 if omitted.
177 177
178*resize set* <width> [px] <height> [px] 178*resize set* <width> [px|ppt] <height> [px|ppt]
179 Sets the width and height of the currently focused container to _width_ 179 Sets the width and height of the currently focused container to _width_ and
180 pixels and _height_ pixels. The [px] parameters are optional and have no 180 _height_, specified in pixels or percentage points. If the units are
181 effect. This command only accepts a size in pixels. Width and height may be 181 omitted, floating containers are resized in px and tiled containers by ppt.
182 specified in either order. 182 If _width_ or _height_ is 0, no resize is done on that axis.
183 183
184*scratchpad show* 184*scratchpad show*
185 Shows a window from the scratchpad. Repeatedly using this command will 185 Shows a window from the scratchpad. Repeatedly using this command will