aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin@gmail.com>2016-07-03 12:11:21 -0500
committerLibravatar Zandr Martin <zandrmartin@gmail.com>2016-07-03 12:11:21 -0500
commitd5e4fff34544deda97f9f7d26eb1cb391fcc86bf (patch)
treeb053d7c2e9cc7651991aea1254a6f1f5232aea7c /sway/commands.c
parentmatch i3 syntax for `resize set` (diff)
downloadsway-d5e4fff34544deda97f9f7d26eb1cb391fcc86bf.tar.gz
sway-d5e4fff34544deda97f9f7d26eb1cb391fcc86bf.tar.zst
sway-d5e4fff34544deda97f9f7d26eb1cb391fcc86bf.zip
resize command updates (#713)
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c105
1 files changed, 74 insertions, 31 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 625f8276..2248e1c7 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -2010,31 +2010,41 @@ static struct cmd_results *cmd_resize(int argc, char **argv) {
2010 return error; 2010 return error;
2011 } 2011 }
2012 2012
2013 int amount = (int)strtol(argv[argc - 1], NULL, 10); 2013 int dim_arg = argc - 1;
2014
2015 enum resize_dim_types dim_type = RESIZE_DIM_DEFAULT;
2016 if (strcasecmp(argv[dim_arg], "ppt") == 0) {
2017 dim_type = RESIZE_DIM_PPT;
2018 dim_arg--;
2019 } else if (strcasecmp(argv[dim_arg], "px") == 0) {
2020 dim_type = RESIZE_DIM_PX;
2021 dim_arg--;
2022 }
2023
2024 int amount = (int)strtol(argv[dim_arg], NULL, 10);
2014 if (errno == ERANGE || amount == 0) { 2025 if (errno == ERANGE || amount == 0) {
2015 errno = 0; 2026 errno = 0;
2016 return cmd_results_new(CMD_INVALID, "resize", "Number is out of range."); 2027 amount = 10; // this is the default resize dimension used by i3 for both px and ppt
2028 sway_log(L_DEBUG, "Tried to get resize dimension out of '%s' but failed; setting dimension to default %d",
2029 argv[dim_arg], amount);
2017 } 2030 }
2018 2031
2032 bool use_width = false;
2033 if (strcasecmp(argv[1], "width") == 0) {
2034 use_width = true;
2035 } else if (strcasecmp(argv[1], "height") != 0) {
2036 return cmd_results_new(CMD_INVALID, "resize",
2037 "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'");
2038 }
2019 2039
2020 if (strcasecmp(argv[0], "shrink") == 0 || strcmp(argv[0], "grow") == 0) { 2040 if (strcasecmp(argv[0], "shrink") == 0) {
2021 if (strcasecmp(argv[0], "shrink") == 0) { 2041 amount *= -1;
2022 amount *= -1; 2042 } else if (strcasecmp(argv[0], "grow") != 0) {
2023 }
2024
2025 if (strcasecmp(argv[1], "width") == 0) {
2026 resize_tiled(amount, true);
2027 } else if (strcmp(argv[1], "height") == 0) {
2028 resize_tiled(amount, false);
2029 } else {
2030 return cmd_results_new(CMD_INVALID, "resize",
2031 "Expected 'resize <shrink|grow> <width|height> <amount>'");
2032 }
2033 } else {
2034 return cmd_results_new(CMD_INVALID, "resize", 2043 return cmd_results_new(CMD_INVALID, "resize",
2035 "Expected 'resize <shrink|grow> <width|height> <amount>'"); 2044 "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'");
2036 } 2045 }
2037 2046
2047 resize(amount, use_width, dim_type);
2038 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 2048 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
2039} 2049}
2040 2050
@@ -2044,26 +2054,59 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) {
2044 return error; 2054 return error;
2045 } 2055 }
2046 2056
2047 int cmd_num = 0; 2057 if (strcasecmp(argv[0], "width") == 0 || strcasecmp(argv[0], "height") == 0) {
2048 int amount; 2058 // handle `reset set width 100 px height 100 px` syntax, also allows
2059 // specifying only one dimension for a `resize set`
2060 int cmd_num = 0;
2061 int dim;
2062
2063 while ((cmd_num + 1) < argc) {
2064 dim = (int)strtol(argv[cmd_num + 1], NULL, 10);
2065 if (errno == ERANGE || dim == 0) {
2066 errno = 0;
2067 return cmd_results_new(CMD_INVALID, "resize set",
2068 "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'");
2069 }
2070
2071 if (strcasecmp(argv[cmd_num], "width") == 0) {
2072 set_size(dim, true);
2073 } else if (strcasecmp(argv[cmd_num], "height") == 0) {
2074 set_size(dim, false);
2075 } else {
2076 return cmd_results_new(CMD_INVALID, "resize set",
2077 "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'");
2078 }
2079
2080 cmd_num += 2;
2049 2081
2050 while (cmd_num < argc) { 2082 if (cmd_num < argc && strcasecmp(argv[cmd_num], "px") == 0) {
2051 amount = (int)strtol(argv[cmd_num + 1], NULL, 10); 2083 // if this was `resize set width 400 px height 300 px`, disregard the `px` arg
2052 if (errno == ERANGE || amount == 0) { 2084 cmd_num++;
2085 }
2086 }
2087 } else {
2088 // handle `reset set 100 px 100 px` syntax
2089 int width = (int)strtol(argv[0], NULL, 10);
2090 if (errno == ERANGE || width == 0) {
2053 errno = 0; 2091 errno = 0;
2054 return cmd_results_new(CMD_INVALID, "resize set", "Number is out of range."); 2092 return cmd_results_new(CMD_INVALID, "resize set",
2093 "Expected 'resize set <width> [px] <height> [px]'");
2055 } 2094 }
2056 2095
2057 if (strcasecmp(argv[cmd_num], "width") == 0) { 2096 int height_arg = 1;
2058 set_size_tiled(amount, true); 2097 if (strcasecmp(argv[1], "px") == 0) {
2059 } else if (strcasecmp(argv[cmd_num], "height") == 0) { 2098 height_arg = 2;
2060 set_size_tiled(amount, false); 2099 }
2061 } else { 2100
2062 return cmd_results_new(CMD_INVALID, "resize", 2101 int height = (int)strtol(argv[height_arg], NULL, 10);
2063 "Expected 'resize set <width|height> <amount> [<width|height> <amount>]'"); 2102 if (errno == ERANGE || height == 0) {
2103 errno = 0;
2104 return cmd_results_new(CMD_INVALID, "resize set",
2105 "Expected 'resize set <width> [px] <height> [px]'");
2064 } 2106 }
2065 2107
2066 cmd_num += 2; 2108 set_size(width, true);
2109 set_size(height, false);
2067 } 2110 }
2068 2111
2069 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 2112 return cmd_results_new(CMD_SUCCESS, NULL, NULL);