geticon: also accept a size parameter
Many themes have prerendered icons of different sizes stored in subdirectories named as '<size>x<size>'. By looking in these directories when a specific icon size is specified, we can support themes in a rather straightforward way. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
d14d6959ea
commit
2ec6635adc
|
@ -180,12 +180,22 @@ end
|
||||||
-- @param iconname The name of the icon to search for.
|
-- @param iconname The name of the icon to search for.
|
||||||
-- @param exts Table of image extensions allowed, otherwise { 'png', gif' }
|
-- @param exts Table of image extensions allowed, otherwise { 'png', gif' }
|
||||||
-- @param dirs Table of dirs to search, otherwise { '/usr/share/pixmaps/' }
|
-- @param dirs Table of dirs to search, otherwise { '/usr/share/pixmaps/' }
|
||||||
function geticonpath(iconname, exts, dirs)
|
-- @param size Optional size. If this is specified, subdirectories <size>x<size>
|
||||||
|
-- of the dirs are searched first
|
||||||
|
function geticonpath(iconname, exts, dirs, size)
|
||||||
exts = exts or { 'png', 'gif' }
|
exts = exts or { 'png', 'gif' }
|
||||||
dirs = dirs or { '/usr/share/pixmaps/' }
|
dirs = dirs or { '/usr/share/pixmaps/' }
|
||||||
for _, d in pairs(dirs) do
|
for _, d in pairs(dirs) do
|
||||||
for _, e in pairs(exts) do
|
for _, e in pairs(exts) do
|
||||||
local icon = d .. iconname .. '.' .. e
|
local icon
|
||||||
|
if size then
|
||||||
|
icon = string.format("%s%ux%u/%s.%s",
|
||||||
|
d, size, size, iconname, e)
|
||||||
|
if file_readable(icon) then
|
||||||
|
return icon
|
||||||
|
end
|
||||||
|
end
|
||||||
|
icon = d .. iconname .. '.' .. e
|
||||||
if file_readable(icon) then
|
if file_readable(icon) then
|
||||||
return icon
|
return icon
|
||||||
end
|
end
|
||||||
|
|
|
@ -406,7 +406,7 @@ function notify(args)
|
||||||
if icon then
|
if icon then
|
||||||
-- try to guess icon if the provided one is non-existent/readable
|
-- try to guess icon if the provided one is non-existent/readable
|
||||||
if type(icon) == "string" and not util.file_readable(icon) then
|
if type(icon) == "string" and not util.file_readable(icon) then
|
||||||
icon = util.geticonpath(icon, config.icon_formats, config.icon_dirs)
|
icon = util.geticonpath(icon, config.icon_formats, config.icon_dirs, icon_size)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if we have an icon, use it
|
-- if we have an icon, use it
|
||||||
|
|
Loading…
Reference in New Issue