-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.lua
92 lines (81 loc) · 2.24 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
local wibox = require("wibox")
local awful = require("awful")
local gears = require("gears")
local beautiful
local volume = {}
volume.init = function(theme)
beautiful = theme
volume.widget = wibox.widget {
{
max_value = 100,
value = 0,
border_width = 1,
margins = 1,
id = "bar",
background_color = beautiful.bg_normal,
border_color = beautiful.border_color,
widget = wibox.widget.progressbar,
},
{
text = "♫",
align = "center",
valign = "bottom",
font = "sans 11",
widget = wibox.widget.textbox
},
forced_width = beautiful.bars_width,
layout = wibox.layout.stack
}
volume.update = function()
awful.spawn.easy_async_with_shell("Vvolume %", function(stdout)
local curr_volume = string.match(stdout, "Volume: (%d+)")
local muted = string.match(stdout, "Mute: (%S+)")
-- set foreground color
if muted == "no" then
volume.widget.bar.color = beautiful.volume_bar_unmute
else
volume.widget.bar.color = beautiful.volume_bar_mute
end
volume.widget.bar:set_value(tonumber(curr_volume))
end)
end
volume.update()
volume.widget:buttons(gears.table.join(
awful.button({}, 2, function() -- middle click
awful.spawn.easy_async_with_shell("Vvolume 100",function()end)
volume.update()
end),
awful.button({}, 3, function() -- right click
os.execute("Vvolume 0")
volume.update()
end),
awful.button({}, 5, function() -- scroll up
awful.spawn.easy_async_with_shell("Vvolume +",function()end)
volume.update()
end),
awful.button({}, 4, function() -- scroll down
awful.spawn.easy_async_with_shell("Vvolume -",function()end)
volume.update()
end)
))
volume.keys = gears.table.join(
awful.key({}, "XF86AudioMute", function()
os.execute("Vvolume 0")
volume.update()
end,
{description = "mute", group = "system"}
),
awful.key({}, "XF86AudioLowerVolume", function()
awful.spawn.easy_async_with_shell("Vvolume -",function()end)
volume.update() end,
{description = "lower volume", group = "system"}
),
awful.key({}, "XF86AudioRaiseVolume", function()
awful.spawn.easy_async_with_shell("Vvolume +",function()end)
volume.update()
end,
{description = "raise volume", group = "system"}
)
)
end
return volume