blob: 3195ee7fed37efff642e36d700e509d0640d5aab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
local awful = require("awful")
local wibox = require("wibox")
--local get_volume_cmd = "wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed 's/Volume: //;s/0*\\.//'"
--local set_volume_cmd = "wpctl set-volume @DEFAULT_AUDIO_SINK@ %d%%%s" -- will be formatted
local get_volume_cmd = "wpctl get-volume @DEFAULT_AUDIO_SINK@"
local widget = {
textbox = wibox.widget.textbox()
}
local updating = false
function update_volume()
if updating then
return
end
awful.spawn.easy_async(get_volume_cmd, function(vol)
updating = true
vol = vol:sub(8) * 100 -- skip `Volume: ` whos len is 8
widget.textbox:set_text(math.floor(vol))
updating = false
end)
end
-- NOTE pulseaudio-utils (pactl) is still required due to the dependence on the
-- `pactl subscribe` command. in the future it would be advantageous to replace
-- this. currently it is (probably) only really possible with dbus.
awful.spawn.with_line_callback("pactl subscribe", { stdout = function(stdout)
--update_volume()
end })
update_volume()
return widget.textbox
|