about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-12-12 14:23:07 +0100
committerMichael Vetter <jubalh@iodoru.org>2019-12-12 14:23:07 +0100
commit3258211f27cd71c9b0d1ec256e9b47052aa871c0 (patch)
tree051fdea9c26d32db678ed54e6226d2d0d1b4ce88
parent27501942798fea8b95e7983166ca7c25fd1a638b (diff)
downloadprofani-tty-3258211f27cd71c9b0d1ec256e9b47052aa871c0.tar.gz
Improve color blindness handling
Rename some things and use a swtich instead of if.
-rw-r--r--src/config/color.c20
-rw-r--r--src/config/color.h4
-rw-r--r--src/config/theme.c4
3 files changed, 16 insertions, 12 deletions
diff --git a/src/config/color.c b/src/config/color.c
index 6af30bf8..34e01247 100644
--- a/src/config/color.c
+++ b/src/config/color.c
@@ -3,6 +3,7 @@
  * vim: expandtab:ts=4:sts=4:sw=4
  *
  * Copyright (C) 2019 Aurelien Aptel <aurelien.aptel@gmail.com>
+ * Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
  *
  * This file is part of Profanity.
  *
@@ -401,14 +402,17 @@ static int color_hash(const char *str, color_profile profile)
 
     double h = ((buf[1] << 8) | buf[0]) / 65536. * 360.;
 
-    // red/green blindness correction
-    if (profile == COLOR_PROFILE_REDGREEN) {
-        h = fmod(fmod(h + 90., 180) - 90., 360.);
-    }
-
-    // blue blindness correction
-    if (profile == COLOR_PROFILE_BLUE) {
-        h = fmod(h, 180.);
+    switch(profile)
+    {
+        case COLOR_PROFILE_REDGREEN_BLINDNESS:
+            // red/green blindness correction
+            h = fmod(fmod(h + 90., 180) - 90., 360.);
+            break;
+        case COLOR_PROFILE_BLUE_BLINDNESS:
+            // blue blindness correction
+            h = fmod(h, 180.);
+        default:
+            break;
     }
 
     rc = find_closest_col((int)h, 100, 50);
diff --git a/src/config/color.h b/src/config/color.h
index 202e87c6..304e862e 100644
--- a/src/config/color.h
+++ b/src/config/color.h
@@ -43,8 +43,8 @@
 
 typedef enum {
     COLOR_PROFILE_DEFAULT,
-    COLOR_PROFILE_REDGREEN,
-    COLOR_PROFILE_BLUE,
+    COLOR_PROFILE_REDGREEN_BLINDNESS,
+    COLOR_PROFILE_BLUE_BLINDNESS,
 } color_profile;
 
 struct color_def {
diff --git a/src/config/theme.c b/src/config/theme.c
index 8d2160dd..48776090 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -677,9 +677,9 @@ theme_hash_attrs(const char *str)
 
     char *color_pref = prefs_get_string(PREF_COLOR_NICK);
     if (strcmp(color_pref, "redgreen") == 0) {
-        profile = COLOR_PROFILE_REDGREEN;
+        profile = COLOR_PROFILE_REDGREEN_BLINDNESS;
     } else if (strcmp(color_pref, "blue") == 0) {
-        profile = COLOR_PROFILE_BLUE;
+        profile = COLOR_PROFILE_BLUE_BLINDNESS;
     }
     prefs_free_string(color_pref);