diff --git a/lib/volume.lua b/lib/volume.lua index a52c557..e2618a5 100644 --- a/lib/volume.lua +++ b/lib/volume.lua @@ -13,13 +13,23 @@ local icons = package.loaded["vbe/icons"] module("vbe/volume") local volid = nil -local function change(what, how) - os.execute("amixer -q -D pulse sset " .. what .. " " .. how, false) - -- Read the current value +local running = true +local function current(what) local out = awful.util.pread("amixer -D pulse sget " .. what) local vol, mute = out:match("([%d]+)%%.*%[([%l]*)") - if not mute or not vol then return end + return vol, mute +end +local function change(what, how) + if how ~= 0 then + local vol, mute = current(what) + how = string.format("%d%%", vol+how) + else + how = "toggle" + end + os.execute("amixer -q -D pulse sset " .. what .. " " .. how, false) + + local vol, mute = current(what) vol = tonumber(vol) local icon = "high" if mute ~= "on" or vol == 0 then @@ -43,15 +53,15 @@ local function change(what, how) end function increase(what) - change(what, "2%+") + change(what, 2) end function decrease(what) - change(what, "2%-") + change(what, -2) end function toggle(what) - change(what, "toggle") + change(what, 0) end -- run pavucontrol