0

I create a wibox.container.background with something like:

local w = wibox.widget({
        {
          id = "texte",
          text = "mon texte",
          widget = wibox.widget.textbox
       },
       bg = beautiful.bg_normal,
       widget = wibox.container.background
})

Now I want to switch between two background colors with:

w.bg = w.bg == beautiful.bg_normal and beautiful.bg_focus or beautiful.bg_normal

But that doesn't work. It seems w.bg refers to a solid pattern and not to a simple hexa color string.

Am I pointing to the correct bg variable?

david
  • 1,302
  • 1
  • 10
  • 21

1 Answers1

1

I would recommend that you keep your own variable local is_focus = true and use that to update the background.

What happens is that the background "string" that you specify goes through gears.color and is transformed into a cairo pattern. That is what is then actually used for drawing. You could also pass in a cairo pattern directly and avoid the "loop" through gears.color.

Example for my proposed solution:

local w = wibox.widget({
        {
          id = "texte",
          text = "mon texte",
          widget = wibox.widget.textbox
       },
       bg = beautiful.bg_normal,
       widget = wibox.container.background
})
local is_focused = false
local function switch_background()
    is_focused = not is_focused
    w.bg = is_focused and beautiful.bg_focus or beautiful.bg_normal
end
Uli Schlachter
  • 9,337
  • 1
  • 23
  • 39