2013-09-07 12:06:42 +02:00
|
|
|
--[[
|
2017-09-04 12:43:00 +02:00
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
2017-09-11 06:51:52 +02:00
|
|
|
* (c) 2013, Luca CPZ
|
2017-09-04 12:43:00 +02:00
|
|
|
* (c) 2010, Adrian C. <anrxc@sysphere.org>
|
|
|
|
|
2013-09-07 12:06:42 +02:00
|
|
|
--]]
|
|
|
|
|
2017-02-08 20:45:11 +01:00
|
|
|
local helpers = require("lain.helpers")
|
|
|
|
local shell = require("awful.util").shell
|
|
|
|
local wibox = require("wibox")
|
2018-11-28 20:43:04 +01:00
|
|
|
local string = string
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2013-09-10 23:02:11 +02:00
|
|
|
-- ALSA volume
|
2017-02-08 14:15:48 +01:00
|
|
|
-- lain.widget.alsa
|
2013-09-10 23:02:11 +02:00
|
|
|
|
2017-02-08 20:45:11 +01:00
|
|
|
local function factory(args)
|
2020-11-29 22:48:32 +01:00
|
|
|
args = args or {}
|
2020-10-31 18:11:29 +01:00
|
|
|
local alsa = { widget = args.widget or wibox.widget.textbox() }
|
2015-10-20 15:17:44 +02:00
|
|
|
local timeout = args.timeout or 5
|
2013-09-10 23:02:11 +02:00
|
|
|
local settings = args.settings or function() end
|
|
|
|
|
2017-01-24 21:33:16 +01:00
|
|
|
alsa.cmd = args.cmd or "amixer"
|
2017-01-23 17:58:35 +01:00
|
|
|
alsa.channel = args.channel or "Master"
|
|
|
|
alsa.togglechannel = args.togglechannel
|
|
|
|
|
2017-01-24 21:33:16 +01:00
|
|
|
local format_cmd = string.format("%s get %s", alsa.cmd, alsa.channel)
|
|
|
|
|
2017-01-23 17:58:35 +01:00
|
|
|
if alsa.togglechannel then
|
2017-01-24 21:33:16 +01:00
|
|
|
format_cmd = { shell, "-c", string.format("%s get %s; %s get %s",
|
2017-01-23 17:58:35 +01:00
|
|
|
alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) }
|
|
|
|
end
|
|
|
|
|
|
|
|
alsa.last = {}
|
2013-09-10 23:02:11 +02:00
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
function alsa.update()
|
2017-01-24 21:33:16 +01:00
|
|
|
helpers.async(format_cmd, function(mixer)
|
2017-01-20 20:58:22 +01:00
|
|
|
local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
|
|
|
if alsa.last.level ~= l or alsa.last.status ~= s then
|
|
|
|
volume_now = { level = l, status = s }
|
|
|
|
widget = alsa.widget
|
|
|
|
settings()
|
|
|
|
alsa.last = volume_now
|
|
|
|
end
|
|
|
|
end)
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2017-01-24 18:19:15 +01:00
|
|
|
helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update)
|
2017-01-23 17:58:35 +01:00
|
|
|
|
2017-01-25 17:13:14 +01:00
|
|
|
return alsa
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2017-02-08 20:45:11 +01:00
|
|
|
return factory
|