icons: move icon lookup in a seperate module

This commit is contained in:
Vincent Bernat 2012-07-15 22:22:38 +02:00
parent 52090d90ea
commit 335b80262d
8 changed files with 104 additions and 26 deletions

View file

@ -6,6 +6,10 @@ local tonumber = tonumber
local string = string
local os = os
-- A bit odd, but...
require("lib/icons")
local icons = package.loaded["vbe/icons"]
module("vbe/brightness")
local nid = nil
@ -15,7 +19,8 @@ local function change(what)
if not out then return end
out = tonumber(out)
local icon = "/usr/share/icons/HighContrast/32x32/status/display-brightness.png"
local icon = icons.lookup({name = "display-brightness",
type = "status"})
nid = naughty.notify({ text = string.format("%3d %%", out),
icon = icon,

63
lib/icons.lua Normal file
View file

@ -0,0 +1,63 @@
-- Lookup function for icons
local paths = {
"/usr/share/icons/gnome-wine",
"/usr/share/icons/gnome",
"/usr/share/icons/hicolor",
"/usr/share/icons/HighContrast",
"/usr/share/fvwm-crystal/fvwm/icons/Default",
}
local sizes = {
'32x32',
'24x24',
'22x22',
'16x16',
}
local types = {
'apps',
'actions',
'devices',
'status',
}
local formats = {
".png",
".xpm"
}
local assert = assert
local type = type
local pairs = pairs
local awful = require("awful")
module("vbe/icons")
-- Lookup for an icon. Return full path.
function lookup(arg)
local inames = assert(arg.name)
local isizes = arg.size or sizes
local itypes = arg.type or types
local ipaths = paths
local iformats = formats
if type(isizes) ~= "table" then isizes = { isizes } end
if type(itypes) ~= "table" then itypes = { itypes } end
if type(inames) ~= "table" then inames = { inames } end
for _, path in pairs(ipaths) do
for _, size in pairs(isizes) do
for _, t in pairs(itypes) do
for _, name in pairs(inames) do
if name then
for _, name in pairs({name, name:lower()}) do
for _, ext in pairs(iformats) do
local icon = path .. "/" .. size .. "/" .. t .. "/" .. name .. ext
if awful.util.file_readable(icon) then
return icon
end
end
end
end
end
end
end
end
end

View file

@ -6,6 +6,10 @@ local tonumber = tonumber
local string = string
local os = os
-- A bit odd, but...
require("lib/icons")
local icons = package.loaded["vbe/icons"]
module("vbe/volume")
local volid = nil
@ -25,7 +29,8 @@ local function change(what)
elseif vol < 60 then
icon = "medium"
end
icon = "/usr/share/icons/gnome/32x32/status/audio-volume-" .. icon .. ".png"
icon = icons.lookup({name = "audio-volume-" .. icon,
type = "status"})
volid = naughty.notify({ text = string.format("%3d %%", vol),
icon = icon,