nix-files/hosts/common/programs/mpv/sane-sysvol-main.lua

38 lines
883 B
Lua

msg = require('mp.msg')
msg.trace('sane-sysvol: load: begin')
function subprocess(args)
mp.command_native({
name = "subprocess",
args = args,
-- these arguments below probably don't matter: copied from sane-cast
detach = false,
capture_stdout = false,
capture_stderr = false,
passthrough_stdin = false,
playback_only = false,
})
end
function translate_out(vol)
-- called when mpv wants to set the system-wide volume
local volstr = tostring(vol) .. "%"
msg.trace("setting system-wide volume:", volstr)
if vol == nil then
return
end
subprocess({
"wpctl",
"set-volume",
"@DEFAULT_AUDIO_SINK@",
volstr
})
end
mp.set_property_native('user-data/sane-sysvol/volume', 0)
mp.observe_property('user-data/sane-sysvol/volume', 'native', function(_, val)
translate_out(val)
end)
msg.trace('sane-sysvol: load: complete')