Top | ![]() |
![]() |
![]() |
![]() |
GtkIconInfo | |
struct | GtkIconTheme |
struct | GtkIconThemeClass |
enum | GtkIconLookupFlags |
#define | GTK_ICON_THEME_ERROR |
enum | GtkIconThemeError |
GtkIconTheme provides a facility for looking up icons by name
and size. 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 for the GdkDisplay so that the icon information is shared with other people looking up icons.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
GError *error = NULL; GtkIconTheme *icon_theme; GdkPixbuf *pixbuf; icon_theme = gtk_icon_theme_get_default (); pixbuf = gtk_icon_theme_load_icon (icon_theme, "my-icon-name", // icon name 48, // icon size 0, // flags &error); if (!pixbuf) { g_warning ("Couldn’t load icon: %s", error->message); g_error_free (error); } else { // Use the pixbuf g_object_unref (pixbuf); } |
GtkIconTheme *
gtk_icon_theme_new (void
);
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 gtk_icon_theme_get_default()
or gtk_icon_theme_get_for_display()
rather than creating
a new icon theme object for scratch.
GtkIconTheme *
gtk_icon_theme_get_default (void
);
Gets the icon theme for the default display. See
gtk_icon_theme_get_for_display()
.
A unique GtkIconTheme associated with the default 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.
[transfer none]
GtkIconTheme *
gtk_icon_theme_get_for_display (GdkDisplay *display
);
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 than gtk_icon_theme_new()
and setting the display yourself; by using this function
a single icon theme object will be shared between users.
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.
[transfer none]
void gtk_icon_theme_set_display (GtkIconTheme *icon_theme
,GdkDisplay *display
);
Sets the display for an icon theme; the display is used to track the user’s currently configured icon theme, which might be different for different displays.
void gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme
,const gchar *path[]
,gint n_elements
);
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.)
void gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme
,gchar **path[]
,gint *n_elements
);
Gets the current search path. See gtk_icon_theme_set_search_path()
.
void gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme
,const gchar *path
);
Appends a directory to the search path.
See gtk_icon_theme_set_search_path()
.
void gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme
,const gchar *path
);
Prepends a directory to the search path.
See gtk_icon_theme_set_search_path()
.
void gtk_icon_theme_add_resource_path (GtkIconTheme *icon_theme
,const gchar *path
);
Adds a resource path that will be looked at when looking for icons, similar to search paths.
This function should be used to make application-specific icons available as part of the icon theme.
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.
void gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme
,const gchar *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 gtk_icon_theme_get_default()
and gtk_icon_theme_get_for_display()
.
gboolean gtk_icon_theme_has_icon (GtkIconTheme *icon_theme
,const gchar *icon_name
);
Checks whether an icon theme includes an icon for a particular name.
GtkIconInfo * gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme
,const gchar *icon_name
,gint size
,GtkIconLookupFlags flags
);
Looks up a named icon and returns a GtkIconInfo containing
information such as the filename of the icon. The icon
can then be rendered into a pixbuf using
gtk_icon_info_load_icon()
. (gtk_icon_theme_load_icon()
combines these two steps if all you need is the pixbuf.)
When rendering on displays with high pixel densities you should not
use a size
multiplied by the scaling factor returned by functions
like gdk_surface_get_scale_factor()
. Instead, you should use
gtk_icon_theme_lookup_icon_for_scale()
, as the assets loaded
for a given scaling factor may be different.
icon_theme |
||
icon_name |
the name of the icon to lookup |
|
size |
desired icon size |
|
flags |
flags modifying the behavior of the icon lookup |
a GtkIconInfo object
containing information about the icon, or NULL
if the
icon wasn’t found.
[nullable][transfer full]
GtkIconInfo * gtk_icon_theme_lookup_icon_for_scale (GtkIconTheme *icon_theme
,const gchar *icon_name
,gint size
,gint scale
,GtkIconLookupFlags flags
);
Looks up a named icon for a particular window scale and returns a
GtkIconInfo containing information such as the filename of the
icon. The icon can then be rendered into a pixbuf using
gtk_icon_info_load_icon()
. (gtk_icon_theme_load_icon()
combines
these two steps if all you need is the pixbuf.)
icon_theme |
||
icon_name |
the name of the icon to lookup |
|
size |
desired icon size |
|
scale |
the desired scale |
|
flags |
flags modifying the behavior of the icon lookup |
a GtkIconInfo object
containing information about the icon, or NULL
if the
icon wasn’t found.
[nullable][transfer full]
GtkIconInfo * gtk_icon_theme_choose_icon (GtkIconTheme *icon_theme
,const gchar *icon_names[]
,gint size
,GtkIconLookupFlags flags
);
Looks up a named icon and returns a GtkIconInfo containing
information such as the filename of the icon. The icon
can then be rendered into a pixbuf using
gtk_icon_info_load_icon()
. (gtk_icon_theme_load_icon()
combines these two steps if all you need is the pixbuf.)
If icon_names
contains more than one name, this function
tries them all in the given order before falling back to
inherited icon themes.
icon_theme |
||
icon_names |
|
[array zero-terminated=1] |
size |
desired icon size |
|
flags |
flags modifying the behavior of the icon lookup |
a GtkIconInfo object
containing information about the icon, or NULL
if the icon wasn’t
found.
[nullable][transfer full]
GtkIconInfo * gtk_icon_theme_choose_icon_for_scale (GtkIconTheme *icon_theme
,const gchar *icon_names[]
,gint size
,gint scale
,GtkIconLookupFlags flags
);
Looks up a named icon for a particular window scale and returns
a GtkIconInfo containing information such as the filename of the
icon. The icon can then be rendered into a pixbuf using
gtk_icon_info_load_icon()
. (gtk_icon_theme_load_icon()
combines these two steps if all you need is the pixbuf.)
If icon_names
contains more than one name, this function
tries them all in the given order before falling back to
inherited icon themes.
icon_theme |
||
icon_names |
|
[array zero-terminated=1] |
size |
desired icon size |
|
scale |
desired scale |
|
flags |
flags modifying the behavior of the icon lookup |
a GtkIconInfo object
containing information about the icon, or NULL
if the
icon wasn’t found.
[nullable][transfer full]
GtkIconInfo * gtk_icon_theme_lookup_by_gicon (GtkIconTheme *icon_theme
,GIcon *icon
,gint size
,GtkIconLookupFlags flags
);
Looks up an icon and returns a GtkIconInfo containing information
such as the filename of the icon. The icon can then be rendered
into a pixbuf using gtk_icon_info_load_icon()
.
When rendering on displays with high pixel densities you should not
use a size
multiplied by the scaling factor returned by functions
like gdk_surface_get_scale_factor()
. Instead, you should use
gtk_icon_theme_lookup_by_gicon_for_scale()
, as the assets loaded
for a given scaling factor may be different.
icon_theme |
||
icon |
the GIcon to look up |
|
size |
desired icon size |
|
flags |
flags modifying the behavior of the icon lookup |
a GtkIconInfo containing
information about the icon, or NULL
if the icon wasn’t
found. Unref with g_object_unref()
.
[nullable][transfer full]
GtkIconInfo * gtk_icon_theme_lookup_by_gicon_for_scale (GtkIconTheme *icon_theme
,GIcon *icon
,gint size
,gint scale
,GtkIconLookupFlags flags
);
Looks up an icon and returns a GtkIconInfo containing information
such as the filename of the icon. The icon can then be rendered into
a pixbuf using gtk_icon_info_load_icon()
.
icon_theme |
||
icon |
the GIcon to look up |
|
size |
desired icon size |
|
scale |
the desired scale |
|
flags |
flags modifying the behavior of the icon lookup |
a GtkIconInfo containing
information about the icon, or NULL
if the icon wasn’t
found. Unref with g_object_unref()
.
[nullable][transfer full]
GdkPixbuf * gtk_icon_theme_load_icon (GtkIconTheme *icon_theme
,const gchar *icon_name
,gint size
,GtkIconLookupFlags flags
,GError **error
);
Looks up an icon in an icon theme, scales it to the given size
and renders it into a pixbuf. This is a convenience function;
if more details about the icon are needed, use
gtk_icon_theme_lookup_icon()
followed by gtk_icon_info_load_icon()
.
Note that you probably want to listen for icon theme changes and
update the icon. This is usually done by connecting to the
GtkWidget::style-set signal. If for some reason you do not want to
update the icon when the icon theme changes, you should consider
using gdk_pixbuf_copy()
to make a private copy of the pixbuf
returned by this function. Otherwise GTK+ may need to keep the old
icon theme loaded, which would be a waste of memory.
icon_theme |
||
icon_name |
the name of the icon to lookup |
|
size |
the desired icon size. The resulting icon may not be
exactly this size; see |
|
flags |
flags modifying the behavior of the icon lookup |
|
error |
Location to store error information on failure,
or |
[allow-none] |
GdkPixbuf * gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme
,const gchar *icon_name
,gint size
,gint scale
,GtkIconLookupFlags flags
,GError **error
);
Looks up an icon in an icon theme for a particular window scale,
scales it to the given size and renders it into a pixbuf. This is a
convenience function; if more details about the icon are needed,
use gtk_icon_theme_lookup_icon()
followed by
gtk_icon_info_load_icon()
.
Note that you probably want to listen for icon theme changes and
update the icon. This is usually done by connecting to the
GtkWidget::style-set signal. If for some reason you do not want to
update the icon when the icon theme changes, you should consider
using gdk_pixbuf_copy()
to make a private copy of the pixbuf
returned by this function. Otherwise GTK+ may need to keep the old
icon theme loaded, which would be a waste of memory.
icon_theme |
||
icon_name |
the name of the icon to lookup |
|
size |
the desired icon size. The resulting icon may not be
exactly this size; see |
|
scale |
desired scale |
|
flags |
flags modifying the behavior of the icon lookup |
|
error |
Location to store error information on failure,
or |
[allow-none] |
GList *
gtk_icon_theme_list_contexts (GtkIconTheme *icon_theme
);
Gets the list of contexts available within the current
hierarchy of icon themes.
See gtk_icon_theme_list_icons()
for details about contexts.
GList * gtk_icon_theme_list_icons (GtkIconTheme *icon_theme
,const gchar *context
);
Lists the icons in the current icon theme. Only a subset
of the icons can be listed by providing a context string.
The set of values for the context string is system dependent,
but will typically include such values as “Applications” and
“MimeTypes”. Contexts are explained in the
Icon Theme Specification.
The standard contexts are listed in the
Icon Naming Specification.
Also see gtk_icon_theme_list_contexts()
.
gint * gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme
,const gchar *icon_name
);
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.
char *
gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme
);
Gets the name of an icon that is representative of the current theme (for instance, to use when presenting a list of themes to the user.)
gboolean
gtk_icon_theme_rescan_if_needed (GtkIconTheme *icon_theme
);
Checks to see if the icon theme has changed; if it has, any
currently cached information is discarded and will be reloaded
next time icon_theme
is accessed.
GtkIconInfo * gtk_icon_info_new_for_pixbuf (GtkIconTheme *icon_theme
,GdkPixbuf *pixbuf
);
Creates a GtkIconInfo for a GdkPixbuf.
gint
gtk_icon_info_get_base_size (GtkIconInfo *icon_info
);
Gets the base size for the icon. The base size is a size for the icon that was specified by the icon theme creator. This may be different than the actual size of image; These icons will be given the same base size as the larger icons to which they are attached.
Note that for scaled icons the base size does not include the base scale.
gint
gtk_icon_info_get_base_scale (GtkIconInfo *icon_info
);
Gets the base scale for the icon. The base scale is a scale for the icon that was specified by the icon theme creator. For instance an icon drawn for a high-dpi monitor with window scale 2 for a base size of 32 will be 64 pixels tall and have a base scale of 2.
const gchar *
gtk_icon_info_get_filename (GtkIconInfo *icon_info
);
Gets the filename for the icon. If the GTK_ICON_LOOKUP_USE_BUILTIN
flag was passed to gtk_icon_theme_lookup_icon()
, there may be no
filename if a builtin icon is returned; in this case, you should
use gtk_icon_info_get_builtin_pixbuf()
.
GdkPixbuf * gtk_icon_info_load_icon (GtkIconInfo *icon_info
,GError **error
);
Renders an icon previously looked up in an icon theme using
gtk_icon_theme_lookup_icon()
; the size will be based on the size
passed to gtk_icon_theme_lookup_icon()
. Note that the resulting
pixbuf may not be exactly this size; an icon theme may have icons
that differ slightly from their nominal sizes, and in addition GTK+
will avoid scaling icons that it considers sufficiently close to the
requested size or for which the source image would have to be scaled
up too far. (This maintains sharpness.). This behaviour can be changed
by passing the GTK_ICON_LOOKUP_FORCE_SIZE
flag when obtaining
the GtkIconInfo. If this flag has been specified, the pixbuf
returned by this function will be scaled to the exact size.
GdkTexture *
gtk_icon_info_load_texture (GtkIconInfo *icon_info
);
Returns a texture object that can be used to render the icon with GSK.
void gtk_icon_info_load_icon_async (GtkIconInfo *icon_info
,GCancellable *cancellable
,GAsyncReadyCallback callback
,gpointer user_data
);
Asynchronously load, render and scale an icon previously looked up
from the icon theme using gtk_icon_theme_lookup_icon()
.
For more details, see gtk_icon_info_load_icon()
which is the synchronous
version of this call.
GdkPixbuf * gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info
,GAsyncResult *res
,GError **error
);
Finishes an async icon load, see gtk_icon_info_load_icon_async()
.
GdkPixbuf * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info
,const GdkRGBA *fg
,const GdkRGBA *success_color
,const GdkRGBA *warning_color
,const GdkRGBA *error_color
,gboolean *was_symbolic
,GError **error
);
Loads an icon, modifying it to match the system colours for the foreground,
success, warning and error colors provided. If the icon is not a symbolic
one, the function will return the result from gtk_icon_info_load_icon()
.
This allows loading symbolic icons that will match the system theme.
Unless you are implementing a widget, you will want to use
g_themed_icon_new_with_default_fallbacks()
to load the icon.
As implementation details, the icon loaded needs to be of SVG type, contain the “symbolic” term as the last component of the icon name, and use the “fg”, “success”, “warning” and “error” CSS styles in the SVG file itself.
See the Symbolic Icons Specification for more information about symbolic icons.
icon_info |
||
fg |
a GdkRGBA representing the foreground color of the icon |
|
success_color |
a GdkRGBA representing the warning color
of the icon or |
[allow-none] |
warning_color |
a GdkRGBA representing the warning color
of the icon or |
[allow-none] |
error_color |
a GdkRGBA representing the error color
of the icon or |
[allow-none] |
was_symbolic |
a gboolean, returns whether the
loaded icon was a symbolic one and whether the |
[out][allow-none] |
error |
location to store error information on failure,
or |
[allow-none] |
void gtk_icon_info_load_symbolic_async (GtkIconInfo *icon_info
,const GdkRGBA *fg
,const GdkRGBA *success_color
,const GdkRGBA *warning_color
,const GdkRGBA *error_color
,GCancellable *cancellable
,GAsyncReadyCallback callback
,gpointer user_data
);
Asynchronously load, render and scale a symbolic icon previously looked up
from the icon theme using gtk_icon_theme_lookup_icon()
.
For more details, see gtk_icon_info_load_symbolic()
which is the synchronous
version of this call.
icon_info |
||
fg |
a GdkRGBA representing the foreground color of the icon |
|
success_color |
a GdkRGBA representing the warning color
of the icon or |
[allow-none] |
warning_color |
a GdkRGBA representing the warning color
of the icon or |
[allow-none] |
error_color |
a GdkRGBA representing the error color
of the icon or |
[allow-none] |
cancellable |
optional GCancellable object,
|
[allow-none] |
callback |
a GAsyncReadyCallback to call when the request is satisfied. |
[scope async] |
user_data |
the data to pass to callback function. |
[closure] |
GdkPixbuf * gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info
,GAsyncResult *res
,gboolean *was_symbolic
,GError **error
);
Finishes an async icon load, see gtk_icon_info_load_symbolic_async()
.
GdkPixbuf * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info
,GtkStyleContext *context
,gboolean *was_symbolic
,GError **error
);
Loads an icon, modifying it to match the system colors for the foreground,
success, warning and error colors provided. If the icon is not a symbolic
one, the function will return the result from gtk_icon_info_load_icon()
.
This function uses the regular foreground color and the symbolic colors
with the names “success_color”, “warning_color” and “error_color” from
the context.
This allows loading symbolic icons that will match the system theme.
See gtk_icon_info_load_symbolic()
for more details.
void gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info
,GtkStyleContext *context
,GCancellable *cancellable
,GAsyncReadyCallback callback
,gpointer user_data
);
Asynchronously load, render and scale a symbolic icon previously
looked up from the icon theme using gtk_icon_theme_lookup_icon()
.
For more details, see gtk_icon_info_load_symbolic_for_context()
which is the synchronous version of this call.
GdkPixbuf * gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info
,GAsyncResult *res
,gboolean *was_symbolic
,GError **error
);
Finishes an async icon load, see gtk_icon_info_load_symbolic_for_context_async()
.
gboolean
gtk_icon_info_is_symbolic (GtkIconInfo *icon_info
);
Checks if the icon is symbolic or not. This currently uses only the file name and not the file contents for determining this. This behaviour may change in the future.
typedef struct _GtkIconInfo GtkIconInfo;
Contains information found when looking up an icon in an icon theme.
struct GtkIconTheme;
Acts as a database of information about an icon theme.
Normally, you retrieve the icon theme for a particular
display using gtk_icon_theme_get_for_display()
and it
will contain information about current icon theme for
that display, but you can also create a new GtkIconTheme
object and set the icon theme name explicitly using
gtk_icon_theme_set_custom_theme()
.
struct GtkIconThemeClass { GObjectClass parent_class; void (* changed) (GtkIconTheme *icon_theme); };
Used to specify options for gtk_icon_theme_lookup_icon()
Never get SVG icons, even if gdk-pixbuf
supports them. Cannot be used together with |
||
Get SVG icons, even if gdk-pixbuf
doesn’t support them.
Cannot be used together with |
||
When passed to
|
||
Try to shorten icon name at '-'
characters before looking at inherited themes. This flag is only
supported in functions that take a single icon name. For more general
fallback, see |
||
Always get the icon scaled to the requested size |
||
Try to always load regular icons, even when symbolic icon names are given |
||
Try to always load symbolic icons, even when regular icon names are given |
||
Try to load a variant of the icon for left-to-right text direction |
||
Try to load a variant of the icon for right-to-left text direction |
#define GTK_ICON_THEME_ERROR gtk_icon_theme_error_quark ()
The GQuark used for GtkIconThemeError errors.
“changed”
signalvoid user_function (GtkIconTheme *icon_theme, gpointer user_data)
Emitted when the current icon theme is switched or GTK+ detects that a change has occurred in the contents of the current icon theme.
Flags: Run Last