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
24 local setmetatable = setmetatable
27 -- lain.widgets.alsabar
33 background = beautiful.bg_normal,
39 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
41 color = beautiful.fg_normal,
49 local function worker(args)
50 local args = args or {}
51 local timeout = args.timeout or 5
52 local settings = args.settings or function() end
53 local width = args.width or 63
54 local height = args.heigth or 1
55 local ticks = args.ticks or false
56 local ticks_size = args.ticks_size or 7
57 local vertical = args.vertical or false
59 alsabar.cmd = args.cmd or "amixer"
60 alsabar.channel = args.channel or alsabar.channel
61 alsabar.step = args.step or alsabar.step
62 alsabar.colors = args.colors or alsabar.colors
63 alsabar.notifications = args.notifications or alsabar.notifications
64 alsabar.followtag = args.followtag or false
66 alsabar.bar = wibox.widget {
67 forced_height = height,
69 color = alsabar.colors.unmute,
70 background_color = alsabar.colors.background,
74 ticks_size = ticks_size,
75 widget = wibox.widget.progressbar,
76 layout = vertical and wibox.container.rotate
79 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
81 function alsabar.update(callback)
82 helpers.async(alsabar.cmd, function(mixer)
83 local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
84 if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted)
86 alsabar._current_level = tonumber(volu) or alsabar._current_level
87 alsabar.bar:set_value(alsabar._current_level / 100)
88 if (not mute and tonumber(volu) == 0) or mute == "off"
91 alsabar.tooltip:set_text ("[Muted]")
92 alsabar.bar.color = alsabar.colors.mute
94 alsabar._muted = false
95 alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu))
96 alsabar.bar.color = alsabar.colors.unmute
100 volume_now.level = tonumber(volu)
101 volume_now.status = mute
105 if type(callback) == "function" then callback() end
110 function alsabar.notify()
111 alsabar.update(function()
116 screen = alsabar.notifications.screen,
117 font = string.format("%s %s", alsabar.notifications.font,
118 alsabar.notifications.font_size),
119 fg = alsabar.notifications.color
122 if alsabar._muted then
123 preset.title = string.format("%s - Muted", alsabar.channel)
125 preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level)
128 int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
129 preset.text = string.format("[%s%s]", string.rep("|", int),
130 string.rep(" ", awful.screen.focused().mywibox.height - int))
132 if alsabar.followtag then preset.screen = awful.screen.focused() end
134 if alsabar._notify then
135 alsabar._notify = naughty.notify ({
136 replaces_id = alsabar._notify.id,
140 alsabar._notify = naughty.notify ({ preset = preset })
145 timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
146 helpers.newtimer(timer_id, timeout, alsabar.update)
151 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })