gi-gtk-3.0.37: Gtk bindings
CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
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.

Named icons are similar to the deprecated [Stock Items][gtkstock], and the distinction between the two may be a bit confusing. A few things to keep in mind:

  • Stock images usually are used in conjunction with [Stock Items][gtkstock], such as STOCK_OK or STOCK_OPEN. Named icons are easier to set up and therefore are more useful for new icons that an application wants to add, such as application icons or window icons.
  • Stock images can only be loaded at the symbolic sizes defined by the IconSize enumeration, or by custom sizes defined by iconSizeRegister, while named icons are more flexible and any pixel size can be specified.
  • Because stock images are closely tied to stock items, and thus to actions in the user interface, stock images may come in multiple variants for different widget states or writing directions.

A good rule of thumb is that if there is a stock image for what you want to use, use it, otherwise use a named icon. It turns out that internally stock images are generally defined in terms of one or more named icons. (An example of the more than one case is icons that depend on writing direction; STOCK_GO_FORWARD uses the two themed icons “gtk-stock-go-forward-ltr” and “gtk-stock-go-forward-rtl”.)

In many cases, named themes are used indirectly, via Image or stock items, 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 Screen 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.

Constructors

IconTheme (ManagedPtr IconTheme) 

Instances

Instances details
Eq IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

GObject IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

ManagedPtrNewtype IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

Methods

toManagedPtr :: IconTheme -> ManagedPtr IconTheme

TypedObject IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

Methods

glibType :: IO GType

HasParentTypes IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

IsGValue (Maybe IconTheme) Source #

Convert IconTheme to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.Gtk.Objects.IconTheme

Methods

gvalueGType_ :: IO GType

gvalueSet_ :: Ptr GValue -> Maybe IconTheme -> IO ()

gvalueGet_ :: Ptr GValue -> IO (Maybe IconTheme)

type ParentTypes IconTheme Source # 
Instance details

Defined in GI.Gtk.Objects.IconTheme

type ParentTypes IconTheme = '[Object]

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.

Methods

addBuiltinIcon

iconThemeAddBuiltinIcon Source #

Arguments

:: (HasCallStack, MonadIO m, IsPixbuf a) 
=> Text

iconName: the name of the icon to register

-> Int32

size: the size in pixels at which to register the icon (different images can be registered for the same icon name at different sizes.)

-> a

pixbuf: Pixbuf that contains the image to use for iconName

-> m () 

Deprecated: (Since version 3.14)Use iconThemeAddResourcePath to add application-specific icons to the icon theme.

Registers a built-in icon for icon theme lookups. The idea of built-in icons is to allow an application or library that uses themed icons to function requiring files to be present in the file system. For instance, the default images for all of GTK+’s stock icons are registered as built-icons.

In general, if you use iconThemeAddBuiltinIcon you should also install the icon in the icon theme, so that the icon is generally available.

This function will generally be used with pixbufs loaded via pixbufNewFromInline.

Since: 2.4

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.

Since: 3.14

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.

Since: 2.4

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.

Since: 2.12

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.

Since: 3.10

getDefault

iconThemeGetDefault Source #

Arguments

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

Returns: A unique IconTheme associated with the default screen. This icon theme is associated with the screen and can be used as long as the screen is open. Do not ref or unref it.

Gets the icon theme for the default screen. See iconThemeGetForScreen.

Since: 2.4

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

Since: 2.4

getForScreen

iconThemeGetForScreen Source #

Arguments

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

screen: a Screen

-> m IconTheme

Returns: A unique IconTheme associated with the given screen. This icon theme is associated with the screen and can be used as long as the screen is open. Do not ref or unref it.

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

Since: 2.4

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.

Since: 2.6

getSearchPath

iconThemeGetSearchPath Source #

Arguments

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

iconTheme: a IconTheme

-> m [[Char]] 

Gets the current search path. See iconThemeSetSearchPath.

Since: 2.4

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.

Since: 2.4

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.

Since: 2.12

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.

Since: 2.4

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](#g: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.

Since: 2.4

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](#g: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.

Since: 3.10

loadSurface

iconThemeLoadSurface Source #

Arguments

:: (HasCallStack, MonadIO m, IsIconTheme a, IsWindow b) 
=> 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

-> Maybe b

forWindow: Window to optimize drawing for, or Nothing

-> [IconLookupFlags]

flags: flags modifying the behavior of the icon lookup

-> m (Maybe Surface)

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 cairo_surface_destroy() 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 cairo surface. This is a convenience function; if more details about the icon are needed, use iconThemeLookupIcon followed by iconInfoLoadSurface.

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](#g:signal:styleSet) signal.

Since: 3.10

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 windowGetScaleFactor. Instead, you should use iconThemeLookupByGiconForScale, as the assets loaded for a given scaling factor may be different.

Since: 2.14

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.

Since: 3.10

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 windowGetScaleFactor. Instead, you should use iconThemeLookupIconForScale, as the assets loaded for a given scaling factor may be different.

Since: 2.4

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

Since: 3.10

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

Since: 2.4

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.

Since: 2.4

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.

Since: 2.4

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

Since: 2.4

setScreen

iconThemeSetScreen Source #

Arguments

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

iconTheme: a IconTheme

-> b

screen: a Screen

-> m () 

Sets the screen for an icon theme; the screen is used to track the user’s currently configured icon theme, which might be different for different screens.

Since: 2.4

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

Since: 2.4

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

genClosure_IconThemeChanged :: MonadIO m => IconThemeChangedCallback -> m (GClosure C_IconThemeChangedCallback) Source #

Wrap the callback into a GClosure.

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