gi-gtk-4.0.1: Gtk bindings
CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellNone
LanguageHaskell2010

GI.Gtk.Objects.IconTheme

Description

IconTheme 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 Image rather than directly, but looking up icons directly is also simple. The IconTheme object acts as a database of all the icons in the current theme. You can create new IconTheme objects, but it’s much more efficient to use the standard icon theme for the Display so that the icon information is shared with other people looking up icons.

C code

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);
  }
Synopsis

Exported types

newtype IconTheme Source #

Memory-managed wrapper type.

Instances

Instances details
Eq IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

IsGValue IconTheme Source #

Convert IconTheme to and from GValue with toGValue and fromGValue.

Instance details

Defined in GI.Gtk.Objects.IconTheme

GObject IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

Methods

gobjectType :: IO GType #

HasParentTypes IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

type ParentTypes IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

class (GObject o, IsDescendantOf IconTheme o) => IsIconTheme o Source #

Type class for types which can be safely cast to IconTheme, for instance with toIconTheme.

Instances

Instances details
(GObject o, IsDescendantOf IconTheme o) => IsIconTheme o Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

toIconTheme :: (MonadIO m, IsIconTheme o) => o -> m IconTheme Source #

Cast to IconTheme, for types for which this is known to be safe. For general casts, use castTo.

noIconTheme :: Maybe IconTheme Source #

A convenience alias for Nothing :: Maybe IconTheme.

Methods

Overloaded methods

addResourcePath

iconThemeAddResourcePath Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Text

path: a resource path

-> m () 

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.

appendSearchPath

iconThemeAppendSearchPath Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> [Char]

path: directory name to append to the icon path

-> m () 

Appends a directory to the search path. See iconThemeSetSearchPath.

chooseIcon

iconThemeChooseIcon Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> [Text]

iconNames: Nothing-terminated array of icon names to lookup

-> Int32

size: desired icon size

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe IconInfo)

Returns: a IconInfo object containing information about the icon, or Nothing if the icon wasn’t found.

Looks up a named icon and returns a IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using iconInfoLoadIcon. (iconThemeLoadIcon combines these two steps if all you need is the pixbuf.)

If iconNames contains more than one name, this function tries them all in the given order before falling back to inherited icon themes.

chooseIconForScale

iconThemeChooseIconForScale Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> [Text]

iconNames: Nothing-terminated array of icon names to lookup

-> Int32

size: desired icon size

-> Int32

scale: desired scale

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe IconInfo)

Returns: a IconInfo object containing information about the icon, or Nothing if the icon wasn’t found.

Looks up a named icon for a particular window scale and returns a IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using iconInfoLoadIcon. (iconThemeLoadIcon combines these two steps if all you need is the pixbuf.)

If iconNames contains more than one name, this function tries them all in the given order before falling back to inherited icon themes.

getDefault

iconThemeGetDefault Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m IconTheme

Returns: A unique IconTheme 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.

Gets the icon theme for the default display. See iconThemeGetForDisplay.

getExampleIconName

iconThemeGetExampleIconName Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> m (Maybe Text)

Returns: the name of an example icon or Nothing. Free with free.

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

getForDisplay

iconThemeGetForDisplay Source #

Arguments

:: (HasCallStack, MonadIO m, IsDisplay a) 
=> a

display: a Display

-> m IconTheme

Returns: A unique 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.

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

getIconSizes

iconThemeGetIconSizes Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Text

iconName: the name of an icon

-> m [Int32]

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

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.

getSearchPath

iconThemeGetSearchPath Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> m [[Char]] 

Gets the current search path. See iconThemeSetSearchPath.

hasIcon

iconThemeHasIcon Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Text

iconName: the name of an icon

-> m Bool

Returns: True if iconTheme includes an icon for iconName.

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

listContexts

iconThemeListContexts Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> m [Text]

Returns: a List list holding the names of all the contexts in the theme. You must first free each element in the list with free, then free the list itself with g_list_free().

Gets the list of contexts available within the current hierarchy of icon themes. See iconThemeListIcons for details about contexts.

listIcons

iconThemeListIcons Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Maybe Text

context: a string identifying a particular type of icon, or Nothing to list all icons.

-> m [Text]

Returns: a List list holding the names of all the icons in the theme. You must first free each element in the list with free, then free the list itself with g_list_free().

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 iconThemeListContexts.

loadIcon

iconThemeLoadIcon Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Text

iconName: the name of the icon to lookup

-> Int32

size: the desired icon size. The resulting icon may not be exactly this size; see iconInfoLoadIcon.

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe Pixbuf)

Returns: the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use objectUnref to release your reference to the icon. Nothing if the icon isn’t found. (Can throw GError)

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 iconThemeLookupIcon followed by iconInfoLoadIcon.

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by connecting to the GtkWidget[styleSet](#signal:styleSet) signal. If for some reason you do not want to update the icon when the icon theme changes, you should consider using pixbufCopy 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.

loadIconForScale

iconThemeLoadIconForScale Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Text

iconName: the name of the icon to lookup

-> Int32

size: the desired icon size. The resulting icon may not be exactly this size; see iconInfoLoadIcon.

-> Int32

scale: desired scale

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe Pixbuf)

Returns: the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use objectUnref to release your reference to the icon. Nothing if the icon isn’t found. (Can throw GError)

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 iconThemeLookupIcon followed by iconInfoLoadIcon.

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by connecting to the GtkWidget[styleSet](#signal:styleSet) signal. If for some reason you do not want to update the icon when the icon theme changes, you should consider using pixbufCopy 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.

lookupByGicon

iconThemeLookupByGicon Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a, IsIcon b) 
=> a

iconTheme: a IconTheme

-> b

icon: the Icon to look up

-> Int32

size: desired icon size

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe IconInfo)

Returns: a IconInfo containing information about the icon, or Nothing if the icon wasn’t found. Unref with objectUnref

Looks up an icon and returns a IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using iconInfoLoadIcon.

When rendering on displays with high pixel densities you should not use a size multiplied by the scaling factor returned by functions like surfaceGetScaleFactor. Instead, you should use iconThemeLookupByGiconForScale, as the assets loaded for a given scaling factor may be different.

lookupByGiconForScale

iconThemeLookupByGiconForScale Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a, IsIcon b) 
=> a

iconTheme: a IconTheme

-> b

icon: the Icon to look up

-> Int32

size: desired icon size

-> Int32

scale: the desired scale

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe IconInfo)

Returns: a IconInfo containing information about the icon, or Nothing if the icon wasn’t found. Unref with objectUnref

Looks up an icon and returns a IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using iconInfoLoadIcon.

lookupIcon

iconThemeLookupIcon Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Text

iconName: the name of the icon to lookup

-> Int32

size: desired icon size

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe IconInfo)

Returns: a IconInfo object containing information about the icon, or Nothing if the icon wasn’t found.

Looks up a named icon and returns a IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using iconInfoLoadIcon. (iconThemeLoadIcon 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 surfaceGetScaleFactor. Instead, you should use iconThemeLookupIconForScale, as the assets loaded for a given scaling factor may be different.

lookupIconForScale

iconThemeLookupIconForScale Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Text

iconName: the name of the icon to lookup

-> Int32

size: desired icon size

-> Int32

scale: the desired scale

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe IconInfo)

Returns: a IconInfo object containing information about the icon, or Nothing if the icon wasn’t found.

Looks up a named icon for a particular window scale and returns a IconInfo containing information such as the filename of the icon. The icon can then be rendered into a pixbuf using iconInfoLoadIcon. (iconThemeLoadIcon combines these two steps if all you need is the pixbuf.)

new

iconThemeNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m IconTheme

Returns: the newly created IconTheme object.

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 iconThemeGetDefault or iconThemeGetForDisplay rather than creating a new icon theme object for scratch.

prependSearchPath

iconThemePrependSearchPath Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> [Char]

path: directory name to prepend to the icon path

-> m () 

Prepends a directory to the search path. See iconThemeSetSearchPath.

rescanIfNeeded

iconThemeRescanIfNeeded Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> m Bool

Returns: True if the icon theme has changed and needed to be reloaded.

Checks to see if the icon theme has changed; if it has, any currently cached information is discarded and will be reloaded next time iconTheme is accessed.

setCustomTheme

iconThemeSetCustomTheme Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> Maybe Text

themeName: name of icon theme to use instead of configured theme, or Nothing to unset a previously set custom theme

-> m () 

Sets the name of the icon theme that the IconTheme object uses overriding system configuration. This function cannot be called on the icon theme objects returned from iconThemeGetDefault and iconThemeGetForDisplay.

setDisplay

iconThemeSetDisplay Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a, IsDisplay b) 
=> a

iconTheme: a IconTheme

-> b

display: a Display

-> m () 

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.

setSearchPath

iconThemeSetSearchPath Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a) 
=> a

iconTheme: a IconTheme

-> [[Char]]

path: array of directories that are searched for icon themes

-> m () 

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

Signals

changed

type C_IconThemeChangedCallback = Ptr () -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type IconThemeChangedCallback = IO () Source #

Emitted when the current icon theme is switched or GTK+ detects that a change has occurred in the contents of the current icon theme.

afterIconThemeChanged :: (IsIconTheme a, MonadIO m) => a -> IconThemeChangedCallback -> m SignalHandlerId Source #

Connect a signal handler for the changed signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after iconTheme #changed callback

onIconThemeChanged :: (IsIconTheme a, MonadIO m) => a -> IconThemeChangedCallback -> m SignalHandlerId Source #

Connect a signal handler for the changed signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on iconTheme #changed callback