aboutsummaryrefslogtreecommitdiff
path: root/modules/awesome/config.dot/awesome.link/volume.lua
blob: 0a5bb451cc40b3e717ef6fd004a5ff237cd10051 (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
-- See http://awesome.naquadah.org/wiki/Volume_control_and_display
volume_widget = widget({ type = "textbox", name = "tb_volume",
                         align = "right" })

function update_volume(widget)
    local fd = io.popen("amixer sget Master")
    local status = fd:read("*all")
    fd:close()
    
    local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) / 100
    -- volume = string.format("% 3d", volume)

    status = string.match(status, "%[(o[^%]]*)%]")

    -- starting colour
    local sr, sg, sb = 0x3F, 0x3F, 0x3F
    -- ending colour
    local er, eg, eb = 0xDC, 0xDC, 0xCC

    local ir = volume * (er - sr) + sr
    local ig = volume * (eg - sg) + sg
    local ib = volume * (eb - sb) + sb
    interpol_colour = string.format("%.2x%.2x%.2x", ir, ig, ib)
    if string.find(status, "on", 1, true) then
        volume = " <span background='#" .. interpol_colour .. "'>   </span>"
    else
        volume = " <span color='red' background='#" .. interpol_colour .. "'> M </span>"
    end
    widget.text = volume
 end

mytimer = timer({ timeout = 1 })
mytimer:add_signal("timeout", function () update_volume(volume_widget) end)
mytimer:start()