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

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:

Delete asyncshell_LOCAL_1080.lua
[etc/awesome.git] / widgets / alsa.lua.orig
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 <<<<<<< HEAD
12
13 local wibox           = require("wibox")
14
15 local io              = { popen  = io.popen }
16 =======
17 local read_pipe       = require("lain.helpers").read_pipe
18
19 local wibox           = require("wibox")
20
21 >>>>>>> upstream/master
22 local string          = { match  = string.match,
23                           format = string.format }
24
25 local setmetatable    = setmetatable
26
27 -- ALSA volume
28 -- lain.widgets.alsa
29 local alsa = {}
30
31 local function worker(args)
32     local args     = args or {}
33     local timeout  = args.timeout or 5
34     local settings = args.settings or function() end
35
36     alsa.cmd     = args.cmd or "amixer"
37     alsa.channel = args.channel or "Master"
38
39     alsa.widget = wibox.widget.textbox('')
40
41     function alsa.update()
42 <<<<<<< HEAD
43         local f = assert(io.popen(string.format("%s get %s", alsa.cmd, alsa.channel)))
44         local mixer = f:read("*a")
45         f:close()
46 =======
47         local mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
48 >>>>>>> upstream/master
49
50         volume_now = {}
51
52         volume_now.level, volume_now.status = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
53
54         if volume_now.level == nil
55         then
56             volume_now.level  = "0"
57             volume_now.status = "off"
58         end
59
60         if volume_now.status == ""
61         then
62             if volume_now.level == "0"
63             then
64                 volume_now.status = "off"
65             else
66                 volume_now.status = "on"
67             end
68         end
69
70         widget = alsa.widget
71         settings()
72     end
73
74     timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
75
76     newtimer(timer_id, timeout, alsa.update)
77
78     return setmetatable(alsa, { __index = alsa.widget })
79 end
80
81 return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })