Closed fakeGenuis closed 2 years ago
Thank you for this, there are a couple of things to fix.
It should go to widget/contrib
, and needs a wiki entry.
Here is my simplified version, can add pull request if needed
local helpers = require("lain.helpers")
local shell = require("awful.util").shell
local wibox = require("wibox")
local string = string
-- Pipewire volume
-- lain.widget.contrib.pipewire
local function factory(args)
args = args or {}
local pipewire = { widget = args.widget or wibox.widget.textbox(), device = "N/A" }
local timeout = args.timeout or 5
local settings = args.settings or function() end
pipewire.cmd = "echo \"Volume: $(pactl get-sink-volume @DEFAULT_SINK@ | awk -F '/' 'NF > 0 {print $4}' | sed 's/^[ \t]*//;s/[ \t]*$//')\"; pactl get-sink-mute @DEFAULT_SINK@"
function pipewire.update()
helpers.async({ shell, "-c", pipewire.cmd },
function(s)
volume_now = {
muted = string.match(s, "Mute: (%S+)") or "N/A",
value = string.match(s, "Volume: (%d+)%%") or "N/A/",
}
widget = pipewire.widget
settings()
end)
end
helpers.newtimer("pipewire", timeout, pipewire.update)
return pipewire
end
return factory
How to use it (an example...)
local volume = lain.widget.pipewire {
settings = function()
vlevel = "V " .. volume_now.value .. "% "
if volume_now.muted == "yes" then
vlevel = vlevel .. "M"
end
widget:set_markup(lain.util.markup("#7493d2", vlevel .. " "))
end
}
At this point, you can simply use a watcher. The following example assumes a stereo configuration.
local volume = awful.widget.watch(
"pactl get-sink-volume @DEFAULT_SINK@ | cut -s -d/ -f2,4; pactl get-sink-mute @DEFAULT_SINK@",
5, -- timeout seconds
function(widget, stdout)
local volume = "Volume: "
for v in stdout:gmatch("(%d+%%)") do volume = volume .. " " .. v end
if #volume == 8 then volume = "N/A" -- if previous loop didn't match anything
local mute = string.match(stdout, "Mute: (%S+)") or "N/A"
-- customize here
widget:set_markup(volume .. " " .. mute)
end
)
@dixiedream You can send it as a PR to awesome-www. See here for previous examples.
Thanks!
From: Luca CPZ @.> Sent: Saturday, June 18, 2022 13:48 To: lcpz/lain @.> Cc: Alessandro Lucarini @.>; Mention @.> Subject: Re: [lcpz/lain] pipewire widget with pactl (PR #534)
At this point, you can simply use a watcherhttps://awesomewm.org/recipes/watch. The following example assumes a stereo configuration.
local volume = awful.widget.watch( "pactl get-sink-volume @DEFAULT_SINK@ | cut -s -d/ -f2,4; pactl get-sink-mute @DEFAULT_SINK@", 5, -- timeout seconds function(widget, stdout) local volume = "Volume: " for v in stdout:gmatch("(%d+%%)") do volume = volume .. " " .. v end if #volume == 8 then volume = "N/A" -- if previous loop didn't match anything local mute = string.match(stdout, "Mute: (%S+)") or "N/A"
-- customize here
widget:set_markup(volume .. " " .. mute)
end
)
@dixiedreamhttps://github.com/dixiedream You can send it as a PR to awesome-wwwhttps://github.com/awesomeWM/awesome-www. See herehttps://github.com/awesomeWM/awesome-www/pulls?q=is%3Apr+is%3Aclosed+watch for previous examples.
— Reply to this email directly, view it on GitHubhttps://github.com/lcpz/lain/pull/534#issuecomment-1159450461, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB3LE4U7FR5ZPL5XWWBP33LVPWZQBANCNFSM5YKWWUZQ. You are receiving this because you were mentioned.Message ID: @.***>
Since awesome-www/pull/167 has been merged, you can find the recipe here and, once they refresh the website, also here.
For someone use
pipewire
as the low-level multimedia framework, thepacmd
may not available, there ispactl
instead (see pacmd - Migrate PulseAudio). And it's outputs is different with those inpulse.lua
, so i changepulse.lua
a little to a new filepipewire.lua
.