Name of icon to search as defined by Icon Theme Specification (i.e. without path and extension parts).
Preferred icon size to get.
Range of icontheme.file.IconThemeFile objects.
Base icon directories.
Allowed file extensions.
Allow searching for non-themed fallback if could not find icon in themes (non-themed icon can be any size).
Icon file path or empty string if not found. Note: If icon of some size was found in the icon theme, this algorithm does not check following themes, even if they contain icons with closer size. Therefore the icon found in the more preferred theme always has presedence over icons from other themes.
auto baseDirs = ["test"]; auto iconThemes = [openIconTheme("Tango", baseDirs), openIconTheme("hicolor", baseDirs)]; string found; //exact match found = findClosestIcon("folder", 32, iconThemes, baseDirs); assert(found == buildPath("test", "Tango", "32x32/places", "folder.png")); found = findClosestIcon("folder", 24, iconThemes, baseDirs); assert(found == buildPath("test", "Tango", "24x24/devices", "folder.png")); found = findClosestIcon!(subdir => subdir.context == "Places")("folder", 32, iconThemes, baseDirs); assert(found == buildPath("test", "Tango", "32x32/places", "folder.png")); found = findClosestIcon!(subdir => subdir.context == "Places")("folder", 24, iconThemes, baseDirs); assert(found == buildPath("test", "Tango", "32x32/places", "folder.png")); found = findClosestIcon!(subdir => subdir.context == "MimeTypes")("folder", 32, iconThemes, baseDirs); assert(found.empty); //hicolor has exact match, but Tango is more preferred. found = findClosestIcon("folder", 64, iconThemes, baseDirs); assert(found == buildPath("test", "Tango", "32x32/places", "folder.png")); //find xpm found = findClosestIcon("folder", 32, iconThemes, baseDirs, [".xpm"]); assert(found == buildPath("test", "Tango", "32x32/places", "folder.xpm")); //find big png, not exact match found = findClosestIcon("folder", 200, iconThemes, baseDirs); assert(found == buildPath("test", "Tango", "128x128/places", "folder.png")); //svg is closer found = findClosestIcon("folder", 200, iconThemes, baseDirs, [".png", ".svg"]); assert(found == buildPath("test", "Tango", "scalable/places", "folder.svg")); //lookup with fallback found = findClosestIcon("pidgin", 96, iconThemes, baseDirs); assert(found == buildPath("test", "pidgin.png")); //lookup without fallback found = findClosestIcon("pidgin", 96, iconThemes, baseDirs, defaultIconExtensions, No.allowFallbackIcon); assert(found.empty); found = findClosestIcon("text-plain", 48, iconThemes, baseDirs); assert(found == buildPath("test", "hicolor", "48x48/mimetypes", "text-plain.png")); found = findClosestIcon!(subdir => subdir.context == "MimeTypes")("text-plain", 48, iconThemes, baseDirs); assert(found == buildPath("test", "hicolor", "48x48/mimetypes", "text-plain.png")); found = findClosestIcon!(subdir => subdir.context == "Actions")("text-plain", 48, iconThemes, baseDirs); assert(found.empty);
icontheme.paths.baseIconDirs, lookupIcon, findFallbackIcon, iconSizeDistance
Find icon closest of the size. It uses icon theme cache wherever possible. The first perfect match is used.