Pop-Up Menu for Awesome WM Tasklist

  Kiến thức lập trình

I am trying to get a pop-up of available tasks for a tasklist which groups tasks.

The code for the tasklist and associated pop-up come from:

Grouping Windows in the tasklist

Using the first bit of code:

s.mytasklist = awful.widget.tasklist {
    screen = s,
    filter = function() return true end, -- Filtering is already done in source
    source = function()
        -- Get all clients
        local cls = client.get()

        -- Filter by an existing filter function and allowing only one client per class
        local result = {}
        local class_seen = {}
        for _, c in pairs(cls) do
            if awful.widget.tasklist.filter.currenttags(c, s) then
                if not class_seen[c.class] then
                    class_seen[c.class] = true
                    table.insert(result, c)
                end
            end
        end
        return result
    end,
}

I was able to get the tasklist to group common tasks. However, I cannot figure out where to add the bit of code for the pop-up button given below:

awful.button({ }, 1, function (c)

    if cl_menu then
        cl_menu:hide()
        cl_menu=nil
    else
        client_num=0
        client_list={}
        for i, cl in pairs(client.get()) do
            if cl.class == c.class then
                client_num = client_num + 1
                client_list[i]=
                  {cl.name,
                   function()
                       client.focus = cl
                       awful.tag.viewonly(cl:tags()[1])
                       cl:raise()
                   end,
                   cl.icon
                  }
           end
        end

        if client_num > 1 then
            cl_menu=awful.menu({items = client_list, theme = {width=300}})
            cl_menu:show()
        else
            client.focus = c
            awful.tag.viewonly(c:tags()[1])
            c:raise() 
        end
    end
end),

I’ve tried placing it by itself outside of any other code in the global scope and within both the tasklist definition and soure definitions.

I am an absolute beginner with LUA, though I’ve been using Awesome Wm for a while doing pretty simple copy-paste editing of pre-made rc.lua and theme.lua files.

I appreciate any and all help with this.

  • Robert

New contributor

Robert Nielsen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT