diff options
author | 2016-06-11 17:02:16 -0500 | |
---|---|---|
committer | 2016-06-11 17:02:16 -0500 | |
commit | 889618d3eeb5786df45e1e4885debe610932fc31 (patch) | |
tree | a73c7e86319900670d4894894902420d9eb9dd72 /sway | |
parent | Merge pull request #701 from zandrmartin/assign-command (diff) | |
download | sway-889618d3eeb5786df45e1e4885debe610932fc31.tar.gz sway-889618d3eeb5786df45e1e4885debe610932fc31.tar.zst sway-889618d3eeb5786df45e1e4885debe610932fc31.zip |
implement resize command for absolute dimensions
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 37 | ||||
-rw-r--r-- | sway/resize.c | 14 | ||||
-rw-r--r-- | sway/sway.5.txt | 4 |
3 files changed, 39 insertions, 16 deletions
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) { | |||
2000 | struct cmd_results *error = NULL; | 2000 | struct cmd_results *error = NULL; |
2001 | if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file."); | 2001 | if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file."); |
2002 | if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running."); | 2002 | if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running."); |
2003 | if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 3))) { | 2003 | if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { |
2004 | return error; | 2004 | return error; |
2005 | } | 2005 | } |
2006 | char *end; | 2006 | |
2007 | int amount = (int)strtol(argv[2], &end, 10); | 2007 | int amount = (int)strtol(argv[argc - 1], NULL, 10); |
2008 | if (errno == ERANGE || amount == 0) { | 2008 | if (errno == ERANGE || amount == 0) { |
2009 | errno = 0; | 2009 | errno = 0; |
2010 | return cmd_results_new(CMD_INVALID, "resize", "Number is out of range."); | 2010 | return cmd_results_new(CMD_INVALID, "resize", "Number is out of range."); |
2011 | } | 2011 | } |
2012 | 2012 | ||
2013 | if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) { | 2013 | if (strcmp(argv[0], "shrink") == 0 || strcmp(argv[0], "grow") == 0) { |
2014 | return cmd_results_new(CMD_INVALID, "resize", | 2014 | if (strcmp(argv[0], "shrink") == 0) { |
2015 | "Expected 'resize <shrink|grow> <width|height> <amount>'"); | 2015 | amount *= -1; |
2016 | } | 2016 | } |
2017 | |||
2018 | if (strcmp(argv[0], "shrink") == 0) { | ||
2019 | amount *= -1; | ||
2020 | } | ||
2021 | 2017 | ||
2022 | if (strcmp(argv[1], "width") == 0) { | 2018 | if (strcmp(argv[1], "width") == 0) { |
2023 | resize_tiled(amount, true); | 2019 | resize_tiled(amount, true); |
2024 | } else if (strcmp(argv[1], "height") == 0) { | 2020 | } else if (strcmp(argv[1], "height") == 0) { |
2025 | resize_tiled(amount, false); | 2021 | resize_tiled(amount, false); |
2022 | } else { | ||
2023 | return cmd_results_new(CMD_INVALID, "resize", | ||
2024 | "Expected 'resize <shrink|grow> <width|height> <amount>' or 'resize <width|height> <amount>'"); | ||
2025 | } | ||
2026 | } else if (strcmp(argv[0], "width") == 0) { | ||
2027 | set_size_tiled(amount, true); | ||
2028 | } else if (strcmp(argv[0], "height") == 0) { | ||
2029 | set_size_tiled(amount, false); | ||
2026 | } else { | 2030 | } else { |
2027 | return cmd_results_new(CMD_INVALID, "resize", | 2031 | return cmd_results_new(CMD_INVALID, "resize", |
2028 | "Expected 'resize <shrink|grow> <width|height> <amount>'"); | 2032 | "Expected 'resize <shrink|grow> <width|height> <amount>' or 'resize <width|height> <amount>'"); |
2029 | } | 2033 | } |
2034 | |||
2030 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 2035 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
2031 | } | 2036 | } |
2032 | 2037 | ||
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 @@ | |||
5 | #include "log.h" | 5 | #include "log.h" |
6 | #include "input_state.h" | 6 | #include "input_state.h" |
7 | #include "handlers.h" | 7 | #include "handlers.h" |
8 | #include "resize.h" | ||
9 | |||
10 | bool set_size_tiled(int amount, bool use_width) { | ||
11 | int desired; | ||
12 | swayc_t *focused = get_focused_view(swayc_active_workspace()); | ||
13 | |||
14 | if (use_width) { | ||
15 | desired = amount - focused->width; | ||
16 | } else { | ||
17 | desired = amount - focused->height; | ||
18 | } | ||
19 | |||
20 | return resize_tiled(desired, use_width); | ||
21 | } | ||
8 | 22 | ||
9 | bool resize_tiled(int amount, bool use_width) { | 23 | bool resize_tiled(int amount, bool use_width) { |
10 | swayc_t *parent = get_focused_view(swayc_active_workspace()); | 24 | 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**( | |||
98 | Resizes the currently focused container or view by _amount_. _amount_ can be | 98 | Resizes the currently focused container or view by _amount_. _amount_ can be |
99 | specified as "n px" or "n ppt" or "n px or n ppt". | 99 | specified as "n px" or "n ppt" or "n px or n ppt". |
100 | 100 | ||
101 | **resize** <width|height> <amount>:: | ||
102 | Sets the _width_ or _height_ of the currently focused container to _amount_. | ||
103 | _amount_ can be specified as "n px" or "n ppt" or "n px or n ppt". | ||
104 | |||
101 | **split** <vertical|v|horizontal|h|toggle|t>:: | 105 | **split** <vertical|v|horizontal|h|toggle|t>:: |
102 | Splits the current container, vertically or horizontally. If toggled then the | 106 | Splits the current container, vertically or horizontally. If toggled then the |
103 | current container is split opposite to the parent container. | 107 | current container is split opposite to the parent container. |