From 2ec6635adcddbc71ff98e71ae2c8a3bf522a7b04 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 28 May 2012 19:16:11 +0200 Subject: [PATCH] geticon: also accept a size parameter Many themes have prerendered icons of different sizes stored in subdirectories named as 'x'. 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 --- lib/awful/util.lua.in | 14 ++++++++++++-- lib/naughty.lua.in | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index 2c6622ce3..8c326fe96 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -180,12 +180,22 @@ end -- @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) +-- @param size Optional size. If this is specified, subdirectories x +-- of the dirs are searched first +function geticonpath(iconname, exts, dirs, size) 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 + 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 return icon end diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in index 5f575590b..98cf9f325 100644 --- a/lib/naughty.lua.in +++ b/lib/naughty.lua.in @@ -406,7 +406,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 = util.geticonpath(icon, config.icon_formats, config.icon_dirs) + icon = util.geticonpath(icon, config.icon_formats, config.icon_dirs, icon_size) end -- if we have an icon, use it