Search code examples
luaawesome-wm

How to change the titlebar's bgimage scale


I have a certain picture I want to turn into my titlebar background, but I don't know how to make it strech so it fits the entire titlebar. Any advice?


Solution

  • Here is a patch to the default config which makes titlebars have a background from a file. The file is scaled to the exact size of the titlebar.

    diff --git a/awesomerc.lua b/awesomerc.lua
    index fa584b8a8..3e3a54c0d 100644
    --- a/awesomerc.lua
    +++ b/awesomerc.lua
    @@ -542,6 +542,14 @@ client.connect_signal("manage", function (c)
         end
     end)
    
    +local tb_bg_image = gears.surface("/tmp/variant_outside.png")
    +local bg_width, bg_height = gears.surface.get_size(tb_bg_image)
    +local function bg_image_function(_, cr, width, height)
    +    cr:scale(width / bg_width, height / bg_height)
    +    cr:set_source_surface(tb_bg_image)
    +    cr:paint()
    +end
    +
     -- @DOC_TITLEBARS@
     -- Add a titlebar if titlebars_enabled is set to true in the rules.
     client.connect_signal("request::titlebars", function(c)
    @@ -557,7 +565,8 @@ client.connect_signal("request::titlebars", function(c)
             end)
         )
    
    -    awful.titlebar(c) : setup {
    +    local args = { bgimage_normal = bg_image_function, bgimage_focus = bg_image_function }
    +    awful.titlebar(c, args) : setup {
             { -- Left
                 awful.titlebar.widget.iconwidget(c),
                 buttons = buttons,