From 033c6ecb9faddb523a0f1b539a060dabad0c6cad Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Thu, 1 Oct 2026 08:13:16 +0100 Subject: [PATCH] Cleanup. Co-Authored-By: Claude Opus 5.5 --- cmd-join-pane.c | 41 +++++++++++++++++++++++------------------ cmd-swap-pane.c | 21 +++++++++++---------- layout-custom.c | 6 ++++-- window-panes.c | 10 ++-------- window.c | 41 +++++++++++++++++++---------------------- 5 files changed, 59 insertions(+), 60 deletions(-) diff --git a/cmd-join-pane.c b/cmd-join-pane.c index 55fde2b7c..55a709c1f 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -68,12 +68,15 @@ const struct cmd_entry cmd_move_pane_entry = { static int cmd_join_pane_is_stacking(const char *position) { - return (strcmp(position, "front") == 0 || - strcmp(position, "back") == 0 || - strcmp(position, "forward") == 0 || - strcmp(position, "backward") == 0 || - strcmp(position, "forward-loop") == 0 || - strcmp(position, "backward-loop") == 0); + const char *names[] = { "front", "back", "forward", "backward", + "forward-loop", "backward-loop" }; + u_int i; + + for (i = 0; i < nitems(names); i++) { + if (strcmp(position, names[i]) == 0) + return (1); + } + return (0); } /* Get the stacking group of a pane: modal, always on top, or other. */ @@ -92,12 +95,13 @@ static struct window_pane * cmd_join_pane_forward(struct window_pane *wp) { struct window_pane *owp = wp; + int group = cmd_join_pane_group(wp); do { owp = TAILQ_PREV(owp, window_panes_zindex, zentry); } while (owp != NULL && !window_pane_is_visible(owp)); - if (owp == NULL || cmd_join_pane_group(owp) != cmd_join_pane_group(wp)) - return (NULL); + if (owp != NULL && cmd_join_pane_group(owp) != group) + owp = NULL; return (owp); } @@ -106,14 +110,15 @@ static struct window_pane * cmd_join_pane_backward(struct window_pane *wp) { struct window_pane *owp = wp; + int group = cmd_join_pane_group(wp); do { owp = TAILQ_NEXT(owp, zentry); } while (owp != NULL && !window_pane_is_visible(owp)); - if (owp == NULL || - !window_pane_is_raised(owp) || - cmd_join_pane_group(owp) != cmd_join_pane_group(wp)) - return (NULL); + if (owp != NULL && !window_pane_is_raised(owp)) + owp = NULL; + if (owp != NULL && cmd_join_pane_group(owp) != group) + owp = NULL; return (owp); } @@ -459,7 +464,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) struct window_pane *src_wp, *dst_wp; const char *s; char *cause = NULL; - int flags = 0, dst_idx, raised; + int flags = 0, dst_idx, raised, stacking; struct layout_cell *lc; dst_s = target->s; @@ -480,8 +485,10 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) args_has(args, 'L') || args_has(args, 'R')) { s = args_get(args, 'P'); - if (args_has(args, 'z') || - (s != NULL && cmd_join_pane_is_stacking(s))) + stacking = args_has(args, 'z'); + if (s != NULL && cmd_join_pane_is_stacking(s)) + stacking = 1; + if (stacking) raised = window_pane_is_raised(dst_wp); else raised = window_pane_is_floating(dst_wp); @@ -490,9 +497,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } /* Moving unzooms a zoomed pane; reordering does not. */ - if ((dst_wp->flags & PANE_ZOOMED) && - !args_has(args, 'z') && - (s == NULL || !cmd_join_pane_is_stacking(s))) + if (!stacking && (dst_wp->flags & PANE_ZOOMED)) window_unzoom_pane(dst_wp, 1); if (s != NULL) return (cmd_join_pane_place(item, dst_wl, dst_wp, s)); diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c index 8ff2aa0ae..568e7a08f 100644 --- a/cmd-swap-pane.c +++ b/cmd-swap-pane.c @@ -58,6 +58,13 @@ cmd_swap_pane_prev_tiled_pane(struct window_pane *wp) return (wp); } +static void +cmd_swap_pane_zoom(struct window *w) +{ + window_unzoom(w, 1); + window_zoom(w->active); +} + static enum cmd_retval cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) { @@ -202,15 +209,9 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) out: /* With -Z, leave the active pane zoomed if the window was. */ - if (src_zoomed) { - window_unzoom(src_w, 1); - if (src_w->active != NULL) - window_zoom(src_w->active); - } - if (src_w != dst_w && dst_zoomed) { - window_unzoom(dst_w, 1); - if (dst_w->active != NULL) - window_zoom(dst_w->active); - } + if (src_zoomed) + cmd_swap_pane_zoom(src_w); + if (src_w != dst_w && dst_zoomed) + cmd_swap_pane_zoom(dst_w); return (CMD_RETURN_NORMAL); } diff --git a/layout-custom.c b/layout-custom.c index 8a03d022c..8f961add9 100644 --- a/layout-custom.c +++ b/layout-custom.c @@ -321,8 +321,10 @@ layout_dump_visible(struct window *w, int flags) struct layout_cell *root, *lc, *lcnext; char *out; - if (zwp == NULL) - return (layout_dump(w, w->layout_root, flags)); + if (zwp == NULL) { + out = layout_dump(w, w->layout_root, flags); + return (out); + } root = layout_create_cell(NULL); layout_set_size(root, w->sx, w->sy, 0, 0); diff --git a/window-panes.c b/window-panes.c index da9db43cf..1add5ca1a 100644 --- a/window-panes.c +++ b/window-panes.c @@ -147,12 +147,6 @@ window_panes_add_area(struct window_panes_modedata *data, area->sy = sy; } -static int -window_panes_pane_floating(struct window_pane *wp) -{ - return (window_pane_is_floating(wp)); -} - static int window_panes_get_geometry(struct window_pane *wp, struct layout_cell *root, u_int osx, u_int osy, u_int dsx, u_int dsy, u_int *xp, u_int *yp, @@ -827,14 +821,14 @@ window_panes_draw_screen(struct window_mode_entry *wme) screen_write_start(&ctx, &data->screen); screen_write_clearscreen(&ctx, 8); TAILQ_FOREACH(wp, &w->panes, entry) { - if (window_panes_pane_floating(wp)) + if (window_pane_is_floating(wp)) continue; window_panes_draw_pane(data, &ctx, wp, root, osx, osy, sx, sy); } window_panes_get_border_cell(data, &border_gc); window_panes_draw_borders(&ctx, w, root, &border_gc, osx, osy, sx, sy); TAILQ_FOREACH_REVERSE(wp, &w->z_index, window_panes_zindex, zentry) { - if (!window_panes_pane_floating(wp)) + if (!window_pane_is_floating(wp)) continue; window_panes_clear_floating_area(&ctx, wp, osx, osy, sx, sy); window_panes_draw_pane(data, &ctx, wp, root, osx, osy, sx, sy); diff --git a/window.c b/window.c index 4f839ef83..dca83b7cd 100644 --- a/window.c +++ b/window.c @@ -675,7 +675,7 @@ window_pane_floating_overlaps(struct window_pane *fwp, struct window_pane *wp) int fxoff, fyoff, xoff, yoff, border = 0; u_int fsx, fsy, sx, sy; - if (!window_pane_is_unzoomed_float(fwp) && (~fwp->flags & PANE_ZOOMED)) + if (!window_pane_is_raised(fwp)) return (0); window_pane_full_size_offset(fwp, &fxoff, &fyoff, &fsx, &fsy); @@ -867,8 +867,7 @@ window_get_active_at(struct window *w, u_int x, u_int y) * their status lines, so check those first. They are in stacking order. */ TAILQ_FOREACH(wp, &w->z_index, zentry) { - if ((window_pane_is_unzoomed_float(wp) || - (wp->flags & PANE_ZOOMED)) && + if (window_pane_is_raised(wp) && window_pane_contains(wp, x, y)) return (wp); } @@ -982,13 +981,12 @@ window_raise_pane(struct window_pane *wp) TAILQ_REMOVE(&w->z_index, wp, zentry); TAILQ_FOREACH(wp1, &w->z_index, zentry) { - if (wp == w->modal) - break; if (wp1 == w->modal) continue; - if ((wp->flags & PANE_FLOATOVERZOOM) || - (~wp1->flags & PANE_FLOATOVERZOOM)) - break; + if ((wp1->flags & PANE_FLOATOVERZOOM) && + (~wp->flags & PANE_FLOATOVERZOOM)) + continue; + break; } if (wp1 == NULL) TAILQ_INSERT_TAIL(&w->z_index, wp, zentry); @@ -1055,9 +1053,9 @@ window_unzoom_one(struct window_pane *wp) window_update_zoomed(w); } -/* Fire the events after panes have been unzoomed. */ +/* Fix the panes and fire the events after panes have been unzoomed. */ static void -window_unzoomed(struct window *w, int notify) +window_unzoom_finish(struct window *w, int notify) { layout_fix_panes(w, NULL); if (notify) { @@ -1107,7 +1105,7 @@ window_unzoom_pane(struct window_pane *wp, int notify) if (~wp->flags & PANE_ZOOMED) return (-1); window_unzoom_one(wp); - window_unzoomed(w, notify); + window_unzoom_finish(w, notify); return (0); } @@ -1123,7 +1121,7 @@ window_unzoom(struct window *w, int notify) if (wp->flags & PANE_ZOOMED) window_unzoom_one(wp); } - window_unzoomed(w, notify); + window_unzoom_finish(w, notify); return (0); } @@ -1142,19 +1140,14 @@ window_zoomed_pane(struct window *w) return (NULL); } -/* - * Move zoom from one pane to another, so a command that made another pane - * active can leave the window looking zoomed. - */ +/* Move the zoom from one pane to another. */ void window_zoom_move(struct window_pane *from, struct window_pane *to) { if (from == to) return; - if (from != NULL) - window_unzoom_pane(from, 1); - if (to != NULL) - window_zoom(to); + window_unzoom_pane(from, 1); + window_zoom(to); } struct window_pane * @@ -3045,12 +3038,16 @@ window_pane_is_floating(struct window_pane *wp) int window_pane_is_unzoomed_float(struct window_pane *wp) { - return (window_pane_is_floating(wp) && (~wp->flags & PANE_ZOOMED)); + if (wp->flags & PANE_ZOOMED) + return (0); + return (window_pane_is_floating(wp)); } /* Is the pane a float or a zoomed pane, that is above the tiled panes? */ int window_pane_is_raised(struct window_pane *wp) { - return (window_pane_is_floating(wp) || (wp->flags & PANE_ZOOMED)); + if (wp->flags & PANE_ZOOMED) + return (1); + return (window_pane_is_floating(wp)); }