[gnome-software/1610-not-possible-to-use-neutral-colour-banner-backgrounds] gs-feature-tile: Prefer colors provided by the user



commit 8932606d409f3970d1ae8de3ada76cf718e34c46
Author: Milan Crha <mcrha redhat com>
Date:   Thu Mar 3 13:40:10 2022 +0100

    gs-feature-tile: Prefer colors provided by the user
    
    When the user provides two or more key colors for an app, prefer
    those colors unmodified. Otherwise modify the calculated colors
    to match the current theme.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1610

 src/gs-feature-tile.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-feature-tile.c b/src/gs-feature-tile.c
index f3b51b781..22a4f218b 100644
--- a/src/gs-feature-tile.c
+++ b/src/gs-feature-tile.c
@@ -470,11 +470,22 @@ gs_feature_tile_refresh (GsAppTile *self)
 
                                chosen_hsbc_modified = *chosen_hsbc;
 
-                               chosen_hsbc_modified.saturation = CLAMP (chosen_hsbc->saturation, 
min_valid_saturation, max_valid_saturation);
-
-                               if (chosen_hsbc->contrast >= -min_abs_contrast &&
-                                   chosen_hsbc->contrast <= min_abs_contrast)
-                                       chosen_hsbc_modified.brightness = wcag_contrast_find_brightness 
(&fg_hsbc, &chosen_hsbc_modified, min_abs_contrast);
+                               /* Prefer colors provided by the user, if there can be chosen better one for 
the light/dark theme. */
+                               if (gs_app_get_user_key_colors (app) && colors->len > 1) {
+                                       for (guint i = 1; i < colors->len; i++) {
+                                               const GsHSBC *hsbc = &g_array_index (colors, GsHSBC, i);
+                                               if (ABS (fg_hsbc.brightness - chosen_hsbc->brightness) < ABS 
(fg_hsbc.brightness - hsbc->brightness)) {
+                                                       chosen_hsbc = hsbc;
+                                                       chosen_hsbc_modified = *chosen_hsbc;
+                                               }
+                                       }
+                               } else {
+                                       chosen_hsbc_modified.saturation = CLAMP (chosen_hsbc->saturation, 
min_valid_saturation, max_valid_saturation);
+
+                                       if (chosen_hsbc->contrast >= -min_abs_contrast &&
+                                           chosen_hsbc->contrast <= min_abs_contrast)
+                                               chosen_hsbc_modified.brightness = 
wcag_contrast_find_brightness (&fg_hsbc, &chosen_hsbc_modified, min_abs_contrast);
+                               }
 
                                gtk_hsv_to_rgb (chosen_hsbc_modified.hue,
                                                chosen_hsbc_modified.saturation,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]