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

Box notifications are like ready

This commit is contained in:
mannol 2014-08-02 00:37:02 +02:00
parent d5710d80e0
commit 8f3989000d
14 changed files with 516 additions and 172 deletions

View File

@ -485,8 +485,7 @@ void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
}
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
/* Callback will print status... */

View File

@ -163,7 +163,11 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, 0, msg);
write_to_log(msg, nick, ctx->log, false);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
if (self->active_box != -1)
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, self->active_box, msg);
else
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, &self->active_box, nick, msg);
}
static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
@ -172,15 +176,14 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_
return;
StatusBar *statusbar = self->stb;
if (status == 1) { /* Friend shows online */
statusbar->is_online = true;
friends[num].is_typing = tox_get_is_typing(m, num);
notify(self, user_log_in, NT_NOFOCUS);
friends[num].is_typing = tox_get_is_typing(m, num);
} else { /* Friend goes offline */
statusbar->is_online = false;
friends[num].is_typing = 0;
notify(self, user_log_out, NT_NOFOCUS);
}
}
@ -207,7 +210,11 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const char *acti
line_info_add(self, timefrmt, nick, NULL, ACTION, 0, 0, action);
write_to_log(action, nick, ctx->log, true);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
if (self->active_box != -1)
box_notify2(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
else
box_notify(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action );
}
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *nick, uint16_t len)
@ -326,7 +333,12 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
friends[num].file_receiver.size[filenum] = filesize;
strcpy(friends[num].file_receiver.filenames[filenum], filename);
notify(self, transfer_pending, NT_WNDALERT_2 | NT_NOFOCUS);
if (self->active_box != -1)
box_notify2(self, transfer_pending, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box,
"Incoming file: %s", filename );
else
box_notify(self, transfer_pending, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, self->name,
"Incoming file: %s", filename );
}
static void chat_close_file_receiver(int32_t num, uint8_t filenum)
@ -365,7 +377,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
if (receive_send == 1) {
snprintf(msg, sizeof(msg), "File transfer for '%s' accepted (%.1f%%)", filename, 0.0);
file_senders[i].line_id = self->chatwin->hst->line_end->id + 1;
notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2);
sound_notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2, NULL);
}
break;
@ -375,15 +387,27 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
if (receive_send == 0)
chat_close_file_receiver(num, filenum);
notify(self, error, NT_NOFOCUS | NT_WNDALERT_2);
if (self->active_box != -1)
box_notify2(self, error, NT_NOFOCUS | NT_WNDALERT_2,
self->active_box, "File transfer for '%s' failed!", filename );
else
box_notify(self, error, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box,
self->name, "File transfer for '%s' failed!", filename );
break;
case TOX_FILECONTROL_FINISHED:
if (receive_send == 0) {
snprintf(msg, sizeof(msg), "File transfer for '%s' complete.", filename);
chat_close_file_receiver(num, filenum);
notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2);
if (self->active_box != -1)
box_notify2(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2,
self->active_box, "File '%s' successfuly sent!", filename );
else
box_notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box,
self->name, "File '%s' successfuly sent!", filename );
}
break;
@ -443,7 +467,12 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, co
friends[friendnumber].groupchat_pending = true;
notify(self, generic_message, NT_WNDALERT_2);
sound_notify(self, generic_message, NT_WNDALERT_2, NULL);
if (self->active_box != -1)
box_silent_notify2(self, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box, "invites you to join group chat");
else
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat");
}
/* Av Stuff */
@ -458,11 +487,12 @@ void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
self->call_idx = call_index;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Incoming audio call! Type: \"/answer\" or \"/reject\"");
#ifdef _SOUND_NOTIFY
if (self->active_sound == -1)
self->active_sound = notify(self, call_incoming, NT_LOOP | NT_WNDALERT_0);
#endif /* _SOUND_NOTIFY */
if (self->ringing_sound != -1)
box_notify2(self, call_incoming, NT_LOOP | NT_WNDALERT_0, self->ringing_sound, "Incoming audio call!");
else
box_notify(self, call_incoming, NT_LOOP | NT_WNDALERT_0, &self->ringing_sound, self->name, "Incoming audio call!");
}
void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
@ -473,8 +503,8 @@ void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ringing...\"cancel\" ?");
#ifdef _SOUND_NOTIFY
if (self->active_sound == -1)
self->active_sound = notify(self, call_outgoing, NT_LOOP);
if (self->ringing_sound == -1)
sound_notify(self, call_outgoing, NT_LOOP, &self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -488,8 +518,7 @@ void chat_onStarting (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -503,8 +532,7 @@ void chat_onEnding (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call ended!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -517,8 +545,7 @@ void chat_onError (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -532,8 +559,7 @@ void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -547,8 +573,7 @@ void chat_onCancel (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call canceled!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -561,8 +586,7 @@ void chat_onReject (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Rejected!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -576,8 +600,7 @@ void chat_onEnd (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call ended!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -590,8 +613,7 @@ void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No answer!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
@ -605,12 +627,10 @@ void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer disconnected; call ended!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
self->active_sound = -1;
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
}
#ifdef _AUDIO
static void init_infobox(ToxWindow *self)
{
ChatContext *ctx = self->chatwin;
@ -627,7 +647,6 @@ static void init_infobox(ToxWindow *self)
ctx->infobox.active = true;
strcpy(ctx->infobox.timestr, "00");
}
#endif
static void kill_infobox(ToxWindow *self)
{
@ -765,7 +784,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
}
} else {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}
} else if (key == '\n') {
@ -1020,11 +1039,10 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
ret.call_idx = -1;
ret.device_selection[0] = ret.device_selection[1] = -1;
ret.ringing_sound = -1;
#endif /* _AUDIO */
#ifdef _SOUND_NOTIFY
ret.active_sound = -1;
#endif /* _SOUND_NOTIFY */
ret.active_box = -1;
char nick[TOX_MAX_NAME_LENGTH];
int n_len = get_nick_truncate(m, nick, friendnum);

View File

@ -170,5 +170,5 @@ void execute(WINDOW *w, ToxWindow *self, Tox *m, const char *input, int mode)
/* Just play sound instead */
/*line_info_add(self, NULL, NULL, NULL, "Invalid command.", SYS_MSG, 0, 0);*/
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}

View File

@ -94,7 +94,14 @@ void do_file_senders(Tox *m)
if (timed_out(file_senders[i].timestamp, get_unix_time(), TIMEOUT_FILESENDER)) {
snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", pathname);
close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, friendnum);
notify(self, error, NT_NOFOCUS | NT_WNDALERT_2);
sound_notify(self, error, NT_NOFOCUS | NT_WNDALERT_2, NULL);
if (self->active_box != -1)
box_notify2(self, error, NT_NOFOCUS | NT_WNDALERT_2,
self->active_box, "File transfer for '%s' failed!", pathname );
else
box_notify(self, error, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box,
self->name, "File transfer for '%s' failed!", pathname );
continue;
}
@ -123,7 +130,14 @@ void do_file_senders(Tox *m)
if (file_senders[i].piecelen == 0) {
snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", pathname);
close_file_sender(self, m, i, msg, TOX_FILECONTROL_FINISHED, filenum, friendnum);
notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2);
if (self->active_box != -1)
box_notify2(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2,
self->active_box, "File '%s' successfuly sent!", pathname );
else
box_notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box,
self->name, "File '%s' successfuly sent!", pathname );
break;
}
}

