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
11 local read_pipe = require("lain.helpers").read_pipe
13 local awful = require("awful")
14 local beautiful = require("beautiful")
15 local naughty = require("naughty")
16 local wibox = require("wibox")
18 local math = { modf = math.modf }
20 local string = { format = string.format,
23 local tonumber = tonumber
25 local setmetatable = setmetatable
27 -- Pulseaudio volume bar
28 -- lain.widgets.pulsebar
34 background = beautiful.bg_normal,
39 mixer = "pavucontrol",
42 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
44 color = beautiful.fg_normal
51 function pulsebar.notify()
58 font = string.format("%s %s", pulsebar.notifications.font,
59 pulsebar.notifications.font_size),
60 fg = pulsebar.notifications.color
65 preset.title = string.format("Sink %s - Muted", pulsebar.sink)
67 preset.title = string.format("%s - %s%%", pulsebar.sink, pulsebar._current_level)
70 int = math.modf((pulsebar._current_level / 100) * awful.screen.focused().mywibox.height)
71 preset.text = string.format("[%s%s]", string.rep("|", int),
72 string.rep(" ", awful.screen.focused().mywibox.height - int))
74 if pulsebar.followtag then
75 preset.screen = awful.screen.focused()
78 if pulsebar._notify ~= nil then
79 pulsebar._notify = naughty.notify ({
80 replaces_id = pulsebar._notify.id,
84 pulsebar._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
99 local scallback = args.scallback
101 pulsebar.cmd = args.cmd or string.format("pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p'")
102 pulsebar.colors = args.colors or pulsebar.colors
103 pulsebar.notifications = args.notifications or pulsebar.notifications
104 pulsebar.sink = args.sink or 0
105 pulsebar.step = args.step or pulsebar.step
106 pulsebar.followtag = args.followtag or false
108 pulsebar.bar = wibox.widget {
109 forced_height = height,
110 forced_width = width,
111 color = pulsebar.colors.unmute,
112 background_color = pulsebar.colors.background,
116 ticks_size = ticks_size,
117 widget = wibox.widget.progressbar,
118 layout = vertical and wibox.container.rotate
121 pulsebar.tooltip = awful.tooltip({ objects = { pulsebar.bar } })
123 function pulsebar.update()
124 if scallback then pulseaudio.cmd = scallback() end
125 local s = read_pipe(pulsebar.cmd)
128 volume_now.left = tonumber(string.match(s, ":.-(%d+)%%"))
129 volume_now.right = tonumber(string.match(s, ":.-(%d+)%%"))
130 volume_now.muted = string.match(s, "muted: (%S+)")
132 local volu = volume_now.left
133 local mute = volume_now.muted
135 if (volu and volu ~= pulsebar._current_level) or (mute and mute ~= pulsebar._muted)
137 pulsebar._current_level = volu
138 pulsebar.bar:set_value(pulsebar._current_level / 100)
139 if (not mute and volu == 0) or mute == "yes"
141 pulsebar._muted = true
142 pulsebar.tooltip:set_text ("[Muted]")
143 pulsebar.bar.color = pulsebar.colors.mute
145 pulsebar._muted = false
146 pulsebar.tooltip:set_text(string.format("%s: %s", pulsebar.sink, volu))
147 pulsebar.bar.color = pulsebar.colors.unmute
153 pulsebar.bar:buttons(awful.util.table.join (
154 awful.button({}, 1, function()
155 awful.util.spawn(pulsebar.mixer)
157 awful.button({}, 2, function()
158 awful.util.spawn(string.format("pactl set-sink-volume %d 100%%", pulsebar.sink))
161 awful.button({}, 3, function()
162 awful.util.spawn(string.format("pactl set-sink-mute %d toggle", pulsebar.sink))
165 awful.button({}, 4, function()
166 awful.util.spawn(string.format("pactl set-sink-volume %d +%s", pulsebar.sink, pulsebar.step))
169 awful.button({}, 5, function()
170 awful.util.spawn(string.format("pactl set-sink-volume %d -%s", pulsebar.sink, pulsebar.step))
175 timer_id = string.format("pulsebar-%s", pulsebar.sink)
177 newtimer(timer_id, timeout, pulsebar.update)
182 return setmetatable(pulsebar, { __call = function(_, ...) return worker(...) end })