[gnome-shell] st/icon: Add API to set the fallback GIcon
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] st/icon: Add API to set the fallback GIcon
- Date: Mon, 13 Jan 2020 13:55:29 +0000 (UTC)
commit e784afe9ac0722b0a4e88eb4ba127dfb35694e4b
Author: Jonas Dreßler <verdre v0yd nl>
Date: Thu Nov 21 17:03:22 2019 +0700
st/icon: Add API to set the fallback GIcon
Let's support the fallback icon a bit better and allow setting its GIcon
just as we do for the normal icon.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/888
src/st/st-icon.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/st/st-icon.h | 4 ++++
2 files changed, 62 insertions(+)
---
diff --git a/src/st/st-icon.c b/src/st/st-icon.c
index 6cc7e4dbad..13f7dd54ff 100644
--- a/src/st/st-icon.c
+++ b/src/st/st-icon.c
@@ -37,6 +37,8 @@ enum
PROP_0,
PROP_GICON,
+ PROP_FALLBACK_GICON,
+
PROP_ICON_NAME,
PROP_ICON_SIZE,
PROP_FALLBACK_ICON_NAME,
@@ -86,6 +88,10 @@ st_icon_set_property (GObject *gobject,
st_icon_set_gicon (icon, g_value_get_object (value));
break;
+ case PROP_FALLBACK_GICON:
+ st_icon_set_fallback_gicon (icon, g_value_get_object (value));
+ break;
+
case PROP_ICON_NAME:
st_icon_set_icon_name (icon, g_value_get_string (value));
break;
@@ -118,6 +124,10 @@ st_icon_get_property (GObject *gobject,
g_value_set_object (value, st_icon_get_gicon (icon));
break;
+ case PROP_FALLBACK_GICON:
+ g_value_set_object (value, st_icon_get_fallback_gicon (icon));
+ break;
+
case PROP_ICON_NAME:
g_value_set_string (value, st_icon_get_icon_name (icon));
break;
@@ -246,6 +256,13 @@ st_icon_class_init (StIconClass *klass)
G_TYPE_ICON,
ST_PARAM_READWRITE);
+ props[PROP_FALLBACK_GICON] =
+ g_param_spec_object ("fallback-gicon",
+ "Fallback GIcon",
+ "The fallback GIcon shown if the normal icon fails to load",
+ G_TYPE_ICON,
+ ST_PARAM_READWRITE);
+
props[PROP_ICON_NAME] =
g_param_spec_string ("icon-name",
"Icon name",
@@ -601,6 +618,47 @@ st_icon_set_gicon (StIcon *icon, GIcon *gicon)
st_icon_update (icon);
}
+/**
+ * st_icon_get_fallback_gicon:
+ * @icon: a #StIcon
+ *
+ * Gets the currently set fallback #GIcon.
+ *
+ * Returns: (transfer none): The fallback #GIcon, if set, otherwise %NULL
+ */
+GIcon *
+st_icon_get_fallback_gicon (StIcon *icon)
+{
+ g_return_val_if_fail (ST_IS_ICON (icon), NULL);
+
+ return icon->priv->fallback_gicon;
+}
+
+/**
+ * st_icon_set_fallback_gicon:
+ * @icon: a #StIcon
+ * @fallback_gicon: (nullable): the fallback #GIcon
+ *
+ * Sets a fallback #GIcon to show if the normal icon fails to load.
+ * If @fallback_gicon is %NULL or fails to load, the icon is unset and no
+ * texture will be visible for the fallback icon.
+ */
+void
+st_icon_set_fallback_gicon (StIcon *icon,
+ GIcon *fallback_gicon)
+{
+ g_return_if_fail (ST_IS_ICON (icon));
+ g_return_if_fail (fallback_gicon == NULL || G_IS_ICON (fallback_gicon));
+
+ if (g_icon_equal (icon->priv->fallback_gicon, fallback_gicon))
+ return;
+
+ g_set_object (&icon->priv->fallback_gicon, fallback_gicon);
+ g_object_notify_by_pspec (G_OBJECT (icon), props[PROP_FALLBACK_GICON]);
+
+ st_icon_update (icon);
+}
+
/**
* st_icon_get_icon_size:
* @icon: an #StIcon
diff --git a/src/st/st-icon.h b/src/st/st-icon.h
index f510520dc2..8714ef931c 100644
--- a/src/st/st-icon.h
+++ b/src/st/st-icon.h
@@ -60,6 +60,10 @@ GIcon *st_icon_get_gicon (StIcon *icon);
void st_icon_set_gicon (StIcon *icon,
GIcon *gicon);
+GIcon *st_icon_get_fallback_gicon (StIcon *icon);
+void st_icon_set_fallback_gicon (StIcon *icon,
+ GIcon *fallback_gicon);
+
const gchar *st_icon_get_icon_name (StIcon *icon);
void st_icon_set_icon_name (StIcon *icon,
const gchar *icon_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]