Class IconTheme
- All Implemented Interfaces:
Proxy
GtkIconTheme
provides a facility for loading 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 Image
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);
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
IconTheme.Builder<B extends IconTheme.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theChangedCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionCreates a new icon theme object.IconTheme
(MemorySegment address) Create a IconTheme proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addResourcePath
(String path) Adds a resource path that will be looked at when looking for icons, similar to search paths.void
addSearchPath
(String path) Appends a directory to the search path.protected IconTheme
asParent()
Returns this instance as if it were its parent type.static IconTheme.Builder
<? extends IconTheme.Builder> builder()
AIconTheme.Builder
object constructs aIconTheme
with the specified properties.void
Emits the "changed" signal.Returns the display that theGtkIconTheme
object was created for.static IconTheme
getForDisplay
(Display display) Gets the icon theme object associated withdisplay
.String[]
Lists the names of icons in the current icon theme.int[]
getIconSizes
(String iconName) Returns an array of integers describing the sizes at which the icon is available without scaling.String[]
Gets the current resource path.String[]
Gets the current search path.Gets the current icon theme name.static Type
getType()
Get the GType of the IconTheme classboolean
Checks whether an icon theme includes an icon for a particularGIcon
.boolean
Checks whether an icon theme includes an icon for a particular name.lookupByGicon
(Icon icon, int size, int scale, TextDirection direction, Set<IconLookupFlags> flags) Looks up a icon for a desired size and window scale.lookupByGicon
(Icon icon, int size, int scale, TextDirection direction, IconLookupFlags... flags) Looks up a icon for a desired size and window scale.lookupIcon
(String iconName, @Nullable String[] fallbacks, int size, int scale, TextDirection direction, Set<IconLookupFlags> flags) Looks up a named icon for a desired size and window scale, returning aGtkIconPaintable
.lookupIcon
(String iconName, @Nullable String[] fallbacks, int size, int scale, TextDirection direction, IconLookupFlags... flags) Looks up a named icon for a desired size and window scale, returning aGtkIconPaintable
.onChanged
(IconTheme.ChangedCallback handler) Emitted when the icon theme changes.void
setResourcePath
(@Nullable String[] path) Sets the resource paths that will be looked at when looking for icons, similar to search paths.void
setSearchPath
(@Nullable String[] path) Sets the search path for the icon theme object.void
setThemeName
(@Nullable String themeName) Sets the name of the icon theme that theGtkIconTheme
object uses overriding system configuration.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
IconTheme
Create a IconTheme proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
IconTheme
public IconTheme()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
getForDisplay(org.gnome.gdk.Display)
rather than creating a new icon theme object for scratch.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getForDisplay
Gets the icon theme object associated withdisplay
.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
IconTheme()
and setting the display yourself; by using this function a single icon theme object will be shared between users.- Parameters:
display
- aGdkDisplay
- Returns:
- 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.
-
addResourcePath
Adds a resource path that will be looked at when looking for icons, similar to search paths.See
setResourcePath(java.lang.String[])
.This function should be used to make application-specific icons available as part of the icon theme.
- Parameters:
path
- a resource path
-
addSearchPath
Appends a directory to the search path.- Parameters:
path
- directory name to append to the icon path
-
getDisplay
Returns the display that theGtkIconTheme
object was created for.- Returns:
- the display of
iconTheme
-
getIconNames
Lists the names of icons in the current icon theme.- Returns:
- a string array holding the names of all the icons in the theme. You must free the array using g_strfreev().
-
getIconSizes
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.
- Parameters:
iconName
- the name of an icon- Returns:
- A newly allocated array describing the sizes at which the icon is available. The array should be freed with g_free() when it is no longer needed.
-
getResourcePath
Gets the current resource path.- Returns:
- A list of resource paths
-
getSearchPath
Gets the current search path.- Returns:
- a list of icon theme path directories
-
getThemeName
Gets the current icon theme name.- Returns:
- the current icon theme name,
-
hasGicon
Checks whether an icon theme includes an icon for a particularGIcon
.- Parameters:
gicon
- aGIcon
- Returns:
true
if this IconTheme includes an icon forgicon
-
hasIcon
Checks whether an icon theme includes an icon for a particular name.- Parameters:
iconName
- the name of an icon- Returns:
true
if this IconTheme includes an icon foriconName
.
-
lookupByGicon
public IconPaintable lookupByGicon(Icon icon, int size, int scale, TextDirection direction, Set<IconLookupFlags> flags) 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.- Parameters:
icon
- theGIcon
to look upsize
- desired icon size, in application pixelsscale
- the desired scaledirection
- text direction the icon will be displayed inflags
- flags modifying the behavior of the icon lookup- Returns:
- a
GtkIconPaintable
containing information about the icon. Unref with g_object_unref()
-
lookupByGicon
public IconPaintable lookupByGicon(Icon icon, int size, int scale, TextDirection direction, IconLookupFlags... flags) 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.- Parameters:
icon
- theGIcon
to look upsize
- desired icon size, in application pixelsscale
- the desired scaledirection
- text direction the icon will be displayed inflags
- flags modifying the behavior of the icon lookup- Returns:
- a
GtkIconPaintable
containing information about the icon. Unref with g_object_unref()
-
lookupIcon
public IconPaintable lookupIcon(String iconName, @Nullable @Nullable String[] fallbacks, int size, int scale, TextDirection direction, Set<IconLookupFlags> flags) Looks up a named icon for a desired size and window scale, returning aGtkIconPaintable
.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
iconName
is not available andfallbacks
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
hasIcon(java.lang.String)
.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.
- Parameters:
iconName
- the name of the icon to lookupfallbacks
- fallback namessize
- desired icon size, in application pixelsscale
- the window scale this will be displayed ondirection
- text direction the icon will be displayed inflags
- flags modifying the behavior of the icon lookup- Returns:
- a
GtkIconPaintable
object containing the icon.
-
lookupIcon
public IconPaintable lookupIcon(String iconName, @Nullable @Nullable String[] fallbacks, int size, int scale, TextDirection direction, IconLookupFlags... flags) Looks up a named icon for a desired size and window scale, returning aGtkIconPaintable
.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
iconName
is not available andfallbacks
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
hasIcon(java.lang.String)
.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.
- Parameters:
iconName
- the name of the icon to lookupfallbacks
- fallback namessize
- desired icon size, in application pixelsscale
- the window scale this will be displayed ondirection
- text direction the icon will be displayed inflags
- flags modifying the behavior of the icon lookup- Returns:
- a
GtkIconPaintable
object containing the icon.
-
setResourcePath
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.
- Parameters:
path
- NULL-terminated array of resource paths that are searched for icons
-
setSearchPath
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.)- Parameters:
path
- NULL-terminated array of directories that are searched for icon themes
-
setThemeName
Sets the name of the icon theme that theGtkIconTheme
object uses overriding system configuration.This function cannot be called on the icon theme objects returned from
getForDisplay(org.gnome.gdk.Display)
.- Parameters:
themeName
- name of icon theme to use instead of configured theme, ornull
to unset a previously set custom theme
-
onChanged
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.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChanged
public void emitChanged()Emits the "changed" signal. SeeonChanged(org.gnome.gtk.IconTheme.ChangedCallback)
. -
builder
AIconTheme.Builder
object constructs aIconTheme
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withIconTheme.Builder.build()
.
-