diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-06-11 19:39:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-11 19:39:39 -0400 |
commit | 3ce8cc807753119104d8836b6c77e19fd644a878 (patch) | |
tree | 978577aae4b59ae33012fb8c181ab61b82279a97 | |
parent | f1268053a62a83c0169b61451d01649a3f3185e3 (diff) | |
parent | a6f4bf60f2a6b9aa2ae5cadee5c1aada2ff1f6b3 (diff) |
Merge pull request #709 from zandrmartin/set-size-command
implement resize command for absolute dimensions
-rw-r--r-- | include/resize.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 37 | ||||
-rw-r--r-- | sway/resize.c | 14 | ||||
-rw-r--r-- | sway/sway.5.txt | 4 |
4 files changed, 40 insertions, 16 deletions
diff --git a/include/resize.h b/include/resize.h index 8d205d3b..d49cc74a 100644 --- a/include/resize.h +++ b/include/resize.h @@ -2,6 +2,7 @@ #define _SWAY_RESIZE_H #include <stdbool.h> +bool set_size_tiled(int amount, bool use_width); bool resize_tiled(int amount, bool use_width); #endif diff --git a/sway/commands.c b/sway/commands.c index 5e84ea9a..4009997b 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -2000,33 +2000,38 @@ static struct cmd_results *cmd_resize(int argc, char **argv) { struct cmd_results *error = NULL; if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file."); if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running."); - if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 3))) { + if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { return error; } - char *end; - int amount = (int)strtol(argv[2], &end, 10); + + int amount = (int)strtol(argv[argc - 1], NULL, 10); if (errno == ERANGE || amount == 0) { errno = 0; return cmd_results_new(CMD_INVALID, "resize", "Number is out of range."); } - if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) { - return cmd_results_new(CMD_INVALID, "resize", - "Expected 'resize <shrink|grow> <width|height> <amount>'"); - } - - if (strcmp(argv[0], "shrink") == 0) { - amount *= -1; - } + if (strcmp(argv[0], "shrink") == 0 || strcmp(argv[0], "grow") == 0) { + if (strcmp(argv[0], "shrink") == 0) { + amount *= -1; + } - if (strcmp(argv[1], "width") == 0) { - resize_tiled(amount, true); - } else if (strcmp(argv[1], "height") == 0) { - resize_tiled(amount, false); + if (strcmp(argv[1], "width") == 0) { + resize_tiled(amount, true); + } else if (strcmp(argv[1], "height") == 0) { + resize_tiled(amount, false); + } else { + return cmd_results_new(CMD_INVALID, "resize", + "Expected 'resize <shrink|grow> <width|height> <amount>' or 'resize <width|height> <amount>'"); + } + } else if (strcmp(argv[0], "width") == 0) { + set_size_tiled(amount, true); + } else if (strcmp(argv[0], "height") == 0) { + set_size_tiled(amount, false); } else { return cmd_results_new(CMD_INVALID, "resize", - "Expected 'resize <shrink|grow> <width|height> <amount>'"); + "Expected 'resize <shrink|grow> <width|height> <amount>' or 'resize <width|height> <amount>'"); } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/resize.c b/sway/resize.c index f1b1f4ae..9411cfd8 100644 --- a/sway/resize.c +++ b/sway/resize.c @@ -5,6 +5,20 @@ #include "log.h" #include "input_state.h" #include "handlers.h" +#include "resize.h" + +bool set_size_tiled(int amount, bool use_width) { + int desired; + swayc_t *focused = get_focused_view(swayc_active_workspace()); + + if (use_width) { + desired = amount - focused->width; + } else { + desired = amount - focused->height; + } + + return resize_tiled(desired, use_width); +} bool resize_tiled(int amount, bool use_width) { swayc_t *parent = get_focused_view(swayc_active_workspace()); diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 00806112..76d09edb 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -98,6 +98,10 @@ They are expected to be used with **bindsym** or at runtime through **swaymsg**( Resizes the currently focused container or view by _amount_. _amount_ can be specified as "n px" or "n ppt" or "n px or n ppt". +**resize** <width|height> <amount>:: + Sets the _width_ or _height_ of the currently focused container to _amount_. + _amount_ can be specified as "n px" or "n ppt" or "n px or n ppt". + **split** <vertical|v|horizontal|h|toggle|t>:: Splits the current container, vertically or horizontally. If toggled then the current container is split opposite to the parent container. |