Migrate the resize command to use typed numbers.
This commit is contained in:
parent
f5f5683fa7
commit
a271666fa7
@ -64,13 +64,13 @@ void cmd_move_con_to_workspace_number(I3_CMD, char *which);
|
|||||||
* Implementation of 'resize set <px> [px] <px> [px]'.
|
* Implementation of 'resize set <px> [px] <px> [px]'.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_size(I3_CMD, char *cwidth, char *cheight);
|
void cmd_resize_set(I3_CMD, long cwidth, long cheight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
|
* Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_resize(I3_CMD, char *way, char *direction, char *resize_px, char *resize_ppt);
|
void cmd_resize(I3_CMD, char *way, char *direction, long resize_px, long resize_ppt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
|
* Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
|
||||||
|
@ -225,10 +225,10 @@ state RESIZE_DIRECTION:
|
|||||||
-> RESIZE_PX
|
-> RESIZE_PX
|
||||||
|
|
||||||
state RESIZE_PX:
|
state RESIZE_PX:
|
||||||
resize_px = word
|
resize_px = number
|
||||||
-> RESIZE_TILING
|
-> RESIZE_TILING
|
||||||
end
|
end
|
||||||
-> call cmd_resize($way, $direction, "10", "10")
|
-> call cmd_resize($way, $direction, 10, 10)
|
||||||
|
|
||||||
state RESIZE_TILING:
|
state RESIZE_TILING:
|
||||||
'px'
|
'px'
|
||||||
@ -236,29 +236,29 @@ state RESIZE_TILING:
|
|||||||
'or'
|
'or'
|
||||||
-> RESIZE_TILING_OR
|
-> RESIZE_TILING_OR
|
||||||
end
|
end
|
||||||
-> call cmd_resize($way, $direction, $resize_px, "10")
|
-> call cmd_resize($way, $direction, &resize_px, 10)
|
||||||
|
|
||||||
state RESIZE_TILING_OR:
|
state RESIZE_TILING_OR:
|
||||||
resize_ppt = word
|
resize_ppt = number
|
||||||
-> RESIZE_TILING_FINAL
|
-> RESIZE_TILING_FINAL
|
||||||
|
|
||||||
state RESIZE_TILING_FINAL:
|
state RESIZE_TILING_FINAL:
|
||||||
'ppt', end
|
'ppt', end
|
||||||
-> call cmd_resize($way, $direction, $resize_px, $resize_ppt)
|
-> call cmd_resize($way, $direction, &resize_px, &resize_ppt)
|
||||||
|
|
||||||
state RESIZE_SET:
|
state RESIZE_SET:
|
||||||
width = word
|
width = number
|
||||||
-> RESIZE_WIDTH
|
-> RESIZE_WIDTH
|
||||||
|
|
||||||
state RESIZE_WIDTH:
|
state RESIZE_WIDTH:
|
||||||
'px'
|
'px'
|
||||||
->
|
->
|
||||||
height = word
|
height = number
|
||||||
-> RESIZE_HEIGHT
|
-> RESIZE_HEIGHT
|
||||||
|
|
||||||
state RESIZE_HEIGHT:
|
state RESIZE_HEIGHT:
|
||||||
'px', end
|
'px', end
|
||||||
-> call cmd_size($width, $height)
|
-> call cmd_resize_set(&width, &height)
|
||||||
|
|
||||||
# rename workspace <name> to <name>
|
# rename workspace <name> to <name>
|
||||||
# rename workspace to <name>
|
# rename workspace to <name>
|
||||||
|
@ -782,15 +782,11 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, char *way, char
|
|||||||
* Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
|
* Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_resize(I3_CMD, char *way, char *direction, char *resize_px, char *resize_ppt) {
|
void cmd_resize(I3_CMD, char *way, char *direction, long resize_px, long resize_ppt) {
|
||||||
/* resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] */
|
DLOG("resizing in way %s, direction %s, px %ld or ppt %ld\n", way, direction, resize_px, resize_ppt);
|
||||||
DLOG("resizing in way %s, direction %s, px %s or ppt %s\n", way, direction, resize_px, resize_ppt);
|
|
||||||
// TODO: We could either handle this in the parser itself as a separate token (and make the stack typed) or we need a better way to convert a string to a number with error checking
|
|
||||||
int px = atoi(resize_px);
|
|
||||||
int ppt = atoi(resize_ppt);
|
|
||||||
if (strcmp(way, "shrink") == 0) {
|
if (strcmp(way, "shrink") == 0) {
|
||||||
px *= -1;
|
resize_px *= -1;
|
||||||
ppt *= -1;
|
resize_ppt *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_EMPTY_MATCH;
|
HANDLE_EMPTY_MATCH;
|
||||||
@ -805,14 +801,16 @@ void cmd_resize(I3_CMD, char *way, char *direction, char *resize_px, char *resiz
|
|||||||
|
|
||||||
Con *floating_con;
|
Con *floating_con;
|
||||||
if ((floating_con = con_inside_floating(current->con))) {
|
if ((floating_con = con_inside_floating(current->con))) {
|
||||||
cmd_resize_floating(current_match, cmd_output, way, direction, floating_con, px);
|
cmd_resize_floating(current_match, cmd_output, way, direction, floating_con, resize_px);
|
||||||
} else {
|
} else {
|
||||||
if (strcmp(direction, "width") == 0 ||
|
if (strcmp(direction, "width") == 0 ||
|
||||||
strcmp(direction, "height") == 0) {
|
strcmp(direction, "height") == 0) {
|
||||||
if (!cmd_resize_tiling_width_height(current_match, cmd_output, current->con, way, direction, ppt))
|
if (!cmd_resize_tiling_width_height(current_match, cmd_output,
|
||||||
|
current->con, way, direction, resize_ppt))
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (!cmd_resize_tiling_direction(current_match, cmd_output, current->con, way, direction, ppt))
|
if (!cmd_resize_tiling_direction(current_match, cmd_output,
|
||||||
|
current->con, way, direction, resize_ppt))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -827,13 +825,10 @@ void cmd_resize(I3_CMD, char *way, char *direction, char *resize_px, char *resiz
|
|||||||
* Implementation of 'resize set <px> [px] <px> [px]'.
|
* Implementation of 'resize set <px> [px] <px> [px]'.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_size(I3_CMD, char *cwidth, char *cheight) {
|
void cmd_resize_set(I3_CMD, long cwidth, long cheight) {
|
||||||
DLOG("resizing to %sx%s px\n", cwidth, cheight);
|
DLOG("resizing to %ldx%ld px\n", cwidth, cheight);
|
||||||
// TODO: We could either handle this in the parser itself as a separate token (and make the stack typed) or we need a better way to convert a string to a number with error checking
|
if (cwidth <= 0 || cheight <= 0) {
|
||||||
int x = atoi(cwidth);
|
ELOG("Resize failed: dimensions cannot be negative (was %ldx%ld)\n", cwidth, cheight);
|
||||||
int y = atoi(cheight);
|
|
||||||
if (x <= 0 || y <= 0) {
|
|
||||||
ELOG("Resize failed: dimensions cannot be negative (was %sx%s)\n", cwidth, cheight);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,7 +838,7 @@ void cmd_size(I3_CMD, char *cwidth, char *cheight) {
|
|||||||
TAILQ_FOREACH(current, &owindows, owindows) {
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
||||||
Con *floating_con;
|
Con *floating_con;
|
||||||
if ((floating_con = con_inside_floating(current->con))) {
|
if ((floating_con = con_inside_floating(current->con))) {
|
||||||
floating_resize(floating_con, x, y);
|
floating_resize(floating_con, cwidth, cheight);
|
||||||
} else {
|
} else {
|
||||||
ELOG("Resize failed: %p not a floating container\n", current->con);
|
ELOG("Resize failed: %p not a floating container\n", current->con);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user