View File

@ -105,8 +105,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const cha
if (friends[num].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
notify(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS);
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
} else {
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
@ -118,7 +117,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const cha
const char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
notify(prompt, error, NT_WNDALERT_1);
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
}
}
}
@ -216,7 +215,14 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
if (friends[num].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
notify(self, transfer_pending, NT_NOFOCUS);
if (self->active_box != -1)
box_notify2(self, transfer_pending, NT_NOFOCUS, self->active_box,
"Incoming file reaquest: %s", filename);
else
box_notify(self, transfer_pending, NT_NOFOCUS, &self->active_box, self->name,
"Incoming file reaquest: %s", filename);
} else {
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
@ -226,7 +232,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
const char *msg = "* File transfer from %s failed: too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg, nick);
notify(prompt, error, NT_WNDALERT_1);
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
}
}
}
@ -239,7 +245,13 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
if (friends[num].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
notify(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS);
if (self->active_box != -1)
box_notify2(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS, self->active_box,
"You are invited to join group" );
else
box_notify(self, generic_message, NT_WNDALERT_0 | NT_NOFOCUS, &self->active_box, self->name,
"You are invited to join group" );
} else {
char nick[TOX_MAX_NAME_LENGTH];
@ -248,7 +260,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
const char *msg = "* Group chat invite from %s failed: too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg, nick);
notify(prompt, error, NT_WNDALERT_1);
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
}
}
}
@ -352,7 +364,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
const char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
notify(prompt, error, NT_WNDALERT_1);
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
}
} else if (key == KEY_DC) {
del_friend_activate(self, m, f);
@ -575,7 +587,7 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
const char *errmsg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
notify(prompt, error, NT_WNDALERT_1);
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
}
}
}
@ -617,10 +629,8 @@ ToxWindow new_friendlist(void)
ret.call_idx = -1;
ret.device_selection[0] = ret.device_selection[1] = -1;
#endif /* _AUDIO */
#ifdef _SOUND_NOTIFY
ret.active_sound = -1;
#endif /* _SOUND_NOTIFY */
ret.active_box = -1;
strcpy(ret.name, "contacts");
return ret;

