Search code examples
awesome-wm

How can I capture which taglist button was clicked?


I've noticed that the taglist buttons don't accept middle mouse events for the default config.

I am hoping to add it to mine, with a twist!

Using the middle mouse button, I would like to run a different command for each tag. The only thing I'm missing is the correct usage of the if statement, I'm not too sure on how to detect the tag that has been clicked on, any help will really be appreciated.

mytaglist.buttons = awful.util.table.join(
    awful.button({ }, 2,
        function(t)
            if     ????? (taglist button 1 has been middle clicked)
                runscript1
            elseif ????? (taglist button 2 has been middle clicked)
                runscript2
            end 

Solution

  • According to the docs, the tag object, that is passed to the function, has a "name" field that contains the tag's name as string.

    That means you need to write it like this:

    mytaglist.buttons = awful.util.table.join(
        awful.button({ }, 2,
            function(t)
                if t.name == "1" -- first tag pressed
                    runscript1
                elseif t.name == "2" -- second tag pressed
                    runscript2
                end
            ...