-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.lua
65 lines (58 loc) · 2.28 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
local awful = require("awful")
local wibox = require("wibox")
local watch = require("awful.widget.watch")
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
local surface = require( "gears.surface" )
local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo
local height = 22 -- TODO : use systray height
local function add_icon(icon_path)
local img = cairo.ImageSurface.create(cairo.Format.ARGB32, height, height)
local cr = cairo.Context(img)
local sur = surface(icon_path)
color.apply_mask(sur, "#333333") -- TODO : remove harcoded color
cr:set_source_surface(sur, 3, 1)
cr:paint()
return img
end
volume_widget = wibox.widget {
{
id = "icon",
image = path_to_icons .. "audio-volume-muted-symbolic.svg",
resize = false,
widget = wibox.widget.imagebox,
},
layout = wibox.container.margin(brightness_icon, 0, 0, 3),
set_image = function(self, path)
self.icon.image = add_icon(path) --path
end
}
--[[ allows control volume level by:
- clicking on the widget to mute/unmute
- scrolling when curson is over the widget
]]
volume_widget:connect_signal("button::press", function(_,_,_,button)
if (button == 4) then
awful.spawn("amixer -D pulse sset Master 5%+")
elseif (button == 5) then
awful.spawn("amixer -D pulse sset Master 5%-")
elseif (button == 1) then
awful.spawn("amixer -D pulse sset Master toggle")
end
end)
watch(
'amixer -D pulse sget Master', 1,
function(widget, stdout, stderr, reason, exit_code)
local mute = string.match(stdout, "%[(o%D%D?)%]")
local volume = string.match(stdout, "(%d?%d?%d)%%")
volume = tonumber(string.format("% 3d", volume))
local volume_icon_name
if mute == "off" then volume_icon_name="audio-volume-muted-symbolic"
elseif (volume >= 0 and volume < 25) then volume_icon_name="audio-volume-muted-symbolic"
elseif (volume >= 25 and volume < 50) then volume_icon_name="audio-volume-low-symbolic"
elseif (volume >= 50 and volume < 75) then volume_icon_name="audio-volume-medium-symbolic"
elseif (volume >= 75 and volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
end
volume_widget.image = path_to_icons .. volume_icon_name .. ".svg"
end
)