Elv13 / tyrannical

Dynamic tagging configuration system for awesomeWM
210 stars 33 forks source link

Make clients keep their tags when restarting awesome #65

Open Akulen opened 8 years ago

Akulen commented 8 years ago

Hey o/,

I wasn't able to try my code with multiple screens, so i don't know if it will work, but here it is:

That's the code that loads the tags after awesome started :

local tyrannical

awful.client.property.persist("startup", "boolean")
awful.client.property.persist("disp", "string")

local tags = {}

if (#client.get() > 1 and client.get()[1].startup) then
    tyrannical = require("tyrannical")
else
    gears.timer.delayed_call(function() 
        tyrannical  = require("tyrannical")
        tyrannical.tags = tags.tags

        for _, c in ipairs(client.get()) do
            c:tags({c.screen.tags[11]})
        end
        for _, c in ipairs(client.get()) do
            disp = nil
            load("disp = " .. c.disp)()
            local ctags = {}
            for i, t in ipairs(disp.tags) do
                ctags[i] = c.screen.tags[t]
            end
            if(#ctags) then
                c:tags(ctags)
            end
        end
    end)
end

-- tags.tags definition

if (#client.get() > 1 and client.get()[1].startup) then
    tyrannical.tags = tags.tags
end

And this is a function to launch before awesome.restart to save client-tag matchings:

function()
    for _, c in ipairs(client.get()) do
        local screen = c.screen.index
        local ctags = {}
        for i, t in ipairs(c:tags()) do
            ctags[i] = t.index
        end
        c.disp = utils.serialise({screen = screen, tags = ctags})
    end
end

(and utils.serialise just comes from your repo Forgotten. I've copied and pasted the function into a utils.lua file and required it)