awesome-wm-widgets/volume-widget/widgets/icon-widget.lua

46 lines
1.5 KiB
Lua
Raw Permalink Normal View History

local wibox = require("wibox")
local widget = {}
local ICON_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/volume-widget/icons/'
2020-12-15 04:33:56 +01:00
function widget.get_widget(widgets_args)
local args = widgets_args or {}
local icon_dir = args.icon_dir or ICON_DIR
return wibox.widget {
{
2020-11-09 21:54:33 +01:00
id = "icon",
resize = false,
widget = wibox.widget.imagebox,
},
2020-11-09 21:54:33 +01:00
valign = 'center',
layout = wibox.container.place,
set_volume_level = function(self, new_value)
2020-12-06 02:57:04 +01:00
local volume_icon_name
2020-11-14 19:29:31 +01:00
if self.is_muted then
2020-12-15 04:33:56 +01:00
volume_icon_name = 'audio-volume-muted-symbolic'
else
2020-11-14 19:29:31 +01:00
local new_value_num = tonumber(new_value)
if (new_value_num >= 0 and new_value_num < 33) then
volume_icon_name="audio-volume-low-symbolic"
elseif (new_value_num < 66) then
volume_icon_name="audio-volume-medium-symbolic"
else
volume_icon_name="audio-volume-high-symbolic"
end
end
2020-12-15 04:33:56 +01:00
self:get_children_by_id('icon')[1]:set_image(icon_dir .. volume_icon_name .. '.svg')
end,
2020-11-14 19:29:31 +01:00
mute = function(self)
self.is_muted = true
2020-12-15 04:33:56 +01:00
self:get_children_by_id('icon')[1]:set_image(icon_dir .. 'audio-volume-muted-symbolic.svg')
2020-11-14 19:29:31 +01:00
end,
unmute = function(self)
self.is_muted = false
end
}
end
return widget