static void cinnamon_tray_manager_style_changed (StWidget *theme_widget, gpointer user_data) { CinnamonTrayManager *manager = user_data; StThemeNode *theme_node; StIconColors *icon_colors; GdkColor foreground, warning, error, success; theme_node = st_widget_get_theme_node (theme_widget); icon_colors = st_theme_node_get_icon_colors (theme_node); foreground.red = icon_colors->foreground.red * 0x101; foreground.green = icon_colors->foreground.green * 0x101; foreground.blue = icon_colors->foreground.blue * 0x101; warning.red = icon_colors->warning.red * 0x101; warning.green = icon_colors->warning.green * 0x101; warning.blue = icon_colors->warning.blue * 0x101; error.red = icon_colors->error.red * 0x101; error.green = icon_colors->error.green * 0x101; error.blue = icon_colors->error.blue * 0x101; success.red = icon_colors->success.red * 0x101; success.green = icon_colors->success.green * 0x101; success.blue = icon_colors->success.blue * 0x101; na_tray_manager_set_colors (manager->priv->na_manager, &foreground, &warning, &error, &success); }
/** * st_texture_cache_load_gicon: * @cache: The texture cache instance * @theme_node: (allow-none): The #StThemeNode to use for colors, or NULL * if the icon must not be recolored * @icon: the #GIcon to load * @size: Size of themed * * This method returns a new #ClutterActor for a given #GIcon. If the * icon isn't loaded already, the texture will be filled * asynchronously. * * Return Value: (transfer none): A new #ClutterActor for the icon, or %NULL if not found */ ClutterActor * st_texture_cache_load_gicon (StTextureCache *cache, StThemeNode *theme_node, GIcon *icon, gint size) { return load_gicon_with_colors (cache, icon, size, theme_node ? st_theme_node_get_icon_colors (theme_node) : NULL); }
/** * st_texture_cache_load_icon_name: * @cache: The texture cache instance * @theme_node: (allow-none): a #StThemeNode * @name: Name of a themed icon * @icon_type: the type of icon to load * @size: Size of themed icon * * Load a themed icon into a texture. See the #StIconType documentation * for an explanation of how @icon_type affects the returned icon. The * colors used for symbolic icons are derived from @theme_node. * * Return Value: (transfer none): A new #ClutterTexture for the icon */ ClutterActor * st_texture_cache_load_icon_name (StTextureCache *cache, StThemeNode *theme_node, const char *name, StIconType icon_type, gint size) { ClutterActor *texture; GIcon *themed; char **names; g_return_val_if_fail (!(icon_type == ST_ICON_SYMBOLIC && theme_node == NULL), NULL); switch (icon_type) { case ST_ICON_SYMBOLIC: names = symbolic_names_for_icon (name); themed = g_themed_icon_new_from_names (names, -1); g_strfreev (names); texture = load_gicon_with_colors (cache, themed, size, st_theme_node_get_icon_colors (theme_node)); g_object_unref (themed); if (texture == NULL) { /* We don't have an equivalent of image-missing * for the symbolic icon theme, so just create a blank * actor. */ texture = (ClutterActor *) create_default_texture (); clutter_actor_set_size (texture, size, size); } return texture; break; case ST_ICON_FULLCOLOR: themed = g_themed_icon_new_with_default_fallbacks (name); texture = load_gicon_with_colors (cache, themed, size, NULL); g_object_unref (themed); if (texture == NULL) { themed = g_themed_icon_new ("image-missing"); texture = load_gicon_with_colors (cache, themed, size, NULL); g_object_unref (themed); } return texture; break; default: g_assert_not_reached (); } }
/** * st_texture_cache_load_gicon: * @cache: The texture cache instance * @theme_node: (nullable): The #StThemeNode to use for colors, or NULL * if the icon must not be recolored * @icon: the #GIcon to load * @size: Size of themed * @scale: Scale factor of display * * This method returns a new #ClutterActor for a given #GIcon. If the * icon isn't loaded already, the texture will be filled * asynchronously. * * Return Value: (transfer none): A new #ClutterActor for the icon, or %NULL if not found */ ClutterActor * st_texture_cache_load_gicon (StTextureCache *cache, StThemeNode *theme_node, GIcon *icon, gint size, gint scale) { AsyncTextureLoadData *request; ClutterActor *texture; char *gicon_string; char *key; GtkIconTheme *theme; GtkIconInfo *info; StTextureCachePolicy policy; StIconColors *colors = NULL; StIconStyle icon_style = ST_ICON_STYLE_REQUESTED; GtkIconLookupFlags lookup_flags; if (theme_node) { colors = st_theme_node_get_icon_colors (theme_node); icon_style = st_theme_node_get_icon_style (theme_node); } /* Do theme lookups in the main thread to avoid thread-unsafety */ theme = cache->priv->icon_theme; lookup_flags = GTK_ICON_LOOKUP_USE_BUILTIN; if (icon_style == ST_ICON_STYLE_REGULAR) lookup_flags |= GTK_ICON_LOOKUP_FORCE_REGULAR; else if (icon_style == ST_ICON_STYLE_SYMBOLIC) lookup_flags |= GTK_ICON_LOOKUP_FORCE_SYMBOLIC; if (clutter_get_default_text_direction () == CLUTTER_TEXT_DIRECTION_RTL) lookup_flags |= GTK_ICON_LOOKUP_DIR_RTL; else lookup_flags |= GTK_ICON_LOOKUP_DIR_LTR; info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, size, scale, lookup_flags); if (info == NULL) return NULL; gicon_string = g_icon_to_string (icon); /* A return value of NULL indicates that the icon can not be serialized, * so don't have a unique identifier for it as a cache key, and thus can't * be cached. If it is cachable, we hardcode a policy of FOREVER here for * now; we should actually blow this away on icon theme changes probably */ policy = gicon_string != NULL ? ST_TEXTURE_CACHE_POLICY_FOREVER : ST_TEXTURE_CACHE_POLICY_NONE; if (colors) { /* This raises some doubts about the practice of using string keys */ key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d,style=%d,colors=%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x", gicon_string, size, scale, icon_style, colors->foreground.red, colors->foreground.blue, colors->foreground.green, colors->foreground.alpha, colors->warning.red, colors->warning.blue, colors->warning.green, colors->warning.alpha, colors->error.red, colors->error.blue, colors->error.green, colors->error.alpha, colors->success.red, colors->success.blue, colors->success.green, colors->success.alpha); } else { key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d,style=%d", gicon_string, size, scale, icon_style); } g_free (gicon_string); texture = (ClutterActor *) create_default_texture (); clutter_actor_set_size (texture, size * scale, size * scale); if (ensure_request (cache, key, policy, &request, texture)) { /* If there's an outstanding request, we've just added ourselves to it */ g_object_unref (info); g_free (key); } else { /* Else, make a new request */ request->cache = cache; /* Transfer ownership of key */ request->key = key; request->policy = policy; request->colors = colors ? st_icon_colors_ref (colors) : NULL; request->icon_info = info; request->width = request->height = size; request->scale = scale; load_texture_async (cache, request); } return CLUTTER_ACTOR (texture); }
/** * st_texture_cache_load_icon_name: * @cache: The texture cache instance * @theme_node: (allow-none): a #StThemeNode * @name: Name of a themed icon * @icon_type: the type of icon to load * @size: Size of themed * * Load a themed icon into a texture. See the #StIconType documentation * for an explanation of how @icon_type affects the returned icon. The * colors used for symbolic icons are derived from @theme_node. * * Return Value: (transfer none): A new #ClutterTexture for the icon */ ClutterActor * st_texture_cache_load_icon_name (StTextureCache *cache, StThemeNode *theme_node, const char *name, StIconType icon_type, gint size) { ClutterActor *texture; GIcon *themed; char *symbolic_name; g_return_val_if_fail (!(icon_type == ST_ICON_SYMBOLIC && theme_node == NULL), NULL); switch (icon_type) { case ST_ICON_APPLICATION: themed = g_themed_icon_new (name); texture = load_gicon_with_colors (cache, themed, size, cache->priv->scale, NULL); g_object_unref (themed); if (texture == NULL) { themed = g_themed_icon_new ("application-x-executable"); texture = load_gicon_with_colors (cache, themed, size, cache->priv->scale, NULL); g_object_unref (themed); } return CLUTTER_ACTOR (texture); break; case ST_ICON_DOCUMENT: themed = g_themed_icon_new (name); texture = load_gicon_with_colors (cache, themed, size, cache->priv->scale, NULL); g_object_unref (themed); if (texture == NULL) { themed = g_themed_icon_new ("x-office-document"); texture = load_gicon_with_colors (cache, themed, size, cache->priv->scale, NULL); g_object_unref (themed); } return CLUTTER_ACTOR (texture); break; case ST_ICON_SYMBOLIC: symbolic_name = symbolic_name_for_icon (name); themed = g_themed_icon_new (symbolic_name); free (symbolic_name); texture = load_gicon_with_colors (cache, themed, size, cache->priv->scale, st_theme_node_get_icon_colors (theme_node)); g_object_unref (themed); return CLUTTER_ACTOR (texture); break; case ST_ICON_FULLCOLOR: themed = g_themed_icon_new (name); texture = load_gicon_with_colors (cache, themed, size, cache->priv->scale, NULL); g_object_unref (themed); if (texture == NULL) { themed = g_themed_icon_new ("image-missing"); texture = load_gicon_with_colors (cache, themed, size, cache->priv->scale, NULL); g_object_unref (themed); } return CLUTTER_ACTOR (texture); break; default: g_assert_not_reached (); } }