summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2022-04-06 14:41:44 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2022-04-06 14:41:44 +0100
commit996e54763c04749860532a0d6b7df0d75671a405 (patch)
tree4d4d2fd085daf4d6b622b0423cef14fc2e6ca542
parent18105c8ecb901c72040db09f58585503a8409fd0 (diff)
Better error reporting when applying custom layouts.
-rw-r--r--cmd-select-layout.c7
-rw-r--r--layout-custom.c23
-rw-r--r--tmux.h2
3 files changed, 22 insertions, 10 deletions
diff --git a/cmd-select-layout.c b/cmd-select-layout.c
index c857a0e1..6dfe2b6a 100644
--- a/cmd-select-layout.c
+++ b/cmd-select-layout.c
@@ -77,7 +77,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window;
struct window_pane *wp = target->wp;
const char *layoutname;
- char *oldlayout;
+ char *oldlayout, *cause;
int next, previous, layout;
server_unzoom_window(w);
@@ -124,8 +124,9 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
}
if (layoutname != NULL) {
- if (layout_parse(w, layoutname) == -1) {
- cmdq_error(item, "can't set layout: %s", layoutname);
+ if (layout_parse(w, layoutname, &cause) == -1) {
+ cmdq_error(item, "%s: %s", cause, layoutname);
+ free(cause);
goto error;
}
goto changed;
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);
diff --git a/tmux.h b/tmux.h
index 90a3f93c..2ec09692 100644
--- a/tmux.h
+++ b/tmux.h
@@ -3020,7 +3020,7 @@ void layout_spread_out(struct window_pane *);
/* layout-custom.c */
char *layout_dump(struct layout_cell *);
-int layout_parse(struct window *, const char *);
+int layout_parse(struct window *, const char *, char **);
/* layout-set.c */
int layout_set_lookup(const char *);