XDGKit v1.0.0-1
C++ XDG Utilities
Loading...
Searching...
No Matches
Public Member Functions | List of all members
XDGIconThemeManager Class Reference

Utility for finding icons. More...

#include <XDGIconThemeManager.h>

Public Member Functions

XDGKitkit () const noexcept
 Handle to the parent kit.
 
const std::vector< std::filesystem::path > & searchDirs () const noexcept
 Retrieves the directories to search for icon themes, in order of precedence.
 
const XDGMap< std::string, std::shared_ptr< XDGIconTheme > > & themes () const noexcept
 Retrieves all discovered icon themes.
 
bool reloadThemes (bool onlyIfCacheChanged=false) noexcept
 Reloads all available themes.
 
const XDGIconfindIcon (const std::string &icon, int32_t size, int32_t scale=1, uint32_t extensions=XDGIcon::PNG|XDGIcon::SVG, const std::vector< std::string > &themes={ "" }, uint32_t contexts=XDGIconDirectory::AnyContext) noexcept
 Searches for an icon within the specified themes.
 
void evictCache () noexcept
 Suggests to the OS to evict all mapped cache files from memory.
 

Detailed Description

Utility for finding icons.

Member Function Documentation

◆ kit()

XDGKit & kit ( ) const
inlinenoexcept

Handle to the parent kit.

◆ searchDirs()

const std::vector< std::filesystem::path > & searchDirs ( ) const
inlinenoexcept

Retrieves the directories to search for icon themes, in order of precedence.

The default search directories in order are:

  • ~/.icons
  • ~/.local/share/icons
  • $XDG_DATA_DIRS/icons
  • /usr/share/pixmaps
Returns
A constant reference to a vector containing the search directories.

◆ themes()

const XDGMap< std::string, std::shared_ptr< XDGIconTheme > > & themes ( ) const
inlinenoexcept

Retrieves all discovered icon themes.

Returns
A constant reference to a map where the key is the theme's directory basename (e.g. "Adwaita"), and the value is the corresponding XDGIconTheme object.

◆ reloadThemes()

bool reloadThemes ( bool  onlyIfCacheChanged = false)
noexcept

Reloads all available themes.

Scans the system and reloads all detected themes, replacing any previously loaded data.

Use this function when the set of themes has changed (e.g., after installation or removal).

Warning
All existing references to themes, theme directories, and icons will be invalidated after this call.
Parameters
onlyIfCacheChangedIf true, themes will only be reloaded if a change in the cache is detected.
Returns
true if themes were reloaded, false otherwise.

◆ findIcon()

const XDGIcon * findIcon ( const std::string &  icon,
int32_t  size,
int32_t  scale = 1,
uint32_t  extensions = XDGIcon::PNG | XDGIcon::SVG,
const std::vector< std::string > &  themes = { "" },
uint32_t  contexts = XDGIconDirectory::AnyContext 
)
noexcept

Searches for an icon within the specified themes.

This function attempts to locate an icon that matches the provided criteria (name, size, scale, and extensions) within the given list of themes.

Warning
It is not recommended to keep a reference to the returned icon, as it will be invalidated when reloadThemes() is called or when the XDGKit instance is removed.
Parameters
iconThe name of the icon to search for.
sizeThe desired nominal size of the icon.
scaleThe scale factor of the icon. Defaults to 1.
extensionsFlags indicating the acceptable image file extensions.
themesA list of theme names to search, in the specified order. An empty string ("") serves as a placeholder to search in all themes available.
contextsFlags to limit the search to the given XDGIconDirectory::Context (s).
Returns
A pointer to the closest matching icon, or nullptr if no match is found.

◆ evictCache()

void evictCache ( )
noexcept

Suggests to the OS to evict all mapped cache files from memory.

Use this function when themes are not expected to be used in the near future, helping to free up memory by prompting the OS to release the data.