About all my projects
Gnome::Gtk4::IconTheme

Gnome::Gtk4::IconTheme

Description

Gnome::Gtk4::IconTheme 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](http://www.freedesktop.org/Standards/icon-theme-spec) 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 Gnome::Gtk4::Image rather than directly, but looking up icons directly is also simple. The Gnome::Gtk4::IconTheme object acts as a database of all the icons in the current theme. You can create new Gnome::Gtk4::IconTheme objects, but it’s much more efficient to use the standard icon theme of the Gnome::Gtk4::Widget so that the icon information is shared with other people looking up icons.

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

new-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 .IconTheme.get-for-display() rather than creating a new icon theme object for scratch.

method new-icontheme ( --> Gnome::Gtk4::IconTheme \)

Methods

add-resource-path

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

See .set-resource-path().

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

method add-resource-path ( Str $path )
  • $path; a resource path.

add-search-path

Appends a directory to the search path.

See .set-search-path().

method add-search-path ( Str $path )
  • $path; directory name to append to the icon path.

get-display

Returns the display that the Gnome::Gtk4::IconTheme object was created for.

method get-display (--> N-Object )

Return value; the display of $icon-theme.

get-icon-names

Lists the names of icons in the current icon theme.

method get-icon-names (--> Array[Str] )

Return value; a string array holding the names of all the icons in the theme. You must free the array using g_strfreev()..

get-icon-sizes

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.

method get-icon-sizes ( Str $icon-name --> Array[Int] )
  • $icon-name; the name of an icon.

Return value; 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..

get-resource-path

Gets the current resource path.

See .set-resource-path().

method get-resource-path (--> Array[Str] )

Return value; A list of resource paths.

get-search-path

Gets the current search path.

See .set-search-path().

method get-search-path (--> Array[Str] )

Return value; a list of icon theme path directories.

get-theme-name

Gets the current icon theme name.

Returns (transfer full): the current icon theme name,

method get-theme-name (--> Str )

Return value; No documentation about its value and use.

has-gicon

Checks whether an icon theme includes an icon for a particular Gnome::Gio::R-Icon.

method has-gicon ( N-Object() $gicon --> Bool )
  • $gicon; a Gnome::Gio::R-Icon.

Return value; True if $self includes an icon for $gicon.

has-icon

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

method has-icon ( Str $icon-name --> Bool )
  • $icon-name; the name of an icon.

Return value; True if $self includes an icon for $icon-name..

lookup-by-gicon This function is not yet available

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

The icon can then be rendered by using it as a Gnome::Gdk4::R-Paintable, or you can get information such as the filename and size.

method lookup-by-gicon ( N-Object() $icon, Int() $size, Int() $scale, GtkTextDirection $direction, UInt $flags --> N-Object )
  • $icon; the Gnome::Gio::R-Icon to look up.

  • $size; desired icon size.

  • $scale; the desired scale.

  • $direction; text direction the icon will be displayed in.

  • $flags; flags modifying the behavior of the icon lookup.

Return value; a Gnome::Gtk4::IconPaintable containing information about the icon. Unref with g_object_unref().

lookup-icon This function is not yet available

Looks up a named icon for a desired size and window scale, returning a Gnome::Gtk4::IconPaintable.

The icon can then be rendered by using it as a Gnome::Gdk4::R-Paintable, 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 .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.

method lookup-icon ( Str $icon-name, Array[Str] $fallbacks, Int() $size, Int() $scale, GtkTextDirection $direction, UInt $flags --> N-Object )
  • $icon-name; the name of the icon to lookup.

  • $fallbacks; .

  • $size; desired icon size..

  • $scale; the window scale this will be displayed on.

  • $direction; text direction the icon will be displayed in.

  • $flags; flags modifying the behavior of the icon lookup.

Return value; a Gnome::Gtk4::IconPaintable object containing the icon..

set-resource-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.

method set-resource-path ( Array[Str] $path )
  • $path; NULL-terminated array of resource paths that are searched for icons.

set-search-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.)

method set-search-path ( Array[Str] $path )
  • $path; NULL-terminated array of directories that are searched for icon themes.

set-theme-name

Sets the name of the icon theme that the Gnome::Gtk4::IconTheme object uses overriding system configuration.

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

method set-theme-name ( Str $theme-name )
  • $theme-name; name of icon theme to use instead of configured theme, or undefined to unset a previously set custom theme.

Functions

get-for-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 .newicontheme() and setting the display yourself; by using this function a single icon theme object will be shared between users.

method get-for-display ( N-Object() $display --> N-Object )
  • $display; a Gnome::Gdk4::Display.

Return value; A unique Gnome::Gtk4::IconTheme 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..

Signals

changed

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.

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::IconTheme :$_widget,
  *C<user>-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::IconTheme object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.