summaryrefslogtreecommitdiff
path: root/awesome/share/pulseaudio.lua
blob: 765fd126b84f7e8708f665146b0695d7c4fbf4dc (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
35
36
37
38
39
40
local io = io
local math = math
local tonumber = tonumber
local tostring = tostring
local string = string
local naughty = require("naughty")

function volumeInfo()
    volmin = 0
    volmax = 65536
    local f = io.popen("pacmd dump |grep set-sink-volume|grep analog-stereo")
    local g = io.popen("pacmd dump |grep set-sink-mute|grep analog-stereo")
    local v = f:read()
    local mute = g:read()
    if mute ~= nil and string.find(mute, "no") then
        volume = math.floor(tonumber(string.sub(v, string.find(v, 'x')-1)) * 100 / volmax)
    else
        volume = "off"
    end
    f:close()
    g:close()
    return "vol:"..volume.."   "
end

function muteAll()
    local outh = io.popen("pactl list short sources | awk '{print $1}'")
    while true do
        local i = outh:read()
        if i == nil then break end
        io.popen("pactl set-source-mute " .. i .. " 1"):close()
    end
    outh:close()
end

function unmuted()
    local outh = io.popen("pactl list sources | grep 'Mute: no'")
    local any = outh:read()
    outh:close()
    return any ~= nil
end