Change pacmd to pactl for better compatibility with pipewire
This commit is contained in:
@@ -101,66 +101,64 @@ return function(s)
|
||||
|
||||
local function update_osd()
|
||||
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)
|
||||
local volume_level = stdout:gsub("\n", "")
|
||||
awesome.emit_signal("widget::volume")
|
||||
volume_osd_widget.container.osd_layout.icon_slider_layout.label_value_layout.value:set_text(volume_level .. "%")
|
||||
local volume_level = stdout:gsub("\n", "")
|
||||
awesome.emit_signal("widget::volume")
|
||||
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(
|
||||
"widget::volume:update",
|
||||
volume_level
|
||||
"module::volume_osd:show",
|
||||
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
|
||||
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_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:connect_signal(
|
||||
"property::value",
|
||||
function()
|
||||
update_osd()
|
||||
end
|
||||
update_osd()
|
||||
end
|
||||
)
|
||||
|
||||
local update_slider = function()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[ pacmd list-sinks | grep "muted" ]],
|
||||
"./.config/awesome/src/scripts/vol.sh mute",
|
||||
function(stdout)
|
||||
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.icon_margin1.icon_margin2.icon:set_image(icondir .. "volume-mute" .. ".svg")
|
||||
else
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[
|
||||
pacmd list-sinks|grep -A 15 '* index'| awk '/volume: front/{ print $5 }' | sed 's/[%|,]//g'
|
||||
]],
|
||||
function(stdout2)
|
||||
stdout2 = stdout2:gsub("\n", "")
|
||||
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2))
|
||||
update_osd()
|
||||
end
|
||||
)
|
||||
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.icon_margin1.icon_margin2.icon:set_image(icondir .. "volume-mute" .. ".svg")
|
||||
else
|
||||
awful.spawn.easy_async_with_shell(
|
||||
"./.config/awesome/src/scripts/vol.sh volume",
|
||||
function(stdout2)
|
||||
stdout2 = stdout2:gsub("\n", "")
|
||||
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(stdout2))
|
||||
update_osd()
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
@@ -168,15 +166,15 @@ return function(s)
|
||||
awesome.connect_signal(
|
||||
"module::slider:update",
|
||||
function()
|
||||
update_slider()
|
||||
end
|
||||
update_slider()
|
||||
end
|
||||
)
|
||||
|
||||
awesome.connect_signal(
|
||||
"widget::volume:update",
|
||||
function(value)
|
||||
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(value))
|
||||
end
|
||||
volume_osd_widget.container.osd_layout.icon_slider_layout.slider_layout.volume_slider:set_value(tonumber(value))
|
||||
end
|
||||
)
|
||||
|
||||
update_slider()
|
||||
@@ -210,36 +208,36 @@ return function(s)
|
||||
awesome.connect_signal(
|
||||
"module::volume_osd:show",
|
||||
function()
|
||||
if s == mouse.screen then
|
||||
volume_container.visible = true
|
||||
end
|
||||
if s == mouse.screen then
|
||||
volume_container.visible = true
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
volume_container:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
volume_container.visible = true
|
||||
hide_volume_osd:stop()
|
||||
end
|
||||
volume_container.visible = true
|
||||
hide_volume_osd:stop()
|
||||
end
|
||||
)
|
||||
|
||||
volume_container:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
volume_container.visible = true
|
||||
hide_volume_osd:again()
|
||||
end
|
||||
volume_container.visible = true
|
||||
hide_volume_osd:again()
|
||||
end
|
||||
)
|
||||
|
||||
awesome.connect_signal(
|
||||
"widget::volume_osd:rerun",
|
||||
function()
|
||||
if hide_volume_osd.started then
|
||||
hide_volume_osd:again()
|
||||
else
|
||||
hide_volume_osd:start()
|
||||
end
|
||||
if hide_volume_osd.started then
|
||||
hide_volume_osd:again()
|
||||
else
|
||||
hide_volume_osd:start()
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
10
awesome/src/scripts/vol.sh
Executable file
10
awesome/src/scripts/vol.sh
Executable 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
|
||||
|
||||
@@ -58,45 +58,43 @@ return function()
|
||||
|
||||
local get_volume = function()
|
||||
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)
|
||||
local icon = icondir .. "volume"
|
||||
stdout = stdout:gsub("%%", "")
|
||||
local volume = tonumber(stdout) or 0
|
||||
audio_widget.container.audio_layout.spacing = dpi(5)
|
||||
audio_widget.container.audio_layout.label.visible = true
|
||||
if volume < 1 then
|
||||
icon = icon .. "-mute"
|
||||
audio_widget.container.audio_layout.spacing = dpi(0)
|
||||
audio_widget.container.audio_layout.label.visible = false
|
||||
elseif volume >= 1 and volume < 34 then
|
||||
icon = icon .. "-low"
|
||||
elseif volume >= 34 and volume < 67 then
|
||||
icon = icon .. "-medium"
|
||||
elseif volume >= 67 then
|
||||
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"]))
|
||||
local icon = icondir .. "volume"
|
||||
stdout = stdout:gsub("%%", "")
|
||||
local volume = tonumber(stdout) or 0
|
||||
audio_widget.container.audio_layout.spacing = dpi(5)
|
||||
audio_widget.container.audio_layout.label.visible = true
|
||||
if volume < 1 then
|
||||
icon = icon .. "-mute"
|
||||
audio_widget.container.audio_layout.spacing = dpi(0)
|
||||
audio_widget.container.audio_layout.label.visible = false
|
||||
elseif volume >= 1 and volume < 34 then
|
||||
icon = icon .. "-low"
|
||||
elseif volume >= 34 and volume < 67 then
|
||||
icon = icon .. "-medium"
|
||||
elseif volume >= 67 then
|
||||
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
|
||||
|
||||
local check_muted = function()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[ pacmd list-sinks | grep "muted" ]],
|
||||
"./.config/awesome/src/scripts/vol.sh mute",
|
||||
function(stdout)
|
||||
if stdout:match("yes") then
|
||||
audio_widget.container.audio_layout.label.visible = false
|
||||
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"]))
|
||||
else
|
||||
audio_widget.container:set_right(10)
|
||||
get_volume()
|
||||
end
|
||||
if stdout:match("yes") then
|
||||
audio_widget.container.audio_layout.label.visible = false
|
||||
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"]))
|
||||
else
|
||||
audio_widget.container:set_right(10)
|
||||
get_volume()
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
@@ -106,18 +104,18 @@ return function()
|
||||
audio_widget:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
awesome.emit_signal("widget::volume")
|
||||
awesome.emit_signal("module::volume_osd:show", true)
|
||||
awesome.emit_signal("module::slider:update")
|
||||
awesome.emit_signal("widget::volume_osd:rerun")
|
||||
end
|
||||
awesome.emit_signal("widget::volume")
|
||||
awesome.emit_signal("module::volume_osd:show", true)
|
||||
awesome.emit_signal("module::slider:update")
|
||||
awesome.emit_signal("widget::volume_osd:rerun")
|
||||
end
|
||||
)
|
||||
|
||||
awesome.connect_signal(
|
||||
"widget::volume",
|
||||
function(c)
|
||||
check_muted()
|
||||
end
|
||||
check_muted()
|
||||
end
|
||||
)
|
||||
|
||||
check_muted()
|
||||
|
||||
Reference in New Issue
Block a user