vicious/extra/ossvol.lua

54 lines
1.3 KiB
Lua
Raw Normal View History

---------------------------------------------------
-- Licensed under the GNU General Public License v2
2010-05-01 20:03:10 +02:00
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
2010-05-01 20:03:10 +02:00
local string = { match = string.match }
-- }}}
-- Ossvol: provides volume levels of requested OSS mixers
module("vicious.widgets.ossvol")
-- {{{ Volume widget type
local function worker(format, warg)
if not warg then return end
local mixer_state = {
["on"] = "", -- "",
["off"] = "" -- "M"
}
-- Get mixer control contents
2010-05-01 20:03:10 +02:00
local f = io.popen("ossmix -c")
local mixer = f:read("*all")
f:close()
-- Capture mixer control state
2010-05-01 20:03:10 +02:00
local volu = tonumber(string.match(mixer, warg .. "[%s]([%d%.]+)"))/0.25
local mute = string.match(mixer, "vol%.mute[%s]([%a]+)")
-- Handle mixers without data
if volu == nil then
2010-05-01 20:03:10 +02:00
return {0, mixer_state["off"]}
end
2010-05-01 20:03:10 +02:00
-- Handle mixers without mute
if mute == "OFF" and volu == "0"
-- Handle mixers that are muted
2010-05-01 20:03:10 +02:00
or mute == "ON" then
mute = mixer_state["off"]
else
2010-05-01 20:03:10 +02:00
mute = mixer_state["on"]
end
return {volu, mute}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })