mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 02:33:25 +01:00
Add options to enable terminal bell on certain events
Some terminals can mark the terminal window as urgent on bell. This is useful for window managers that provide a shortcut to jump to an urgent client.
This commit is contained in:
parent
2ec180789b
commit
d3effa26b5
26
src/chat.c
26
src/chat.c
@ -160,9 +160,11 @@ static void recv_message_helper(ToxWindow *self, Tox *m, uint32_t num, const cha
|
||||
write_to_log(msg, nick, ctx->log, false);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, self->active_box, "%s", msg);
|
||||
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->beep_on_message,
|
||||
self->active_box, "%s", msg);
|
||||
else
|
||||
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, &self->active_box, nick, "%s", msg);
|
||||
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->beep_on_message,
|
||||
&self->active_box, nick, "%s", msg);
|
||||
}
|
||||
|
||||
static void recv_action_helper(ToxWindow *self, Tox *m, uint32_t num, const char *action, size_t len,
|
||||
@ -174,9 +176,11 @@ static void recv_action_helper(ToxWindow *self, Tox *m, uint32_t num, const char
|
||||
write_to_log(action, nick, ctx->log, true);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
|
||||
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->beep_on_message,
|
||||
self->active_box, "* %s %s", nick, action );
|
||||
else
|
||||
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action );
|
||||
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->beep_on_message,
|
||||
&self->active_box, self->name, "* %s %s", nick, action );
|
||||
}
|
||||
|
||||
static void chat_onMessage(ToxWindow *self, Tox *m, uint32_t num, TOX_MESSAGE_TYPE type, const char *msg, size_t len)
|
||||
@ -454,7 +458,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t friendnum, uint
|
||||
char progline[MAX_STR_SIZE];
|
||||
init_progress_bar(progline);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", progline);
|
||||
sound_notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2, NULL);
|
||||
sound_notify(self, silent, NT_NOFOCUS | user_settings->beep_on_filetrans_accept | NT_WNDALERT_2, NULL);
|
||||
ft->line_id = self->chatwin->hst->line_end->id + 2;
|
||||
} else if (ft->state == FILE_TRANSFER_PAUSED) { /* transfer is resumed */
|
||||
ft->state = FILE_TRANSFER_STARTED;
|
||||
@ -596,11 +600,11 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
|
||||
tox_file_get_file_id(m, friendnum, filenum, ft->file_id, NULL);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_notify2(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS, self->active_box,
|
||||
"Incoming file: %s", filename );
|
||||
box_notify2(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | user_settings->beep_on_filetrans,
|
||||
self->active_box, "Incoming file: %s", filename );
|
||||
else
|
||||
box_notify(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS, &self->active_box, self->name,
|
||||
"Incoming file: %s", filename );
|
||||
box_notify(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | user_settings->beep_on_filetrans,
|
||||
&self->active_box, self->name, "Incoming file: %s", filename );
|
||||
}
|
||||
|
||||
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t type, const char *group_pub_key,
|
||||
@ -623,7 +627,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, ui
|
||||
Friends.list[friendnumber].group_invite.length = length;
|
||||
Friends.list[friendnumber].group_invite.type = type;
|
||||
|
||||
sound_notify(self, generic_message, NT_WNDALERT_2, NULL);
|
||||
sound_notify(self, generic_message, NT_WNDALERT_2 | user_settings->beep_on_invite, NULL);
|
||||
|
||||
char name[TOX_MAX_NAME_LENGTH];
|
||||
get_nick_truncate(m, name, friendnumber);
|
||||
@ -651,7 +655,7 @@ void chat_onInvite (ToxWindow *self, ToxAV *av, uint32_t friend_number, int stat
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Incoming audio call! Type: \"/answer\" or \"/reject\"");
|
||||
|
||||
if (self->ringing_sound == -1)
|
||||
sound_notify(self, call_incoming, NT_LOOP, &self->ringing_sound);
|
||||
sound_notify(self, call_incoming, NT_LOOP | user_settings->beep_on_invite, &self->ringing_sound);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_silent_notify2(self, NT_NOFOCUS | NT_WNDALERT_0, self->active_box, "Incoming audio call!");
|
||||
|
@ -258,7 +258,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
|
||||
/* Only play sound if mentioned by someone else */
|
||||
if (strcasestr(msg, selfnick) && strcmp(selfnick, nick)) {
|
||||
sound_notify(self, generic_message, NT_WNDALERT_0, NULL);
|
||||
sound_notify(self, generic_message, NT_WNDALERT_0 | user_settings->beep_on_message, NULL);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "%s %s", nick, msg);
|
||||
@ -296,7 +296,7 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
|
||||
selfnick[n_len] = '\0';
|
||||
|
||||
if (strcasestr(action, selfnick)) {
|
||||
sound_notify(self, generic_message, NT_WNDALERT_0, NULL);
|
||||
sound_notify(self, generic_message, NT_WNDALERT_0 | user_settings->beep_on_message, NULL);
|
||||
|
||||
if (self->active_box != -1)
|
||||
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
|
||||
|
@ -472,7 +472,7 @@ int play_notify_sound(Notification notif, uint64_t flags)
|
||||
int rc = -1;
|
||||
|
||||
if (flags & NT_BEEP) beep();
|
||||
else if (notif != silent) {
|
||||
if (notif != silent) {
|
||||
if ( !Control.poll_active || !Control.sounds[notif] )
|
||||
return -1;
|
||||
|
||||
|
@ -51,6 +51,10 @@ static struct ui_strings {
|
||||
const char* timestamp_format;
|
||||
const char* log_timestamp_format;
|
||||
const char* alerts;
|
||||
const char* beep_on_message;
|
||||
const char* beep_on_filetrans;
|
||||
const char* beep_on_filetrans_accept;
|
||||
const char* beep_on_invite;
|
||||
const char* native_colors;
|
||||
const char* autolog;
|
||||
const char* history_size;
|
||||
@ -73,6 +77,10 @@ static struct ui_strings {
|
||||
"timestamp_format",
|
||||
"log_timestamp_format",
|
||||
"alerts",
|
||||
"beep_on_message",
|
||||
"beep_on_filetrans",
|
||||
"beep_on_filetrans_accept",
|
||||
"beep_on_invite",
|
||||
"native_colors",
|
||||
"autolog",
|
||||
"history_size",
|
||||
@ -96,6 +104,10 @@ static void ui_defaults(struct user_settings* settings)
|
||||
|
||||
settings->autolog = AUTOLOG_OFF;
|
||||
settings->alerts = ALERTS_ENABLED;
|
||||
settings->beep_on_message = 0;
|
||||
settings->beep_on_filetrans = 0;
|
||||
settings->beep_on_filetrans_accept = 0;
|
||||
settings->beep_on_invite = 0;
|
||||
settings->colour_theme = DFLT_COLS;
|
||||
settings->history_size = 700;
|
||||
settings->show_typing_self = SHOW_TYPING_ON;
|
||||
@ -319,6 +331,20 @@ int settings_load(struct user_settings *s, const char *patharg)
|
||||
}
|
||||
|
||||
config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts);
|
||||
|
||||
if (config_setting_lookup_bool(setting, ui_strings.beep_on_message, &s->beep_on_message)) {
|
||||
s->beep_on_message = s->beep_on_message ? NT_BEEP : 0;
|
||||
}
|
||||
if (config_setting_lookup_bool(setting, ui_strings.beep_on_filetrans, &s->beep_on_filetrans)) {
|
||||
s->beep_on_filetrans = s->beep_on_filetrans ? NT_BEEP : 0;
|
||||
}
|
||||
if (config_setting_lookup_bool(setting, ui_strings.beep_on_filetrans_accept, &s->beep_on_filetrans_accept)) {
|
||||
s->beep_on_filetrans_accept = s->beep_on_filetrans_accept ? NT_BEEP : 0;
|
||||
}
|
||||
if (config_setting_lookup_bool(setting, ui_strings.beep_on_invite, &s->beep_on_invite)) {
|
||||
s->beep_on_invite = s->beep_on_invite ? NT_BEEP : 0;
|
||||
}
|
||||
|
||||
config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
|
||||
config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
|
||||
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
|
||||
|
@ -37,6 +37,12 @@ struct user_settings {
|
||||
int autolog; /* boolean */
|
||||
int alerts; /* boolean */
|
||||
|
||||
/* boolean (is set to NT_BEEP or 0 after loading) */
|
||||
int beep_on_message;
|
||||
int beep_on_filetrans;
|
||||
int beep_on_filetrans_accept;
|
||||
int beep_on_invite;
|
||||
|
||||
int timestamps; /* boolean */
|
||||
char timestamp_format[TIME_STR_SIZE];
|
||||
char log_timestamp_format[TIME_STR_SIZE];
|
||||
|
Loading…
Reference in New Issue
Block a user