View File

@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <wchar.h>
@ -144,10 +145,16 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
/* Only play sound if mentioned */
if (strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH - 1)) {
notify(self, generic_message, NT_WNDALERT_0);
sound_notify(self, generic_message, NT_WNDALERT_0, NULL);
if (self->active_box != -1)
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "%s %s", nick, msg);
else
box_silent_notify(self, NT_NOFOCUS, &self->active_box, self->name, "%s %s", nick, msg);
nick_clr = RED;
}
else notify(self, silent, NT_WNDALERT_1);
else sound_notify(self, silent, NT_WNDALERT_1, NULL);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
@ -169,9 +176,19 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
selfnick[n_len] = '\0';
if (strcasestr(action, selfnick)) {
notify(self, generic_message, NT_WNDALERT_0);
sound_notify(self, generic_message, NT_WNDALERT_0, NULL);
char nick[TOX_MAX_NAME_LENGTH];
int n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); /* enforce client max name length */
nick[n_len] = '\0';
if (self->active_box != -1)
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
else
box_silent_notify(self, NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action);
}
else notify(self, silent, NT_WNDALERT_1);
else sound_notify(self, silent, NT_WNDALERT_1, NULL);
char nick[TOX_MAX_NAME_LENGTH];
n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
@ -304,7 +321,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
break;
}
notify(self, silent, NT_WNDALERT_2);
sound_notify(self, silent, NT_WNDALERT_2, NULL);
}
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
@ -363,10 +380,10 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
}
} else {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}
} else {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}
} else if (key == T_KEY_C_RB) { /* Scroll peerlist up and down one position */
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
@ -523,6 +540,7 @@ ToxWindow new_group_chat(Tox *m, int groupnum)
ret.help = help;
ret.num = groupnum;
ret.active_box = -1;
return ret;
}

View File

