Merge pull request #1893 from rr-/resize

Added cmd_size
This commit is contained in:
Michael Stapelberg
2015-09-11 14:31:33 -07:00
8 changed files with 178 additions and 1 deletions

View File

@ -823,6 +823,37 @@ void cmd_resize(I3_CMD, char *way, char *direction, char *resize_px, char *resiz
ysuccess(true);
}
/*
* Implementation of 'resize set <px> [px] <px> [px]'.
*
*/
void cmd_size(I3_CMD, char *cwidth, char *cheight) {
DLOG("resizing to %sx%s 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
int x = atoi(cwidth);
int y = atoi(cheight);
if (x <= 0 || y <= 0) {
ELOG("Resize failed: dimensions cannot be negative (was %sx%s)\n", cwidth, cheight);
return;
}
HANDLE_EMPTY_MATCH;
owindow *current;
TAILQ_FOREACH(current, &owindows, owindows) {
Con *floating_con;
if ((floating_con = con_inside_floating(current->con))) {
floating_resize(floating_con, x, y);
} else {
ELOG("Resize failed: %p not a floating container\n", current->con);
}
}
cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply
ysuccess(true);
}
/*
* Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
*

View File

@ -825,6 +825,37 @@ void floating_reposition(Con *con, Rect newrect) {
tree_render();
}
/*
* Sets size of the CT_FLOATING_CON to specified dimensions. Might limit the
* actual size with regard to size constraints taken from user settings.
* Additionally, the dimensions may be upscaled until they're divisible by the
* window's size hints.
*
*/
void floating_resize(Con *floating_con, int x, int y) {
DLOG("floating resize to %dx%d px\n", x, y);
Rect *rect = &floating_con->rect;
Con *focused_con = con_descend_focused(floating_con);
if (focused_con->window == NULL) {
DLOG("No window is focused. Not resizing.\n");
return;
}
int wi = focused_con->window->width_increment;
int hi = focused_con->window->height_increment;
rect->width = x;
rect->height = y;
if (wi)
rect->width += (wi - 1 - rect->width) % wi;
if (hi)
rect->height += (hi - 1 - rect->height) % hi;
floating_check_size(floating_con);
/* If this is a scratchpad window, don't auto center it from now on. */
if (floating_con->scratchpad_state == SCRATCHPAD_FRESH)
floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
}
/*
* Fixes the coordinates of the floating window whenever the window gets
* reassigned to a different output (or when the outputs rect changes).