From d185af3b87c17d9afd5602930e3128ba22ab6835 Mon Sep 17 00:00:00 2001 From: Pavel Makhov Date: Fri, 5 Oct 2018 11:02:05 -0400 Subject: refactor volume widget --- volume-widget/volume.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua index 31a66e4..8124bcf 100644 --- a/volume-widget/volume.lua +++ b/volume-widget/volume.lua @@ -5,7 +5,7 @@ -- https://github.com/streetturtle/awesome-wm-widgets/tree/master/volume-widget -- @author Pavel Makhov --- @copyright 2017 Pavel Makhov +-- @copyright 2018 Pavel Makhov ------------------------------------------------- local awful = require("awful") @@ -14,7 +14,11 @@ local watch = require("awful.widget.watch") local spawn = require("awful.spawn") local path_to_icons = "/usr/share/icons/Arc/status/symbolic/" -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 volume_widget = wibox.widget { { @@ -48,16 +52,16 @@ end - scrolling when cursor is over the widget ]] volume_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, false) + elseif (button == 5) then awful.spawn(DEC_VOLUME_CMD, false) + elseif (button == 1) then awful.spawn(TOG_VOLUME_CMD, false) end - spawn.easy_async(request_command, function(stdout, stderr, exitreason, exitcode) + spawn.easy_async(GET_VOLUME_CMD, function(stdout, stderr, exitreason, exitcode) update_graphic(volume_widget, stdout, stderr, exitreason, exitcode) end) end) -watch(request_command, 1, update_graphic, volume_widget) +watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget) return volume_widget \ No newline at end of file -- cgit v1.2.3