diff --git a/doc/toxic.conf.5 b/doc/toxic.conf.5 index edf88ac75..b07676bd9 100644 --- a/doc/toxic.conf.5 +++ b/doc/toxic.conf.5 @@ -465,10 +465,17 @@ Toggle the peer list on and off\&. .RS 4 Toggle treating linebreaks as enter key press\&. .RE +.PP +\fBreload_config\fR +.RS 4 +Reload the Toxic config file\&. +.RE .RE .SH "BUGS" .sp -Non\-default colours (gray, brown, orange, and pink) will not work on terminal emulators that don\(cqt support 256\-colors\&. Konsole, qterminal and possibly others are also known to have issues with them\&. If you\(cqre using screen or tmux, try to configure it to use the xterm\-256color TERM environment variable\&. +\-Non\-default colours (gray, brown, orange, and pink) will not work on terminal emulators that don\(cqt support 256\-colors\&. Konsole, qterminal and possibly others are also known to have issues with them\&. If you\(cqre using screen or tmux, try to configure it to use the xterm\-256color TERM environment variable\&. +.sp +\-When reloading the config file during a live session, some UI changes may be buggy and require a full client restart\&. .SH "FILES" .PP ~/\&.config/tox/toxic\&.conf diff --git a/doc/toxic.conf.5.asc b/doc/toxic.conf.5.asc index 7c2a4d618..971cd6c23 100644 --- a/doc/toxic.conf.5.asc +++ b/doc/toxic.conf.5.asc @@ -290,14 +290,20 @@ OPTIONS *toggle_paste_mode*;; Toggle treating linebreaks as enter key press. + *reload_config*;; + Reload the Toxic config file. + BUGS ---- -Non-default colours (gray, brown, orange, and pink) will not work on terminal emulators that +-Non-default colours (gray, brown, orange, and pink) will not work on terminal emulators that don't support 256-colors. Konsole, qterminal and possibly others are also known to have issues with them. If you're using screen or tmux, try to configure it to use the xterm-256color TERM environment variable. +-When reloading the config file during a live session, some UI changes may be buggy and require +a full client restart. + FILES ----- ~/.config/tox/toxic.conf:: diff --git a/misc/toxic.conf.example b/misc/toxic.conf.example index c1913b744..7014f32fb 100644 --- a/misc/toxic.conf.example +++ b/misc/toxic.conf.example @@ -219,4 +219,5 @@ keys = { page_bottom="Ctrl+H"; toggle_peerlist="Ctrl+B"; toggle_paste_mode="Ctrl+T"; + reload_config="Ctrl+R"; }; diff --git a/src/help.c b/src/help.c index f7dc1eac5..dee648a8e 100644 --- a/src/help.c +++ b/src/help.c @@ -347,6 +347,7 @@ static void help_draw_keys(ToxWindow *self) wprintw(win, " Ctrl+B : Toggle groupchat/conference peer list\n"); wprintw(win, " Ctrl+J : Insert new line\n"); wprintw(win, " Ctrl+T : Toggle paste mode\n\n"); + wprintw(win, " Ctrl+R : Reload the Toxic config file\n\n"); wprintw(win, " (Note: Custom keybindings override these defaults.)\n\n"); help_draw_bottom_menu(win); diff --git a/src/input.c b/src/input.c index abe1a7dbf..9e3c7f48d 100644 --- a/src/input.c +++ b/src/input.c @@ -336,7 +336,10 @@ bool input_handle(ToxWindow *self, const Toxic *toxic, wint_t key, int x, int mx /* TODO: this special case is ugly. maybe convert entire function to if/else and make them all customizable keys? */ if (!match) { - if (key == c_config->key_toggle_peerlist) { + if (key == c_config->key_reload_config) { + settings_reload(toxic->c_config, toxic->run_opts); + match = true; + } else if (key == c_config->key_toggle_peerlist) { if (self->type == WINDOW_TYPE_CONFERENCE) { self->show_peerlist ^= 1; redraw_conference_win(self); diff --git a/src/settings.c b/src/settings.c index 1560db2df..a46f0ee60 100644 --- a/src/settings.c +++ b/src/settings.c @@ -177,6 +177,7 @@ static const struct keys_strings { const char *page_bottom; const char *toggle_peerlist; const char *toggle_pastemode; + const char *reload_config; } key_strings = { "keys", "next_tab", @@ -188,6 +189,7 @@ static const struct keys_strings { "page_bottom", "toggle_peerlist", "toggle_paste_mode", + "reload_config", }; /* defines from toxic.h */ @@ -202,6 +204,7 @@ static void key_defaults(Client_Config *settings) settings->key_page_bottom = T_KEY_C_H; settings->key_toggle_peerlist = T_KEY_C_B; settings->key_toggle_pastemode = T_KEY_C_T; + settings->key_reload_config = T_KEY_C_R; } static const struct tox_strings { @@ -848,6 +851,10 @@ int settings_load_main(Client_Config *s, const Run_Options *run_opts) if (config_setting_lookup_string(setting, key_strings.toggle_pastemode, &tmp)) { set_key_binding(&s->key_toggle_pastemode, &tmp); } + + if (config_setting_lookup_string(setting, key_strings.reload_config, &tmp)) { + set_key_binding(&s->key_reload_config, &tmp); + } } #ifdef AUDIO @@ -949,3 +956,33 @@ int settings_load_main(Client_Config *s, const Run_Options *run_opts) config_destroy(cfg); return 0; } + +void settings_reload(Client_Config *c_config, const Run_Options *run_opts) +{ + int ret = settings_load_main(c_config, run_opts); + + if (ret < 0) { + fprintf(stderr, "Failed to reload global settings (error %d)\n", ret); + } + + ret = settings_load_friends(run_opts); + + if (ret < 0) { + fprintf(stderr, "Failed to reload friend settings (error %d)\n", ret); + } + + ret = settings_load_conferences(run_opts); + + if (ret < 0) { + fprintf(stderr, "Failed to reload conference settings (error %d)\n", ret); + } + + ret = settings_load_groups(run_opts); + + if (ret < 0) { + fprintf(stderr, "Failed to reload group settings (error %d)\n", ret); + } + + endwin(); + init_term(c_config, run_opts->default_locale); +} diff --git a/src/settings.h b/src/settings.h index ceeb5633b..1318a7b10 100644 --- a/src/settings.h +++ b/src/settings.h @@ -88,6 +88,7 @@ typedef struct Client_Config { int key_page_bottom; int key_toggle_peerlist; int key_toggle_pastemode; + int key_reload_config; int mplex_away; /* boolean (1 for reaction to terminal attach/detach) */ char mplex_away_note [TOX_MAX_STATUS_MESSAGE_LENGTH]; @@ -209,4 +210,9 @@ int settings_load_groups(const Run_Options *run_opts); */ int settings_load_conferences(const Run_Options *run_opts); +/* + * Reloads config settings. + */ +void settings_reload(Client_Config *c_config, const Run_Options *run_opts); + #endif /* SETTINGS_H */ diff --git a/src/toxic.c b/src/toxic.c index 864c6e4ce..164cea389 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -156,12 +156,16 @@ static void kill_toxic(Toxic *toxic) free(toxic); } +static void cleanup_init_messages(void); + void exit_toxic_success(Toxic *toxic) { if (toxic == NULL) { exit(EXIT_FAILURE); } + cleanup_init_messages(); + store_data(toxic); terminate_notify(); @@ -384,7 +388,7 @@ static void get_custom_toxic_colours(const Client_Config *c_config, short *bar_b } } -static void init_term(const Client_Config *c_config, bool use_default_locale) +void init_term(const Client_Config *c_config, bool use_default_locale) { #if HAVE_WIDECHAR @@ -493,7 +497,7 @@ static void queue_init_message(const char *msg, ...) vsnprintf(frmt_msg, sizeof(frmt_msg), msg, args); va_end(args); - int i = init_messages.num; + const int i = init_messages.num; ++init_messages.num; char **new_msgs = realloc(init_messages.msgs, sizeof(char *) * init_messages.num); @@ -512,7 +516,7 @@ static void queue_init_message(const char *msg, ...) init_messages.msgs = new_msgs; } -/* called after messages have been printed to prompt and are no longer needed */ +/* called on exit */ static void cleanup_init_messages(void) { if (init_messages.num <= 0) { @@ -524,6 +528,8 @@ static void cleanup_init_messages(void) } free(init_messages.msgs); + init_messages.msgs = NULL; + init_messages.num = 0; } static void print_init_messages(ToxWindow *home_window, const Client_Config *c_config) @@ -1851,8 +1857,6 @@ int main(int argc, char **argv) flag_interface_refresh(); pthread_mutex_unlock(&Winthread.lock); - cleanup_init_messages(); - /* set user avatar from config file. if no path is supplied tox_unset_avatar is called */ char avatarstr[PATH_MAX + 11]; snprintf(avatarstr, sizeof(avatarstr), "/avatar %s", c_config->avatar_path); diff --git a/src/toxic.h b/src/toxic.h index d3663c4e9..85818e62e 100644 --- a/src/toxic.h +++ b/src/toxic.h @@ -97,6 +97,8 @@ void exit_toxic_err(const char *errmsg, int errcode) __attribute__((__noreturn__ int store_data(const Toxic *toxic); +void init_term(const Client_Config *c_config, bool use_default_locale); + /* callbacks */ void on_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata); void on_friend_connection_status(Tox *tox, uint32_t friendnumber, Tox_Connection status, void *userdata); diff --git a/src/toxic_constants.h b/src/toxic_constants.h index 16deb8b89..f29179312 100644 --- a/src/toxic_constants.h +++ b/src/toxic_constants.h @@ -62,6 +62,7 @@ #define T_KEY_C_L 0x0C /* ctrl-l */ #define T_KEY_C_W 0x17 /* ctrl-w */ #define T_KEY_C_B 0x02 /* ctrl-b */ +#define T_KEY_C_R 0x12 /* ctrl-r */ #define T_KEY_C_T 0x14 /* ctrl-t */ #define T_KEY_C_LEFT 0x221 /* ctrl-left arrow */ #define T_KEY_C_RIGHT 0x230 /* ctrl-right arrow */