From 9d65997871102d941e7c973b76acd27bb6d7b977 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Sat, 21 Nov 2020 11:25:41 -0500 Subject: [PATCH] Add notification counters to bottom tab A counter now increments in the bottom bar for unfocused windows showing how many unread messages are pending. Tabs with no pending messages show [*] instead of their index (showing the index is useless and somewhat confusing) --- src/global_commands.c | 2 +- src/notify.c | 2 ++ src/windows.c | 13 +++++++++++-- src/windows.h | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/global_commands.c b/src/global_commands.c index 6b0d0d7..13fb43d 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -365,7 +365,7 @@ void cmd_conference(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar return; } - uint32_t conferencenum; + uint32_t conferencenum = 0; if (type == TOX_CONFERENCE_TYPE_TEXT) { Tox_Err_Conference_New err; diff --git a/src/notify.c b/src/notify.c index f5b015f..6298783 100644 --- a/src/notify.c +++ b/src/notify.c @@ -126,6 +126,8 @@ static void tab_notify(ToxWindow *self, uint64_t flags) } else if ((flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1)) { self->alert = WINDOW_ALERT_2; } + + ++self->pending_messages; } static bool notifications_are_disabled(uint64_t flags) diff --git a/src/windows.c b/src/windows.c index 4c9b267..72d4685 100644 --- a/src/windows.c +++ b/src/windows.c @@ -502,14 +502,22 @@ static void draw_window_tab(ToxWindow *toxwin, bool active_window) attron(COLOR_PAIR(toxwin->alert)); } + unsigned int pending_messages = toxwin->pending_messages; + pthread_mutex_unlock(&Winthread.lock); clrtoeol(); - if (active_window || toxwin->index <= 1) { + WINDOW_TYPE type = toxwin->type; + + if (active_window || (type == WINDOW_TYPE_PROMPT || type == WINDOW_TYPE_FRIEND_LIST)) { printw(" [%s]", toxwin->name); } else { - printw(" [%u]", toxwin->index - 1); + if (pending_messages > 0) { + printw(" [%u]", pending_messages); + } else { + printw(" [*]"); + } } pthread_mutex_lock(&Winthread.lock); @@ -673,6 +681,7 @@ void draw_active_window(Tox *m) pthread_mutex_lock(&Winthread.lock); a->alert = WINDOW_ALERT_NONE; + a->pending_messages = 0; pthread_mutex_unlock(&Winthread.lock); draw_bar(); diff --git a/src/windows.h b/src/windows.h index 526c1f4..d3c9bf7 100644 --- a/src/windows.h +++ b/src/windows.h @@ -167,6 +167,7 @@ struct ToxWindow { char name[TOXIC_MAX_NAME_LENGTH + 1]; uint32_t num; /* corresponds to friendnumber in chat windows */ uint8_t index; /* This window's index in the windows array */ + unsigned int pending_messages; /* # of new messages in this window since the last time it was focused */ int x; WINDOW_TYPE type;