refactor volume widget

This commit is contained in:
Pavel Makhov 2018-10-05 11:02:05 -04:00
parent 60eff0c48f
commit d185af3b87
1 changed files with 11 additions and 7 deletions

View File

@ -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