Fix next-layout to ignore floating panes.

This commit is contained in:
Michael Grant
2026-03-24 12:41:04 +00:00
parent 0328fe44e4
commit f201d246fd
11 changed files with 74 additions and 33 deletions

View File

@@ -73,7 +73,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
}
server_unzoom_window(w);
if (window_count_panes(w) == 1) {
if (window_count_panes(w, 1) == 1) {
if (server_link_window(src_s, wl, dst_s, idx, 0,
!args_has(args, 'd'), &cause) != 0) {
cmdq_error(item, "%s", cause);

View File

@@ -170,7 +170,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
} else
server_status_session(dst_s);
if (window_count_panes(src_w) == 0)
if (window_count_panes(src_w, 1) == 0)
server_kill_window(src_w, 1);
else
notify_window("window-layout-changed", src_w);

View File

@@ -103,7 +103,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
* spawned without being visited (for example split-window -d).
*/
lastwp = TAILQ_FIRST(&w->last_panes);
if (lastwp == NULL && window_count_panes(w) == 2) {
if (lastwp == NULL && window_count_panes(w, 1) == 2) {
lastwp = TAILQ_PREV(w->active, window_panes, entry);
if (lastwp == NULL)
lastwp = TAILQ_NEXT(w->active, entry);

View File

@@ -2886,7 +2886,7 @@ static void *
format_cb_window_panes(struct format_tree *ft)
{
if (ft->w != NULL)
return (format_printf("%u", window_count_panes(ft->w)));
return (format_printf("%u", window_count_panes(ft->w, 1)));
return (NULL);
}

View File

@@ -213,7 +213,7 @@ layout_parse(struct window *w, const char *layout, char **cause)
/* Check this window will fit into the layout. */
for (;;) {
npanes = window_count_panes(w);
npanes = window_count_panes(w, 1);
ncells = layout_count_cells(tiled_lc);
ncells += layout_count_cells(floating_lc);
if (npanes > ncells) {

View File

@@ -123,6 +123,18 @@ layout_set_previous(struct window *w)
return (layout);
}
static struct window_pane *
layout_first_tiled(struct window *w)
{
struct window_pane *wp;
TAILQ_FOREACH(wp, &w->panes, entry) {
if (~wp->flags & PANE_FLOATING)
return (wp);
}
return (NULL);
}
static void
layout_set_even(struct window *w, enum layout_type type)
{
@@ -133,7 +145,7 @@ layout_set_even(struct window *w, enum layout_type type)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
@@ -156,6 +168,8 @@ layout_set_even(struct window *w, enum layout_type type)
/* Build new leaf cells. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp->flags & PANE_FLOATING)
continue;
lcnew = layout_create_cell(lc);
layout_make_leaf(lcnew, wp);
lcnew->sx = w->sx;
@@ -201,7 +215,7 @@ layout_set_main_h(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -250,14 +264,16 @@ layout_set_main_h(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, sx, mainh, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Create the other pane. */
lcother = layout_create_cell(lc);
layout_set_size(lcother, sx, otherh, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && (wp->flags & PANE_FLOATING))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -266,7 +282,9 @@ layout_set_main_h(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (wp->flags & PANE_FLOATING)
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, PANE_MINIMUM, otherh, 0, 0);
@@ -299,7 +317,7 @@ layout_set_main_h_mirrored(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -349,7 +367,9 @@ layout_set_main_h_mirrored(struct window *w)
lcother = layout_create_cell(lc);
layout_set_size(lcother, sx, otherh, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && (wp->flags & PANE_FLOATING))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -358,7 +378,9 @@ layout_set_main_h_mirrored(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (wp->flags & PANE_FLOATING)
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, PANE_MINIMUM, otherh, 0, 0);
@@ -371,7 +393,7 @@ layout_set_main_h_mirrored(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, sx, mainh, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Fix cell offsets. */
@@ -397,7 +419,7 @@ layout_set_main_v(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -446,14 +468,16 @@ layout_set_main_v(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, mainw, sy, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Create the other pane. */
lcother = layout_create_cell(lc);
layout_set_size(lcother, otherw, sy, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && (wp->flags & PANE_FLOATING))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -462,7 +486,9 @@ layout_set_main_v(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (wp->flags & PANE_FLOATING)
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, otherw, PANE_MINIMUM, 0, 0);
@@ -495,7 +521,7 @@ layout_set_main_v_mirrored(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -545,7 +571,9 @@ layout_set_main_v_mirrored(struct window *w)
lcother = layout_create_cell(lc);
layout_set_size(lcother, otherw, sy, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && (wp->flags & PANE_FLOATING))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -554,7 +582,9 @@ layout_set_main_v_mirrored(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (wp->flags & PANE_FLOATING)
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, otherw, PANE_MINIMUM, 0, 0);
@@ -567,7 +597,7 @@ layout_set_main_v_mirrored(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, mainw, sy, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Fix cell offsets. */
@@ -593,7 +623,7 @@ layout_set_tiled(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
@@ -629,8 +659,10 @@ layout_set_tiled(struct window *w)
layout_set_size(lc, sx, sy, 0, 0);
layout_make_node(lc, LAYOUT_TOPBOTTOM);
/* Create a grid of the cells. */
/* Create a grid of the cells, skipping any floating panes. */
wp = TAILQ_FIRST(&w->panes);
while (wp != NULL && (wp->flags & PANE_FLOATING))
wp = TAILQ_NEXT(wp, entry);
for (j = 0; j < rows; j++) {
/* If this is the last cell, all done. */
if (wp == NULL)
@@ -645,6 +677,8 @@ layout_set_tiled(struct window *w)
if (n - (j * columns) == 1 || columns == 1) {
layout_make_leaf(lcrow, wp);
wp = TAILQ_NEXT(wp, entry);
while (wp != NULL && (wp->flags & PANE_FLOATING))
wp = TAILQ_NEXT(wp, entry);
continue;
}
@@ -657,8 +691,11 @@ layout_set_tiled(struct window *w)
layout_make_leaf(lcchild, wp);
TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry);
/* Move to the next cell. */
if ((wp = TAILQ_NEXT(wp, entry)) == NULL)
/* Move to the next non-floating cell. */
wp = TAILQ_NEXT(wp, entry);
while (wp != NULL && (wp->flags & PANE_FLOATING))
wp = TAILQ_NEXT(wp, entry);
if (wp == NULL)
break;
}

View File

@@ -270,7 +270,8 @@ layout_fix_offsets1(struct layout_cell *lc)
} else {
yoff = lc->yoff;
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->wp->flags & PANE_MINIMISED)
if (lcchild->type == LAYOUT_WINDOWPANE &&
lcchild->wp->flags & PANE_MINIMISED)
continue;
lcchild->xoff = lc->xoff;
lcchild->yoff = yoff;

View File

@@ -184,7 +184,7 @@ server_kill_pane(struct window_pane *wp)
{
struct window *w = wp->window;
if (window_count_panes(w) == 1) {
if (window_count_panes(w, 1) == 1) {
server_kill_window(w, 1);
recalculate_sizes();
} else {

2
tmux.h
View File

@@ -3375,7 +3375,7 @@ struct window_pane *window_pane_next_by_number(struct window *,
struct window_pane *window_pane_previous_by_number(struct window *,
struct window_pane *, u_int);
int window_pane_index(struct window_pane *, u_int *);
u_int window_count_panes(struct window *);
u_int window_count_panes(struct window *, int);
void window_destroy_panes(struct window *);
struct window_pane *window_pane_find_by_id_str(const char *);
struct window_pane *window_pane_find_by_id(u_int);

View File

@@ -387,7 +387,7 @@ window_tree_build(void *modedata, struct sort_criteria *sort_crit,
*tag = (uint64_t)data->fs.wl;
break;
case WINDOW_TREE_PANE:
if (window_count_panes(data->fs.wl->window) == 1)
if (window_count_panes(data->fs.wl->window, 1) == 1)
*tag = (uint64_t)data->fs.wl;
else
*tag = (uint64_t)data->fs.wp;
@@ -566,7 +566,7 @@ window_tree_draw_window(struct window_tree_modedata *data, struct session *s,
int colour, active_colour, left, right;
char *label;
total = window_count_panes(w);
total = window_count_panes(w, 1);
memcpy(&gc, &grid_default_cell, sizeof gc);
colour = options_get_number(oo, "display-panes-colour");

View File

@@ -950,14 +950,17 @@ window_pane_index(struct window_pane *wp, u_int *i)
}
u_int
window_count_panes(struct window *w)
window_count_panes(struct window *w, int inc_floating)
{
struct window_pane *wp;
u_int n;
n = 0;
TAILQ_FOREACH(wp, &w->panes, entry)
TAILQ_FOREACH(wp, &w->panes, entry) {
if ((inc_floating == 0) && (wp->flags & PANE_FLOATING))
continue;
n++;
}
return (n);
}