@ -42,12 +42,12 @@ void input_new_char(ToxWindow *self, wint_t key, int x, int y, int mx_x, int mx_
/* this is the only place we need to do this check */
if (cur_len == -1) {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
return;
}
if (add_char_to_buf(ctx, key) == -1) {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
return;
}
@ -63,7 +63,7 @@ static void input_backspace(ToxWindow *self, int x, int mx_x)
ChatContext *ctx = self->chatwin;
if (del_char_buf_bck(ctx) == -1) {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
return;
}
@ -80,21 +80,21 @@ static void input_backspace(ToxWindow *self, int x, int mx_x)
static void input_delete(ToxWindow *self)
{
if (del_char_buf_frnt(self->chatwin) == -1)
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}
/* deletes entire line before cursor from input field and buffer */
static void input_discard(ToxWindow *self)
{
if (discard_buf(self->chatwin) == -1)
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}
/* deletes entire line after cursor from input field and buffer */
static void input_kill(ChatContext *ctx)
{
if (kill_buf(ctx) == -1)
notify(NULL, error, NT_ALWAYS);
sound_notify(NULL, error, NT_ALWAYS, NULL);
}
static void input_yank(ToxWindow *self, int x, int mx_x)
@ -102,7 +102,7 @@ static void input_yank(ToxWindow *self, int x, int mx_x)
ChatContext *ctx = self->chatwin;
if (yank_buf(ctx) == -1) {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
return;
}

View File

@ -415,14 +415,14 @@ static void line_info_scroll_up(struct history *hst)
{
if (hst->line_start->prev)
hst->line_start = hst->line_start->prev;
else notify(NULL, error, NT_ALWAYS);
else sound_notify(NULL, error, NT_ALWAYS, NULL);
}
static void line_info_scroll_down(struct history *hst)
{
if (hst->line_start->next)
hst->line_start = hst->line_start->next;
else notify(NULL, error, NT_ALWAYS);
else sound_notify(NULL, error, NT_ALWAYS, NULL);
}
static void line_info_page_up(ToxWindow *self, struct history *hst)

View File

@ -23,6 +23,7 @@
#include "notify.h"
#include "device.h"
#include "settings.h"
#include "line_info.h"
#include <stdlib.h>
#include <string.h>
@ -33,7 +34,7 @@
#include <assert.h>
#include <sys/stat.h>
#ifdef _AUDIO
#if defined(_AUDIO) || defined(_SOUND_NOTIFY)
#ifdef __APPLE__
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
@ -70,10 +71,13 @@ struct _Control {
Display *display;
#endif /* _X11 */
#ifdef _SOUND_NOTIFY
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
pthread_mutex_t poll_mutex[1];
uint32_t device_idx; /* index of output device */
_Bool poll_active;
#endif
#ifdef _SOUND_NOTIFY
uint32_t device_idx; /* index of output device */
char* sounds[SOUNDS_SIZE];
#endif /* _SOUND_NOTIFY */
} Control = {0};
@ -82,16 +86,16 @@ struct _ActiveNotifications {
#ifdef _SOUND_NOTIFY
uint32_t source;
uint32_t buffer;
_Bool active;
_Bool looping;
#endif
_Bool active;
int *id_indicator;
#ifdef _BOX_NOTIFY
NotifyNotification* box;
char messages[128][128];
char title[24];
size_t size;
time_t timeout;
time_t n_timeout;
#endif
} actives[ACTIVE_NOTIFS_MAX] = {{0}};
/**********************************************************************************/
@ -114,8 +118,21 @@ long unsigned int get_focused_window_id()
#endif /* _X11 */
}
#ifdef _SOUND_NOTIFY
static void control_lock()
{
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
pthread_mutex_lock(Control.poll_mutex);
#endif
}
static void control_unlock()
{
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
pthread_mutex_unlock(Control.poll_mutex);
#endif
}
#ifdef _SOUND_NOTIFY
_Bool is_playing(int source)
{
int ready;
@ -127,17 +144,20 @@ _Bool is_playing(int source)
void graceful_clear()
{
int i;
pthread_mutex_lock(Control.poll_mutex);
control_lock();
while (1) {
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
if (actives[i].active) {
#ifdef _BOX_NOTIFY
if (actives[i].box) {
notify_notification_close(actives[i].box, NULL);
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
GError* ignore;
notify_notification_close(actives[i].box, &ignore);
actives[i].box = NULL;
}
#endif
if(actives[i].id_indicator) *actives[i].id_indicator = -1; // reset indicator value
if ( actives[i].looping ) {
stop_sound(i);
} else {
@ -150,7 +170,7 @@ void graceful_clear()
}
if (i == ACTIVE_NOTIFS_MAX) {
pthread_mutex_unlock(Control.poll_mutex);
control_unlock();
return;
}
@ -163,7 +183,7 @@ void* do_playing(void* _p)
(void)_p;
int i;
while(Control.poll_active) {
pthread_mutex_lock(Control.poll_mutex);
control_lock();
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
if (actives[i].active && !actives[i].looping
#ifdef _BOX_NOTIFY
@ -171,44 +191,43 @@ void* do_playing(void* _p)
#endif
) {
if (!is_playing(actives[i].source)) {
/* Close */
/* Close */
alSourceStop(actives[i].source);
alDeleteSources(1, &actives[i].source);
alDeleteBuffers(1,&actives[i].buffer);
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
}
}
}
#ifdef _BOX_NOTIFY
else if (actives[i].box && !actives[i].looping &&
time(NULL) >= actives[i].timeout && !is_playing(actives[i].source))
else if (actives[i].box && time(NULL) >= actives[i].n_timeout)
{
alSourceStop(actives[i].source);
alDeleteSources(1, &actives[i].source);
alDeleteBuffers(1,&actives[i].buffer);
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
GError* ignore;
notify_notification_close(actives[i].box, &ignore);
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
assert(0);
actives[i].box = NULL;
if(actives[i].id_indicator) *actives[i].id_indicator = -1; // reset indicator value
if (!actives[i].looping && !is_playing(actives[i].source)) {
/* stop source if not looping or playing, just terminate box */
alSourceStop(actives[i].source);
alDeleteSources(1, &actives[i].source);
alDeleteBuffers(1,&actives[i].buffer);
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
}
}
#endif
}
pthread_mutex_unlock(Control.poll_mutex);
control_unlock();
usleep(10000);
}
pthread_exit(NULL);
}
int play_source(uint32_t source, uint32_t buffer, _Bool looping)
{
pthread_mutex_lock(Control.poll_mutex);
int i = 0;
for (; i < ACTIVE_NOTIFS_MAX && actives[i].active; i ++);
if ( i == ACTIVE_NOTIFS_MAX ) {
pthread_mutex_unlock(Control.poll_mutex);
return -1; /* Full */
}
@ -219,10 +238,53 @@ int play_source(uint32_t source, uint32_t buffer, _Bool looping)
actives[i].buffer = buffer;
actives[i].looping = looping;
pthread_mutex_unlock(Control.poll_mutex);
return i;
}
#elif _BOX_NOTIFY
void* do_playing(void* _p)
{
(void)_p;
int i;
while(Control.poll_active) {
control_lock();
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
if (actives[i].box && time(NULL) >= actives[i].n_timeout)
{
GError* ignore;
notify_notification_close(actives[i].box, &ignore);
actives[i].box = NULL;
if(actives[i].id_indicator) *actives[i].id_indicator = -1; // reset indicator value
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
}
}
control_unlock();
usleep(10000);
}
pthread_exit(NULL);
}
void graceful_clear()
{
int i;
control_lock();
for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) {
if (actives[i].box) {
GError* ignore;
notify_notification_close(actives[i].box, &ignore);
actives[i].box = NULL;
}
if(actives[i].id_indicator) *actives[i].id_indicator = -1; // reset indicator value
memset(&actives[i], 0, sizeof(struct _ActiveNotifications));
}
control_unlock();
}
#endif
/**********************************************************************************/
/**********************************************************************************/
/**********************************************************************************/
@ -238,7 +300,9 @@ int init_notify(int login_cooldown, int notification_timeout)
alutInitWithoutContext(NULL, NULL);
if (open_primary_device(output, &Control.device_idx, 48000, 20, 1) != de_None)
return -1;
#endif /* _SOUND_NOTIFY */
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
pthread_mutex_init(Control.poll_mutex, NULL);
pthread_t thread;
if (pthread_create(&thread, NULL, do_playing, NULL) != 0 || pthread_detach(thread) != 0 ) {
@ -246,7 +310,7 @@ int init_notify(int login_cooldown, int notification_timeout)
return -1;
}
Control.poll_active = 1;
#endif /* _SOUND_NOTIFY */
#endif
Control.cooldown = time(NULL) + login_cooldown;
#ifdef _X11
@ -265,19 +329,20 @@ int init_notify(int login_cooldown, int notification_timeout)
}
void terminate_notify()
{
#ifdef _SOUND_NOTIFY
{
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
if ( !Control.poll_active ) return;
Control.poll_active = 0;
graceful_clear();
#endif
#ifdef _SOUND_NOTIFY
int i = 0;
for (; i < SOUNDS_SIZE; i ++) free(Control.sounds[i]);
graceful_clear();
close_device(output, Control.device_idx);
alutExit();
#endif /* _SOUND_NOTIFY */
#endif /* _SOUND_NOTIFY */
#ifdef _BOX_NOTIFY
notify_uninit();
@ -327,7 +392,7 @@ int play_notify_sound(Notification notif, uint64_t flags)
if (flags & NT_BEEP) beep();
else if (notif != silent) {
if ( !Control.poll_active || (flags & NT_RESTOL && Control.cooldown > time(NULL)) || !Control.sounds[notif] )
if ( !Control.poll_active || !Control.sounds[notif] )
return -1;
rc = play_sound_internal(notif, flags & NT_LOOP ? 1 : 0);
@ -337,14 +402,21 @@ int play_notify_sound(Notification notif, uint64_t flags)
}
void stop_sound(int sound)
void stop_sound(int id)
{
if (sound >= 0 && sound < ACTIVE_NOTIFS_MAX && actives[sound].looping && actives[sound].active ) {
alSourcei(actives[sound].source, AL_LOOPING, false);
alSourceStop(actives[sound].source);
alDeleteSources(1, &actives[sound].source);
alDeleteBuffers(1,&actives[sound].buffer);
memset(&actives[sound], 0, sizeof(struct _ActiveNotifications));
if (id >= 0 && id < ACTIVE_NOTIFS_MAX && actives[id].looping && actives[id].active ) {
#ifdef _BOX_NOTIFY
if (actives[id].box) {
GError* ignore;
notify_notification_close(actives[id].box, &ignore);
}
#endif
*actives[id].id_indicator = -1;
// alSourcei(actives[id].source, AL_LOOPING, false);
alSourceStop(actives[id].source);
alDeleteSources(1, &actives[id].source);
alDeleteBuffers(1,&actives[id].buffer);
memset(&actives[id], 0, sizeof(struct _ActiveNotifications));
}
}
#endif
@ -358,11 +430,16 @@ static int m_play_sound(Notification notif, uint64_t flags)
beep();
return -1;
#endif /* _SOUND_NOTIFY */
#endif /* _SOUND_NOTIFY */
}
int notify(ToxWindow* self, Notification notif, uint64_t flags)
#ifdef _BOX_NOTIFY
void m_notify_action(NotifyNotification *box, char *action, void* data)
{
}
#endif
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) {
@ -371,43 +448,119 @@ int notify(ToxWindow* self, Notification notif, uint64_t flags)
else if (flags & NT_WNDALERT_2) self->alert = WINDOW_ALERT_2;
}
if (flags & NT_NOFOCUS && Control.this_window == get_focused_window_id())
if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
return -1;
int rc = -1;
int id = -1;
control_lock();
if (self && (!self->stb || self->stb->status != TOX_USERSTATUS_BUSY) && user_settings_->alerts == ALERTS_ENABLED)
rc = m_play_sound(notif, flags);
id = m_play_sound(notif, flags);
else if (flags & NT_ALWAYS)
rc = m_play_sound(notif, flags);
id = m_play_sound(notif, flags);
return rc;
#if defined(_BOX_NOTIFY) && !defined(_SOUND_NOTIFY)
if (id == -1) {
for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].box; id ++);
if ( id == ACTIVE_NOTIFS_MAX ) {
control_unlock();
return -1; /* Full */
}
}
#endif
if ( id_indicator && id != -1 ) {
actives[id].id_indicator = id_indicator;
*id_indicator = id;
}
control_unlock();
return id;
}
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, char* title, char* format, ...)
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 (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;
}
if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
return -1;
if (id < 0 || id >= ACTIVE_NOTIFS_MAX) return -1;
#ifdef _SOUND_NOTIFY
control_lock();
if (!actives[id].active || !Control.sounds[notif]) {
control_unlock();
return -1;
}
alSourceStop(actives[id].source);
alDeleteSources(1, &actives[id].source);
alDeleteBuffers(1,&actives[id].buffer);
alGenSources(1, &actives[id].source);
alGenBuffers(1, &actives[id].buffer);
actives[id].buffer = alutCreateBufferFromFile(Control.sounds[notif]);
alSourcei(actives[id].source, AL_BUFFER, actives[id].buffer);
alSourcei(actives[id].source, AL_LOOPING, flags & NT_LOOP);
alSourcePlay(actives[id].source);
control_unlock();
return id;
#else
if (notif != silent)
beep();
return 0;
#endif /* _SOUND_NOTIFY */
}
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, char* title, const char* format, ...)
{
if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
return -1;
#ifdef _BOX_NOTIFY
int id = notify(self, notif, flags);
pthread_mutex_lock(Control.poll_mutex);
int id = sound_notify(self, notif, flags, id_indicator);
if (id == -1 && !(flags & NT_NOFOCUS && Control.this_window == get_focused_window_id())) { /* Could not play */
control_lock();
#ifdef _SOUND_NOTIFY
if (id == -1) { /* Could not play */
for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].active; id ++);
if ( id == ACTIVE_NOTIFS_MAX ) {
pthread_mutex_unlock(Control.poll_mutex);
control_unlock();
return -1; /* Full */
}
actives[id].active = 1;
actives[id].active = 1;
actives[id].id_indicator = id_indicator;
if (id_indicator) *id_indicator = id;
}
#endif
strncpy(actives[id].title, title, 24);
if (strlen(title) > 23) strcpy(actives[id].title + 20, "...");
va_list __ARGS__; va_start (__ARGS__, format);
snprintf (actives[id].messages[0], 127, format, __ARGS__);
vsnprintf (actives[id].messages[0], 127, format, __ARGS__);
va_end (__ARGS__);
if (strlen(actives[id].messages[0]) > 124)
@ -415,46 +568,48 @@ int box_notify(ToxWindow* self, Notification notif, uint64_t flags, char* title,
actives[id].box = notify_notification_new(actives[id].title, actives[id].messages[0], NULL);
actives[id].size ++;
actives[id].timeout = time(NULL) + Control.notif_timeout;
actives[id].n_timeout = time(NULL) + Control.notif_timeout / 1000;
notify_notification_set_timeout(actives[id].box, Control.notif_timeout);
notify_notification_set_app_name(actives[id].box, "toxic");
/*notify_notification_add_action(actives[id].box, "lel", "default", m_notify_action, self, NULL);*/
notify_notification_show(actives[id].box, NULL);
pthread_mutex_unlock(Control.poll_mutex);
control_unlock();
return id;
#else
return notify(self, notif, flags);
return sound_notify(self, notif, flags, id_indicator);
#endif
}
int box_notify_append(ToxWindow* self, Notification notif, uint64_t flags, int id, char* format, ...)
int box_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id, const char* format, ...)
{
if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
return -1;
#ifdef _BOX_NOTIFY
if (id < 0 || id >= ACTIVE_NOTIFS_MAX || !actives[id].box || actives[id].size >= 128 ) return -1;
/* Consider colored notify as primary */
if (self && self->alert == WINDOW_ALERT_NONE) {
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;
}
if (flags & NT_NOFOCUS && Control.this_window == get_focused_window_id())
if (sound_notify2(self, notif, flags, id) == -1)
return -1;
pthread_mutex_lock(Control.poll_mutex);
control_lock();
if (!actives[id].box || actives[id].size >= 128 ) {
control_unlock();
return -1;
}
/* Play the sound again */
alSourcePlay(actives[id].source);
va_list __ARGS__; va_start (__ARGS__, format);
snprintf (actives[id].messages[actives[id].size], 127, format, __ARGS__);
vsnprintf (actives[id].messages[actives[id].size], 127, format, __ARGS__);
va_end (__ARGS__);
if (strlen(actives[id].messages[actives[id].size]) > 124)
if (strlen(actives[id].messages[actives[id].size]) > 124)
strcpy(actives[id].messages[actives[id].size] + 124, "...");
actives[id].size ++;
actives[id].timeout = time(NULL) + Control.notif_timeout;
actives[id].n_timeout = time(NULL) + Control.notif_timeout / 1000;
char formated[128 * 129] = {'\0'};
@ -469,10 +624,119 @@ int box_notify_append(ToxWindow* self, Notification notif, uint64_t flags, int i
notify_notification_update(actives[id].box, actives[id].title, formated, NULL);
notify_notification_show(actives[id].box, NULL);
pthread_mutex_unlock(Control.poll_mutex);
control_unlock();
return id;
#else
return notify(self, notif, flags);
return sound_notify2(self, notif, flags, id);
#endif
}
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 (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;
}
if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
return -1;
#ifdef _BOX_NOTIFY
control_lock();
int id;
for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].active; id ++);
if ( id == ACTIVE_NOTIFS_MAX ) {
control_unlock();
return -1; /* Full */
}
if (id_indicator) {
actives[id].id_indicator = id_indicator;
*id_indicator = id;
}
strncpy(actives[id].title, title, 24);
if (strlen(title) > 23) strcpy(actives[id].title + 20, "...");
va_list __ARGS__; va_start (__ARGS__, format);
vsnprintf (actives[id].messages[0], 127, format, __ARGS__);
va_end (__ARGS__);
if (strlen(actives[id].messages[0]) > 124)
strcpy(actives[id].messages[0] + 124, "...");
actives[id].active = 1;
actives[id].box = notify_notification_new(actives[id].title, actives[id].messages[0], NULL);
actives[id].size ++;
actives[id].n_timeout = time(NULL) + Control.notif_timeout / 1000;
notify_notification_set_timeout(actives[id].box, Control.notif_timeout);
notify_notification_set_app_name(actives[id].box, "toxic");
/*notify_notification_add_action(actives[id].box, "lel", "default", m_notify_action, self, NULL);*/
notify_notification_show(actives[id].box, NULL);
control_unlock();
return id;
#else
return -1;
#endif
}
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 (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;
}
if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
return -1;
#ifdef _BOX_NOTIFY
control_lock();
if (id < 0 || id >= ACTIVE_NOTIFS_MAX || !actives[id].box || actives[id].size >= 128 ) {
control_unlock();
return -1;
}
va_list __ARGS__; va_start (__ARGS__, format);
vsnprintf (actives[id].messages[actives[id].size], 127, format, __ARGS__);
va_end (__ARGS__);
if (strlen(actives[id].messages[actives[id].size]) > 124)
strcpy(actives[id].messages[actives[id].size] + 124, "...");
actives[id].size ++;
actives[id].n_timeout = time(NULL) + Control.notif_timeout / 1000;
char formated[128 * 129] = {'\0'};
int i = 0;
for (; i <actives[id].size; i ++) {
strcat(formated, actives[id].messages[i]);
strcat(formated, "\n");
}
formated[strlen(formated) - 1] = '\0';
notify_notification_update(actives[id].box, actives[id].title, formated, NULL);
notify_notification_show(actives[id].box, NULL);
control_unlock();
return id;
#else
return -1;
#endif
}

