Iterate through all selected tasks. Awesome Window Manager

69 Views Asked by At

Access to all selected tasks in my taskslist. Awesome WM

I defined the following tasklist:

    s.mytasklist = awful.widget.tasklist {
        screen  = s,
        filter  = awful.widget.tasklist.filter.currenttags,
        buttons = bindings.tasklist_mouse,
        widget_template = {
             {
                layout = wibox.layout.fixed.vertical,
                {
                    {
                        left = 100,
                        right = 100,
                        bottom = 5,
                        widget = wibox.container.margin,
                    },
                    id = "overline",
                    bg = beautiful.underline_color,
                    shape = gears.shape.rectangle,
                    widget = wibox.container.background
                },
                {
                    layout = wibox.layout.fixed.horizontal,
                    {
                        {
                            id = "icon_role",
                            widget = wibox.widget.imagebox,
                            resize = true,
                            forced_width = 20
                        },
                        margins = 5,
                        widget = wibox.container.margin
                    },
                    {
                        id = "text_role",
                        widget = wibox.widget.textbox
                    },
                },
             },
             id = "background_role",
             widget = wibox.container.background,
             shape = gears.shape.rectangle,
             create_callback = function(self, c, index, objects)
                 for i, task in ipairs(objects) do
                     print(task.name)
                 end
             end
         },
    }

I would like to iterate through all the selected tasks, in the functions "create_callback" and "update_callback", and if the task is selected, change the color to "overline" item. I tried using "awful.tasklist.filter.currenttags" but didn't work.

1

There are 1 best solutions below

0
Uli Schlachter On

To iterate over all selected tags for a screen, you can use s.selected_tags.

Example from https://github.com/awesomeWM/awesome/blob/485661b706752212dac35e91bb24a0e16a677b70/tests/test-awful-client.lua#L231 :

        -- Just in case
        for _, t in ipairs(s.selected_tags) do
            assert(t.screen == s)
        end

(This code comes from a test and thus doesn't do anything too useful. It still iterates over all tags.)


and if the task is selected, change the color to "overline" item.

I think you do not actually want to iterate over all tags for this. The caller of update_callback already does the iteration for you. In this function, you just need to do the actual update that you want to do.

Untested example (I am guessing overline has a .bg property based on how you create it, I half-guess that t.selected is a thing (at least git grep .selected finds something) and the colors are only a proof of concept and can obviously be replaced):

update_callback = function(self, t, index, objects)
  overline = self:get_children_by_id("overline")[1]
  if t.selected then
    overline.bg = "#000000"
  else
    overline.bg = "#ffffff"
  end
end