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
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,
53 function pulsebar.notify()
60 screen = pulsebar.notifications.screen,
61 font = string.format("%s %s", alsabar.notifications.font,
62 alsabar.notifications.font_size),
63 fg = pulsebar.notifications.color
68 preset.title = string.format("Sink %s - Muted", pulsebar.sink)
70 preset.title = string.format("%s - %s%%", pulsebar.sink, pulsebar._current_level)
73 int = math.modf((pulsebar._current_level / 100) * pulsebar.notifications.bar_size)
74 preset.text = string.format("[%s%s]", string.rep("|", int),
75 string.rep(" ", pulsebar.notifications.bar_size - int))
77 if pulsebar.followmouse then
78 preset.screen = mouse.screen
81 if pulsebar._notify ~= nil then
82 pulsebar._notify = naughty.notify ({
83 replaces_id = pulsebar._notify.id,
87 pulsebar._notify = naughty.notify ({
93 local function worker(args)
94 local args = args or {}
95 local timeout = args.timeout or 5
96 local settings = args.settings or function() end
97 local width = args.width or 63
98 local height = args.heigth or 1
99 local ticks = args.ticks or false
100 local ticks_size = args.ticks_size or 7
101 local vertical = args.vertical or false
102 local scallback = args.scallback
104 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'")
105 pulsebar.colors = args.colors or pulsebar.colors
106 pulsebar.notifications = args.notifications or pulsebar.notifications
107 pulsebar.sink = args.sink or 0
108 pulsebar.step = args.step or pulsebar.step
109 pulsebar.followmouse = args.followmouse or false
111 pulsebar.bar = wibox.widget {
112 forced_height = height,
113 forced_width = width,
114 color = pulsebar.colors.unmute,
115 background_color = pulsebar.colors.background,
119 ticks_size = ticks_size,
120 widget = wibox.widget.progressbar,
121 layout = vertical and wibox.container.rotate
124 pulsebar.tooltip = awful.tooltip({ objects = { pulsebar.bar } })
126 function pulsebar.update()
127 if scallback then pulseaudio.cmd = scallback() end
128 local s = read_pipe(pulsebar.cmd)
131 volume_now.left = tonumber(string.match(s, ":.-(%d+)%%"))
132 volume_now.right = tonumber(string.match(s, ":.-(%d+)%%"))
133 volume_now.muted = string.match(s, "muted: (%S+)")
135 local volu = volume_now.left
136 local mute = volume_now.muted
138 if (volu and volu ~= pulsebar._current_level) or (mute and mute ~= pulsebar._muted)
140 pulsebar._current_level = volu
141 pulsebar.bar:set_value(pulsebar._current_level / 100)
142 if (not mute and volu == 0) or mute == "yes"
144 pulsebar._muted = true
145 pulsebar.tooltip:set_text ("[Muted]")
146 pulsebar.bar.color(pulsebar.colors.mute)
148 pulsebar._muted = false
149 pulsebar.tooltip:set_text(string.format("%s: %s", pulsebar.sink, volu))
150 pulsebar.bar.color(pulsebar.colors.unmute)
156 pulsebar.bar:buttons(awful.util.table.join (
157 awful.button({}, 1, function()
158 awful.util.spawn(pulsebar.mixer)
160 awful.button({}, 2, function()
161 awful.util.spawn(string.format("pactl set-sink-volume %d 100%%", pulsebar.sink))
164 awful.button({}, 3, function()
165 awful.util.spawn(string.format("pactl set-sink-mute %d toggle", pulsebar.sink))
168 awful.button({}, 4, function()
169 awful.util.spawn(string.format("pactl set-sink-volume %d +%s", pulsebar.sink, pulsebar.step))
172 awful.button({}, 5, function()
173 awful.util.spawn(string.format("pactl set-sink-volume %d -%s", pulsebar.sink, pulsebar.step))
178 timer_id = string.format("pulsebar-%s", pulsebar.sink)
180 newtimer(timer_id, timeout, pulsebar.update)
185 return setmetatable(pulsebar, { __call = function(_, ...) return worker(...) end })