View File

@ -63,14 +63,18 @@ typedef enum _Flags {
int init_notify(int login_cooldown, int notification_timeout);
void terminate_notify();
int notify(ToxWindow* self, Notification notif, uint64_t flags);
int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator);
int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id);
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, char* title, char* format, ...);
int box_notify_append(ToxWindow* self, Notification notif, uint64_t flags, int id, char* format, ...);
void stop_sound(int id);
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, char* title, const char* format, ...);
int box_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id, const char* format, ...);
int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const char* title, const char* format, ...);
int box_silent_notify2(ToxWindow* self, uint64_t flags, int id, const char* format, ...);
#ifdef _SOUND_NOTIFY
int set_sound(Notification sound, const char* value);
void stop_sound(int sound);
#endif /* _SOUND_NOTIFY */
#endif /* _notify_h */

View File

@ -185,10 +185,10 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
}
} else {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}
} else {
notify(self, error, 0);
sound_notify(self, error, 0, NULL);
}
} else if (key == '\n') {
rm_trailing_spaces_buf(ctx);
@ -309,13 +309,23 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, GREEN, msg);
write_to_log(msg, nick, ctx->log, true);
notify(self, user_log_in, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL);
if (self->active_box != -1)
box_notify2(self, user_log_in, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, self->active_box,
"%s has come online", nick );
else
box_notify(self, user_log_in, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, &self->active_box,
"Toxic", "%s has come online", nick );
} else {
msg = "has gone offline";
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, RED, msg);
write_to_log(msg, nick, ctx->log, true);
notify(self, user_log_out, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL);
if (self->active_box != -1)
box_notify2(self, user_log_out, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, self->active_box,
"%s has gone offline", nick );
else
box_notify(self, user_log_out, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, &self->active_box,
"Toxic", "%s has gone offline", nick );
}
}
@ -342,7 +352,7 @@ static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, con
msg = "Type \"/accept %d\" to accept it.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, n);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOTIFWND);
sound_notify(self, generic_message, NT_WNDALERT_1 | NT_NOTIFWND, NULL);
}
void prompt_init_statusbar(ToxWindow *self, Tox *m)
@ -458,5 +468,7 @@ ToxWindow new_prompt(void)
ret.stb = stb;
ret.help = help;
ret.active_box = -1;
return ret;
}

