mirror of
https://github.com/swaywm/sway.git
synced 2025-11-07 13:29:56 -05:00
resize command updates (#713)
This commit is contained in:
parent
aced6daa19
commit
d5e4fff345
6 changed files with 229 additions and 52 deletions
107
sway/commands.c
107
sway/commands.c
|
|
@ -2010,31 +2010,41 @@ static struct cmd_results *cmd_resize(int argc, char **argv) {
|
|||
return error;
|
||||
}
|
||||
|
||||
int amount = (int)strtol(argv[argc - 1], NULL, 10);
|
||||
int dim_arg = argc - 1;
|
||||
|
||||
enum resize_dim_types dim_type = RESIZE_DIM_DEFAULT;
|
||||
if (strcasecmp(argv[dim_arg], "ppt") == 0) {
|
||||
dim_type = RESIZE_DIM_PPT;
|
||||
dim_arg--;
|
||||
} else if (strcasecmp(argv[dim_arg], "px") == 0) {
|
||||
dim_type = RESIZE_DIM_PX;
|
||||
dim_arg--;
|
||||
}
|
||||
|
||||
int amount = (int)strtol(argv[dim_arg], NULL, 10);
|
||||
if (errno == ERANGE || amount == 0) {
|
||||
errno = 0;
|
||||
return cmd_results_new(CMD_INVALID, "resize", "Number is out of range.");
|
||||
amount = 10; // this is the default resize dimension used by i3 for both px and ppt
|
||||
sway_log(L_DEBUG, "Tried to get resize dimension out of '%s' but failed; setting dimension to default %d",
|
||||
argv[dim_arg], amount);
|
||||
}
|
||||
|
||||
|
||||
if (strcasecmp(argv[0], "shrink") == 0 || strcmp(argv[0], "grow") == 0) {
|
||||
if (strcasecmp(argv[0], "shrink") == 0) {
|
||||
amount *= -1;
|
||||
}
|
||||
|
||||
if (strcasecmp(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>'");
|
||||
}
|
||||
} else {
|
||||
bool use_width = false;
|
||||
if (strcasecmp(argv[1], "width") == 0) {
|
||||
use_width = true;
|
||||
} else if (strcasecmp(argv[1], "height") != 0) {
|
||||
return cmd_results_new(CMD_INVALID, "resize",
|
||||
"Expected 'resize <shrink|grow> <width|height> <amount>'");
|
||||
"Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'");
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[0], "shrink") == 0) {
|
||||
amount *= -1;
|
||||
} else if (strcasecmp(argv[0], "grow") != 0) {
|
||||
return cmd_results_new(CMD_INVALID, "resize",
|
||||
"Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'");
|
||||
}
|
||||
|
||||
resize(amount, use_width, dim_type);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
||||
|
|
@ -2044,26 +2054,59 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) {
|
|||
return error;
|
||||
}
|
||||
|
||||
int cmd_num = 0;
|
||||
int amount;
|
||||
if (strcasecmp(argv[0], "width") == 0 || strcasecmp(argv[0], "height") == 0) {
|
||||
// handle `reset set width 100 px height 100 px` syntax, also allows
|
||||
// specifying only one dimension for a `resize set`
|
||||
int cmd_num = 0;
|
||||
int dim;
|
||||
|
||||
while (cmd_num < argc) {
|
||||
amount = (int)strtol(argv[cmd_num + 1], NULL, 10);
|
||||
if (errno == ERANGE || amount == 0) {
|
||||
while ((cmd_num + 1) < argc) {
|
||||
dim = (int)strtol(argv[cmd_num + 1], NULL, 10);
|
||||
if (errno == ERANGE || dim == 0) {
|
||||
errno = 0;
|
||||
return cmd_results_new(CMD_INVALID, "resize set",
|
||||
"Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'");
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[cmd_num], "width") == 0) {
|
||||
set_size(dim, true);
|
||||
} else if (strcasecmp(argv[cmd_num], "height") == 0) {
|
||||
set_size(dim, false);
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "resize set",
|
||||
"Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'");
|
||||
}
|
||||
|
||||
cmd_num += 2;
|
||||
|
||||
if (cmd_num < argc && strcasecmp(argv[cmd_num], "px") == 0) {
|
||||
// if this was `resize set width 400 px height 300 px`, disregard the `px` arg
|
||||
cmd_num++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// handle `reset set 100 px 100 px` syntax
|
||||
int width = (int)strtol(argv[0], NULL, 10);
|
||||
if (errno == ERANGE || width == 0) {
|
||||
errno = 0;
|
||||
return cmd_results_new(CMD_INVALID, "resize set", "Number is out of range.");
|
||||
return cmd_results_new(CMD_INVALID, "resize set",
|
||||
"Expected 'resize set <width> [px] <height> [px]'");
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[cmd_num], "width") == 0) {
|
||||
set_size_tiled(amount, true);
|
||||
} else if (strcasecmp(argv[cmd_num], "height") == 0) {
|
||||
set_size_tiled(amount, false);
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "resize",
|
||||
"Expected 'resize set <width|height> <amount> [<width|height> <amount>]'");
|
||||
int height_arg = 1;
|
||||
if (strcasecmp(argv[1], "px") == 0) {
|
||||
height_arg = 2;
|
||||
}
|
||||
|
||||
cmd_num += 2;
|
||||
int height = (int)strtol(argv[height_arg], NULL, 10);
|
||||
if (errno == ERANGE || height == 0) {
|
||||
errno = 0;
|
||||
return cmd_results_new(CMD_INVALID, "resize set",
|
||||
"Expected 'resize set <width> [px] <height> [px]'");
|
||||
}
|
||||
|
||||
set_size(width, true);
|
||||
set_size(height, false);
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue