2017-01-23 17:01:16 +01:00
|
|
|
local awful = require("awful")
|
2017-02-04 04:15:16 +01:00
|
|
|
local wibox = require("wibox")
|
|
|
|
local watch = require("awful.widget.watch")
|
2017-01-23 17:01:16 +01:00
|
|
|
|
2017-02-04 04:15:16 +01:00
|
|
|
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
2017-01-23 17:01:16 +01:00
|
|
|
|
2017-02-04 04:15:16 +01:00
|
|
|
volume_widget = wibox.widget {
|
|
|
|
{
|
|
|
|
id = "icon",
|
2017-02-13 03:05:14 +01:00
|
|
|
image = path_to_icons .. "audio-volume-muted-symbolic.svg",
|
|
|
|
resize = false,
|
2017-02-04 04:15:16 +01:00
|
|
|
widget = wibox.widget.imagebox,
|
|
|
|
},
|
|
|
|
layout = wibox.container.margin(brightness_icon, 0, 0, 3),
|
|
|
|
set_image = function(self, path)
|
|
|
|
self.icon.image = path
|
|
|
|
end
|
|
|
|
}
|
2017-01-23 17:01:16 +01:00
|
|
|
|
2017-02-13 03:05:14 +01:00
|
|
|
--[[ allows control volume level by:
|
2017-02-10 03:56:09 +01:00
|
|
|
- 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
|
2017-03-11 18:33:33 +01:00
|
|
|
awful.spawn("amixer -D pulse sset Master 5%+", false)
|
2017-02-10 03:56:09 +01:00
|
|
|
elseif (button == 5) then
|
2017-03-11 18:33:33 +01:00
|
|
|
awful.spawn("amixer -D pulse sset Master 5%-", false)
|
2017-02-10 03:56:09 +01:00
|
|
|
elseif (button == 1) then
|
2017-03-11 18:33:33 +01:00
|
|
|
awful.spawn("amixer -D pulse sset Master toggle", false)
|
2017-02-10 03:56:09 +01:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-02-04 04:15:16 +01:00
|
|
|
watch(
|
|
|
|
'amixer -D pulse sget Master', 1,
|
|
|
|
function(widget, stdout, stderr, reason, exit_code)
|
2017-02-04 11:58:04 +01:00
|
|
|
local mute = string.match(stdout, "%[(o%D%D?)%]")
|
2017-02-04 04:15:16 +01:00
|
|
|
local volume = string.match(stdout, "(%d?%d?%d)%%")
|
|
|
|
volume = tonumber(string.format("% 3d", volume))
|
|
|
|
local volume_icon_name
|
2017-02-04 11:58:04 +01:00
|
|
|
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"
|
2017-02-04 04:15:16 +01:00
|
|
|
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
|
2017-04-14 16:02:54 +02:00
|
|
|
widget.image = path_to_icons .. volume_icon_name .. ".svg"
|
|
|
|
end,
|
|
|
|
volume_widget
|
2017-02-04 11:58:04 +01:00
|
|
|
)
|