summaryrefslogtreecommitdiffstats
path: root/layout-custom.c
diff options
context:
space:
mode:
authornicm <nicm>2022-05-30 12:52:02 +0000
committernicm <nicm>2022-05-30 12:52:02 +0000
commit4ae2c646576cc4e9f91c730c80bf75fd5122e4b3 (patch)
tree3fd4391af22bc82e3f42c2c89c28b456abf0d9d1 /layout-custom.c
parentcd692b5a68be0eb95252380db97fbbec587d6350 (diff)
Better error reporting when applying custom layouts.
Diffstat (limited to 'layout-custom.c')
-rw-r--r--layout-custom.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/layout-custom.c b/layout-custom.c
index e7fb4253..932b30e7 100644
--- a/layout-custom.c
+++ b/layout-custom.c
@@ -154,7 +154,7 @@ layout_check(struct layout_cell *lc)
/* Parse a layout string and arrange window as layout. */
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 window_pane *wp;
@@ -165,22 +165,31 @@ layout_parse(struct window *w, const char *layout)
if (sscanf(layout, "%hx,", &csum) != 1)
return (-1);
layout += 5;
- if (csum != layout_checksum(layout))
+ if (csum != layout_checksum(layout)) {
+ *cause = xstrdup("invalid layout");
return (-1);
+ }
/* Build the layout. */
lc = layout_construct(NULL, &layout);
- if (lc == NULL)
+ if (lc == NULL) {
+ *cause = xstrdup("invalid layout");
return (-1);
- if (*layout != '\0')
+ }
+ if (*layout != '\0') {
+ *cause = xstrdup("invalid layout");
goto fail;
+ }
/* Check this window will fit into the layout. */
for (;;) {
npanes = window_count_panes(w);
ncells = layout_count_cells(lc);
- if (npanes > ncells)
+ if (npanes > ncells) {
+ xasprintf(cause, "have %u panes but need %u", npanes,
+ ncells);
goto fail;
+ }
if (npanes == ncells)
break;
@@ -217,8 +226,10 @@ layout_parse(struct window *w, const char *layout)
}
/* Check the new layout. */
- if (!layout_check(lc))
+ if (!layout_check(lc)) {
+ *cause = xstrdup("size mismatch after applying layout");
return (-1);
+ }
/* Resize to the layout size. */
window_resize(w, lc->sx, lc->sy, -1, -1);