version 1.20, 2021/03/11 06:31:05 |
version 1.21, 2022/05/30 12:52:02 |
|
|
|
|
/* Parse a layout string and arrange window as layout. */ |
/* Parse a layout string and arrange window as layout. */ |
int |
int |
layout_parse(struct window *w, const char *layout) |
layout_parse(struct window *w, const char *layout, char **cause) |
{ |
{ |
struct layout_cell *lc, *lcchild; |
struct layout_cell *lc, *lcchild; |
struct window_pane *wp; |
struct window_pane *wp; |
|
|
if (sscanf(layout, "%hx,", &csum) != 1) |
if (sscanf(layout, "%hx,", &csum) != 1) |
return (-1); |
return (-1); |
layout += 5; |
layout += 5; |
if (csum != layout_checksum(layout)) |
if (csum != layout_checksum(layout)) { |
|
*cause = xstrdup("invalid layout"); |
return (-1); |
return (-1); |
|
} |
|
|
/* Build the layout. */ |
/* Build the layout. */ |
lc = layout_construct(NULL, &layout); |
lc = layout_construct(NULL, &layout); |
if (lc == NULL) |
if (lc == NULL) { |
|
*cause = xstrdup("invalid layout"); |
return (-1); |
return (-1); |
if (*layout != '\0') |
} |
|
if (*layout != '\0') { |
|
*cause = xstrdup("invalid layout"); |
goto fail; |
goto fail; |
|
} |
|
|
/* Check this window will fit into the layout. */ |
/* Check this window will fit into the layout. */ |
for (;;) { |
for (;;) { |
npanes = window_count_panes(w); |
npanes = window_count_panes(w); |
ncells = layout_count_cells(lc); |
ncells = layout_count_cells(lc); |
if (npanes > ncells) |
if (npanes > ncells) { |
|
xasprintf(cause, "have %u panes but need %u", npanes, |
|
ncells); |
goto fail; |
goto fail; |
|
} |
if (npanes == ncells) |
if (npanes == ncells) |
break; |
break; |
|
|
|
|
} |
} |
|
|
/* Check the new layout. */ |
/* Check the new layout. */ |
if (!layout_check(lc)) |
if (!layout_check(lc)) { |
|
*cause = xstrdup("size mismatch after applying layout"); |
return (-1); |
return (-1); |
|
} |
|
|
/* Resize to the layout size. */ |
/* Resize to the layout size. */ |
window_resize(w, lc->sx, lc->sy, -1, -1); |
window_resize(w, lc->sx, lc->sy, -1, -1); |