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 newtimer = require("lain.helpers").newtimer
12 local awful = require("awful")
13 local beautiful = require("beautiful")
14 local naughty = require("naughty")
16 local io = { popen = io.popen }
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,
37 terminal = terminal or "xterm",
38 mixer = terminal .. " -e alsamixer",
41 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
43 color = beautiful.fg_normal,
52 function alsabar.notify()
59 screen = alsabar.notifications.screen,
60 font = alsabar.notifications.font .. " " ..
61 alsabar.notifications.font_size,
62 fg = alsabar.notifications.color
67 preset.title = alsabar.channel .. " - Muted"
69 preset.title = alsabar.channel .. " - " .. alsabar._current_level .. "%"
72 int = math.modf((alsabar._current_level / 100) * alsabar.notifications.bar_size)
74 .. string.rep("|", int)
75 .. string.rep(" ", alsabar.notifications.bar_size - int)
78 if alsabar._notify ~= nil then
79 alsabar._notify = naughty.notify ({
80 replaces_id = alsabar._notify.id,
84 alsabar._notify = naughty.notify ({
90 local function worker(args)
91 local args = args or {}
92 local timeout = args.timeout or 5
93 local settings = args.settings or function() end
94 local width = args.width or 63
95 local height = args.heigth or 1
96 local ticks = args.ticks or false
97 local ticks_size = args.ticks_size or 7
98 local vertical = args.vertical or false
100 alsabar.cmd = args.cmd or "amixer"
101 alsabar.channel = args.channel or alsabar.channel
102 alsabar.step = args.step or alsabar.step
103 alsabar.colors = args.colors or alsabar.colors
104 alsabar.notifications = args.notifications or alsabar.notifications
106 alsabar.bar = awful.widget.progressbar()
108 alsabar.bar:set_background_color(alsabar.colors.background)
109 alsabar.bar:set_color(alsabar.colors.unmute)
110 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
111 alsabar.bar:set_width(width)
112 alsabar.bar:set_height(height)
113 alsabar.bar:set_ticks(ticks)
114 alsabar.bar:set_ticks_size(ticks_size)
115 alsabar.bar:set_vertical(vertical)
117 function alsabar.update()
118 -- Get mixer control contents
119 local f = assert(io.popen(string.format("%s get %s", alsabar.cmd, alsabar.channel)))
120 local mixer = f:read("*a")
123 -- Capture mixer control state: [5%] ... ... [on]
124 local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
131 alsabar._current_level = tonumber(volu)
132 alsabar.bar:set_value(alsabar._current_level / 100)
133 if not mute and tonumber(volu) == 0 or mute == "off"
135 alsabar._muted = true
136 alsabar.tooltip:set_text (" [Muted] ")
137 alsabar.bar:set_color(alsabar.colors.mute)
139 alsabar._muted = false
140 alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
141 alsabar.bar:set_color(alsabar.colors.unmute)
145 volume_now.level = tonumber(volu)
146 volume_now.status = mute
150 alsabar.bar:buttons (awful.util.table.join (
151 awful.button ({}, 1, function()
152 awful.util.spawn(alsabar.mixer)
154 awful.button ({}, 3, function()
155 awful.util.spawn(string.format("%s set %s toggle", alsabar.cmd, alsabar.channel))
158 awful.button ({}, 4, function()
159 awful.util.spawn(string.format("%s set %s %s+", alsabar.cmd, alsabar.channel, alsabar.step))
162 awful.button ({}, 5, function()
163 awful.util.spawn(string.format("%s set %s %s-", alsabar.cmd, alsabar.channel, alsabar.step))
168 timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
170 newtimer(timer_id, timeout, alsabar.update)
175 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })