1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-15 02:53:02 +01:00

Fix regression causing typing notifications to break

Also a small refactor so we use less duplicate code and reduce mutex usage
This commit is contained in:
jfreegman 2021-12-07 22:14:32 -05:00
parent 66e4c590dc
commit d02ac24de8
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 26 additions and 32 deletions

View File

@ -1270,9 +1270,16 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
} }
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
StatusBar *statusbar = self->stb;
pthread_mutex_lock(&Winthread.lock); pthread_mutex_lock(&Winthread.lock);
line_info_print(self); line_info_print(self);
Tox_Connection connection = statusbar->connection;
Tox_User_Status status = statusbar->status;
const bool is_typing = Friends.list[self->num].is_typing;
pthread_mutex_unlock(&Winthread.lock); pthread_mutex_unlock(&Winthread.lock);
wclear(ctx->linewin); wclear(ctx->linewin);
@ -1283,14 +1290,6 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
curs_set(1); curs_set(1);
/* Draw status bar */
StatusBar *statusbar = self->stb;
pthread_mutex_lock(&Winthread.lock);
Tox_Connection connection = statusbar->connection;
Tox_User_Status status = statusbar->status;
pthread_mutex_unlock(&Winthread.lock);
wmove(statusbar->topline, 0, 0); wmove(statusbar->topline, 0, 0);
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT)); wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
@ -1321,10 +1320,10 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
wprintw(statusbar->topline, "] "); wprintw(statusbar->topline, "] ");
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT)); wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
if (status != TOX_USER_STATUS_NONE) {
const char *status_text = "ERROR"; const char *status_text = "ERROR";
int colour = MAGENTA; int colour = BAR_TEXT;
if (connection != TOX_CONNECTION_NONE) {
switch (status) { switch (status) {
case TOX_USER_STATUS_AWAY: case TOX_USER_STATUS_AWAY:
colour = STATUS_AWAY; colour = STATUS_AWAY;
@ -1339,7 +1338,9 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
default: default:
break; break;
} }
}
if (colour != BAR_TEXT) {
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT)); wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
wprintw(statusbar->topline, "["); wprintw(statusbar->topline, "[");
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT)); wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
@ -1351,10 +1352,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT)); wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
wprintw(statusbar->topline, "] "); wprintw(statusbar->topline, "] ");
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT)); wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
}
pthread_mutex_lock(&Winthread.lock);
const bool is_typing = Friends.list[self->num].is_typing;
pthread_mutex_unlock(&Winthread.lock);
if (is_typing) { if (is_typing) {
wattron(statusbar->topline, A_BOLD | COLOR_PAIR(BAR_NOTIFY)); wattron(statusbar->topline, A_BOLD | COLOR_PAIR(BAR_NOTIFY));
@ -1369,11 +1367,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
} else { } else {
wattroff(statusbar->topline, A_BOLD | COLOR_PAIR(BAR_TEXT)); wattroff(statusbar->topline, A_BOLD | COLOR_PAIR(BAR_TEXT));
} }
} else {
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
wprintw(statusbar->topline, " %s", statusbar->nick);
wattroff(statusbar->topline, COLOR_PAIR(BAR_TEXT));
}
/* Reset statusbar->statusmsg on window resize */ /* Reset statusbar->statusmsg on window resize */
if (x2 != self->x) { if (x2 != self->x) {

BIN
test

Binary file not shown.