Cleaned up some of the implementation and moved flags to the front.

This commit is contained in:
Dane Jensen
2026-07-12 13:00:11 -07:00
parent 5b6498ace4
commit b448cf8726
2 changed files with 27 additions and 43 deletions

View File

@@ -78,7 +78,7 @@ layout_append(struct layout_cell *lc, char *buf, size_t len)
enum layout_type type = lc->type;
char tmp[64];
size_t buflen, tmplen;
const char *brackets = "][";
const char *brackets = "][", *flags;
if (len == 0)
return (-1);
@@ -93,9 +93,10 @@ layout_append(struct layout_cell *lc, char *buf, size_t len)
return (-1);
if (lc->wp != NULL) {
tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%d,%d,%u%s",
lc->g.sx, lc->g.sy, lc->g.xoff, lc->g.yoff, lc->wp->id,
lc->flags & LAYOUT_CELL_FLOATING ? ",f" : "\0");
flags = window_pane_printable_flags(lc->wp);
tmplen = xsnprintf(tmp, sizeof tmp, "%s%s%ux%u,%d,%d,%u",
flags, *flags != '\0' ? "," : "", lc->g.sx, lc->g.sy,
lc->g.xoff, lc->g.yoff, lc->wp->id);
} else {
tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%d,%d",
lc->g.sx, lc->g.sy, lc->g.xoff, lc->g.yoff);
@@ -307,11 +308,17 @@ static int
layout_custom_set_flags(struct layout_cell *lc, const char **layout)
{
switch (**layout) {
case 'f':
case 'F':
lc->flags |= LAYOUT_CELL_FLOATING;
(*layout)++;
return (1);
case ')':
case '-': /* unsupported fallthrough */
case '*':
case 'Z':
(*layout)++;
return (1);
case ',':
(*layout)++;
return (0);
default:
return (-1);
@@ -342,6 +349,16 @@ layout_custom_create_cell(struct layout_cell *lcparent, const char **layout)
lc = layout_create_cell(lcparent);
lc->type = type;
if (!isdigit((u_char) **layout)) {
while (1) {
result = layout_custom_set_flags(lc, layout);
if (result == 0)
break;
if (result == -1)
goto fail;
}
}
if (sscanf(*layout, "%ux%u,%d,%d", &lc->g.sx, &lc->g.sy, &lc->g.xoff,
&lc->g.yoff) != 4)
goto fail;
@@ -374,19 +391,6 @@ layout_custom_create_cell(struct layout_cell *lcparent, const char **layout)
while (isdigit((u_char) **layout))
(*layout)++;
/* Pane with no flags. */
if (**layout == ')')
return (lc);
(*layout)++;
while (1) {
result = layout_custom_set_flags(lc, layout);
if (result == 0)
break;
if (result == -1)
goto fail;
}
return (lc);
fail:
free(lc);

View File

@@ -233,28 +233,6 @@ layout_make_node(struct layout_cell *lc, enum layout_type type)
lc->wp = NULL;
}
static void
layout_fix_zindexes1(struct window *w, struct layout_cell *lc)
{
struct layout_cell *lcchild;
// TODO: Why does this operate on cells? Couldn't it operate on
// panes directly?
if (lc == NULL)
return;
switch (lc->type) {
case LAYOUT_WINDOWPANE:
if (~lc->flags & LAYOUT_CELL_FLOATING)
TAILQ_INSERT_TAIL(&w->z_index, lc->wp, zentry);
break;
case LAYOUT_LEFTRIGHT:
case LAYOUT_TOPBOTTOM:
TAILQ_FOREACH(lcchild, &lc->cells, entry)
layout_fix_zindexes1(w, lcchild);
return;
}
}
/* Fix z-indexes. */
void
layout_fix_zindexes(struct window *w)
@@ -271,8 +249,10 @@ layout_fix_zindexes(struct window *w)
wp = wpnext;
}
/* Add back the non-floating panes. */
layout_fix_zindexes1(w, w->layout_root);
TAILQ_FOREACH(wp, &w->panes, entry) {
if (!window_pane_is_floating(wp))
TAILQ_INSERT_TAIL(&w->z_index, wp, zentry);
}
}
int