]> 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:

Created Layouts (markdown)
[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 newtimer        = require("lain.helpers").newtimer
11
12 local wibox           = require("wibox")
13
14 local io              = { popen  = io.popen }
15 local string          = { match  = string.match }
16
17 local setmetatable    = setmetatable
18
19 -- ALSA volume
20 -- lain.widgets.alsa
21 local alsa = {}
22
23 local function worker(args)
24     local args     = args or {}
25     local timeout  = args.timeout or 5
26     local channel  = args.channel or "Master"
27     local settings = args.settings or function() end
28
29     alsa.widget = wibox.widget.textbox('')
30
31     function alsa.update()
32         local f = assert(io.popen('amixer get ' .. channel))
33         local mixer = f:read("*all")
34         f:close()
35
36         volume_now = {}
37
38         volume_now.level, volume_now.status = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
39
40         if volume_now.level == nil
41         then
42             volume_now.level  = "0"
43             volume_now.status = "off"
44         end
45
46         if volume_now.status == ""
47         then
48             if volume_now.level == "0"
49             then
50                 volume_now.status = "off"
51             else
52                 volume_now.status = "on"
53             end
54         end
55
56         widget = alsa.widget
57         settings()
58     end
59
60     newtimer("alsa", timeout, alsa.update)
61
62     return setmetatable(alsa, { __index = alsa.widget })
63 end
64
65 return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })