Change pacmd to pactl for better compatibility with pipewire

This commit is contained in:
Rene Kievits
2022-04-26 18:08:00 +02:00
parent ae192ca61c
commit bfd342deac
3 changed files with 103 additions and 97 deletions

View File

@@ -101,7 +101,7 @@ return function(s)
local function update_osd() local function update_osd()
awful.spawn.easy_async_with_shell( awful.spawn.easy_async_with_shell(
"pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'", "./.config/awesome/src/scripts/vol.sh volume",
function(stdout) function(stdout)
local volume_level = stdout:gsub("\n", "") local volume_level = stdout:gsub("\n", "")
awesome.emit_signal("widget::volume") awesome.emit_signal("widget::volume")
@@ -143,16 +143,14 @@ return function(s)
local update_slider = function() local update_slider = function()
awful.spawn.easy_async_with_shell( awful.spawn.easy_async_with_shell(
[[ pacmd list-sinks | grep "muted" ]], "./.config/awesome/src/scripts/vol.sh mute",
function(stdout) function(stdout)
if stdout:match("yes") then if stdout:match("yes") then
volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text("0%") volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text("0%")
volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icondir .. "volume-mute" .. ".svg") volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icondir .. "volume-mute" .. ".svg")
else else
awful.spawn.easy_async_with_shell( awful.spawn.easy_async_with_shell(
[[ "./.config/awesome/src/scripts/vol.sh volume",
pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'
]],
function(stdout2) function(stdout2)
stdout2 = stdout2:gsub("\n", "") stdout2 = stdout2:gsub("\n", "")
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2)) volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2))

10
awesome/src/scripts/vol.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
if [[ $1 == "volume" ]]
then
echo $(LC_ALL=C pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( 47 + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')
elif [[ $1 == "mute" ]]
then
echo $(LC_ALL=C pactl list sinks | grep '^[[:space:]]Mute:' | head -n $(( 47 + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')
fi

View File

@@ -58,9 +58,7 @@ return function()
local get_volume = function() local get_volume = function()
awful.spawn.easy_async_with_shell( awful.spawn.easy_async_with_shell(
[[ "./.config/awesome/src/scripts/vol.sh volume",
pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'
]],
function(stdout) function(stdout)
local icon = icondir .. "volume" local icon = icondir .. "volume"
stdout = stdout:gsub("%%", "") stdout = stdout:gsub("%%", "")
@@ -86,7 +84,7 @@ return function()
local check_muted = function() local check_muted = function()
awful.spawn.easy_async_with_shell( awful.spawn.easy_async_with_shell(
[[ pacmd list-sinks | grep "muted" ]], "./.config/awesome/src/scripts/vol.sh mute",
function(stdout) function(stdout)
if stdout:match("yes") then if stdout:match("yes") then
audio_widget.container.audio_layout.label.visible = false audio_widget.container.audio_layout.label.visible = false