summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@users.noreply.github.com>2017-05-30 09:21:14 -0400
committerGitHub <noreply@github.com>2017-05-30 09:21:14 -0400
commitcbe2cce0469dcb72daee5f45cf4f6e0986c018c0 (patch)
tree8b00c2ffd921aa36d4623c9cc3dc7efd55f5caf1
parentbe8156ea12c4694b8eac47d5235d4b25b10ad9b4 (diff)
parent1fa4dc3508fbdd4b004902374cd73f4f8ba4933c (diff)
Merge pull request #13 from ashleydavies/patch-1
Add instant update to volume graphic upon changes caused by interactions
-rw-r--r--volume-widget/volume.lua47
1 files changed, 24 insertions, 23 deletions
diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua
index efb9d20..481d244 100644
--- a/volume-widget/volume.lua
+++ b/volume-widget/volume.lua
@@ -1,8 +1,10 @@
local awful = require("awful")
local wibox = require("wibox")
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'
volume_widget = wibox.widget {
{
@@ -17,34 +19,33 @@ volume_widget = wibox.widget {
end
}
+local update_graphic = function(widget, stdout, stderr, reason, exit_code)
+ local mute = string.match(stdout, "%[(o%D%D?)%]")
+ local volume = string.match(stdout, "(%d?%d?%d)%%")
+ volume = tonumber(string.format("% 3d", volume))
+ local volume_icon_name
+ if mute == "off" then volume_icon_name="audio-volume-muted-symbolic"
+ elseif (volume >= 0 and volume < 25) then volume_icon_name="audio-volume-muted-symbolic"
+ elseif (volume < 50) then volume_icon_name="audio-volume-low-symbolic"
+ elseif (volume < 75) then volume_icon_name="audio-volume-medium-symbolic"
+ elseif (volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
+ end
+ widget.image = path_to_icons .. volume_icon_name .. ".svg"
+end
+
--[[ allows control volume level by:
- clicking on the widget to mute/unmute
- scrolling when curson 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("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)
end
+
+ spawn.easy_async(request_command, function(stdout, stderr, exitreason, exitcode)
+ update_graphic(volume_widget, stdout, stderr, exitreason, exitcode)
+ end)
end)
-watch(
- 'amixer -D pulse sget Master', 1,
- function(widget, stdout, stderr, reason, exit_code)
- local mute = string.match(stdout, "%[(o%D%D?)%]")
- local volume = string.match(stdout, "(%d?%d?%d)%%")
- volume = tonumber(string.format("% 3d", volume))
- local volume_icon_name
- if mute == "off" then volume_icon_name="audio-volume-muted-symbolic"
- elseif (volume >= 0 and volume < 25) then volume_icon_name="audio-volume-muted-symbolic"
- elseif (volume >= 25 and volume < 50) then volume_icon_name="audio-volume-low-symbolic"
- elseif (volume >= 50 and volume < 75) then volume_icon_name="audio-volume-medium-symbolic"
- elseif (volume >= 75 and volume <= 100) then volume_icon_name="audio-volume-high-symbolic"
- end
- widget.image = path_to_icons .. volume_icon_name .. ".svg"
- end,
- volume_widget
-)
+watch(request_command, 1, update_graphic, volume_widget)