Documentation
¶
Overview ¶
Package icontheme is a pure-Go (CGO_ENABLED=0) implementation of the freedesktop.org Icon Theme Specification lookup algorithm.
It resolves an icon name (such as the value of a .desktop file's Icon= key) to a concrete file path on disk at a requested pixel size and scale, following the specification exactly: it parses index.theme files, honours theme inheritance (with an implicit fall back to the hicolor base theme), and applies the DirectoryMatchesSize / DirectorySizeDistance rules to pick the best directory before falling back to unthemed pixmaps and, finally, a generic name-truncation fallback.
The package returns a path only; rasterising the file (PNG/XPM/SVG) is the caller's responsibility. It never rasterises, decodes or otherwise inspects the pixels, so it stays dependency-light and fast.
Specification: https://specifications.freedesktop.org/icon-theme/latest/
Index ¶
Constants ¶
const HicolorTheme = "hicolor"
HicolorTheme is the name of the base theme every icon theme implicitly inherits from, as mandated by the specification.
Variables ¶
var ErrNotFound = errors.New("icontheme: icon not found")
ErrNotFound is returned by Lookup and FindIcon when no matching icon file can be located anywhere in the search path.
Functions ¶
func DefaultBaseDirs ¶
func DefaultBaseDirs() []string
DefaultBaseDirs returns the ordered list of icon base directories per the specification: $HOME/.icons, $XDG_DATA_HOME/icons, each $XDG_DATA_DIRS/icons, and finally /usr/share/pixmaps.
Types ¶
type Theme ¶
type Theme struct {
// contains filtered or unexported fields
}
Theme resolves icon names for a chosen icon theme. It parses and caches the index.theme of the theme and every theme it inherits from, and memoises individual lookups. A Theme is safe for concurrent use by multiple goroutines.
func New ¶
New returns a Theme for the named icon theme using the standard base directories derived from the XDG base-directory specification, plus $HOME/.icons and /usr/share/pixmaps.
func NewWithBaseDirs ¶
NewWithBaseDirs returns a Theme for the named icon theme that searches the supplied base directories in order. It is the injection seam used for testing and for callers that manage their own icon search path.
func (*Theme) FindIcon ¶
FindIcon resolves the first of the candidate names that can be found, searching them in order. It is a convenience for a .desktop Icon= value followed by generic fallbacks. It returns ErrNotFound if none match.
func (*Theme) Lookup ¶
Lookup resolves icon name at the requested size (in device-independent pixels) and scale, returning the path to the best matching file. It searches the theme's inheritance chain, then hicolor, then unthemed pixmaps, then a generic fallback that strips trailing "-" separated components. It returns ErrNotFound if no file matches.