From 476dec46b6f10407762d0c141397b35fd7f80f67 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 29 Jul 2014 20:10:28 -0400 Subject: [PATCH] add settings to toggle typing notifications for self and others --- doc/toxic.conf.5 | 22 ++++++++++++++++++++++ misc/toxic.conf.example | 16 +++++++++++----- src/chat.c | 19 +++++++++++++------ src/settings.c | 12 ++++++++++-- src/settings.h | 8 +++++++- src/windows.c | 4 ++++ 6 files changed, 67 insertions(+), 14 deletions(-) diff --git a/doc/toxic.conf.5 b/doc/toxic.conf.5 index c5d00a7..9956008 100644 --- a/doc/toxic.conf.5 +++ b/doc/toxic.conf.5 @@ -66,6 +66,20 @@ Select between 24 and 12 hour time. Values: 24, 12 .RE .PP +.B show_typing_other +.RS +Show you when others are typing in a 1-on-1 chat +.br +Values: 'true' to enable, 'false' to disable +.RE +.PP +.B show_typing_self +.RS +Show others when you're typing in a 1-on-1 chat +.br +Values: 'true' to enable, 'false' to disable +.RE +.PP .B history_size .RS Maximum lines for chat window history. @@ -294,6 +308,14 @@ ui = { // 24 or 12 hour time .br time_format=24; +.br + // true to show you when others are typing a message in 1-on-1 chats +.br + show_typing_other=true; +.br + // true to show others when you're typing a message in 1-on-1 chats +.br + show_typing_self=true; .br // maximum lines for chat window history .br diff --git a/misc/toxic.conf.example b/misc/toxic.conf.example index 80ad9d1..bc321f0 100644 --- a/misc/toxic.conf.example +++ b/misc/toxic.conf.example @@ -3,20 +3,26 @@ ui = { // true to enable timestamps, false to disable - timestamps:true; + timestamps=true; // true to enable terminal alerts on messages, false to disable - alerts:true; + alerts=true; // true to use native terminal colours, false to use toxic default colour theme - native_colors:false; + native_colors=false; // true to enable autologging, false to disable - autolog:false; - + autolog=false; + // 24 or 12 hour time time_format=24; + // true to show you when others are typing a message in 1-on-1 chats + show_typing_other=true; + + // true to show others when you're typing a message in 1-on-1 chats + show_typing_self=true; + // maximum lines for chat window history history_size=700; }; diff --git a/src/chat.c b/src/chat.c index 62e497f..33ef157 100644 --- a/src/chat.c +++ b/src/chat.c @@ -103,8 +103,11 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = { #endif /* _AUDIO */ }; -static void set_typingstatus(ToxWindow *self, Tox *m, uint8_t is_typing) +static void set_self_typingstatus(ToxWindow *self, Tox *m, uint8_t is_typing) { + if (user_settings_->show_typing_self == SHOW_TYPING_OFF) + return; + ChatContext *ctx = self->chatwin; tox_set_user_is_typing(m, self->num, is_typing); @@ -173,14 +176,18 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_ StatusBar *statusbar = self->stb; - if (status == 1) { /* Friend shows online */ + if (status == 1) { /* Friend goes online */ statusbar->is_online = true; - friends[num].is_typing = tox_get_is_typing(m, num); + friends[num].is_typing = user_settings_->show_typing_other == SHOW_TYPING_ON + ? tox_get_is_typing(m, num) : 0; notify(self, user_log_in, NT_NOFOCUS); } else { /* Friend goes offline */ statusbar->is_online = false; friends[num].is_typing = 0; notify(self, user_log_out, NT_NOFOCUS); + + if (self->chatwin->self_is_typing) + set_self_typingstatus(self, m, 0); } } @@ -743,8 +750,8 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) if (ltr) { /* char is printable */ input_new_char(self, key, x, y, x2, y2); - if (ctx->line[0] != '/') - set_typingstatus(self, m, 1); + if (ctx->line[0] != '/' && !ctx->self_is_typing && statusbar->is_online) + set_self_typingstatus(self, m, 1); return; } @@ -815,7 +822,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) } if (ctx->len <= 0 && ctx->self_is_typing) - set_typingstatus(self, m, 0); + set_self_typingstatus(self, m, 0); } static void chat_onDraw(ToxWindow *self, Tox *m) diff --git a/src/settings.c b/src/settings.c index 6f89fe3..0a6724e 100644 --- a/src/settings.c +++ b/src/settings.c @@ -49,6 +49,8 @@ const struct _ui_strings { const char* autolog; const char* time_format; const char* history_size; + const char* show_typing_self; + const char* show_typing_other; } ui_strings = { "ui", "timestamps", @@ -56,7 +58,9 @@ const struct _ui_strings { "native_colors", "autolog", "time_format", - "history_size" + "history_size", + "show_typing_self", + "show_typing_other", }; static void ui_defaults(struct user_settings* settings) @@ -67,6 +71,8 @@ static void ui_defaults(struct user_settings* settings) settings->alerts = ALERTS_ENABLED; settings->colour_theme = DFLT_COLS; settings->history_size = 700; + settings->show_typing_self = SHOW_TYPING_ON; + settings->show_typing_other = SHOW_TYPING_ON; } const struct _keys_strings { @@ -233,8 +239,9 @@ int settings_load(struct user_settings *s, const char *patharg) config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts); 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); + config_setting_lookup_bool(setting, ui_strings.show_typing_self, &s->show_typing_self); + config_setting_lookup_bool(setting, ui_strings.show_typing_other, &s->show_typing_other); config_setting_lookup_int(setting, ui_strings.time_format, &s->time); s->time = s->time == TIME_24 || s->time == TIME_12 ? s->time : TIME_24; /* Check defaults */ } @@ -244,6 +251,7 @@ int settings_load(struct user_settings *s, const char *patharg) strcpy(s->download_path, str); } } + /* keys */ if((setting = config_lookup(cfg, key_strings.self)) != NULL) { const char* tmp = NULL; diff --git a/src/settings.h b/src/settings.h index 79c1df1..13e3092 100644 --- a/src/settings.h +++ b/src/settings.h @@ -31,6 +31,9 @@ struct user_settings { int timestamps; /* boolean */ int colour_theme; /* boolean (0 for default toxic colours) */ int history_size; /* int between MIN_HISTORY and MAX_HISTORY */ + int show_typing_self; /* boolean */ + int show_typing_other; /* boolean */ + char download_path[MAX_STR_SIZE]; int key_next_tab; /* character code */ @@ -62,8 +65,11 @@ enum { ALERTS_DISABLED = 0, ALERTS_ENABLED = 1, - NATIVE_COLS = 1, DFLT_COLS = 0, + NATIVE_COLS = 1, + + SHOW_TYPING_OFF = 0, + SHOW_TYPING_ON = 1, DFLT_HST_SIZE = 700, } settings_values; diff --git a/src/windows.c b/src/windows.c index f073df8..295d5c4 100644 --- a/src/windows.c +++ b/src/windows.c @@ -43,6 +43,7 @@ extern ToxWindow *prompt; extern struct user_settings *user_settings_; static int num_active_windows; + /* CALLBACKS START */ void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) { @@ -66,6 +67,9 @@ void on_connectionchange(Tox *m, int32_t friendnumber, uint8_t status, void *use void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata) { + if (user_settings_->show_typing_other == SHOW_TYPING_OFF) + return; + int i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) {