refactor volumebar/arc widgets

This commit is contained in:
Pavel Makhov 2018-10-04 10:26:27 -04:00
parent 9c181c5c70
commit 46541730eb
2 changed files with 18 additions and 20 deletions

View File

@ -5,7 +5,7 @@
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumearc-widget -- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumearc-widget
-- @author Pavel Makhov -- @author Pavel Makhov
-- @copyright 2017 Pavel Makhov -- @copyright 2018 Pavel Makhov
------------------------------------------------- -------------------------------------------------
local awful = require("awful") local awful = require("awful")
@ -38,11 +38,9 @@ local update_graphic = function(widget, stdout, _, _, _)
volume = tonumber(string.format("% 3d", volume)) volume = tonumber(string.format("% 3d", volume))
widget.value = volume / 100; widget.value = volume / 100;
if mute == "off" then widget.colors = mute == 'off' and { beautiful.widget_red }
widget.colors = { beautiful.widget_red } or { beautiful.widget_main_color }
else
widget.colors = { beautiful.widget_main_color }
end
end end
volumearc:connect_signal("button::press", function(_, _, _, button) volumearc:connect_signal("button::press", function(_, _, _, button)

View File

@ -5,7 +5,7 @@
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget -- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget
-- @author Pavel Makhov -- @author Pavel Makhov
-- @copyright 2017 Pavel Makhov -- @copyright 2018 Pavel Makhov
------------------------------------------------- -------------------------------------------------
local awful = require("awful") local awful = require("awful")
@ -14,7 +14,10 @@ local spawn = require("awful.spawn")
local watch = require("awful.widget.watch") local watch = require("awful.widget.watch")
local wibox = require("wibox") local wibox = require("wibox")
local request_command = 'amixer -D pulse sget Master' local GET_VOLUME_CMD = 'amixer -D pulse sget Master'
local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+'
local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
local bar_color = "#74aeab" local bar_color = "#74aeab"
local mute_color = "#ff0000" local mute_color = "#ff0000"
@ -41,26 +44,23 @@ local update_graphic = function(widget, stdout, _, _, _)
local volume = string.match(stdout, "(%d?%d?%d)%%") local volume = string.match(stdout, "(%d?%d?%d)%%")
volume = tonumber(string.format("% 3d", volume)) volume = tonumber(string.format("% 3d", volume))
if mute == "off" then widget.value = volume / 100;
widget.color = mute_color widget.color = mute == "off" and mute_color
widget.value = volume / 100; or bar_color
else
widget.color = bar_color
widget.value = volume / 100;
end
end end
volumebar_widget:connect_signal("button::press", function(_,_,_,button) volumebar_widget:connect_signal("button::press", function(_,_,_,button)
if (button == 4) then awful.spawn("amixer -D pulse sset Master 5%+", false) if (button == 4) then awful.spawn(INC_VOLUME_CMD)
elseif (button == 5) then awful.spawn("amixer -D pulse sset Master 5%-", false) elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD)
elseif (button == 1) then awful.spawn("amixer -D pulse sset Master toggle", false) elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD)
end end
spawn.easy_async(request_command, function(stdout, stderr, exitreason, exitcode) spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode)
update_graphic(volumebar_widget, stdout, stderr, exitreason, exitcode) update_graphic(volumebar_widget, stdout, stderr, exitreason, exitcode)
end) end)
end) end)
watch(request_command, 1, update_graphic, volumebar_widget) watch(GET_VOLUME_CMD, 1, update_graphic, volumebar_widget)
return volumebar_widget return volumebar_widget