diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2010-08-29 00:49:57 +0200 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2010-08-29 00:49:57 +0200 |
commit | 26b0395ba988948a7cc8b79d08faf6a57058886a (patch) | |
tree | ae475623e8b249aa8b8d29b57878737f09c165f5 /contrib/ossvol.lua | |
parent | 0d6333ed61a305c8a18fd4eb42ad33a353627bc9 (diff) | |
download | vicious-legacy-26b0395ba988948a7cc8b79d08faf6a57058886a.tar.xz |
contrib: imported contrib widgets
Diffstat (limited to 'contrib/ossvol.lua')
-rw-r--r-- | contrib/ossvol.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/contrib/ossvol.lua b/contrib/ossvol.lua new file mode 100644 index 0000000..eb14cb8 --- /dev/null +++ b/contrib/ossvol.lua @@ -0,0 +1,53 @@ +--------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2010, Adrian C. <anrxc@sysphere.org> +--------------------------------------------------- + +-- {{{ Grab environment +local tonumber = tonumber +local io = { popen = io.popen } +local setmetatable = setmetatable +local string = { match = string.match } +-- }}} + + +-- Ossvol: provides volume levels of requested OSS mixers +module("vicious.contrib.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 + local f = io.popen("ossmix -c") + local mixer = f:read("*all") + f:close() + + -- Capture mixer control state + 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 + return {0, mixer_state["off"]} + end + + -- Handle mixers without mute + if mute == "OFF" and volu == "0" + -- Handle mixers that are muted + or mute == "ON" then + mute = mixer_state["off"] + else + mute = mixer_state["on"] + end + + return {volu, mute} +end +-- }}} + +setmetatable(_M, { __call = function(_, ...) return worker(...) end }) |