From 833c7fbf6d57481dd16f1fda78145e2f8b0be954 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 22 May 2025 07:43:38 +0000 Subject: [PATCH 1/2] Add a set-default style attribute which replaces the current default colours and attributes completely, useful at the start of compound format strings (like status-format) to set the default colours for all the following options. --- format-draw.c | 10 +++++++++- style.c | 4 ++++ tmux.1 | 4 ++++ tmux.h | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/format-draw.c b/format-draw.c index a42dfe1d..efc6ab1a 100644 --- a/format-draw.c +++ b/format-draw.c @@ -719,7 +719,7 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base, int focus_start = -1, focus_end = -1; int list_state = -1, fill = -1, even; enum style_align list_align = STYLE_ALIGN_DEFAULT; - struct grid_cell gc, current_default; + struct grid_cell gc, current_default, base_default; struct style sy, saved_sy; struct utf8_data *ud = &sy.gc.data; const char *cp, *end; @@ -729,7 +729,9 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base, struct format_ranges frs; struct style_range *sr; + memcpy(&base_default, base, sizeof base_default); memcpy(¤t_default, base, sizeof current_default); + base = &base_default; style_set(&sy, ¤t_default); TAILQ_INIT(&frs); log_debug("%s: %s", __func__, expanded); @@ -847,6 +849,12 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base, } else if (sy.default_type == STYLE_DEFAULT_POP) { memcpy(¤t_default, base, sizeof current_default); sy.default_type = STYLE_DEFAULT_BASE; + } else if (sy.default_type == STYLE_DEFAULT_SET) { + memcpy(&base_default, &saved_sy.gc, + sizeof base_default); + memcpy(¤t_default, &saved_sy.gc, + sizeof current_default); + sy.default_type = STYLE_DEFAULT_BASE; } /* Check the list state. */ diff --git a/style.c b/style.c index c9e5b15e..4e4f6fcc 100644 --- a/style.c +++ b/style.c @@ -98,6 +98,8 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in) sy->default_type = STYLE_DEFAULT_PUSH; else if (strcasecmp(tmp, "pop-default") == 0) sy->default_type = STYLE_DEFAULT_POP; + else if (strcasecmp(tmp, "set-default") == 0) + sy->default_type = STYLE_DEFAULT_SET; else if (strcasecmp(tmp, "nolist") == 0) sy->list = STYLE_LIST_OFF; else if (strncasecmp(tmp, "list=", 5) == 0) { @@ -310,6 +312,8 @@ style_tostring(struct style *sy) tmp = "push-default"; else if (sy->default_type == STYLE_DEFAULT_POP) tmp = "pop-default"; + else if (sy->default_type == STYLE_DEFAULT_SET) + tmp = "set-default"; off += xsnprintf(s + off, sizeof s - off, "%s%s", comma, tmp); comma = ","; } diff --git a/tmux.1 b/tmux.1 index 250e781d..896c6164 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6357,6 +6357,10 @@ will be available in the format variable. .Ql X must be at most 15 bytes in length. +.It Ic set-default +Set the current colours and attributes as the default, overwriting any previous +default. +The previous default cannot be restored. .El .Pp Examples are: diff --git a/tmux.h b/tmux.h index 7db37dc2..7bcd4e2e 100644 --- a/tmux.h +++ b/tmux.h @@ -881,7 +881,8 @@ TAILQ_HEAD(style_ranges, style_range); enum style_default_type { STYLE_DEFAULT_BASE, STYLE_DEFAULT_PUSH, - STYLE_DEFAULT_POP + STYLE_DEFAULT_POP, + STYLE_DEFAULT_SET }; /* Style option. */ From a0ac2a5d6352510d50016747124c113fece937cb Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 22 May 2025 07:46:38 +0000 Subject: [PATCH 2/2] When there are more than two horizontal windows and the active window is in not on an edge, correctly highlight both its left and right borders. GitHub issue 4513 from Michael Grant. --- screen-redraw.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/screen-redraw.c b/screen-redraw.c index fb530007..3f339443 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -121,7 +121,12 @@ screen_redraw_pane_border(struct screen_redraw_ctx *ctx, struct window_pane *wp, u_int ex = wp->xoff + wp->sx, ey = wp->yoff + wp->sy; int hsplit = 0, vsplit = 0, pane_status = ctx->pane_status; int pane_scrollbars = ctx->pane_scrollbars, sb_w = 0; - int sb_pos = ctx->pane_scrollbars_pos; + int sb_pos; + + if (pane_scrollbars != 0) + sb_pos = ctx->pane_scrollbars_pos; + else + sb_pos = 0; /* Inside pane. */ if (px >= wp->xoff && px < ex && py >= wp->yoff && py < ey) @@ -149,16 +154,24 @@ screen_redraw_pane_border(struct screen_redraw_ctx *ctx, struct window_pane *wp, if (wp->xoff - sb_w == 0 && px == wp->sx + sb_w) if (!hsplit || (hsplit && py <= wp->sy / 2)) return (SCREEN_REDRAW_BORDER_RIGHT); - if (wp->xoff - sb_w != 0 && px == wp->xoff - sb_w - 1) - if (!hsplit || (hsplit && py > wp->sy / 2)) + if (wp->xoff - sb_w != 0) { + if (px == wp->xoff - sb_w - 1 && + (!hsplit || (hsplit && py > wp->sy / 2))) return (SCREEN_REDRAW_BORDER_LEFT); - } else { /* sb_pos == PANE_SCROLLBARS_RIGHT */ + if (px == wp->xoff + wp->sx + sb_w - 1) + return (SCREEN_REDRAW_BORDER_RIGHT); + } + } else { /* sb_pos == PANE_SCROLLBARS_RIGHT or disabled*/ if (wp->xoff == 0 && px == wp->sx + sb_w) if (!hsplit || (hsplit && py <= wp->sy / 2)) return (SCREEN_REDRAW_BORDER_RIGHT); - if (wp->xoff != 0 && px == wp->xoff - 1) - if (!hsplit || (hsplit && py > wp->sy / 2)) + if (wp->xoff != 0) { + if (px == wp->xoff - 1 && + (!hsplit || (hsplit && py > wp->sy / 2))) return (SCREEN_REDRAW_BORDER_LEFT); + if (px == wp->xoff + wp->sx + sb_w) + return (SCREEN_REDRAW_BORDER_RIGHT); + } } }