Different background color for each taglist item AwesomeWM

Viewed 781

how can I set a different background color for each taglist item? I know I have to use widget_template but I don't know how, I'm on awesomeWM 4.3

2 Answers

Suppose you have tags named with keys of this colors table:

colors = {
   term = "#FF0000",
   www = "#00FF00",
   divers = "#0000FF",
   travail = "#FF0000",
   default = "#00FF00"
}

and maybe some others.

With widget_template, (you've cited), within awful.widget.taglist:

widget_template = {
       {
          id     = 'text_role',
          widget = wibox.widget.textbox
        },
        id     = 'bg',
        widget = wibox.container.background,
        create_callback = function(self, t, index, tagsList)
           self.bg = colors[t.name] or colors.default
        end,
    }

enter image description here

See also: documentation

I was able to change the colors by overriding internal function taglist.taglist_label:

local original_taglist_label = awful.widget.taglist.taglist_label
local tag_colors_b = { "#3a3f50", "#3a3a50", "#3f3a50", "#453a50",
  "#4b3b51", "#4a3a50", "#503a50", "#503a4a", "#503a45" }
local tag_colors_s = { "#606a85", "#606085", "#6a6085", "#736085",
  "#7b6085", "#7c6085", "#856085", "#85607c", "#856073" }
function awful.widget.taglist.taglist_label(tag, args, tb)
  local idx = (tag.index - 1) % #tag_colors_b + 1
  local args = {bg_focus = tag_colors_s[idx]}
  local text, bg, bg_image, icon, other_args =
    original_taglist_label(tag, args, tb)
  if bg == nil then
    bg = tag_colors_b[idx]
  end
  return text, bg, bg_image, icon, other_args
end

enter image description here

Related