Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (inaki@blueleaf.cc) |
Safe Haskell | None |
Language | Haskell2010 |
- Exported types
- Methods
- addBuiltinIcon
- addResourcePath
- appendSearchPath
- chooseIcon
- chooseIconForScale
- getDefault
- getExampleIconName
- getForScreen
- getIconSizes
- getSearchPath
- hasIcon
- listContexts
- listIcons
- loadIcon
- loadIconForScale
- loadSurface
- lookupByGicon
- lookupByGiconForScale
- lookupIcon
- lookupIconForScale
- new
- prependSearchPath
- rescanIfNeeded
- setCustomTheme
- setScreen
- setSearchPath
- Signals
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
orSTOCK_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 byiconSizeRegister
, 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
- newtype IconTheme = IconTheme (ManagedPtr IconTheme)
- class (GObject o, IsDescendantOf IconTheme o) => IsIconTheme o
- toIconTheme :: (MonadIO m, IsIconTheme o) => o -> m IconTheme
- noIconTheme :: Maybe IconTheme
- iconThemeAddBuiltinIcon :: (HasCallStack, MonadIO m, IsPixbuf a) => Text -> Int32 -> a -> m ()
- iconThemeAddResourcePath :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Text -> m ()
- iconThemeAppendSearchPath :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> [Char] -> m ()
- iconThemeChooseIcon :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> [Text] -> Int32 -> [IconLookupFlags] -> m (Maybe IconInfo)
- iconThemeChooseIconForScale :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> [Text] -> Int32 -> Int32 -> [IconLookupFlags] -> m (Maybe IconInfo)
- iconThemeGetDefault :: (HasCallStack, MonadIO m) => m IconTheme
- iconThemeGetExampleIconName :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> m (Maybe Text)
- iconThemeGetForScreen :: (HasCallStack, MonadIO m, IsScreen a) => a -> m IconTheme
- iconThemeGetIconSizes :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Text -> m [Int32]
- iconThemeGetSearchPath :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> m [[Char]]
- iconThemeHasIcon :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Text -> m Bool
- iconThemeListContexts :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> m [Text]
- iconThemeListIcons :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Maybe Text -> m [Text]
- iconThemeLoadIcon :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Text -> Int32 -> [IconLookupFlags] -> m (Maybe Pixbuf)
- iconThemeLoadIconForScale :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Text -> Int32 -> Int32 -> [IconLookupFlags] -> m (Maybe Pixbuf)
- iconThemeLoadSurface :: (HasCallStack, MonadIO m, IsIconTheme a, IsWindow b) => a -> Text -> Int32 -> Int32 -> Maybe b -> [IconLookupFlags] -> m (Maybe Surface)
- iconThemeLookupByGicon :: (HasCallStack, MonadIO m, IsIconTheme a, IsIcon b) => a -> b -> Int32 -> [IconLookupFlags] -> m (Maybe IconInfo)
- iconThemeLookupByGiconForScale :: (HasCallStack, MonadIO m, IsIconTheme a, IsIcon b) => a -> b -> Int32 -> Int32 -> [IconLookupFlags] -> m (Maybe IconInfo)
- iconThemeLookupIcon :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Text -> Int32 -> [IconLookupFlags] -> m (Maybe IconInfo)
- iconThemeLookupIconForScale :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Text -> Int32 -> Int32 -> [IconLookupFlags] -> m (Maybe IconInfo)
- iconThemeNew :: (HasCallStack, MonadIO m) => m IconTheme
- iconThemePrependSearchPath :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> [Char] -> m ()
- iconThemeRescanIfNeeded :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> m Bool
- iconThemeSetCustomTheme :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> Maybe Text -> m ()
- iconThemeSetScreen :: (HasCallStack, MonadIO m, IsIconTheme a, IsScreen b) => a -> b -> m ()
- iconThemeSetSearchPath :: (HasCallStack, MonadIO m, IsIconTheme a) => a -> [[Char]] -> m ()
- type C_IconThemeChangedCallback = Ptr () -> Ptr () -> IO ()
- type IconThemeChangedCallback = IO ()
- afterIconThemeChanged :: (IsIconTheme a, MonadIO m) => a -> IconThemeChangedCallback -> m SignalHandlerId
- genClosure_IconThemeChanged :: MonadIO m => IconThemeChangedCallback -> m (GClosure C_IconThemeChangedCallback)
- mk_IconThemeChangedCallback :: C_IconThemeChangedCallback -> IO (FunPtr C_IconThemeChangedCallback)
- noIconThemeChangedCallback :: Maybe IconThemeChangedCallback
- onIconThemeChanged :: (IsIconTheme a, MonadIO m) => a -> IconThemeChangedCallback -> m SignalHandlerId
- wrap_IconThemeChangedCallback :: IconThemeChangedCallback -> C_IconThemeChangedCallback
Exported types
Memory-managed wrapper type.
Instances
GObject IconTheme Source # | |
Defined in GI.Gtk.Objects.IconTheme gobjectType :: IO GType # | |
HasParentTypes IconTheme Source # | |
Defined in GI.Gtk.Objects.IconTheme | |
type ParentTypes IconTheme Source # | |
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
(GObject o, IsDescendantOf IconTheme o) => IsIconTheme o Source # | |
Defined in GI.Gtk.Objects.IconTheme |
toIconTheme :: (MonadIO m, IsIconTheme o) => o -> m IconTheme Source #
Methods
addBuiltinIcon
iconThemeAddBuiltinIcon Source #
:: (HasCallStack, MonadIO m, IsPixbuf a) | |
=> Text |
|
-> Int32 |
|
-> a |
|
-> 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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> 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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> [Char] |
|
-> m () |
Appends a directory to the search path.
See iconThemeSetSearchPath
.
Since: 2.4
chooseIcon
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> [Text] |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> m (Maybe IconInfo) | Returns: a |
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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> [Text] |
|
-> Int32 |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> m (Maybe IconInfo) | Returns: a |
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
:: (HasCallStack, MonadIO m) | |
=> m IconTheme | Returns: A unique |
Gets the icon theme for the default screen. See
iconThemeGetForScreen
.
Since: 2.4
getExampleIconName
iconThemeGetExampleIconName Source #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> m (Maybe Text) | Returns: the name of an example icon or |
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 #
:: (HasCallStack, MonadIO m, IsScreen a) | |
=> a |
|
-> m IconTheme | Returns: A unique |
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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> m [Int32] | Returns: An newly
allocated array describing the sizes at which the icon is
available. The array should be freed with |
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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> m [[Char]] |
Gets the current search path. See iconThemeSetSearchPath
.
Since: 2.4
hasIcon
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> m Bool | Returns: |
Checks whether an icon theme includes an icon for a particular name.
Since: 2.4
listContexts
iconThemeListContexts Source #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> m [Text] | Returns: a |
Gets the list of contexts available within the current
hierarchy of icon themes.
See iconThemeListIcons
for details about contexts.
Since: 2.12
listIcons
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Maybe Text |
|
-> m [Text] | Returns: a |
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
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> 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 |
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::style-set 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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> Int32 |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> 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 |
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::style-set 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
:: (HasCallStack, MonadIO m, IsIconTheme a, IsWindow b) | |
=> a |
|
-> Text |
|
-> Int32 |
|
-> Int32 |
|
-> Maybe b | |
-> [IconLookupFlags] |
|
-> 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 |
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::style-set signal.
Since: 3.10
lookupByGicon
iconThemeLookupByGicon Source #
:: (HasCallStack, MonadIO m, IsIconTheme a, IsIcon b) | |
=> a |
|
-> b |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> m (Maybe IconInfo) | Returns: a |
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 #
:: (HasCallStack, MonadIO m, IsIconTheme a, IsIcon b) | |
=> a |
|
-> b |
|
-> Int32 |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> m (Maybe IconInfo) | Returns: a |
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
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> m (Maybe IconInfo) | Returns: a |
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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> Int32 |
|
-> Int32 |
|
-> [IconLookupFlags] |
|
-> m (Maybe IconInfo) | Returns: a |
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
:: (HasCallStack, MonadIO m) | |
=> m IconTheme | Returns: the newly created |
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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> [Char] |
|
-> m () |
Prepends a directory to the search path.
See iconThemeSetSearchPath
.
Since: 2.4
rescanIfNeeded
iconThemeRescanIfNeeded Source #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> m Bool | Returns: |
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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Maybe Text |
|
-> 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
:: (HasCallStack, MonadIO m, IsIconTheme a, IsScreen b) | |
=> a |
|
-> b |
|
-> 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 #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> [[Char]] |
|
-> 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
.
mk_IconThemeChangedCallback :: C_IconThemeChangedCallback -> IO (FunPtr C_IconThemeChangedCallback) Source #
Generate a function pointer callable from C code, from a C_IconThemeChangedCallback
.
noIconThemeChangedCallback :: Maybe IconThemeChangedCallback Source #
A convenience synonym for
.Nothing
:: Maybe
IconThemeChangedCallback
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