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")
12 local awful = require("awful")
13 local beautiful = require("beautiful")
14 local naughty = require("naughty")
15 local wibox = require("wibox")
17 local math = { modf = math.modf }
18 local string = { format = string.format,
21 local tonumber = tonumber
23 local setmetatable = setmetatable
26 -- lain.widgets.alsabar
32 background = beautiful.bg_normal,
38 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
40 color = beautiful.fg_normal,
48 local function worker(args)
49 local args = args or {}
50 local timeout = args.timeout or 5
51 local settings = args.settings or function() end
52 local width = args.width or 63
53 local height = args.heigth or 1
54 local ticks = args.ticks or false
55 local ticks_size = args.ticks_size or 7
56 local vertical = args.vertical or false
58 alsabar.cmd = args.cmd or "amixer"
59 alsabar.channel = args.channel or alsabar.channel
60 alsabar.step = args.step or alsabar.step
61 alsabar.colors = args.colors or alsabar.colors
62 alsabar.notifications = args.notifications or alsabar.notifications
63 alsabar.followtag = args.followtag or false
65 alsabar.bar = wibox.widget {
66 forced_height = height,
68 color = alsabar.colors.unmute,
69 background_color = alsabar.colors.background,
73 ticks_size = ticks_size,
74 widget = wibox.widget.progressbar,
75 layout = vertical and wibox.container.rotate
78 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
80 function alsabar.update(callback)
81 helpers.async(alsabar.cmd, function(mixer)
82 local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
83 if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted)
85 alsabar._current_level = tonumber(volu) or alsabar._current_level
86 alsabar.bar:set_value(alsabar._current_level / 100)
87 if (not mute and tonumber(volu) == 0) or mute == "off"
90 alsabar.tooltip:set_text ("[Muted]")
91 alsabar.bar.color = alsabar.colors.mute
93 alsabar._muted = false
94 alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu))
95 alsabar.bar.color = alsabar.colors.unmute
99 volume_now.level = tonumber(volu)
100 volume_now.status = mute
104 if callback then callback() end
109 function alsabar.notify()
110 alsabar.update(function()
115 screen = alsabar.notifications.screen,
116 font = string.format("%s %s", alsabar.notifications.font,
117 alsabar.notifications.font_size),
118 fg = alsabar.notifications.color
121 if alsabar._muted then
122 preset.title = string.format("%s - Muted", alsabar.channel)
124 preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level)
127 int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
128 preset.text = string.format("[%s%s]", string.rep("|", int),
129 string.rep(" ", awful.screen.focused().mywibox.height - int))
131 if alsabar.followtag then preset.screen = awful.screen.focused() end
133 if alsabar._notify then
134 alsabar._notify = naughty.notify ({
135 replaces_id = alsabar._notify.id,
139 alsabar._notify = naughty.notify ({ preset = preset })
144 timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
145 helpers.newtimer(timer_id, timeout, alsabar.update)
150 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })