summaryrefslogtreecommitdiff
path: root/experiments
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2020-12-16 21:44:37 -0500
committerstreetturtle <streetturtle@gmail.com>2020-12-16 21:44:59 -0500
commit30738407d8936a8a73209e7bddce8f22c0d4e35c (patch)
treeb5e37625fd8e287fb115fbf2c2c61ac65b97083f /experiments
parent3cacea5d4e40ddac2f5c4affab3c9625d6a3e03d (diff)
make new volume widget more responsive
Diffstat (limited to 'experiments')
-rw-r--r--experiments/volume/volume.lua38
1 files changed, 22 insertions, 16 deletions
diff --git a/experiments/volume/volume.lua b/experiments/volume/volume.lua
index 0b5c546..e4af2b3 100644
--- a/experiments/volume/volume.lua
+++ b/experiments/volume/volume.lua
@@ -18,9 +18,9 @@ local utils = require("awesome-wm-widgets.experiments.volume.utils")
local LIST_DEVICES_CMD = [[sh -c "pacmd list-sinks; pacmd list-sources"]]
local GET_VOLUME_CMD = 'amixer -D pulse sget Master'
-local INC_VOLUME_CMD = 'amixer -q -D pulse sset Master 5%+'
-local DEC_VOLUME_CMD = 'amixer -q -D pulse sset Master 5%-'
-local TOG_VOLUME_CMD = 'amixer -q -D pulse sset Master toggle'
+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 widget_types = {
@@ -173,6 +173,16 @@ local function worker(user_args)
volume_widget = widget_types[widget_type].get_widget(user_args[widget_type .. '_args'])
end
+ local function update_graphic(widget, stdout)
+ local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
+ if mute == 'off' then widget:mute()
+ elseif mute == 'on' then widget:unmute()
+ end
+ local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
+ volume = string.format("% 3d", volume)
+ widget:set_volume_level(volume)
+ end
+
volume_widget:buttons(
awful.util.table.join(
awful.button({}, 3, function()
@@ -183,22 +193,18 @@ local function worker(user_args)
popup:move_next_to(mouse.current_widget_geometry)
end
end),
- awful.button({}, 4, function() spawn(INC_VOLUME_CMD, false) end),
- awful.button({}, 5, function() spawn(DEC_VOLUME_CMD, false) end),
- awful.button({}, 1, function() spawn(TOG_VOLUME_CMD, false) end)
+ awful.button({}, 4, function()
+ spawn.easy_async(INC_VOLUME_CMD, function(stdout) update_graphic(volume_widget, stdout) end)
+ end),
+ awful.button({}, 5, function()
+ spawn.easy_async(DEC_VOLUME_CMD, function(stdout) update_graphic(volume_widget, stdout) end)
+ end),
+ awful.button({}, 1, function()
+ spawn.easy_async(TOG_VOLUME_CMD, function(stdout) update_graphic(volume_widget, stdout) end)
+ end)
)
)
- local function update_graphic(widget, stdout)
- local mute = string.match(stdout, "%[(o%D%D?)%]") -- \[(o\D\D?)\] - [on] or [off]
- if mute == 'off' then widget:mute()
- elseif mute == 'on' then widget:unmute()
- end
- local volume = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%)
- volume = string.format("% 3d", volume)
- widget:set_volume_level(volume)
- end
-
watch(GET_VOLUME_CMD, refresh_rate, update_graphic, volume_widget)
return volume_widget