From e75cf4f3ad546af6e4ddc566ca2eeaff50c170a1 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 7 Aug 2014 19:53:47 -0400 Subject: [PATCH] fix bug where tab alert colours weren't being properly prioritized --- src/notify.c | 24 ++++++++++++------------ src/windows.c | 11 +++++------ src/windows.h | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/notify.c b/src/notify.c index 5dd555d..54f2e70 100644 --- a/src/notify.c +++ b/src/notify.c @@ -443,10 +443,10 @@ void m_notify_action(NotifyNotification *box, char *action, void* data) int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator) { /* Consider colored notify as primary */ - if (self && self->alert == WINDOW_ALERT_NONE) { + if (self) { if (flags & NT_WNDALERT_0) self->alert = WINDOW_ALERT_0; - else if (flags & NT_WNDALERT_1) self->alert = WINDOW_ALERT_1; - else if (flags & NT_WNDALERT_2) self->alert = WINDOW_ALERT_2; + else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) ) self->alert = WINDOW_ALERT_1; + else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || @@ -487,10 +487,10 @@ int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_in int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id) { /* Consider colored notify as primary */ - if (self && self->alert == WINDOW_ALERT_NONE) { + if (self) { if (flags & NT_WNDALERT_0) self->alert = WINDOW_ALERT_0; - else if (flags & NT_WNDALERT_1) self->alert = WINDOW_ALERT_1; - else if (flags & NT_WNDALERT_2) self->alert = WINDOW_ALERT_2; + else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) ) self->alert = WINDOW_ALERT_1; + else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || @@ -636,10 +636,10 @@ int box_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id, con int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const char* title, const char* format, ...) { /* Always do colored notify */ - if (self && self->alert == WINDOW_ALERT_NONE) { + if (self) { if (flags & NT_WNDALERT_0) self->alert = WINDOW_ALERT_0; - else if (flags & NT_WNDALERT_1) self->alert = WINDOW_ALERT_1; - else if (flags & NT_WNDALERT_2) self->alert = WINDOW_ALERT_2; + else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) ) self->alert = WINDOW_ALERT_1; + else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || @@ -692,10 +692,10 @@ int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const int box_silent_notify2(ToxWindow* self, uint64_t flags, int id, const char* format, ...) { /* Always do colored notify */ - if (self && self->alert == WINDOW_ALERT_NONE) { + if (self) { if (flags & NT_WNDALERT_0) self->alert = WINDOW_ALERT_0; - else if (flags & NT_WNDALERT_1) self->alert = WINDOW_ALERT_1; - else if (flags & NT_WNDALERT_2) self->alert = WINDOW_ALERT_2; + else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) ) self->alert = WINDOW_ALERT_1; + else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || diff --git a/src/windows.c b/src/windows.c index 0f447ed..58c47e8 100644 --- a/src/windows.c +++ b/src/windows.c @@ -368,13 +368,12 @@ void on_window_resize(void) } } -static void draw_window_tab(ToxWindow toxwin) +static void draw_window_tab(ToxWindow *toxwin) { - if (toxwin.alert) attron(COLOR_PAIR(toxwin.alert)); + if (toxwin->alert != WINDOW_ALERT_NONE) attron(COLOR_PAIR(toxwin->alert)); clrtoeol(); - printw(" [%s]", toxwin.name); - - if (toxwin.alert) attroff(COLOR_PAIR(toxwin.alert)); + printw(" [%s]", toxwin->name); + if (toxwin->alert != WINDOW_ALERT_NONE) attroff(COLOR_PAIR(toxwin->alert)); } static void draw_bar(void) @@ -404,7 +403,7 @@ static void draw_bar(void) attron(A_BOLD); - draw_window_tab(windows[i]); + draw_window_tab(&windows[i]); if (windows + i == active_window) diff --git a/src/windows.h b/src/windows.h index cbe18d6..a06a37c 100644 --- a/src/windows.h +++ b/src/windows.h @@ -52,7 +52,7 @@ enum { BLACK, } C_COLOURS; -/* tab alert types: lower types take priority */ +/* tab alert types: lower types take priority (this relies on the order of C_COLOURS) */ typedef enum { WINDOW_ALERT_NONE = 0, WINDOW_ALERT_0 = GREEN,