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
34 background = beautiful.bg_normal,
39 terminal = terminal or "xterm",
40 mixer = terminal .. " -e alsamixer",
44 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
46 color = beautiful.fg_focus,
54 function alsabar.notify()
62 font = alsabar.notifications.font .. " " ..
63 alsabar.notifications.font_size,
64 fg = alsabar.notifications.color
69 preset.title = alsabar.channel .. " - Muted"
71 preset.title = alsabar.channel .. " - " .. alsabar._current_level * 100 .. "%"
74 int = math.modf(alsabar._current_level * alsabar.notifications.bar_size)
76 .. string.rep("|", int)
77 .. string.rep(" ", alsabar.notifications.bar_size - int)
80 if alsabar._notify ~= nil then
81 alsabar._notify = naughty.notify ({
82 replaces_id = alsabar._notify.id,
86 alsabar._notify = naughty.notify ({
92 local function worker(args)
93 local args = args or {}
94 local timeout = args.timeout or 4
95 local settings = args.settings or function() end
96 local width = args.width or 63
97 local height = args.heigth or 1
98 local ticks = args.ticks or true
99 local ticks_size = args.ticks_size or 7
100 local vertical = args.vertical or false
102 alsabar.channel = args.channel or alsabar.channel
103 alsabar.step = args.step or alsabar.step
104 alsabar.colors = args.colors or alsabar.colors
105 alsabar.notifications = args.notifications or alsabar.notifications
107 alsabar.bar = awful.widget.progressbar()
109 alsabar.bar:set_background_color(alsabar.colors.background)
110 alsabar.bar:set_color(alsabar.colors.unmute)
111 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
112 alsabar.bar:set_width(width)
113 alsabar.bar:set_height(height)
114 alsabar.bar:set_ticks(ticks)
115 alsabar.bar:set_ticks_size(ticks_size)
117 if vertical then alsabar.bar:set_vertical(true) end
119 function alsabar.update()
120 -- Get mixer control contents
121 local f = io.popen("amixer get " .. alsabar.channel)
122 local mixer = f:read("*all")
125 -- Capture mixer control state: [5%] ... ... [on]
126 local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
133 alsabar._current_level = tonumber(volu) / 100
134 alsabar.bar:set_value(alsabar._current_level)
136 if not mute and tonumber(volu) == 0 or mute == "off"
138 alsabar._muted = true
139 alsabar.tooltip:set_text (" [Muted] ")
140 alsabar.bar:set_color(alsabar.colors.mute)
142 alsabar._muted = false
143 alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
144 alsabar.bar:set_color(alsabar.colors.unmute)
148 volume_now.level = tonumber(volu)
149 volume_now.status = mute
153 newtimer("alsabar", timeout, alsabar.update)
155 alsabar.bar:buttons (awful.util.table.join (
156 awful.button ({}, 1, function()
157 awful.util.spawn(alsabar.mixer)
159 awful.button ({}, 3, function()
160 awful.util.spawn(string.format("amixer set %s toggle", alsabar.channel))
163 awful.button ({}, 4, function()
164 awful.util.spawn(string.format("amixer set %s %s+", alsabar.channel, alsabar.step))
167 awful.button ({}, 5, function()
168 awful.util.spawn(string.format("amixer set %s %s-", alsabar.channel, alsabar.step))
176 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })