lcpz / lain

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

Do not use global variables #550

Open lcpz opened 1 year ago

lcpz commented 1 year ago

The following widgets use _now global variables:

$ git grep "_now" | cut -d: -f1 | uniq                                                                                                                                                                            
alsa.lua
alsabar.lua
bat.lua
contrib/moc.lua
contrib/tp_smapi.lua
cpu.lua
fs.lua
imap.lua
mem.lua
mpd.lua
net.lua
pulse.lua
pulsebar.lua
temp.lua
weather.lua

We should use table-based variables instead, and thus eliminate the use of widget within a settings() function. Example:

local mpd = lain.widget.mpd {
    settings = function()
        local title  = "mpd"
        local artist = "off"

        if mpd.now.state == "play" then -- instead of `mpd_now`
            title  = mpd.now.title
            artist = mpd.now.artist
        end

        mpd.widget:set_text(title .. " " .. artist) -- instead of `widget:set_text`
    end
}

This will break the current usage.

razamatan commented 1 year ago

i can start doing this for the widgets that i actively use (pulsebar, mpd), touched recently for prototyping (weather), and anything else when i feel bored.

as for how this should land wrt #549, i get the sense you want it separated and after it?

razamatan commented 1 year ago

PTAL @ https://github.com/razamatan/lain/pull/1/files.

i actually went with the direction of assuming that i would land the libsoup change first, then this one, hence i didn't do a pr yet (and showing the pr diff to address this issue in my own repo). if you feel strongly about flipping the order, i can do the work to put the glob pr before the libsoup one.

lmk.

razamatan commented 1 year ago

everything ok..?