[gnome-control-center/wip/hadess/handle-logo-dark] info-overview: Make sure -dark non-text logo variant is handled




commit 43b40b3b4a18a37cb3741179bf0b627f535731b4
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Aug 23 17:10:41 2021 +0200

    info-overview: Make sure -dark non-text logo variant is handled
    
    gtk_image_set_from_icon_name() would fallback from $LOGO-text-dark to
    $LOGO-text to $LOGO, leaving out $LOGO-dark which might be available.
    
    Make sure it's in the list of possibilities by using
    g_themed_icon_new_from_names() and listing it explicitly as a possible
    icon name instead.
    
    Fixes: a3b8964a1936274dc4021455648d51edb11b520d
    Closes: #1415

 panels/info-overview/cc-info-overview-panel.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/panels/info-overview/cc-info-overview-panel.c b/panels/info-overview/cc-info-overview-panel.c
index 9ee9d2910..6e832eb35 100644
--- a/panels/info-overview/cc-info-overview-panel.c
+++ b/panels/info-overview/cc-info-overview-panel.c
@@ -880,8 +880,8 @@ cc_info_panel_row_activated_cb (CcInfoOverviewPanel *self,
     open_software_update (self);
 }
 
-static const char *
-get_asset_suffix (CcInfoOverviewPanel *panel)
+static gboolean
+use_dark_theme (CcInfoOverviewPanel *panel)
 {
   GdkScreen *screen;
   GtkSettings *settings;
@@ -889,27 +889,37 @@ get_asset_suffix (CcInfoOverviewPanel *panel)
 
   theme_name = g_strdup (g_getenv ("GTK_THEME"));
   if (theme_name != NULL)
-    return g_str_has_suffix (theme_name, "dark") ? "-dark" : "";
+    return g_str_has_suffix (theme_name, "dark") ? TRUE : FALSE;
 
   screen = gtk_widget_get_screen (GTK_WIDGET (panel));
   settings = gtk_settings_get_for_screen (screen);
 
   g_object_get (settings, "gtk-theme-name", &theme_name, NULL);
-  return (theme_name != NULL && g_str_has_suffix (theme_name, "dark")) ? "-dark" : "";
+  return (theme_name != NULL && g_str_has_suffix (theme_name, "dark")) ? TRUE : FALSE;
 }
 
 static void
 setup_os_logo (CcInfoOverviewPanel *panel)
 {
   g_autofree char *logo_name = g_get_os_info ("LOGO");
-  g_autofree char *logo_name_with_variant = NULL;
+  g_autoptr(GPtrArray) array = NULL;
+  g_autoptr(GIcon) icon = NULL;
+  gboolean dark;
 
+  dark = use_dark_theme (panel);
   if (logo_name == NULL)
     logo_name = g_strdup ("gnome-logo");
 
-  logo_name_with_variant = g_strdup_printf ("%s-text%s", logo_name, get_asset_suffix (panel));
-  gtk_image_set_from_icon_name (panel->os_logo, logo_name_with_variant, GTK_ICON_SIZE_INVALID);
-  gtk_image_set_pixel_size (panel->os_logo, -1);
+  array = g_ptr_array_new_with_free_func (g_free);
+  if (dark)
+    g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-text-dark", logo_name));
+  g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-text", logo_name));
+  if (dark)
+    g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-dark", logo_name));
+  g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s", logo_name));
+
+  icon = g_themed_icon_new_from_names ((char **) array->pdata, array->len);
+  gtk_image_set_from_gicon (panel->os_logo, icon, GTK_ICON_SIZE_INVALID);
 }
 
 static void


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