From b16ff16abcdce0bc4ac24d50fedfda22996726ad Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 19 Nov 2013 02:31:22 -0500 Subject: [PATCH] move window blink/beep to a function --- src/chat.c | 16 +++++----------- src/misc_tools.c | 7 +++++++ src/misc_tools.h | 5 ++++- src/prompt.c | 3 +-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/chat.c b/src/chat.c index e7f85f9..1f6a229 100644 --- a/src/chat.c +++ b/src/chat.c @@ -41,8 +41,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1 } else wprintw(ctx->history, "%s\n", msg); - self->blink = true; - beep(); + alert_window(self); } static void chat_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t status) @@ -70,8 +69,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin wprintw(ctx->history, "* %s %s\n", nick, action); wattroff(ctx->history, COLOR_PAIR(YELLOW)); - self->blink = true; - beep(); + alert_window(self); } static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len) @@ -155,8 +153,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil friends[num].file_receiver.pending[filenum] = true; strcpy(friends[num].file_receiver.filenames[filenum], filename); - self->blink = true; - beep(); + alert_window(self); } static void chat_onFileControl(ToxWindow *self, Tox *m, int num, uint8_t receive_send, @@ -189,8 +186,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int num, uint8_t receive break; } - self->blink = true; - beep(); + alert_window(self); } static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, uint8_t *data, @@ -232,10 +228,8 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_ } memcpy(friends[friendnumber].pending_groupchat, group_pub_key, TOX_CLIENT_ID_SIZE); - wprintw(ctx->history, "Type \"/join\" to join the chat.\n"); - self->blink = true; - beep(); + alert_window(self); } static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) { diff --git a/src/misc_tools.c b/src/misc_tools.c index bfa7069..2d6c05b 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -106,3 +106,10 @@ bool timed_out(uint64_t timestamp, uint64_t curtime, uint64_t timeout) { return timestamp + timeout <= curtime; } + +/* Beeps and makes window tab blink */ +void alert_window(ToxWindow *self) +{ + self->blink = true; + beep(); +} diff --git a/src/misc_tools.h b/src/misc_tools.h index dec1bd1..9c18398 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -21,4 +21,7 @@ uint8_t *wcs_to_char(wchar_t *string); char *wc_to_char(wchar_t ch); /* Returns true if connection has timed out, false otherwise */ -bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime); \ No newline at end of file +bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime); + +/* Beeps and makes window tab blink */ +void alert_window(ToxWindow *self); \ No newline at end of file diff --git a/src/prompt.c b/src/prompt.c index ce261f6..e480042 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -227,8 +227,7 @@ static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, } wprintw(self->window, "Type \"/accept %d\" to accept it.\n", n); - self->blink = true; - beep(); + alert_window(self); } void prompt_init_statusbar(ToxWindow *self, Tox *m)