From 420af9e1088d194ea113be106890a0c5d295af51 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 25 Nov 2024 08:34:01 +0000 Subject: [PATCH 1/2] Do not rely on window reference count for linked formats because they are also used for notifications, GitHub issue 4258. --- format.c | 39 ++++++++++++++++++++++++++++++++++----- session.c | 7 ++----- tmux.h | 3 +++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/format.c b/format.c index 6ca5ad07..7cd5b2a8 100644 --- a/format.c +++ b/format.c @@ -2490,9 +2490,20 @@ format_cb_window_last_flag(struct format_tree *ft) static void * format_cb_window_linked(struct format_tree *ft) { + struct winlink *wl; + struct session *s; + int found = 0; + if (ft->wl != NULL) { - if (session_is_linked(ft->wl->session, ft->wl->window)) - return (xstrdup("1")); + RB_FOREACH(s, sessions, &sessions) { + RB_FOREACH(wl, winlinks, &s->windows) { + if (wl->window == ft->wl->window) { + if (found) + return (xstrdup("1")); + found = 1; + } + } + } return (xstrdup("0")); } return (NULL); @@ -2502,9 +2513,27 @@ format_cb_window_linked(struct format_tree *ft) static void * format_cb_window_linked_sessions(struct format_tree *ft) { - if (ft->wl != NULL) - return (format_printf("%u", ft->wl->window->references)); - return (NULL); + struct window *w; + struct session_group *sg; + struct session *s; + u_int n = 0; + + if (ft->wl == NULL) + return (NULL); + w = ft->wl->window; + + RB_FOREACH(sg, session_groups, &session_groups) { + s = TAILQ_FIRST(&sg->sessions); + if (winlink_find_by_window(&s->windows, w) != NULL) + n++; + } + RB_FOREACH(s, sessions, &sessions) { + if (session_group_contains(s) != NULL) + continue; + if (winlink_find_by_window(&s->windows, w) != NULL) + n++; + } + return (format_printf("%u", n)); } /* Callback for window_marked_flag. */ diff --git a/session.c b/session.c index d01e4ba2..a3adafdd 100644 --- a/session.c +++ b/session.c @@ -33,12 +33,9 @@ u_int next_session_id; struct session_groups session_groups = RB_INITIALIZER(&session_groups); static void session_free(int, short, void *); - static void session_lock_timer(int, short, void *); - static struct winlink *session_next_alert(struct winlink *); static struct winlink *session_previous_alert(struct winlink *); - static void session_group_remove(struct session *); static void session_group_synchronize1(struct session *, struct session *); @@ -49,12 +46,12 @@ session_cmp(struct session *s1, struct session *s2) } RB_GENERATE(sessions, session, entry, session_cmp); -static int +int session_group_cmp(struct session_group *s1, struct session_group *s2) { return (strcmp(s1->name, s2->name)); } -RB_GENERATE_STATIC(session_groups, session_group, entry, session_group_cmp); +RB_GENERATE(session_groups, session_group, entry, session_group_cmp); /* * Find if session is still alive. This is true if it is still on the global diff --git a/tmux.h b/tmux.h index aaa8ad5f..c6e5f4d3 100644 --- a/tmux.h +++ b/tmux.h @@ -3348,9 +3348,12 @@ void control_notify_paste_buffer_deleted(const char *); /* session.c */ extern struct sessions sessions; +extern struct session_groups session_groups; extern u_int next_session_id; int session_cmp(struct session *, struct session *); RB_PROTOTYPE(sessions, session, entry, session_cmp); +int session_group_cmp(struct session_group *, struct session_group *s2); +RB_PROTOTYPE(session_groups, session_group, entry, session_group_cmp); int session_alive(struct session *); struct session *session_find(const char *); struct session *session_find_by_id_str(const char *); From f57131e11bb2e1a065ade793960c564e6ed2ef82 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 25 Nov 2024 08:36:46 +0000 Subject: [PATCH 2/2] Use cursor style from global options instead of default for popups, from Alexander Arch. --- popup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/popup.c b/popup.c index b753e4a1..21be8f05 100644 --- a/popup.c +++ b/popup.c @@ -692,6 +692,7 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, pd->border_cell.attr = 0; screen_init(&pd->s, jx, jy, 0); + screen_set_default_cursor(&pd->s, global_w_options); colour_palette_init(&pd->palette); colour_palette_from_option(&pd->palette, global_w_options);