mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-23 02:08:35 +02:00
volume: move volume functions into a lib
Also add some notification when changing the volume. Also move sharetags to the `lib/` directory. And modify `loadrc` to be able to load modules.
This commit is contained in:
parent
5d55609657
commit
3415d39992
6 changed files with 79 additions and 11 deletions
52
lib/volume.lua
Normal file
52
lib/volume.lua
Normal file
|
@ -0,0 +1,52 @@
|
|||
-- Handle volume (through pulseaudio)
|
||||
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
local tonumber = tonumber
|
||||
local string = string
|
||||
local os = os
|
||||
local setmetatable = setmetatable
|
||||
|
||||
module("volume")
|
||||
|
||||
local volid = nil
|
||||
local function change(what)
|
||||
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 = "/usr/share/icons/gnome/32x32/status/audio-volume-" .. icon .. ".png"
|
||||
|
||||
volid = naughty.notify({ text = string.format("%3d %%", vol),
|
||||
icon = icon,
|
||||
font = "Free Sans Bold 24",
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue