port volume widget to freebsd

This commit is contained in:
mutlusun 2017-01-25 17:56:22 +01:00 committed by Jörg Thalheim
parent f86c60d2fd
commit 54baa996c4
No known key found for this signature in database
GPG Key ID: CA4106B8D7CC79FA
2 changed files with 40 additions and 2 deletions

View File

@ -0,0 +1,38 @@
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { match = string.match }
local helpers = require("vicious.helpers")
-- }}}
-- Volume: provides volume levels and state of requested mixer
-- vicious.widgets.volume_freebsd
local volume_freebsd = {}
-- {{{ Volume widget type
local function worker(format, warg)
if not warg then return end
local mixer_state = { "", "" }
-- Get mixer control contents
f = io.popen("mixer -s " .. helpers.shellquote(warg))
local mixer = f:read()
f:close()
-- Capture mixer control state: [5%] ... ... [on]
local voll, volr = string.match(mixer, "([%d]+):([%d]+)$")
if voll == "0" and volr == "0" then
return {0, 0, mixer_state[2]}
else
return {voll, volr, mixer_state[1]}
end
end
-- }}}
return setmetatable(volume_freebsd, { __call = function(_, ...) return worker(...) end })

View File

@ -14,7 +14,7 @@ local helpers = require("vicious.helpers")
-- Volume: provides volume levels and state of requested ALSA mixers
-- vicious.widgets.volume
local volume = {}
local volume_linux = {}
-- {{{ Volume widget type
@ -51,4 +51,4 @@ local function worker(format, warg)
end
-- }}}
return setmetatable(volume, { __call = function(_, ...) return worker(...) end })
return setmetatable(volume_linux, { __call = function(_, ...) return worker(...) end })