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.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
10 local helpers = require("lain.helpers")
11 local awful = require("awful")
12 local naughty = require("naughty")
13 local wibox = require("wibox")
14 local math = { modf = math.modf }
15 local string = { format = string.format,
18 local tonumber = tonumber
19 local setmetatable = setmetatable
22 -- lain.widgets.alsabar
25 background = "#000000",
34 local function worker(args)
35 local args = args or {}
36 local timeout = args.timeout or 5
37 local settings = args.settings or function() end
38 local width = args.width or 63
39 local height = args.height or 1
40 local ticks = args.ticks or false
41 local ticks_size = args.ticks_size or 7
42 local vertical = args.vertical or false
44 alsabar.cmd = args.cmd or "amixer"
45 alsabar.channel = args.channel or "Master"
46 alsabar.colors = args.colors or alsabar.colors
47 alsabar.followtag = args.followtag or false
48 alsabar._notify = args.notify or "on"
49 alsabar.notification_preset = args.notification_preset
51 if not alsabar.notification_preset then
52 alsabar.notification_preset = naughty.config.defaults
53 alsabar.notification_preset.font = "Monospace 11"
56 alsabar.bar = wibox.widget {
57 forced_height = height,
59 color = alsabar.colors.unmute,
60 background_color = alsabar.colors.background,
64 ticks_size = ticks_size,
65 widget = wibox.widget.progressbar,
66 layout = vertical and wibox.container.rotate
69 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
71 function alsabar.update()
72 helpers.async(alsabar.cmd, function(mixer)
73 local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
74 if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) then
75 alsabar._current_level = tonumber(volu) or alsabar._current_level
76 alsabar.bar:set_value(alsabar._current_level / 100)
77 if (not mute and tonumber(volu) == 0) or mute == "off" then
79 alsabar.tooltip:set_text ("[Muted]")
80 alsabar.bar.color = alsabar.colors.mute
82 alsabar._muted = false
83 alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu))
84 alsabar.bar.color = alsabar.colors.unmute
88 volume_now.level = tonumber(volu)
89 volume_now.status = mute
96 function alsabar.notify()
97 alsabar.update(function()
98 local preset = alsabar.notification_preset
100 if alsabar._muted then
101 preset.title = string.format("%s - Muted", alsabar.channel)
103 preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level)
106 int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
107 preset.text = string.format("[%s%s]", string.rep("|", int),
108 string.rep(" ", awful.screen.focused().mywibox.height - int))
110 if alsabar.followtag then preset.screen = awful.screen.focused() end
112 alsabar.id = naughty.notify ({
113 replaces_id = alsabar.id,
119 timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
121 helpers.newtimer(timer_id, timeout, alsabar.update)
126 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })