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,66 +101,64 @@ 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")
volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(volume_level .. "%") volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(volume_level .. "%")
awesome.emit_signal(
"widget::volume:update",
volume_level
)
if awful.screen.focused().show_volume_osd then
awesome.emit_signal( awesome.emit_signal(
"widget::volume:update", "module::volume_osd:show",
volume_level true
) )
if awful.screen.focused().show_volume_osd then
awesome.emit_signal(
"module::volume_osd:show",
true
)
end
volume_level = tonumber(volume_level)
local icon = icondir .. "volume"
if volume_level < 1 then
icon = icon .. "-mute"
elseif volume_level >= 1 and volume_level < 34 then
icon = icon .. "-low"
elseif volume_level >= 34 and volume_level < 67 then
icon = icon .. "-medium"
elseif volume_level >= 67 then
icon = icon .. "-high"
end
volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end end
volume_level = tonumber(volume_level)
local icon = icondir .. "volume"
if volume_level < 1 then
icon = icon .. "-mute"
elseif volume_level >= 1 and volume_level < 34 then
icon = icon .. "-low"
elseif volume_level >= 34 and volume_level < 67 then
icon = icon .. "-medium"
elseif volume_level >= 67 then
icon = icon .. "-high"
end
volume_osd_widget.container.osd_layout.icon_slider_layout.icon_margin1.icon_margin2.icon:set_image(icon .. ".svg")
end
) )
end end
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:connect_signal( volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:connect_signal(
"property::value", "property::value",
function() function()
update_osd() update_osd()
end end
) )
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)
]], stdout2 = stdout2:gsub("\n", "")
function(stdout2) volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2))
stdout2 = stdout2:gsub("\n", "") update_osd()
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2))
update_osd()
end
)
end end
)
end end
end
) )
end end
@@ -168,15 +166,15 @@ return function(s)
awesome.connect_signal( awesome.connect_signal(
"module::slider:update", "module::slider:update",
function() function()
update_slider() update_slider()
end end
) )
awesome.connect_signal( awesome.connect_signal(
"widget::volume:update", "widget::volume:update",
function(value) function(value)
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(value)) volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(value))
end end
) )
update_slider() update_slider()
@@ -210,36 +208,36 @@ return function(s)
awesome.connect_signal( awesome.connect_signal(
"module::volume_osd:show", "module::volume_osd:show",
function() function()
if s == mouse.screen then if s == mouse.screen then
volume_container.visible = true volume_container.visible = true
end
end end
end
) )
volume_container:connect_signal( volume_container:connect_signal(
"mouse::enter", "mouse::enter",
function() function()
volume_container.visible = true volume_container.visible = true
hide_volume_osd:stop() hide_volume_osd:stop()
end end
) )
volume_container:connect_signal( volume_container:connect_signal(
"mouse::leave", "mouse::leave",
function() function()
volume_container.visible = true volume_container.visible = true
hide_volume_osd:again() hide_volume_osd:again()
end end
) )
awesome.connect_signal( awesome.connect_signal(
"widget::volume_osd:rerun", "widget::volume_osd:rerun",
function() function()
if hide_volume_osd.started then if hide_volume_osd.started then
hide_volume_osd:again() hide_volume_osd:again()
else else
hide_volume_osd:start() hide_volume_osd:start()
end
end end
end
) )
end end

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,45 +58,43 @@ 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("%%", "")
local volume = tonumber(stdout) or 0 local volume = tonumber(stdout) or 0
audio_widget.container.audio_layout.spacing = dpi(5) audio_widget.container.audio_layout.spacing = dpi(5)
audio_widget.container.audio_layout.label.visible = true audio_widget.container.audio_layout.label.visible = true
if volume < 1 then if volume < 1 then
icon = icon .. "-mute" icon = icon .. "-mute"
audio_widget.container.audio_layout.spacing = dpi(0) audio_widget.container.audio_layout.spacing = dpi(0)
audio_widget.container.audio_layout.label.visible = false audio_widget.container.audio_layout.label.visible = false
elseif volume >= 1 and volume < 34 then elseif volume >= 1 and volume < 34 then
icon = icon .. "-low" icon = icon .. "-low"
elseif volume >= 34 and volume < 67 then elseif volume >= 34 and volume < 67 then
icon = icon .. "-medium" icon = icon .. "-medium"
elseif volume >= 67 then elseif volume >= 67 then
icon = icon .. "-high" icon = icon .. "-high"
end
audio_widget.container.audio_layout.label:set_text(volume .. "%")
audio_widget.container.audio_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icon .. ".svg", color["Grey900"]))
end end
audio_widget.container.audio_layout.label:set_text(volume .. "%")
audio_widget.container.audio_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icon .. ".svg", color["Grey900"]))
end
) )
end end
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
audio_widget.container:set_right(0) audio_widget.container:set_right(0)
audio_widget.container.audio_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icondir .. "volume-mute" .. ".svg", color["Grey900"])) audio_widget.container.audio_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icondir .. "volume-mute" .. ".svg", color["Grey900"]))
else else
audio_widget.container:set_right(10) audio_widget.container:set_right(10)
get_volume() get_volume()
end
end end
end
) )
end end
@@ -106,18 +104,18 @@ return function()
audio_widget:connect_signal( audio_widget:connect_signal(
"button::press", "button::press",
function() function()
awesome.emit_signal("widget::volume") awesome.emit_signal("widget::volume")
awesome.emit_signal("module::volume_osd:show", true) awesome.emit_signal("module::volume_osd:show", true)
awesome.emit_signal("module::slider:update") awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun") awesome.emit_signal("widget::volume_osd:rerun")
end end
) )
awesome.connect_signal( awesome.connect_signal(
"widget::volume", "widget::volume",
function(c) function(c)
check_muted() check_muted()
end end
) )
check_muted() check_muted()