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

improve window alert functionality

This commit is contained in:
Jfreegman 2013-11-28 19:45:28 -05:00
parent 2057e7bc4f
commit a98ec22fd6
8 changed files with 50 additions and 31 deletions

View File

@ -41,7 +41,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1
} else } else
wprintw(ctx->history, "%s\n", msg); wprintw(ctx->history, "%s\n", msg);
alert_window(self); alert_window(self, WINDOW_ALERT_1, true);
} }
static void chat_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t status) static void chat_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t status)
@ -69,7 +69,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
wprintw(ctx->history, "* %s %s\n", nick, action); wprintw(ctx->history, "* %s %s\n", nick, action);
wattroff(ctx->history, COLOR_PAIR(YELLOW)); wattroff(ctx->history, COLOR_PAIR(YELLOW));
alert_window(self); alert_window(self, WINDOW_ALERT_1, true);
} }
static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len) static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len)
@ -158,7 +158,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil
friends[num].file_receiver.pending[filenum] = true; friends[num].file_receiver.pending[filenum] = true;
strcpy(friends[num].file_receiver.filenames[filenum], filename); strcpy(friends[num].file_receiver.filenames[filenum], filename);
alert_window(self); alert_window(self, WINDOW_ALERT_2, true);
} }
static void chat_onFileControl(ToxWindow *self, Tox *m, int num, uint8_t receive_send, static void chat_onFileControl(ToxWindow *self, Tox *m, int num, uint8_t receive_send,
@ -191,7 +191,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int num, uint8_t receive
break; break;
} }
alert_window(self); alert_window(self, WINDOW_ALERT_2, true);
} }
static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, uint8_t *data, static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, uint8_t *data,
@ -242,7 +242,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_
memcpy(friends[friendnumber].pending_groupchat, group_pub_key, TOX_CLIENT_ID_SIZE); memcpy(friends[friendnumber].pending_groupchat, group_pub_key, TOX_CLIENT_ID_SIZE);
wprintw(ctx->history, "Type \"/join\" to join the chat.\n"); wprintw(ctx->history, "Type \"/join\" to join the chat.\n");
alert_window(self); alert_window(self, WINDOW_ALERT_2, true);
} }
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) { static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) {

View File

@ -120,7 +120,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
} else } else
wprintw(ctx->history, "%s\n", msg); wprintw(ctx->history, "%s\n", msg);
self->blink = true; alert_window(self, WINDOW_ALERT_1, false);
} }
/* Puts two copies of peerlist in chat instance */ /* Puts two copies of peerlist in chat instance */
@ -214,6 +214,8 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
wattroff(ctx->history, COLOR_PAIR(MAGENTA)); wattroff(ctx->history, COLOR_PAIR(MAGENTA));
break; break;
} }
alert_window(self, WINDOW_ALERT_2, false);
} }
static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key) static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)

View File

@ -384,7 +384,7 @@ static void do_file_senders(Tox *m)
if (ctx != NULL) { if (ctx != NULL) {
wprintw(ctx->history, "File transfer for '%s' timed out.\n", pathname); wprintw(ctx->history, "File transfer for '%s' timed out.\n", pathname);
alert_window(file_senders[i].toxwin); alert_window(file_senders[i].toxwin, WINDOW_ALERT_2, true);
} }
tox_file_sendcontrol(m, friendnum, 0, filenum, TOX_FILECONTROL_KILL, 0, 0); tox_file_sendcontrol(m, friendnum, 0, filenum, TOX_FILECONTROL_KILL, 0, 0);
@ -408,7 +408,7 @@ static void do_file_senders(Tox *m)
if (ctx != NULL) { if (ctx != NULL) {
wprintw(ctx->history, "File '%s' successfuly sent.\n", pathname); wprintw(ctx->history, "File '%s' successfuly sent.\n", pathname);
alert_window(file_senders[i].toxwin); alert_window(file_senders[i].toxwin, WINDOW_ALERT_2, true);
} }
tox_file_sendcontrol(m, friendnum, 0, filenum, TOX_FILECONTROL_FINISHED, 0, 0); tox_file_sendcontrol(m, friendnum, 0, filenum, TOX_FILECONTROL_FINISHED, 0, 0);

View File

