[gnome-shell] Add symbolic icons to TextureCache's load_icon_name()
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] Add symbolic icons to TextureCache's load_icon_name()
- Date: Fri, 24 Sep 2010 14:57:50 +0000 (UTC)
commit a6e4bab9901d5841bd106dd0f406d3dead29b85c
Author: Dan Winship <danw gnome org>
Date: Thu Sep 16 11:04:51 2010 -0400
Add symbolic icons to TextureCache's load_icon_name()
Icons can be loaded as St.Icon.SYMBOLIC, FULLCOLOR, APPLICATION or
DOCUMENT. The first will look for a symbolic equivalent, the second
looks for a full-color version (and does fallback, eg, from
"drive-harddisk-usb" to "drive-harddisk"). APPLICATION and DOCUMENT do
full-color icons without fallback (as specified by the icon spec).
And update various callers to use the right flags.
Based on a patch from Matt Novenstern.
https://bugzilla.gnome.org/show_bug.cgi?id=621311
js/ui/lookingGlass.js | 5 ++-
js/ui/messageTray.js | 2 +-
js/ui/notificationDaemon.js | 4 +-
js/ui/panelMenu.js | 2 +-
js/ui/placeDisplay.js | 4 +-
js/ui/popupMenu.js | 2 +-
js/ui/statusMenu.js | 8 ++--
js/ui/telepathyClient.js | 2 +-
src/st/st-texture-cache.c | 72 ++++++++++++++++++++++++++++++++++++++-----
src/st/st-texture-cache.h | 8 +++++
10 files changed, 87 insertions(+), 22 deletions(-)
---
diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js
index 19b8f19..1734299 100644
--- a/js/ui/lookingGlass.js
+++ b/js/ui/lookingGlass.js
@@ -678,8 +678,9 @@ LookingGlass.prototype = {
let toolbar = new St.BoxLayout({ name: 'Toolbar' });
this.actor.add_actor(toolbar);
- let inspectIcon = St.TextureCache.get_default().load_gicon(new Gio.ThemedIcon({ name: 'gtk-color-picker' }),
- 24);
+ let inspectIcon = St.TextureCache.get_default().load_icon_name('gtk-color-picker',
+ St.IconType.SYMBOLIC,
+ 24);
toolbar.add_actor(inspectIcon);
inspectIcon.reactive = true;
inspectIcon.connect('button-press-event', Lang.bind(this, function () {
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 3546fa7..d653eab 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -346,7 +346,7 @@ Notification.prototype = {
if (Gtk.IconTheme.get_default().has_icon(id)) {
button.add_style_class_name('notification-icon-button');
- button.child = St.TextureCache.get_default().load_icon_name(id, BUTTON_ICON_SIZE);
+ button.child = St.TextureCache.get_default().load_icon_name(id, St.IconType.SYMBOLIC, BUTTON_ICON_SIZE);
} else {
button.add_style_class_name('notification-button');
button.label = label;
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
index 899de97..87f07cd 100644
--- a/js/ui/notificationDaemon.js
+++ b/js/ui/notificationDaemon.js
@@ -148,7 +148,7 @@ NotificationDaemon.prototype = {
let uri = GLib.filename_to_uri(icon, null);
return textureCache.load_uri_async(uri, size, size);
} else
- return textureCache.load_icon_name(icon, size);
+ return textureCache.load_icon_name(icon, St.IconType.FULLCOLOR, size);
} else if (hints.icon_data) {
let [width, height, rowStride, hasAlpha,
bitsPerSample, nChannels, data] = hints.icon_data;
@@ -165,7 +165,7 @@ NotificationDaemon.prototype = {
stockIcon = 'gtk-dialog-error';
break;
}
- return textureCache.load_icon_name(stockIcon, size);
+ return textureCache.load_icon_name(stockIcon, St.IconType.FULLCOLOR, size);
}
},
diff --git a/js/ui/panelMenu.js b/js/ui/panelMenu.js
index e5fdc98..029e08e 100644
--- a/js/ui/panelMenu.js
+++ b/js/ui/panelMenu.js
@@ -61,7 +61,7 @@ SystemStatusButton.prototype = {
this._iconName = iconName;
if (this._iconActor)
this._iconActor.destroy();
- this._iconActor = St.TextureCache.get_default().load_icon_name(this._iconName, 24);
+ this._iconActor = St.TextureCache.get_default().load_icon_name(this._iconName, St.IconType.SYMBOLIC, 24);
this.actor.set_child(this._iconActor);
},
diff --git a/js/ui/placeDisplay.js b/js/ui/placeDisplay.js
index aaae4f7..0e5d4fa 100644
--- a/js/ui/placeDisplay.js
+++ b/js/ui/placeDisplay.js
@@ -158,7 +158,7 @@ PlacesManager.prototype = {
this._connect = new PlaceInfo('special:connect', _("Connect to..."),
function (size) {
- return St.TextureCache.get_default().load_icon_name('applications-internet', size);
+ return St.TextureCache.get_default().load_icon_name('applications-internet', St.IconType.FULLCOLOR, size);
},
function () {
new Shell.Process({ args: ['nautilus-connect-server'] }).run();
@@ -432,7 +432,7 @@ DashPlaceDisplayItem.prototype = {
box.add(text, { expand: true, x_fill: true });
if (info.isRemovable()) {
- let removeIcon = St.TextureCache.get_default().load_icon_name ('media-eject', PLACES_ICON_SIZE);
+ let removeIcon = St.TextureCache.get_default().load_icon_name ('media-eject', St.IconType.FULLCOLOR, PLACES_ICON_SIZE);
let removeIconBox = new St.Clickable({ child: removeIcon,
reactive: true });
box.add(removeIconBox);
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 6423268..89f56e7 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -252,7 +252,7 @@ PopupImageMenuItem.prototype = {
if (!show) {
this._imageBin.hide();
} else {
- let img = St.TextureCache.get_default().load_icon_name(this._iconName, this._size);
+ let img = St.TextureCache.get_default().load_icon_name(this._iconName, St.IconType.SYMBOLIC, this._size);
this._imageBin.set_child(img);
this._imageBin.show();
}
diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js
index fee4e9f..5eb4b38 100644
--- a/js/ui/statusMenu.js
+++ b/js/ui/statusMenu.js
@@ -40,10 +40,10 @@ StatusMenuButton.prototype = {
box.add(this._iconBox, { y_align: St.Align.MIDDLE, y_fill: false });
let textureCache = St.TextureCache.get_default();
- this._availableIcon = textureCache.load_icon_name('user-available', 16);
- this._busyIcon = textureCache.load_icon_name('user-busy', 16);
- this._invisibleIcon = textureCache.load_icon_name('user-invisible', 16);
- this._idleIcon = textureCache.load_icon_name('user-idle', 16);
+ this._availableIcon = textureCache.load_icon_name('user-available', St.IconType.SYMBOLIC, 16);
+ this._busyIcon = textureCache.load_icon_name('user-busy', St.IconType.SYMBOLIC, 16);
+ this._invisibleIcon = textureCache.load_icon_name('user-invisible', St.IconType.SYMBOLIC, 16);
+ this._idleIcon = textureCache.load_icon_name('user-idle', St.IconType.SYMBOLIC, 16);
this._presence.connect('StatusChanged', Lang.bind(this, this._updatePresenceIcon));
this._presence.getStatus(Lang.bind(this, this._updatePresenceIcon));
diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js
index 199471a..f5c6663 100644
--- a/js/ui/telepathyClient.js
+++ b/js/ui/telepathyClient.js
@@ -347,7 +347,7 @@ ContactManager.prototype = {
let uri = GLib.filename_to_uri(file, null);
iconBox.child = textureCache.load_uri_async(uri, iconBox._size, iconBox._size);
} else {
- iconBox.child = textureCache.load_icon_name('stock_person', iconBox._size);
+ iconBox.child = textureCache.load_icon_name('stock_person', St.IconType.FULLCOLOR, iconBox._size);
}
},
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index b1a2925..a40590e 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -927,9 +927,16 @@ create_texture_and_ensure_request (StTextureCache *cache,
/**
* st_texture_cache_load_gicon:
+ * @cache: The texture cache instance
+ * @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.
*
- * This method returns a new #ClutterClone for a given #GIcon. If the
- * icon isn't loaded already, the texture will be filled asynchronously.
+ * This will load @icon as a full-color icon; if you want a symbolic
+ * icon, you must use st_texture_cache_load_icon_name().
*
* Return Value: (transfer none): A new #ClutterActor for the icon
*/
@@ -1123,28 +1130,77 @@ st_texture_cache_load_sliced_image (StTextureCache *cache,
}
/**
+ * StIconType:
+ * @ST_ICON_SYMBOLIC: a symbolic (ie, mostly monochrome) icon
+ * @ST_ICON_FULLCOLOR: a full-color icon
+ * @ST_ICON_APPLICATION: a full-color icon, which is expected
+ * to be an application icon
+ * @ST_ICON_DOCUMENT: a full-color icon, which is expected
+ * to be a document (MIME type) icon
+ *
+ * Describes what style of icon is desired in a call to
+ * st_texture_cache_load_icon_name() or st_texture_cache_load_gicon().
+ * Use %ST_ICON_SYMBOLIC for symbolic icons (eg, for the panel and
+ * much of the rest of the shell chrome) or %ST_ICON_FULLCOLOR for a
+ * full-color icon.
+ *
+ * If you know that the requested icon is either an application icon
+ * or a document type icon, you should use %ST_ICON_APPLICATION or
+ * %ST_ICON_DOCUMENT, which may do a better job of selecting the
+ * correct theme icon for those types. If you are unsure what kind of
+ * icon you are loading, use %ST_ICON_FULLCOLOR.
+ */
+
+/**
* st_texture_cache_load_icon_name:
* @cache: The texture cache instance
* @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.
+ * Load a themed icon into a texture. See the #StIconType documentation
+ * for an explanation of how @icon_type affects the returned icon.
*
* Return Value: (transfer none): A new #ClutterTexture for the icon
*/
ClutterActor *
st_texture_cache_load_icon_name (StTextureCache *cache,
const char *name,
+ StIconType icon_type,
gint size)
{
ClutterActor *texture;
GIcon *themed;
+ char *symbolic;
- themed = g_themed_icon_new (name);
- texture = st_texture_cache_load_gicon (cache, themed, size);
- g_object_unref (themed);
-
- return CLUTTER_ACTOR (texture);
+ switch (icon_type)
+ {
+ case ST_ICON_APPLICATION:
+ case ST_ICON_DOCUMENT:
+ themed = g_themed_icon_new (name);
+ texture = st_texture_cache_load_gicon (cache, themed, size);
+ g_object_unref (themed);
+
+ return CLUTTER_ACTOR (texture);
+ break;
+ case ST_ICON_SYMBOLIC:
+ symbolic = g_strconcat (name, "-symbolic", NULL);
+ themed = g_themed_icon_new_with_default_fallbacks ((const gchar*)symbolic);
+ g_free (symbolic);
+ texture = st_texture_cache_load_gicon (cache, themed, size);
+ g_object_unref (themed);
+
+ return CLUTTER_ACTOR (texture);
+ break;
+ case ST_ICON_FULLCOLOR:
+ themed = g_themed_icon_new_with_default_fallbacks (name);
+ texture = st_texture_cache_load_gicon (cache, themed, size);
+
+ return CLUTTER_ACTOR (texture);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
}
/**
diff --git a/src/st/st-texture-cache.h b/src/st/st-texture-cache.h
index 79cf0b6..df4ef43 100644
--- a/src/st/st-texture-cache.h
+++ b/src/st/st-texture-cache.h
@@ -33,6 +33,13 @@ struct _StTextureCacheClass
};
typedef enum {
+ ST_ICON_SYMBOLIC,
+ ST_ICON_FULLCOLOR,
+ ST_ICON_APPLICATION,
+ ST_ICON_DOCUMENT
+} StIconType;
+
+typedef enum {
ST_TEXTURE_CACHE_POLICY_NONE,
ST_TEXTURE_CACHE_POLICY_FOREVER
} StTextureCachePolicy;
@@ -53,6 +60,7 @@ ClutterActor *st_texture_cache_bind_pixbuf_property (StTextureCache *cache,
ClutterActor *st_texture_cache_load_icon_name (StTextureCache *cache,
const char *name,
+ StIconType icon_type,
gint size);
ClutterActor *st_texture_cache_load_gicon (StTextureCache *cache,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]