diff --git a/config/awesome/elemental/bar/ephemeral.lua b/config/awesome/elemental/bar/ephemeral.lua index 28db84a..0c71cdd 100644 --- a/config/awesome/elemental/bar/ephemeral.lua +++ b/config/awesome/elemental/bar/ephemeral.lua @@ -53,16 +53,16 @@ local volume = create_button(volume_symbol, volume_unmuted_color, x.color8.."30" volume:buttons(gears.table.join( -- Left click - Mute / Unmute awful.button({ }, 1, function () - helpers.volume_control(0) + helpers.volume_control.toggle() end), -- Right click - Run or raise volume control client awful.button({ }, 3, apps.volume), -- Scroll - Increase / Decrease volume awful.button({ }, 4, function () - helpers.volume_control(5) + helpers.volume_control.increase(5) end), awful.button({ }, 5, function () - helpers.volume_control(-5) + helpers.volume_control.decrease(5) end) )) diff --git a/config/awesome/elemental/sidebar/amarena.lua b/config/awesome/elemental/sidebar/amarena.lua index 9f730e8..10346d0 100644 --- a/config/awesome/elemental/sidebar/amarena.lua +++ b/config/awesome/elemental/sidebar/amarena.lua @@ -279,16 +279,16 @@ local volume = format_progress_bar(volume_bar) volume:buttons(gears.table.join( -- Left click - Mute / Unmute awful.button({ }, 1, function () - helpers.volume_control(0) + helpers.volume_control.toggle() end), -- Right click - Run or raise pavucontrol awful.button({ }, 3, apps.volume), -- Scroll - Increase / Decrease volume - awful.button({ }, 4, function () - helpers.volume_control(2) + awful.button({ }, 4, function () + helpers.volume_control.increase(2) end), - awful.button({ }, 5, function () - helpers.volume_control(-2) + awful.button({ }, 5, function () + helpers.volume_control.decrease(2) end) )) diff --git a/config/awesome/elemental/sidebar/lovelace.lua b/config/awesome/elemental/sidebar/lovelace.lua index b1d7e42..46e3a8a 100644 --- a/config/awesome/elemental/sidebar/lovelace.lua +++ b/config/awesome/elemental/sidebar/lovelace.lua @@ -280,16 +280,16 @@ local volume = format_progress_bar(volume_bar, volume_icon) volume:buttons(gears.table.join( -- Left click - Mute / Unmute awful.button({ }, 1, function () - helpers.volume_control(0) + helpers.volume_control.toggle() end), -- Right click - Run or raise pavucontrol awful.button({ }, 3, apps.volume), -- Scroll - Increase / Decrease volume awful.button({ }, 4, function () - helpers.volume_control(2) + helpers.volume_control.increase(2) end), awful.button({ }, 5, function () - helpers.volume_control(-2) + helpers.volume_control.decrease(2) end) )) diff --git a/config/awesome/helpers.lua b/config/awesome/helpers.lua index e45f76e..1ab37e4 100644 --- a/config/awesome/helpers.lua +++ b/config/awesome/helpers.lua @@ -247,16 +247,20 @@ function helpers.round(number, decimals) return math.floor(number * power) / power end -function helpers.volume_control(step) - local cmd - if step == 0 then - cmd = "pactl set-sink-mute @DEFAULT_SINK@ toggle" - else - sign = step > 0 and "+" or "" - cmd = "pactl set-sink-mute @DEFAULT_SINK@ 0 && pactl set-sink-volume @DEFAULT_SINK@ "..sign..tostring(step).."%" +helpers.volume_control = { + toggle = function() + awful.spawn.with_shell("pactl set-sink-mute @DEFAULT_SINK@ toggle") + end, + increase = function(value) + awful.spawn.with_shell("pactl set-sink-mute @DEFAULT_SINK@ 0 && pactl set-sink-volume @DEFAULT_SINK@ +"..tostring(value).."%") + end, + decrease = function(value) + awful.spawn.with_shell("pactl set-sink-volume @DEFAULT_SINK@ -"..tostring(value).."%") + end, + set = function(value) + awful.spawn.with_shell("pactl set-sink-mute @DEFAULT_SINK@ 0 && pactl set-sink-volume @DEFAULT_SINK@ "..tostring(value).."%") end - awful.spawn.with_shell(cmd) -end +} function helpers.send_key(c, key) awful.spawn.with_shell("xdotool key --window "..tostring(c.window).." "..key) diff --git a/config/awesome/keys.lua b/config/awesome/keys.lua index 985f8f8..56a1c1b 100644 --- a/config/awesome/keys.lua +++ b/config/awesome/keys.lua @@ -60,8 +60,8 @@ keys.desktopbuttons = gears.table.join( awful.button({ }, 5, awful.tag.viewnext), -- Side buttons - Control volume - awful.button({ }, 9, function () helpers.volume_control(5) end), - awful.button({ }, 8, function () helpers.volume_control(-5) end) + awful.button({ }, 9, function () helpers.volume_control.increase(5) end), + awful.button({ }, 8, function () helpers.volume_control.decrease(5) end) -- Side buttons - Minimize and restore minimized client -- awful.button({ }, 8, function() @@ -371,34 +371,34 @@ keys.globalkeys = gears.table.join( -- Volume Control with volume keys awful.key( { }, "XF86AudioMute", function() - helpers.volume_control(0) + helpers.volume_control.toggle() end, {description = "(un)mute volume", group = "volume"}), awful.key( { }, "XF86AudioLowerVolume", function() - helpers.volume_control(-5) + helpers.volume_control.decrease(5) end, {description = "lower volume", group = "volume"}), awful.key( { }, "XF86AudioRaiseVolume", function() - helpers.volume_control(5) + helpers.volume_control.increase(5) end, {description = "raise volume", group = "volume"}), -- Volume Control with alt+F1/F2/F3 awful.key( { altkey }, "F1", function() - helpers.volume_control(0) + helpers.volume_control.toggle() end, {description = "(un)mute volume", group = "volume"}), awful.key( { altkey }, "F2", function() - helpers.volume_control(-5) + helpers.volume_control.decrease(5) end, {description = "lower volume", group = "volume"}), awful.key( { altkey }, "F3", function() - helpers.volume_control(5) + helpers.volume_control.increase(5) end, {description = "raise volume", group = "volume"}),