@ -107,11 +107,16 @@ bool timed_out(uint64_t timestamp, uint64_t curtime, uint64_t timeout)
return timestamp + timeout <= curtime; return timestamp + timeout <= curtime;
} }
/* Beeps and makes window tab blink */ /* Colours the window tab according to type. Beeps if is_beep is true */
void alert_window(ToxWindow *self) void alert_window(ToxWindow *self, int type, bool is_beep)
{ {
self->blink = true; if (type == WINDOW_ALERT_1)
beep(); self->alert1 = true;
else if(type == WINDOW_ALERT_2)
self->alert2 = true;
if (is_beep)
beep();
} }
/* case-insensitive string compare function for use with qsort - same return logic as strcmp */ /* case-insensitive string compare function for use with qsort - same return logic as strcmp */

View File

@ -25,8 +25,8 @@ char *wc_to_char(wchar_t ch);
/* Returns true if connection has timed out, false otherwise */ /* Returns true if connection has timed out, false otherwise */
bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime); bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime);
/* Beeps and makes window tab blink */ /* Colours the window tab according to type. Beeps if is_beep is true */
void alert_window(ToxWindow *self); void alert_window(ToxWindow *self, int type, bool is_beep);
/* case-insensitive string compare function for use with qsort - same return logic as strcmp */ /* case-insensitive string compare function for use with qsort - same return logic as strcmp */
int name_compare(const void *nick1, const void *nick2); int name_compare(const void *nick1, const void *nick2);

View File

@ -230,7 +230,7 @@ static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data,
} }
wprintw(self->window, "Type \"/accept %d\" to accept it.\n", n); wprintw(self->window, "Type \"/accept %d\" to accept it.\n", n);
alert_window(self); alert_window(self, WINDOW_ALERT_2, true);
} }
void prompt_init_statusbar(ToxWindow *self, Tox *m) void prompt_init_statusbar(ToxWindow *self, Tox *m)

View File

@ -42,6 +42,11 @@ enum {
BLACK, BLACK,
}; };
enum {
WINDOW_ALERT_1,
WINDOW_ALERT_2,
};
/* Fixes text color problem on some terminals. /* Fixes text color problem on some terminals.
Uncomment if necessary */ Uncomment if necessary */
//#define URXVT_FIX //#define URXVT_FIX
@ -68,7 +73,8 @@ struct ToxWindow_ {
void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t); void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t);
char name[TOX_MAX_NAME_LENGTH]; char name[TOX_MAX_NAME_LENGTH];
bool blink; bool alert1;
bool alert2;
int num; int num;
int x; int x;

View File

@ -263,12 +263,25 @@ ToxWindow *init_windows(Tox *mToAssign)
return prompt; return prompt;
} }
#define TAB_BLINKRATE 30 static void draw_window_tab(ToxWindow toxwin)
{
/* alert1 takes priority */
if (toxwin.alert1)
attron(COLOR_PAIR(RED));
else if (toxwin.alert2)
attron(COLOR_PAIR(BLUE));
clrtoeol();
printw(" [%s]", toxwin.name);
if (toxwin.alert1)
attroff(COLOR_PAIR(RED));
else if (toxwin.alert2)
attroff(COLOR_PAIR(BLUE));
}
static void draw_bar(void) static void draw_bar(void)
{ {
static int odd = 0;
attron(COLOR_PAIR(BLUE)); attron(COLOR_PAIR(BLUE));
mvhline(LINES - 2, 0, '_', COLS); mvhline(LINES - 2, 0, '_', COLS);
attroff(COLOR_PAIR(BLUE)); attroff(COLOR_PAIR(BLUE));
@ -291,18 +304,9 @@ static void draw_bar(void)
attron(A_BOLD); attron(A_BOLD);
} }
odd = (odd + 1) % TAB_BLINKRATE; draw_window_tab(windows[i]);
if (windows[i].blink && (odd < (TAB_BLINKRATE / 2))) if (windows + i == active_window) {
attron(COLOR_PAIR(RED));
clrtoeol();
printw(" [%s]", windows[i].name);
if (windows[i].blink && (odd < (TAB_BLINKRATE / 2)))
attroff(COLOR_PAIR(RED));
if (windows + i == active_window) {
#ifdef URXVT_FIX #ifdef URXVT_FIX
attroff(A_BOLD | COLOR_PAIR(GREEN)); attroff(A_BOLD | COLOR_PAIR(GREEN));
} else { } else {
@ -325,7 +329,9 @@ void draw_active_window(Tox *m)
wresize(a->window, LINES - 2, COLS); wresize(a->window, LINES - 2, COLS);
#endif #endif
a->blink = false; a->alert1 = false;
a->alert2 = false;
draw_bar(); draw_bar();
a->onDraw(a, m); a->onDraw(a, m);