Implement Color Vision Deficiencies setting
Implement settings for redgreen and blue blindness. Regards https://github.com/profanity-im/profanity/issues/1191
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <glib.h>
|
||||
|
||||
#ifdef HAVE_NCURSESW_NCURSES_H
|
||||
@@ -380,7 +381,7 @@ static int find_col(const char *col_name, int n)
|
||||
return COL_ERR;
|
||||
}
|
||||
|
||||
static int color_hash(const char *str)
|
||||
static int color_hash(const char *str, color_profile profile)
|
||||
{
|
||||
GChecksum *cs = NULL;
|
||||
guint8 buf[256] = {0};
|
||||
@@ -401,10 +402,14 @@ static int color_hash(const char *str)
|
||||
double h = ((buf[1] << 8) | buf[0]) / 65536. * 360.;
|
||||
|
||||
// red/green blindness correction
|
||||
// h = fmod(fmod(h + 90., 180) - 90., 360.);
|
||||
if (profile == COLOR_PROFILE_REDGREEN) {
|
||||
h = fmod(fmod(h + 90., 180) - 90., 360.);
|
||||
}
|
||||
|
||||
// blue blindness correction
|
||||
// h = fmod(h, 180.);
|
||||
if (profile == COLOR_PROFILE_BLUE) {
|
||||
h = fmod(h, 180.);
|
||||
}
|
||||
|
||||
rc = find_closest_col((int)h, 100, 50);
|
||||
|
||||
@@ -487,9 +492,9 @@ static int _color_pair_cache_get(int fg, int bg)
|
||||
* hash a string into a color that will be used as fg
|
||||
* use default color as bg
|
||||
*/
|
||||
int color_pair_cache_hash_str(const char *str)
|
||||
int color_pair_cache_hash_str(const char *str, color_profile profile)
|
||||
{
|
||||
int fg = color_hash(str);
|
||||
int fg = color_hash(str, profile);
|
||||
int bg = -1;
|
||||
|
||||
return _color_pair_cache_get(fg, bg);
|
||||
|
||||
@@ -41,6 +41,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
COLOR_PROFILE_DEFAULT,
|
||||
COLOR_PROFILE_REDGREEN,
|
||||
COLOR_PROFILE_BLUE,
|
||||
} color_profile;
|
||||
|
||||
struct color_def {
|
||||
uint16_t h; uint8_t s, l;
|
||||
const char *name;
|
||||
@@ -48,7 +54,7 @@ struct color_def {
|
||||
extern const struct color_def color_names[];
|
||||
|
||||
/* hash string to color pair */
|
||||
int color_pair_cache_hash_str(const char *str);
|
||||
int color_pair_cache_hash_str(const char *str, color_profile profile);
|
||||
/* parse fg_bg string to color pair */
|
||||
int color_pair_cache_get(const char *pair_name);
|
||||
/* clear cache */
|
||||
|
||||
@@ -673,7 +673,17 @@ theme_free_string(char *str)
|
||||
int
|
||||
theme_hash_attrs(const char *str)
|
||||
{
|
||||
return COLOR_PAIR(color_pair_cache_hash_str(str));
|
||||
color_profile profile = COLOR_PROFILE_DEFAULT;
|
||||
|
||||
char *color_pref = prefs_get_string(PREF_COLOR_NICK);
|
||||
if (strcmp(color_pref, "redgreen") == 0) {
|
||||
profile = COLOR_PROFILE_REDGREEN;
|
||||
} else if (strcmp(color_pref, "blue") == 0) {
|
||||
profile = COLOR_PROFILE_BLUE;
|
||||
}
|
||||
prefs_free_string(color_pref);
|
||||
|
||||
return COLOR_PAIR(color_pair_cache_hash_str(str, profile));
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user