-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvolume.lua
77 lines (67 loc) · 1.56 KB
/
volume.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local volume = {}
local awful = require ("awful")
local wibox = require ("wibox")
-- Helper Function
local function cmd(command)
awful.spawn.with_shell(command)
end
-- Local Varibales
local level = 16 -- initial level
local muted = false
local MIN = 0 -- minimum volume level of 'amixer plyback'
local MAX = 31 -- maximum volume level of 'amixer playback'
local STEP = 1 -- step to update volume level (up / down).
local widget = wibox.widget{
markup = '',
halign = "center",
valign = "center",
widget = wibox.widget.textbox
}
-- Local Fucntions
local function getmessage(value)
return string.format(" vol:%-4s|", value)
end
local function updatewidget()
levelperc = math.floor((level / MAX)*100)
if(muted) then
widget.markup = getmessage("M")
return
end
widget.markup = getmessage(levelperc .. "%")
end
-- Update the widget to set an initial value
updatewidget()
--
local function updatelevel(val)
level = level + val
if(level > MAX) then
level = MAX
elseif (level < MIN) then
level = MIN
else
return
end
end
-- Public Functions
function volume.getwidget()
return widget
end
function volume.up()
cmd("pactl set-sink-volume @DEFAULT_SINK@ +" .. STEP .. "%")
--cmd("amixer set Master playback " .. STEP .. "+")
updatelevel(STEP)
updatewidget()
end
function volume.down()
cmd("pactl set-sink-volume @DEFAULT_SINK@ +" .. STEP .."%")
--cmd("amixer set Master playback " .. STEP .. "-")
updatelevel(-STEP)
updatewidget()
end
-- Mute / Unmute
function volume.toggle()
cmd("amixer set Master playback toggle")
muted = not muted
updatewidget()
end
return volume