From 10a9ce1ed282e29bbc65065956689ebf5bad0919 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Fri, 20 Mar 2026 07:59:25 +0000 Subject: [PATCH] Prohibit swapping 2 floating panes, that doesn't make sense. --- cmd-swap-pane.c | 12 ++++++++++++ layout.c | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c index 7271e50e..f0238e24 100644 --- a/cmd-swap-pane.c +++ b/cmd-swap-pane.c @@ -79,6 +79,11 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) if (src_wp == dst_wp) goto out; + if ((src_wp->flags & PANE_FLOATING) && (dst_wp->flags & PANE_FLOATING)) { + cmdq_error(item, "cannot swap two floating panes"); + return (CMD_RETURN_ERROR); + } + server_client_remove_pane(src_wp); server_client_remove_pane(dst_wp); @@ -99,6 +104,13 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) dst_lc->wp = src_wp; src_wp->layout_cell = dst_lc; + /* Swap PANE_FLOATING flag to keep each pane consistent with its new + * layout cell (floating cells have parent == NULL). */ + if ((src_wp->flags ^ dst_wp->flags) & PANE_FLOATING) { + src_wp->flags ^= PANE_FLOATING; + dst_wp->flags ^= PANE_FLOATING; + } + src_wp->window = dst_w; options_set_parent(src_wp->options, dst_w->options); src_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED); diff --git a/layout.c b/layout.c index ca85a7af..c2811f1e 100644 --- a/layout.c +++ b/layout.c @@ -301,6 +301,8 @@ layout_cell_is_top(struct window *w, struct layout_cell *lc) while (lc != w->layout_root) { next = lc->parent; + if (next == NULL) + return (0); if (next->type == LAYOUT_TOPBOTTOM && lc != TAILQ_FIRST(&next->cells)) return (0); @@ -317,6 +319,8 @@ layout_cell_is_bottom(struct window *w, struct layout_cell *lc) while (lc != w->layout_root) { next = lc->parent; + if (next == NULL) + return (0); if (next->type == LAYOUT_TOPBOTTOM && lc != TAILQ_LAST(&next->cells, layout_cells)) return (0);