2

In awesome 4.0, is there a way to only display the titlebar on floating windows?

Looking at the docs, there doesn't seem to be an option out of the box.

To specify; I'm looking for a solution that work when I dynamically switch windows between tiling and floating.

Juicy
  • 11,840
  • 35
  • 123
  • 212

3 Answers3

7

A bit late, but I wanted to do this too and I got it mostly working. It doesn't cover all the cases when you'd expect a client to show or hide its titlebar, but it's close enough for my use case. It's rather simple, first you need to disable titlebars for every client, so add titlebars_enabled = false in the properties of the default rule matching all clients.
Then, when a client becomes floating you need to toggle on his titlebar, and toggle it off when it stops floating.
I wrote this little helper function to make the code clearer. It's rather simple, if s is true then show the bar, hide it otherwise. But there's a catch, in our case the windows never had a titlebar so it isn't created yet. We send the signal to have one built for us if the current one is empty.

-- Toggle titlebar on or off depending on s. Creates titlebar if it doesn't exist
local function setTitlebar(client, s)
    if s then
        if client.titlebar == nil then
            client:emit_signal("request::titlebars", "rules", {})
        end
        awful.titlebar.show(client)
    else 
        awful.titlebar.hide(client)
    end
end

Now we can hook the property change:

--Toggle titlebar on floating status change
client.connect_signal("property::floating", function(c)
    setTitlebar(c, c.floating)
end)

But that only applies to clients that changes states after being created. We need a hook for new clients that are born floating or in a floating tag:

-- Hook called when a client spawns
client.connect_signal("manage", function(c) 
    setTitlebar(c, c.floating or c.first_tag.layout == awful.layout.suit.floating)
end)

And finally, if the current layout is floating, clients don't have the floating property set, so we need to add a hook for layout changes to add the tittlebars on clients inside.

-- Show titlebars on tags with the floating layout
tag.connect_signal("property::layout", function(t)
    -- New to Lua ? 
    -- pairs iterates on the table and return a key value pair
    -- I don't need the key here, so I put _ to ignore it
    for _, c in pairs(t:clients()) do
        if t.layout == awful.layout.suit.floating then
            setTitlebar(c, true)
        else
            setTitlebar(c, false)
        end
    end
end)

I didn't want to spend to much time on this so it doesn't cover cases where a client gets tagged in a floating layout, or when a client is tagged multiple times and one of those tag is floating.

Niverton
  • 163
  • 1
  • 2
  • 6
  • Awesome, thanks. But for some reason with these changes when you switch between floating and tiling awesome doesn't remember size of floating windows anymore, it just makes floating window cover whole screen area. – devalone Oct 06 '18 at 15:15
1

Change

{ rule_any = {type = { "normal", "dialog" }
  }, properties = { titlebars_enabled = true }
},

to

{ rule_any = {type = { "dialog" }
  }, properties = { titlebars_enabled = true }
},
  • it seems like this would only apply to new clients and not clients that I switch from tiled to floating? – Juicy Feb 21 '17 at 21:11
  • In that case, you need to connect to both `property::floating` (`client.connec_signal("property::floating", function(c) ... end`) and on the tag `property::layout` (and foreach all visible clients). Then toggle titlebars on them. But watch out, you will hit https://github.com/awesomeWM/awesome/issues/1588, it doesn't break the feature, but will only work if the client had a titlebar at some point. – Emmanuel Lepage Vallee Feb 21 '17 at 21:19
0

Niverton's solution works very well for simply switching from tiling to floating modes; however, floating windows will lose their titlebar when maximized and then unmaximized. To fix this, a better solution would be to replace

client.connect_signal("property::floating", function(c)
    setTitlebar(c, c.floating)
end)

with

client.connect_signal("property::floating", function(c)
    setTitlebar(c, c.floating or c.first_tag and c.first_tag.layout.name == "floating")
end)

This should fix the issue so that windows can be properly maximized without having to switch to tiling mode and back to get the titlebars again.

I found this general idea on a reddit post about the subject, provided by u/Ham5andw1ch. I have just simplified the code using Niverton's proposed function and some short-circuit logic.