1.101 <GtkIconTheme>

Class: <GtkIconTheme>

It derives from <GObject>.

Loads themed icons.

The main reason for using a name rather than simply providing a filename is to allow different icons to be used depending on what “icon theme” is selected by the user. The operation of icon themes on Linux and Unix follows the Icon Theme Specification There is a fallback icon theme, named hicolor, where applications should install their icons, but additional icon themes can be installed as operating system vendors and users choose.

In many cases, named themes are used indirectly, via <GtkImage> rather than directly, but looking up icons directly is also simple. The <GtkIconTheme> object acts as a database of all the icons in the current theme. You can create new <GtkIconTheme> objects, but it’s much more efficient to use the standard icon theme of the <GtkWidget> so that the icon information is shared with other people looking up icons.

GtkIconTheme *icon_theme;
GtkIconPaintable *icon;
GdkPaintable *paintable;

icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (my_widget));
icon = gtk_icon_theme_lookup_icon (icon_theme,
                                   "my-icon-name", // icon name
                                   48, // icon size
                                   1,  // scale
                                   0,  // flags);
paintable = GDK_PAINTABLE (icon);
// Use the paintable
g_object_unref (icon);

Properties

Property: icon-theme:display self

The display that this icon theme object is attached to.

Its value is a <GdkDisplay>, or #f.

Set it with (set! (icon-theme:display self) value).

Property: icon-theme:icon-names self

The icon names that are supported by the icon theme.

Its value is a vector, each a string, or #f.

It is read only.

Property: icon-theme:resource-path self

Resource paths that will be looked at when looking for icons, similar to search paths.

The resources are considered as part of the hicolor icon theme and must be located in subdirectories that are defined in the hicolor icon theme, such as @path/16x16/actions/run.png. Icons that are directly placed in the resource path instead of a subdirectory are also considered as ultimate fallback.

Its value is a vector, each a string (or, to set it, a list), or #f.

Set it with (set! (icon-theme:resource-path self) value).

Property: icon-theme:search-path self

The search path for this icon theme.

When looking for icons, GTK will search for a subdirectory of one or more of the directories in the search path with the same name as the icon theme containing an index.theme file. (Themes from multiple of the path elements are combined to allow themes to be extended by adding icons in the user’s home directory.)

Its value is a vector, each a string (or, to set it, a list), or #f.

Set it with (set! (icon-theme:search-path self) value).

Property: icon-theme:theme-name self

The name of the icon theme that is being used.

Unless set to a different value, this will be the value of the settings:gtk-icon-theme-name property of the <GtkSettings> object associated to the display of the icontheme object.

Its value is a string, or #f.

Set it with (set! (icon-theme:theme-name self) value).

Procedures

Method: icon-theme:add-resource-path self path
Method: add-resource-path self path

Adds a resource path that will be looked at when looking for icons, similar to search paths.

See icon-theme:set-resource-path.

This function should be used to make application-specific icons available as part of the icon theme.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

path

Passed: a string.

a resource path

Method: icon-theme:add-search-path self path
Method: add-search-path self path

Appends a directory to the search path.

See icon-theme:set-search-path.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

path

Passed: a file name, as a string.

directory name to append to the icon path

Method: icon-theme:get-display self ⇒ %return
Method: get-display self ⇒ %return

Returns the display that the <GtkIconTheme> object was created for.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

%return

Returned: a <GdkDisplay>, or #f.

the display of icon-theme

Procedure: icon-theme:get-for-display display ⇒ %return

Gets the icon theme object associated with display.

If this function has not previously been called for the given display, a new icon theme object will be created and associated with the display. Icon theme objects are fairly expensive to create, so using this function is usually a better choice than calling icon-theme:new and setting the display yourself; by using this function a single icon theme object will be shared between users.

display

Passed: a <GdkDisplay>.

a <GdkDisplay>

%return

Returned: a <GtkIconTheme>.

A unique <GtkIconTheme> associated with the given display. This icon theme is associated with the display and can be used as long as the display is open. Do not ref or unref it.

Method: icon-theme:get-icon-names self ⇒ %return
Method: get-icon-names self ⇒ %return

Lists the names of icons in the current icon theme.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

%return

Returned: a vector, each a string.

a string array holding the names of all the icons in the theme. You must free the array using strfreev.

Method: icon-theme:get-icon-sizes self icon-name ⇒ %return
Method: get-icon-sizes self icon-name ⇒ %return

Returns an array of integers describing the sizes at which the icon is available without scaling.

A size of -1 means that the icon is available in a scalable format. The array is zero-terminated.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

icon-name

Passed: a string.

the name of an icon

%return

Returned: a s32vector.

A newly allocated array describing the sizes at which the icon is available. The array should be freed with byte-array:free when it is no longer needed.

Method: icon-theme:get-resource-path self ⇒ %return
Method: get-resource-path self ⇒ %return

Gets the current resource path.

See icon-theme:set-resource-path.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

%return

Returned: a vector, each a string, or #f.

A list of resource paths

Method: icon-theme:get-search-path self ⇒ %return
Method: get-search-path self ⇒ %return

Gets the current search path.

See icon-theme:set-search-path.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

%return

Returned: a vector, each a file name, as a string, or #f.

a list of icon theme path directories

Method: icon-theme:get-theme-name self ⇒ %return
Method: get-theme-name self ⇒ %return

Gets the current icon theme name.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

%return

Returned: a string.

the current icon theme name,

Method: icon-theme:has-gicon? self gicon ⇒ %return
Method: has-gicon? self gicon ⇒ %return

Checks whether an icon theme includes an icon for a particular <GIcon>.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

gicon

Passed: a <GIcon>.

a <GIcon>

%return

Returned: a boolean.

#t if self includes an icon for gicon

Method: icon-theme:has-icon? self icon-name ⇒ %return
Method: has-icon? self icon-name ⇒ %return

Checks whether an icon theme includes an icon for a particular name.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

icon-name

Passed: a string.

the name of an icon

%return

Returned: a boolean.

#t if self includes an icon for icon-name.

Method: icon-theme:lookup-by-gicon self icon size scale direction flags ⇒ %return
Method: lookup-by-gicon self icon size scale direction flags ⇒ %return

Looks up a icon for a desired size and window scale.

The icon can then be rendered by using it as a <GdkPaintable>, or you can get information such as the filename and size.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

icon

Passed: a <GIcon>.

the <GIcon> to look up

size

Passed: a 32-bit integer.

desired icon size, in application pixels

scale

Passed: a 32-bit integer.

the desired scale

direction

Passed: a <GtkTextDirection>, or one of its symbols.

text direction the icon will be displayed in

flags

Passed: a <GtkIconLookupFlags>, or a list of its symbols, or one of them.

flags modifying the behavior of the icon lookup

%return

Returned: a <GtkIconPaintable>.

a <GtkIconPaintable> containing information about the icon. Unref with object:unref

Method: icon-theme:lookup-icon self icon-name fallbacks size scale direction flags ⇒ %return
Method: lookup-icon self icon-name fallbacks size scale direction flags ⇒ %return

Looks up a named icon for a desired size and window scale, returning a <GtkIconPaintable>.

The icon can then be rendered by using it as a <GdkPaintable>, or you can get information such as the filename and size.

If the available icon-name is not available and fallbacks are provided, they will be tried in order.

If no matching icon is found, then a paintable that renders the "missing icon" icon is returned. If you need to do something else for missing icons you need to use icon-theme:has-icon?.

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by overriding the GtkWidgetClass.css-changed() function.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

icon-name

Passed: a string.

the name of the icon to lookup

fallbacks

Passed: a list or vector, each a string, or #f.

fallback names

size

Passed: a 32-bit integer.

desired icon size, in application pixels

scale

Passed: a 32-bit integer.

the window scale this will be displayed on

direction

Passed: a <GtkTextDirection>, or one of its symbols.

text direction the icon will be displayed in

flags

Passed: a <GtkIconLookupFlags>, or a list of its symbols, or one of them.

flags modifying the behavior of the icon lookup

%return

Returned: a <GtkIconPaintable>.

a <GtkIconPaintable> object containing the icon.

Procedure: icon-theme:new ⇒ %return

Creates a new icon theme object.

Icon theme objects are used to lookup up an icon by name in a particular icon theme. Usually, you’ll want to use icon-theme:get-for-display rather than creating a new icon theme object for scratch.

%return

Returned: a <GtkIconTheme>.

the newly created <GtkIconTheme> object.

Method: icon-theme:set-resource-path self [path]
Method: set-resource-path self [path]

Sets the resource paths that will be looked at when looking for icons, similar to search paths.

The resources are considered as part of the hicolor icon theme and must be located in subdirectories that are defined in the hicolor icon theme, such as @path/16x16/actions/run.png or @path/scalable/actions/run.svg.

Icons that are directly placed in the resource path instead of a subdirectory are also considered as ultimate fallback, but they are treated like unthemed icons.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

path

Passed, or left out: a list or vector, each a string, or #f.

NULL-terminated array of resource paths that are searched for icons

Method: icon-theme:set-search-path self [path]
Method: set-search-path self [path]

Sets the search path for the icon theme object.

When looking for an icon theme, GTK will search for a subdirectory of one or more of the directories in path with the same name as the icon theme containing an index.theme file. (Themes from multiple of the path elements are combined to allow themes to be extended by adding icons in the user’s home directory.)

In addition if an icon found isn’t found either in the current icon theme or the default icon theme, and an image file with the right name is found directly in one of the elements of path, then that image will be used for the icon name. (This is legacy feature, and new icons should be put into the fallback icon theme, which is called hicolor, rather than directly on the icon path.)

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

path

Passed, or left out: a list or vector, each a file name, as a string, or #f.

NULL-terminated array of directories that are searched for icon themes

Method: icon-theme:set-theme-name self [theme-name]
Method: set-theme-name self [theme-name]

Sets the name of the icon theme that the <GtkIconTheme> object uses overriding system configuration.

This function cannot be called on the icon theme objects returned from icon-theme:get-for-display.

self

Passed: a <GtkIconTheme>.

a <GtkIconTheme>

theme-name

Passed, or left out: a string, or #f.

name of icon theme to use instead of configured theme, or #f to unset a previously set custom theme

Signals

Signal: icon-theme:changed

Connect a handler with (connect object icon-theme:changed handler). It is called as (handler self).

Emitted when the icon theme changes.

This can happen because current icon theme is switched or because GTK detects that a change has occurred in the contents of the current icon theme.

self

Passed: a <GtkIconTheme>.