summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Makhov <pmakhov@touchtunes.com>2018-10-04 10:26:27 -0400
committerPavel Makhov <pmakhov@touchtunes.com>2018-10-04 10:26:27 -0400
commit46541730ebd93eb90e006da832c3ba4bdecfe699 (patch)
tree3e56bfb9b2714bb7c8b2c81bd6ce8fc220f710e0
parent9c181c5c7002947c61f0632f8d8d395ac48afa58 (diff)
refactor volumebar/arc widgets
-rw-r--r--volumearc-widget/volumearc.lua10
-rw-r--r--volumebar-widget/volumebar.lua28
2 files changed, 18 insertions, 20 deletions
diff --git a/volumearc-widget/volumearc.lua b/volumearc-widget/volumearc.lua
index c2c0af9..9cd7865 100644
--- a/volumearc-widget/volumearc.lua
+++ b/volumearc-widget/volumearc.lua
@@ -5,7 +5,7 @@
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumearc-widget
-- @author Pavel Makhov
--- @copyright 2017 Pavel Makhov
+-- @copyright 2018 Pavel Makhov
-------------------------------------------------
local awful = require("awful")
@@ -38,11 +38,9 @@ local update_graphic = function(widget, stdout, _, _, _)
volume = tonumber(string.format("% 3d", volume))
widget.value = volume / 100;
- if mute == "off" then
- widget.colors = { beautiful.widget_red }
- else
- widget.colors = { beautiful.widget_main_color }
- end
+ widget.colors = mute == 'off' and { beautiful.widget_red }
+ or { beautiful.widget_main_color }
+
end
volumearc:connect_signal("button::press", function(_, _, _, button)
diff --git a/volumebar-widget/volumebar.lua b/volumebar-widget/volumebar.lua
index 545313a..9fd6a99 100644
--- a/volumebar-widget/volumebar.lua
+++ b/volumebar-widget/volumebar.lua
@@ -5,7 +5,7 @@
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volumebar-widget
-- @author Pavel Makhov
--- @copyright 2017 Pavel Makhov
+-- @copyright 2018 Pavel Makhov
-------------------------------------------------
local awful = require("awful")
@@ -14,7 +14,10 @@ local spawn = require("awful.spawn")
local watch = require("awful.widget.watch")
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 mute_color = "#ff0000"
@@ -41,26 +44,23 @@ local update_graphic = function(widget, stdout, _, _, _)
local volume = string.match(stdout, "(%d?%d?%d)%%")
volume = tonumber(string.format("% 3d", volume))
- if mute == "off" then
- widget.color = mute_color
- widget.value = volume / 100;
- else
- widget.color = bar_color
- widget.value = volume / 100;
- end
+ widget.value = volume / 100;
+ widget.color = mute == "off" and mute_color
+ or bar_color
+
end
volumebar_widget:connect_signal("button::press", function(_,_,_,button)
- if (button == 4) then awful.spawn("amixer -D pulse sset Master 5%+", false)
- elseif (button == 5) then awful.spawn("amixer -D pulse sset Master 5%-", false)
- elseif (button == 1) then awful.spawn("amixer -D pulse sset Master toggle", false)
+ if (button == 4) then awful.spawn(INC_VOLUME_CMD)
+ elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD)
+ elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD)
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)
end)
end)
-watch(request_command, 1, update_graphic, volumebar_widget)
+watch(GET_VOLUME_CMD, 1, update_graphic, volumebar_widget)
return volumebar_widget \ No newline at end of file