vincentbernat.i3wm-configur.../lib/volume.lua

60 lines
1.3 KiB
Lua
Raw Normal View History

-- Handle volume (through pulseaudio)
local awful = require("awful")
local naughty = require("naughty")
2018-08-25 00:58:08 +02:00
local beautiful = require("beautiful")
local tonumber = tonumber
local string = string
local os = os
2018-08-25 00:58:08 +02:00
local theme = beautiful.get()
-- A bit odd, but...
require("lib/icons")
local icons = package.loaded["vbe/icons"]
module("vbe/volume")
local volid = nil
local function change(what)
2018-08-25 00:58:08 +02:00
os.execute("amixer -q sset Master " .. what, false)
-- Read the current value
local out = awful.util.pread("amixer sget Master")
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
icon = icons.lookup({name = "audio-volume-" .. icon,
type = "status"})
volid = naughty.notify({ text = string.format("%3d %%", vol),
icon = icon,
2018-08-16 18:46:55 +02:00
font = "Free Sans Bold " .. 24*theme.scale,
replaces_id = volid }).id
end
function increase()
change("5%+")
end
function decrease()
change("5%-")
end
function toggle()
change("toggle")
end
-- run pavucontrol
function mixer()
awful.util.spawn("pavucontrol", false)
end