2012-07-14 16:29:19 +02:00
|
|
|
-- Handle volume (through pulseaudio)
|
|
|
|
|
|
|
|
local awful = require("awful")
|
|
|
|
local naughty = require("naughty")
|
|
|
|
local tonumber = tonumber
|
|
|
|
local string = string
|
|
|
|
local os = os
|
|
|
|
|
2012-07-15 22:22:38 +02:00
|
|
|
-- A bit odd, but...
|
|
|
|
require("lib/icons")
|
|
|
|
local icons = package.loaded["vbe/icons"]
|
|
|
|
|
2012-07-14 16:37:32 +02:00
|
|
|
module("vbe/volume")
|
2012-07-14 16:29:19 +02:00
|
|
|
|
|
|
|
local volid = nil
|
2020-03-08 00:07:01 +01:00
|
|
|
local function change(what, how)
|
|
|
|
os.execute("amixer -q -D pulse sset " .. what .. " " .. how, false)
|
2012-07-14 16:29:19 +02:00
|
|
|
-- Read the current value
|
2020-03-08 00:07:01 +01:00
|
|
|
local out = awful.util.pread("amixer -D pulse sget " .. what)
|
2012-07-14 16:29:19 +02:00
|
|
|
local vol, mute = out:match("([%d]+)%%.*%[([%l]*)")
|
|
|
|
if not mute or not vol then return end
|
|
|
|
|
|
|
|
vol = tonumber(vol)
|
|
|
|
local icon = "high"
|
|
|
|
if mute ~= "on" or vol == 0 then
|
|
|
|
icon = "muted"
|
|
|
|
elseif vol < 30 then
|
|
|
|
icon = "low"
|
|
|
|
elseif vol < 60 then
|
|
|
|
icon = "medium"
|
|
|
|
end
|
2020-03-08 00:07:01 +01:00
|
|
|
local prefix = "audio-volume"
|
|
|
|
if what == "Capture" then
|
|
|
|
prefix = "microphone-sensitivity"
|
|
|
|
end
|
|
|
|
icon = icons.lookup({name = prefix .. "-" .. icon,
|
2012-07-15 22:22:38 +02:00
|
|
|
type = "status"})
|
2012-07-14 16:29:19 +02:00
|
|
|
|
|
|
|
volid = naughty.notify({ text = string.format("%3d %%", vol),
|
|
|
|
icon = icon,
|
2018-08-25 00:58:37 +02:00
|
|
|
font = "Free Sans Bold 24",
|
2012-07-14 16:29:19 +02:00
|
|
|
replaces_id = volid }).id
|
|
|
|
end
|
|
|
|
|
2020-03-08 00:07:01 +01:00
|
|
|
function increase(what)
|
2020-08-22 21:34:16 +02:00
|
|
|
change(what, "2%+")
|
2012-07-14 16:29:19 +02:00
|
|
|
end
|
|
|
|
|
2020-03-08 00:07:01 +01:00
|
|
|
function decrease(what)
|
2020-08-22 21:34:16 +02:00
|
|
|
change(what, "2%-")
|
2012-07-14 16:29:19 +02:00
|
|
|
end
|
|
|
|
|
2020-03-08 00:07:01 +01:00
|
|
|
function toggle(what)
|
|
|
|
change(what, "toggle")
|
2020-03-08 00:02:07 +01:00
|
|
|
end
|
|
|
|
|
2012-07-14 16:29:19 +02:00
|
|
|
-- run pavucontrol
|
|
|
|
function mixer()
|
|
|
|
awful.util.spawn("pavucontrol", false)
|
|
|
|
end
|