diff --git a/doc/toxic.conf.5 b/doc/toxic.conf.5 index 9a1f15e..40c1d75 100644 --- a/doc/toxic.conf.5 +++ b/doc/toxic.conf.5 @@ -85,7 +85,7 @@ Time format string for logging enclosed by double quotes\&. See .PP \fBalerts\fR .RS 4 -Enable or disable terminal alerts on events\&. true or false +Enable or disable acoustic alerts on events\&. true or false .RE .PP \fBnative_colors\fR @@ -152,6 +152,30 @@ Set user status when attaching and detaching from GNU screen or tmux\&. true or .RS 4 Status message to set when status is set to away due to screen/tmux detach\&. When attaching, the status message is set back to the original value\&. .RE +.PP +The following options control whether to output a terminal bell on certain events\&. +.br +Some terminals mark the window as urgent when a bell is received\&. Urgent windows are usually highlighted in the taskbar and some window managers even provide shortcuts to jump to the next urgent window\&. These options don't affect the "alerts" option\&. +.PP +\fBbell_on_message\fR +.RS 4 +Enable/Disable the terminal bell when receiving a message\&. true or false +.RE +.PP +\fBbell_on_filetrans\fR +.RS 4 +Enable/Disable the terminal bell when receiving a filetransfer\&. true or false +.RE +.PP +\fBbell_on_filetrans_accept\fR +.RS 4 +Enable/Disable the terminal bell when a filetransfer was accepted\&. true or false +.RE +.PP +\fBbell_on_invite\fR +.RS 4 +Enable/Disable the terminal bell when receiving a group/call invite\&. true or false +.RE .RE .PP \fBaudio\fR diff --git a/doc/toxic.conf.5.asc b/doc/toxic.conf.5.asc index a6c70db..8e0b22f 100644 --- a/doc/toxic.conf.5.asc +++ b/doc/toxic.conf.5.asc @@ -55,7 +55,7 @@ OPTIONS See *date*(1) *alerts*;; - Enable or disable terminal alerts on events. true or false + Enable or disable acoustic alerts on events. true or false *native_colors*;; Select between native terminal colors and toxic color theme. true or false @@ -100,6 +100,23 @@ OPTIONS detach. When attaching, the status message is set back to the original value. + The following options control whether to output a terminal bell on certain events. + Some terminals mark the window as urgent when a bell is received. Urgent windows are usually highlighted in the taskbar and some window managers even provide shortcuts to jump to the next urgent window. + These options don't affect the "alerts" option. + + *bell_on_message* + Enable/Disable the terminal bell when receiving a message. true or false + + *bell_on_filetrans* + Enable/Disable the terminal bell when receiving a filetransfer. true or false + + *bell_on_filetrans_accept* + Enable/Disable the terminal bell when a filetransfer was accepted. true or false + + *bell_on_invite* + Enable/Disable the terminal bell when receiving a group/call invite. true or false + + *audio*:: Configuration related to audio devices. diff --git a/misc/toxic.conf.example b/misc/toxic.conf.example index f6302b4..c162cdf 100644 --- a/misc/toxic.conf.example +++ b/misc/toxic.conf.example @@ -5,9 +5,21 @@ ui = { // true to enable timestamps, false to disable timestamps=true; - // true to enable terminal alerts on messages, false to disable + // true to enable acoustic alerts on messages, false to disable alerts=true; + // Output a bell when receiving a message (see manpage) + bell_on_message=true + + // Output a bell when receiving a filetransfer (see manpage) + bell_on_filetrans=true + + // Don't output a bell when a filetransfer was accepted (see manpage) + bell_on_filetrans_accept=false + + // Output a bell when receiving a group/call invite (see manpage) + bell_on_invite=true + // true to use native terminal colours, false to use toxic default colour theme native_colors=false; diff --git a/src/chat.c b/src/chat.c index cdebf8d..3df5288 100644 --- a/src/chat.c +++ b/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->bell_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->bell_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->bell_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->bell_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->bell_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->bell_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->bell_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->bell_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->bell_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!"); diff --git a/src/groupchat.c b/src/groupchat.c index 1c07981..0e58cf3 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -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->bell_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->bell_on_message, NULL); if (self->active_box != -1) box_silent_notify2(self, NT_NOFOCUS, self->active_box, "* %s %s", nick, action ); diff --git a/src/notify.c b/src/notify.c index 093ad95..2d2cec0 100644 --- a/src/notify.c +++ b/src/notify.c @@ -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; diff --git a/src/settings.c b/src/settings.c index 75ecc80..cef92a2 100644 --- a/src/settings.c +++ b/src/settings.c @@ -51,6 +51,10 @@ static struct ui_strings { const char* timestamp_format; const char* log_timestamp_format; const char* alerts; + const char* bell_on_message; + const char* bell_on_filetrans; + const char* bell_on_filetrans_accept; + const char* bell_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", + "bell_on_message", + "bell_on_filetrans", + "bell_on_filetrans_accept", + "bell_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->bell_on_message = 0; + settings->bell_on_filetrans = 0; + settings->bell_on_filetrans_accept = 0; + settings->bell_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.bell_on_message, &s->bell_on_message)) { + s->bell_on_message = s->bell_on_message ? NT_BEEP : 0; + } + if (config_setting_lookup_bool(setting, ui_strings.bell_on_filetrans, &s->bell_on_filetrans)) { + s->bell_on_filetrans = s->bell_on_filetrans ? NT_BEEP : 0; + } + if (config_setting_lookup_bool(setting, ui_strings.bell_on_filetrans_accept, &s->bell_on_filetrans_accept)) { + s->bell_on_filetrans_accept = s->bell_on_filetrans_accept ? NT_BEEP : 0; + } + if (config_setting_lookup_bool(setting, ui_strings.bell_on_invite, &s->bell_on_invite)) { + s->bell_on_invite = s->bell_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); diff --git a/src/settings.h b/src/settings.h index 53418af..a195ad0 100644 --- a/src/settings.h +++ b/src/settings.h @@ -37,6 +37,12 @@ struct user_settings { int autolog; /* boolean */ int alerts; /* boolean */ + /* boolean (is set to NT_BEEP or 0 after loading) */ + int bell_on_message; + int bell_on_filetrans; + int bell_on_filetrans_accept; + int bell_on_invite; + int timestamps; /* boolean */ char timestamp_format[TIME_STR_SIZE]; char log_timestamp_format[TIME_STR_SIZE];