From 3636b884d35b9736f98328891897c0c0aabe7d83 Mon Sep 17 00:00:00 2001 From: Majic Date: Tue, 1 Nov 2011 18:42:37 -0700 Subject: [PATCH] Private naughty.getIcon() -> public awful.util.geticonpath() Signed-off-by: Uli Schlachter --- lib/awful/util.lua.in | 18 ++++++++++++++++++ lib/naughty.lua.in | 16 +--------------- 2 files changed, 19 insertions(+), 15 deletions(-) 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