diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index 3b15ebcc..fb813d65 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -174,6 +174,24 @@ function getdir(d) end end +--- Search for an icon and return the full path. +-- It searches for the icon path under the directories given w/the right ext +-- @param iconname The name of the icon to search for. +-- @param exts Table of image extensions allowed, otherwise { 'png', gif' } +-- @param dirs Table of dirs to search, otherwise { '/usr/share/pixmaps/' } +function geticonpath(iconname, exts, dirs) + exts = exts or { 'png', 'gif' } + dirs = dirs or { '/usr/share/pixmaps/' } + for _, d in pairs(dirs) do + for _, e in pairs(exts) do + local icon = d .. iconname .. '.' .. e + if file_readable(icon) then + return icon + end + end + end +end + --- Check if file exists and is readable. -- @param filename The file path -- @return True if file exists and readable. diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in index 62f03280..f7e52717 100644 --- a/lib/naughty.lua.in +++ b/lib/naughty.lua.in @@ -243,20 +243,6 @@ local function getById(id) end end --- Search for an icon in specified directories with a specified format --- @param icon Name of the icon --- @return full path of the icon, or nil of no icon was found -local function getIcon(name) - for d, dir in pairs(config.icon_dirs) do - for f, format in pairs(config.icon_formats) do - local icon = dir .. name .. "." .. format - if util.file_readable(icon) then - return icon - end - end - end -end - --- Create notification. args is a dictionary of (optional) arguments. -- @param text Text of the notification. Default: '' -- @param title Title of the notification. Default: nil @@ -397,7 +383,7 @@ function notify(args) if icon then -- try to guess icon if the provided one is non-existent/readable if type(icon) == "string" and not util.file_readable(icon) then - icon = getIcon(icon) + icon = util.geticonpath(icon, config.icon_formats, config.icon_dirs) end -- if we have an icon, use it