From 1a00368888118ed8d5aa620b164cc466fa005045 Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Mon, 25 Nov 2019 20:59:56 +0100 Subject: [PATCH] core: add option weechat.look.nick_color_hash_salt to allow for reshuffling of colors (issue #635) --- src/core/wee-config.c | 8 ++++++++ src/core/wee-config.h | 1 + src/gui/gui-nick.c | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/core/wee-config.c b/src/core/wee-config.c index e1cecc7ee..11d399fd2 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -153,6 +153,7 @@ struct t_config_option *config_look_mouse; struct t_config_option *config_look_mouse_timer_delay; struct t_config_option *config_look_nick_color_force; struct t_config_option *config_look_nick_color_hash; +struct t_config_option *config_look_nick_color_hash_salt; struct t_config_option *config_look_nick_color_stop_chars; struct t_config_option *config_look_nick_prefix; struct t_config_option *config_look_nick_suffix; @@ -3246,6 +3247,13 @@ config_weechat_init_options () "using 32-bit instead of 64-bit integer"), "djb2|sum|djb2_32|sum_32", 0, 0, "djb2", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + config_look_nick_color_hash_salt = config_file_new_option ( + weechat_config_file, ptr_section, + "nick_color_hash_salt", "string", + N_("salt to be used with the hash algorithm used for nick colors; " + "modifying this shuffles nick colors"), + NULL, 0, 0, "", NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); config_look_nick_color_stop_chars = config_file_new_option ( weechat_config_file, ptr_section, "nick_color_stop_chars", "string", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index 8cf1a61bf..40c24515b 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -206,6 +206,7 @@ extern struct t_config_option *config_look_mouse; extern struct t_config_option *config_look_mouse_timer_delay; extern struct t_config_option *config_look_nick_color_force; extern struct t_config_option *config_look_nick_color_hash; +extern struct t_config_option *config_look_nick_color_hash_salt; extern struct t_config_option *config_look_nick_color_stop_chars; extern struct t_config_option *config_look_nick_prefix; extern struct t_config_option *config_look_nick_suffix; diff --git a/src/gui/gui-nick.c b/src/gui/gui-nick.c index 9a575cb2a..c1ad7622a 100644 --- a/src/gui/gui-nick.c +++ b/src/gui/gui-nick.c @@ -48,6 +48,8 @@ gui_nick_hash_color (const char *nickname) { uint64_t color; uint32_t color_32; + int length; + char *str; const char *ptr_nick; if (!nickname || !nickname[0]) @@ -59,7 +61,24 @@ gui_nick_hash_color (const char *nickname) if (config_num_nick_colors == 0) return 0; + str = NULL; ptr_nick = nickname; + + if (CONFIG_STRING(config_look_nick_color_hash_salt) + && CONFIG_STRING(config_look_nick_color_hash_salt)[0]) + { + length = strlen (CONFIG_STRING(config_look_nick_color_hash_salt)) + + strlen (nickname) + 1; + str = malloc (length); + if (str) + { + snprintf (str, length, "%s%s", + CONFIG_STRING(config_look_nick_color_hash_salt), + nickname); + ptr_nick = str; + } + } + color = 0; switch (CONFIG_INTEGER(config_look_nick_color_hash)) @@ -105,6 +124,9 @@ gui_nick_hash_color (const char *nickname) break; } + if (str) + free (str); + return (color % config_num_nick_colors); }