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.
2 Licensed under GNU General Public License v2
3 * (c) 2013, Luke Bonham
7 local helpers = require("lain.helpers")
8 local awful = require("awful")
9 local naughty = require("naughty")
10 local wibox = require("wibox")
11 local math = { modf = math.modf }
12 local string = { format = string.format,
15 local tonumber = tonumber
17 local setmetatable = setmetatable
18 local terminal = "urxvtc" or "xterm"
21 -- lain.widgets.alsabar
29 >>>>>>> 09c0a3f27b6c0b61a55e7875b9a967e98cd3daf8
31 background = "#000000",
40 local function worker(args)
41 local args = args or {}
42 local timeout = args.timeout or 5
43 local settings = args.settings or function() end
44 local width = args.width or 63
45 local height = args.height or 1
46 local ticks = args.ticks or false
47 local ticks_size = args.ticks_size or 7
48 local vertical = args.vertical or false
51 alsabar.cmd = args.cmd or "amixer"
52 alsabar.channel = args.channel or "Master"
53 alsabar.colors = args.colors or alsabar.colors
54 alsabar.followtag = args.followtag or false
55 alsabar._notify = args.notify or "on"
56 alsabar.notification_preset = args.notification_preset
58 if not alsabar.notification_preset then
59 alsabar.notification_preset = naughty.config.defaults
60 alsabar.notification_preset.font = "Monospace 11"
62 alsabar.mixer = args.mixer or alsabar.mixer
63 alsabar.channel = args.channel or alsabar.channel
64 alsabar.togglechannel = args.togglechannel or alsabar.togglechannel
65 alsabar.cmd = args.cmd or {"bash", "-c", string.format("%s get %s", alsabar.mixer, alsabar.channel)}
66 alsabar.step = args.step or alsabar.step
67 alsabar.colors = args.colors or alsabar.colors
68 alsabar.notifications = args.notifications or alsabar.notifications
69 alsabar.followtag = args.followtag or false
70 if alsabar.togglechannel then
71 alsabar.cmd = args.cmd or { "bash", "-c", string.format("%s get %s; %s get %s", alsabar.mixer, alsabar.channel, alsabar.mixer, alsabar.togglechannel)}
72 >>>>>>> 09c0a3f27b6c0b61a55e7875b9a967e98cd3daf8
75 alsabar.bar = wibox.widget {
76 forced_height = height,
78 color = alsabar.colors.unmute,
79 background_color = alsabar.colors.background,
83 ticks_size = ticks_size,
84 widget = wibox.widget.progressbar,
85 layout = vertical and wibox.container.rotate
88 alsabar.bar:buttons (awful.util.table.join(
89 awful.button({}, 1, function()
90 awful.spawn(string.format('%s -e alsamixer', terminal))
92 awful.button({}, 2, function()
93 awful.spawn(string.format("%s set %s 100%%", alsabar.mixer, alsabar.channel))
96 awful.button({}, 3, function()
97 awful.spawn(string.format("%s set %s toggle", alsabar.mixer, alsabar.togglechannel or alsabar.channel))
100 awful.button({}, 4, function()
101 awful.spawn(string.format("%s set %s %s+", alsabar.mixer, alsabar.channel, alsabar.step))
104 awful.button({}, 5, function()
105 awful.spawn(string.format("%s set %s %s-", alsabar.mixer, alsabar.channel, alsabar.step))
109 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
111 function alsabar.update(callback)
112 helpers.async(alsabar.cmd, function(mixer)
113 local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
114 if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted)
116 alsabar._current_level = tonumber(volu) or alsabar._current_level
117 alsabar.bar:set_value(alsabar._current_level / 100)
118 if (not mute and tonumber(volu) == 0) or mute == "off" then
119 alsabar._muted = true
120 alsabar.tooltip:set_text ("[Muted]")
121 alsabar.bar.color = alsabar.colors.mute
123 alsabar._muted = false
124 alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu))
125 alsabar.bar.color = alsabar.colors.unmute
129 volume_now.level = tonumber(volu)
130 volume_now.status = mute
134 if type(callback) == "function" then callback() end
139 function alsabar.notify()
140 alsabar.update(function()
141 local preset = alsabar.notification_preset
143 if alsabar._muted then
144 preset.title = string.format("%s - Muted", alsabar.channel)
146 preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level)
149 int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
150 preset.text = string.format("[%s%s]", string.rep("|", int),
151 string.rep(" ", awful.screen.focused().mywibox.height - int))
153 if alsabar.followtag then preset.screen = awful.screen.focused() end
155 if alsabar._notify == "on" then
156 alsabar.id = naughty.notify ({
157 replaces_id = alsabar.id,
164 timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
166 helpers.newtimer(timer_id, timeout, alsabar.update)
171 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })