]> git.madduck.net Git - etc/awesome.git/blob - .config/awesome/lain/widget/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:

Flameshot shortcut
[etc/awesome.git] / .config / awesome / lain / widget / alsa.lua
1 --[[
2
3      Licensed under GNU General Public License v2
4       * (c) 2013, Luca CPZ
5       * (c) 2010, Adrian C. <anrxc@sysphere.org>
6
7 --]]
8
9 local helpers = require("lain.helpers")
10 local shell   = require("awful.util").shell
11 local wibox   = require("wibox")
12 local string  = string
13
14 -- ALSA volume
15 -- lain.widget.alsa
16
17 local function factory(args)
18     local alsa     = { widget = wibox.widget.textbox() }
19     local args     = args or {}
20     local timeout  = args.timeout or 5
21     local settings = args.settings or function() end
22
23     alsa.cmd           = args.cmd or "amixer"
24     alsa.channel       = args.channel or "Master"
25     alsa.togglechannel = args.togglechannel
26
27     local format_cmd = string.format("%s get %s", alsa.cmd, alsa.channel)
28
29     if alsa.togglechannel then
30         format_cmd = { shell, "-c", string.format("%s get %s; %s get %s",
31         alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) }
32     end
33
34     alsa.last = {}
35
36     function alsa.update()
37         helpers.async(format_cmd, function(mixer)
38             local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
39             if alsa.last.level ~= l or alsa.last.status ~= s then
40                 volume_now = { level = l, status = s }
41                 widget = alsa.widget
42                 settings()
43                 alsa.last = volume_now
44             end
45         end)
46     end
47
48     helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update)
49
50     return alsa
51 end
52
53 return factory