Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
- Exported types
- Methods
- Overloaded methods
- addResourcePath
- appendSearchPath
- chooseIcon
- chooseIconForScale
- getDefault
- getExampleIconName
- getForDisplay
- getIconSizes
- getSearchPath
- hasIcon
- listContexts
- listIcons
- loadIcon
- loadIconForScale
- lookupByGicon
- lookupByGiconForScale
- lookupIcon
- lookupIconForScale
- new
- prependSearchPath
- rescanIfNeeded
- setCustomTheme
- setDisplay
- 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.
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
- newtype IconTheme = IconTheme (ManagedPtr IconTheme)
- class (GObject o, IsDescendantOf IconTheme o) => IsIconTheme o
- toIconTheme :: (MonadIO m, IsIconTheme o) => o -> m IconTheme
- noIconTheme :: Maybe IconTheme
- 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)
- iconThemeGetForDisplay :: (HasCallStack, MonadIO m, IsDisplay 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)
- 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 ()
- iconThemeSetDisplay :: (HasCallStack, MonadIO m, IsIconTheme a, IsDisplay 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
Eq IconTheme Source # | |
IsGValue IconTheme Source # | Convert |
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
Overloaded methods
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.
appendSearchPath
iconThemeAppendSearchPath Source #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> [Char] |
|
-> m () |
Appends a directory to the search path.
See iconThemeSetSearchPath
.
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.
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.
getDefault
:: (HasCallStack, MonadIO m) | |
=> m IconTheme | Returns: A unique |
Gets the icon theme for the default display. See
iconThemeGetForDisplay
.
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.)
getForDisplay
iconThemeGetForDisplay Source #
:: (HasCallStack, MonadIO m, IsDisplay a) | |
=> a |
|
-> m IconTheme | Returns: A unique |
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 #
:: (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.
getSearchPath
iconThemeGetSearchPath Source #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> m [[Char]] |
Gets the current search path. See iconThemeSetSearchPath
.
hasIcon
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> Text |
|
-> m Bool | Returns: |
Checks whether an icon theme includes an icon for a particular name.
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.
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
.
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[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 #
:: (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[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 #
:: (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 surfaceGetScaleFactor
. Instead, you should use
iconThemeLookupByGiconForScale
, as the assets loaded
for a given scaling factor may be different.
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
.
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 surfaceGetScaleFactor
. Instead, you should use
iconThemeLookupIconForScale
, as the assets loaded
for a given scaling factor may be different.
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.)
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 iconThemeGetForDisplay
rather than creating
a new icon theme object for scratch.
prependSearchPath
iconThemePrependSearchPath Source #
:: (HasCallStack, MonadIO m, IsIconTheme a) | |
=> a |
|
-> [Char] |
|
-> m () |
Prepends a directory to the search path.
See iconThemeSetSearchPath
.
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.
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 iconThemeGetForDisplay
.
setDisplay
:: (HasCallStack, MonadIO m, IsIconTheme a, IsDisplay b) | |
=> a |
|
-> b |
|
-> 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 #
:: (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.)
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