每个标签列表项的不同背景颜色 AwesomeWM

我该如何为每个标签列表项设置不同的背景颜色呢?我知道我得使用 widget_template,但我不知道该怎么做,我使用的是 awesomeWM 4.3

点赞
用户5539707
用户5539707

假设您有一个使用这个颜色表键名的标签:

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

还可能有其他的标签。

使用 awful.widget.taglist 中的 widget_template(您已经引用过):

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

另请参阅:文档

2020-07-09 16:32:15
用户191224
用户191224

我能够通过覆盖内部函数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

2020-10-03 22:24:16