]> git.madduck.net Git - etc/awesome.git/blob - widgets/alsa.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

from asynchshell to awful.spawn.easy_async; started making every widget asynchronous
[etc/awesome.git] / widgets / alsa.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Luke Bonham                     
6       * (c) 2010, Adrian C. <anrxc@sysphere.org>  
7                                                   
8 --]]
9
10 local helpers      = require("lain.helpers")
11 local wibox        = require("wibox")
12 local string       = { match  = string.match,
13                        format = string.format }
14 local setmetatable = setmetatable
15
16 -- ALSA volume
17 -- lain.widgets.alsa
18 local alsa = helpers.make_widget_textbox()
19
20 local function worker(args)
21     local args     = args or {}
22     local timeout  = args.timeout or 5
23     local settings = args.settings or function() end
24
25     alsa.cmd     = args.cmd or "amixer"
26     alsa.channel = args.channel or "Master"
27     alsa.last    = {}
28
29     function alsa.update()
30         helpers.async(alsa.cmd, function(mixer)
31             local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
32             if alsa.last.level ~= l or alsa.last.status ~= s then
33                 volume_now = { level = l, status = s }
34                 widget = alsa.widget
35                 settings()
36                 alsa.last = volume_now
37             end
38         end)
39     end
40
41     timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
42     helpers.newtimer(timer_id, timeout, alsa.update)
43
44     return alsa
45 end
46
47 return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })