From 30738407d8936a8a73209e7bddce8f22c0d4e35c Mon Sep 17 00:00:00 2001 From: streetturtle Date: Wed, 16 Dec 2020 21:44:37 -0500 Subject: [PATCH] make new volume widget more responsive --- experiments/volume/volume.lua | 44 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 19 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,22 +173,6 @@ local function worker(user_args) volume_widget = widget_types[widget_type].get_widget(user_args[widget_type .. '_args']) end - volume_widget:buttons( - awful.util.table.join( - awful.button({}, 3, function() - if popup.visible then - popup.visible = not popup.visible - else - rebuild_popup() - 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) - ) - ) - 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() @@ -199,6 +183,28 @@ local function worker(user_args) widget:set_volume_level(volume) end + volume_widget:buttons( + awful.util.table.join( + awful.button({}, 3, function() + if popup.visible then + popup.visible = not popup.visible + else + rebuild_popup() + popup:move_next_to(mouse.current_widget_geometry) + end + 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) + ) + ) + watch(GET_VOLUME_CMD, refresh_rate, update_graphic, volume_widget) return volume_widget