View File

@ -102,7 +102,7 @@ void exit_toxic_success(Tox *m)
free(user_settings_);
#ifdef _SOUND_NOTIFY
notify(NULL, self_log_out, NT_ALWAYS);
// sound_notify(NULL, self_log_out, NT_ALWAYS, NULL);
#endif /* _SOUND_NOTIFY */
terminate_notify();
#ifdef _AUDIO
@ -638,11 +638,11 @@ int main(int argc, char *argv[])
init_notify(60, 3000);
#ifdef _SOUND_NOTIFY
notify(prompt, self_log_in, 0);
// sound_notify(prompt, self_log_in, 0, NULL);
#endif /* _SOUND_NOTIFY */
const char *msg;
if (config_err) {
msg = "Unable to determine configuration directory. Defaulting to 'data' for a keyfile...";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
@ -657,6 +657,12 @@ int main(int argc, char *argv[])
uint64_t last_save = (uint64_t) time(NULL);
/* Redirect stdout to /dev/null
* NOTE: Might not be best solution
*/
freopen("/dev/null", "w", stderr);
while (true) {
update_unix_time();
do_toxic(m, prompt);

View File

@ -192,7 +192,7 @@ void fetch_hist_item(ChatContext *ctx, int key_dir)
if (key_dir == KEY_UP) {
if (--ctx->hst_pos < 0) {
ctx->hst_pos = 0;
notify(NULL, error, NT_ALWAYS);
sound_notify(NULL, error, NT_ALWAYS, NULL);
}
} else {
if (++ctx->hst_pos >= ctx->hst_tot) {

View File

@ -116,12 +116,11 @@ struct ToxWindow {
* Don't modify outside av callbacks. */
int device_selection[2]; /* -1 if not set, if set uses these selections instead of primary device */
int ringing_sound;
#endif /* _AUDIO */
#ifdef _SOUND_NOTIFY
int active_sound;
#endif
int active_box; /* For box notify */
char name[TOXIC_MAX_NAME_LENGTH];
int32_t num; /* corresponds to friendnumber in chat windows */
bool active;