2013-09-07 12:06:42 +02:00
|
|
|
|
|
|
|
--[[
|
2013-09-13 18:15:25 +02:00
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
|
|
|
* (c) 2013, Luke Bonham
|
|
|
|
* (c) 2010, Adrian C. <anrxc@sysphere.org>
|
|
|
|
|
2013-09-07 12:06:42 +02:00
|
|
|
--]]
|
|
|
|
|
2013-09-10 23:02:11 +02:00
|
|
|
local newtimer = require("lain.helpers").newtimer
|
2013-09-07 12:06:42 +02:00
|
|
|
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
2013-09-10 23:02:11 +02:00
|
|
|
local io = { popen = io.popen }
|
2015-02-16 22:43:06 +01:00
|
|
|
local string = { match = string.match,
|
|
|
|
format = string.format }
|
2013-09-07 12:06:42 +02:00
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
2013-09-10 23:02:11 +02:00
|
|
|
-- ALSA volume
|
|
|
|
-- lain.widgets.alsa
|
|
|
|
local alsa = {}
|
|
|
|
|
|
|
|
local function worker(args)
|
|
|
|
local args = args or {}
|
|
|
|
local timeout = args.timeout or 5
|
|
|
|
local settings = args.settings or function() end
|
|
|
|
|
2015-03-09 21:33:11 +01:00
|
|
|
alsa.card = args.card or "0"
|
|
|
|
alsa.channel = args.channel or "Master"
|
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
alsa.widget = wibox.widget.textbox('')
|
2013-09-10 23:02:11 +02:00
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
function alsa.update()
|
2015-03-09 21:33:11 +01:00
|
|
|
local f = assert(io.popen(string.format("amixer -c %s -M get %s", alsa.card, alsa.channel)))
|
2014-09-26 12:41:35 +02:00
|
|
|
local mixer = f:read("*a")
|
2013-09-07 12:06:42 +02:00
|
|
|
f:close()
|
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
volume_now = {}
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
volume_now.level, volume_now.status = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
2013-09-10 23:02:11 +02:00
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
if volume_now.level == nil
|
2013-09-07 12:06:42 +02:00
|
|
|
then
|
2013-09-13 00:07:44 +02:00
|
|
|
volume_now.level = "0"
|
|
|
|
volume_now.status = "off"
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
if volume_now.status == ""
|
2013-09-07 12:06:42 +02:00
|
|
|
then
|
2013-09-13 00:07:44 +02:00
|
|
|
if volume_now.level == "0"
|
2013-09-10 23:02:11 +02:00
|
|
|
then
|
2013-09-13 00:07:44 +02:00
|
|
|
volume_now.status = "off"
|
2013-09-10 23:02:11 +02:00
|
|
|
else
|
2013-09-13 00:07:44 +02:00
|
|
|
volume_now.status = "on"
|
2013-09-10 23:02:11 +02:00
|
|
|
end
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
widget = alsa.widget
|
2013-09-10 23:02:11 +02:00
|
|
|
settings()
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
newtimer("alsa", timeout, alsa.update)
|
2013-09-10 23:02:11 +02:00
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
return setmetatable(alsa, { __index = alsa.widget })
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
|