diff options
author | 2016-07-03 07:05:10 -0500 | |
---|---|---|
committer | 2016-07-03 07:05:10 -0500 | |
commit | aced6daa198d22d32ead71eec097321fd2b279de (patch) | |
tree | d687b7e7758742fe8e8801acef8d7367380b25c6 /sway/commands.c | |
parent | Merge remote-tracking branch 'upstream/master' into set-size-command (diff) | |
download | sway-aced6daa198d22d32ead71eec097321fd2b279de.tar.gz sway-aced6daa198d22d32ead71eec097321fd2b279de.tar.zst sway-aced6daa198d22d32ead71eec097321fd2b279de.zip |
match i3 syntax for `resize set`
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/sway/commands.c b/sway/commands.c index 55f46f79..625f8276 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -83,6 +83,7 @@ static sway_cmd cmd_orientation; | |||
83 | static sway_cmd cmd_output; | 83 | static sway_cmd cmd_output; |
84 | static sway_cmd cmd_reload; | 84 | static sway_cmd cmd_reload; |
85 | static sway_cmd cmd_resize; | 85 | static sway_cmd cmd_resize; |
86 | static sway_cmd cmd_resize_set; | ||
86 | static sway_cmd cmd_scratchpad; | 87 | static sway_cmd cmd_scratchpad; |
87 | static sway_cmd cmd_set; | 88 | static sway_cmd cmd_set; |
88 | static sway_cmd cmd_smart_gaps; | 89 | static sway_cmd cmd_smart_gaps; |
@@ -2000,6 +2001,11 @@ static struct cmd_results *cmd_resize(int argc, char **argv) { | |||
2000 | struct cmd_results *error = NULL; | 2001 | struct cmd_results *error = NULL; |
2001 | if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file."); | 2002 | 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."); | 2003 | if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running."); |
2004 | |||
2005 | if (strcasecmp(argv[0], "set") == 0) { | ||
2006 | return cmd_resize_set(argc - 1, &argv[1]); | ||
2007 | } | ||
2008 | |||
2003 | if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { | 2009 | if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { |
2004 | return error; | 2010 | return error; |
2005 | } | 2011 | } |
@@ -2010,26 +2016,54 @@ static struct cmd_results *cmd_resize(int argc, char **argv) { | |||
2010 | return cmd_results_new(CMD_INVALID, "resize", "Number is out of range."); | 2016 | return cmd_results_new(CMD_INVALID, "resize", "Number is out of range."); |
2011 | } | 2017 | } |
2012 | 2018 | ||
2013 | if (strcmp(argv[0], "shrink") == 0 || strcmp(argv[0], "grow") == 0) { | 2019 | |
2014 | if (strcmp(argv[0], "shrink") == 0) { | 2020 | if (strcasecmp(argv[0], "shrink") == 0 || strcmp(argv[0], "grow") == 0) { |
2021 | if (strcasecmp(argv[0], "shrink") == 0) { | ||
2015 | amount *= -1; | 2022 | amount *= -1; |
2016 | } | 2023 | } |
2017 | 2024 | ||
2018 | if (strcmp(argv[1], "width") == 0) { | 2025 | if (strcasecmp(argv[1], "width") == 0) { |
2019 | resize_tiled(amount, true); | 2026 | resize_tiled(amount, true); |
2020 | } else if (strcmp(argv[1], "height") == 0) { | 2027 | } else if (strcmp(argv[1], "height") == 0) { |
2021 | resize_tiled(amount, false); | 2028 | resize_tiled(amount, false); |
2022 | } else { | 2029 | } else { |
2023 | return cmd_results_new(CMD_INVALID, "resize", | 2030 | return cmd_results_new(CMD_INVALID, "resize", |
2024 | "Expected 'resize <shrink|grow> <width|height> <amount>' or 'resize <width|height> <amount>'"); | 2031 | "Expected 'resize <shrink|grow> <width|height> <amount>'"); |
2025 | } | 2032 | } |
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); | ||
2030 | } else { | 2033 | } else { |
2031 | return cmd_results_new(CMD_INVALID, "resize", | 2034 | return cmd_results_new(CMD_INVALID, "resize", |
2032 | "Expected 'resize <shrink|grow> <width|height> <amount>' or 'resize <width|height> <amount>'"); | 2035 | "Expected 'resize <shrink|grow> <width|height> <amount>'"); |
2036 | } | ||
2037 | |||
2038 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2039 | } | ||
2040 | |||
2041 | static struct cmd_results *cmd_resize_set(int argc, char **argv) { | ||
2042 | struct cmd_results *error = NULL; | ||
2043 | if ((error = checkarg(argc, "resize set", EXPECTED_AT_LEAST, 2))) { | ||
2044 | return error; | ||
2045 | } | ||
2046 | |||
2047 | int cmd_num = 0; | ||
2048 | int amount; | ||
2049 | |||
2050 | while (cmd_num < argc) { | ||
2051 | amount = (int)strtol(argv[cmd_num + 1], NULL, 10); | ||
2052 | if (errno == ERANGE || amount == 0) { | ||
2053 | errno = 0; | ||
2054 | return cmd_results_new(CMD_INVALID, "resize set", "Number is out of range."); | ||
2055 | } | ||
2056 | |||
2057 | if (strcasecmp(argv[cmd_num], "width") == 0) { | ||
2058 | set_size_tiled(amount, true); | ||
2059 | } else if (strcasecmp(argv[cmd_num], "height") == 0) { | ||
2060 | set_size_tiled(amount, false); | ||
2061 | } else { | ||
2062 | return cmd_results_new(CMD_INVALID, "resize", | ||
2063 | "Expected 'resize set <width|height> <amount> [<width|height> <amount>]'"); | ||
2064 | } | ||
2065 | |||
2066 | cmd_num += 2; | ||
2033 | } | 2067 | } |
2034 | 2068 | ||
2035 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 2069 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |