mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-03 06:44:21 +02:00
volume: set volume in absolute value
Otherwise, it seems we can get a left/right imbalance when using relative changes.
This commit is contained in:
parent
db26403508
commit
ec3a31d9d6
1 changed files with 17 additions and 7 deletions
|
@ -13,13 +13,23 @@ local icons = package.loaded["vbe/icons"]
|
||||||
module("vbe/volume")
|
module("vbe/volume")
|
||||||
|
|
||||||
local volid = nil
|
local volid = nil
|
||||||
local function change(what, how)
|
local running = true
|
||||||
os.execute("amixer -q -D pulse sset " .. what .. " " .. how, false)
|
local function current(what)
|
||||||
-- Read the current value
|
|
||||||
local out = awful.util.pread("amixer -D pulse sget " .. what)
|
local out = awful.util.pread("amixer -D pulse sget " .. what)
|
||||||
local vol, mute = out:match("([%d]+)%%.*%[([%l]*)")
|
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)
|
vol = tonumber(vol)
|
||||||
local icon = "high"
|
local icon = "high"
|
||||||
if mute ~= "on" or vol == 0 then
|
if mute ~= "on" or vol == 0 then
|
||||||
|
@ -43,15 +53,15 @@ local function change(what, how)
|
||||||
end
|
end
|
||||||
|
|
||||||
function increase(what)
|
function increase(what)
|
||||||
change(what, "2%+")
|
change(what, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function decrease(what)
|
function decrease(what)
|
||||||
change(what, "2%-")
|
change(what, -2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function toggle(what)
|
function toggle(what)
|
||||||
change(what, "toggle")
|
change(what, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- run pavucontrol
|
-- run pavucontrol
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue