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")
17 local math = { modf = math.modf }
19 local string = { format = string.format,
22 local tonumber = tonumber
24 local setmetatable = setmetatable
27 -- lain.widgets.pulsebar
33 background = beautiful.bg_normal,
38 mixer = "pavucontrol",
41 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
43 color = beautiful.fg_normal,
52 function pulsebar.notify()
59 screen = pulsebar.notifications.screen,
60 font = pulsebar.notifications.font .. " " ..
61 pulsebar.notifications.font_size,
62 fg = pulsebar.notifications.color
67 preset.title = "Sink " .. pulsebar.sink .. " - Muted"
69 preset.title = "Sink " .. pulsebar.sink .. " - " .. pulsebar._current_level .. "%"
72 int = math.modf((pulsebar._current_level / 100) * pulsebar.notifications.bar_size)
74 .. string.rep("|", int)
75 .. string.rep(" ", pulsebar.notifications.bar_size - int)
78 if pulsebar.followmouse then
79 preset.screen = mouse.screen
82 if pulsebar._notify ~= nil then
83 pulsebar._notify = naughty.notify ({
84 replaces_id = pulsebar._notify.id,
88 pulsebar._notify = naughty.notify ({
94 local function worker(args)
95 local args = args or {}
96 local timeout = args.timeout or 5
97 local settings = args.settings or function() end
98 local width = args.width or 63
99 local height = args.heigth or 1
100 local ticks = args.ticks or false
101 local ticks_size = args.ticks_size or 7
102 local vertical = args.vertical or false
103 local scallback = args.scallback
105 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'")
106 pulsebar.colors = args.colors or pulsebar.colors
107 pulsebar.notifications = args.notifications or pulsebar.notifications
108 pulsebar.sink = args.sink or 0
109 pulsebar.step = args.step or pulsebar.step
110 pulsebar.followmouse = args.followmouse or false
112 pulsebar.bar = awful.widget.progressbar()
114 pulsebar.bar:set_background_color(pulsebar.colors.background)
115 pulsebar.bar:set_color(pulsebar.colors.unmute)
116 pulsebar.tooltip = awful.tooltip({ objects = { pulsebar.bar } })
117 pulsebar.bar:set_width(width)
118 pulsebar.bar:set_height(height)
119 pulsebar.bar:set_ticks(ticks)
120 pulsebar.bar:set_ticks_size(ticks_size)
121 pulsebar.bar:set_vertical(vertical)
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:set_color(pulsebar.colors.mute)
145 pulsebar._muted = false
146 pulsebar.tooltip:set_text(string.format(" %s:%s ", pulsebar.sink, volu))
147 pulsebar.bar:set_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))
160 awful.button({}, 3, function()
161 awful.util.spawn(string.format("pactl set-sink-mute %d toggle", pulsebar.sink))
164 awful.button({}, 4, function()
165 awful.util.spawn(string.format("pactl set-sink-volume %d +%s", pulsebar.sink, pulsebar.step))
168 awful.button({}, 5, function()
169 awful.util.spawn(string.format("pactl set-sink-volume %d -%s", pulsebar.sink, pulsebar.step))
174 timer_id = string.format("pulsebar-%s", pulsebar.sink)
176 newtimer(timer_id, timeout, pulsebar.update)
181 eturn setmetatable(pulsebar, { __call = function(_, ...) return worker(...) end })