lcpz / lain

Awesome WM complements
GNU General Public License v2.0
1.06k stars 210 forks source link

pipewire widget with pactl #534

Closed fakeGenuis closed 2 years ago

fakeGenuis commented 2 years ago

For someone use pipewire as the low-level multimedia framework, the pacmd may not available, there is pactl instead (see pacmd - Migrate PulseAudio). And it's outputs is different with those in pulse.lua, so i change pulse.lua a little to a new file pipewire.lua.

lcpz commented 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.

dixiedream commented 2 years ago

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
}
lcpz commented 2 years ago

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.

dixiedream commented 2 years ago

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: @.***>

lcpz commented 2 years ago

Since awesome-www/pull/167 has been merged, you can find the recipe here and, once they refresh the website, also here.

Aire-One commented 2 years ago

and, once they refresh the website, also here.

It should be done automatically 🤔

Oh lol! I remember now, there is this "Travis no longer offers a free tier" story that we need to resolve by switching to GitHub Actions.