How to hide borders dynamically from windows when not tiled (Awesome WM)?
Asked Answered
Z

3

6

I'd like to remove the border from any window which is not tiled (no matter where it is maximized or just a single window assigned to a tag) and add borders as soon as it get's tiled, all while using the same layout.

I tried this solution (with changing client.add_signal to client.connect_signal): http://blog.lazut.in/2012/11/awesome-wm-remove-border-from-maximized.html

client.connect_signal("focus",
     function(c)
        if c.maximized_horizontal == true and c.maximized_vertical == true then
           c.border_width = "0"
           c.border_color = beautiful.border_focus
        else
           c.border_width = beautiful.border_width
           c.border_color = beautiful.border_focus
        end
     end)

but it only worked for some maximized windows and overwrote the borders I removed (e.g. for the synapse launcher) through properties in awful.rules.rules.

I saw the tiled(screen) function listed in the official awesome API documentation, maybe something could be done with that? I'm still new to the Awesome WM, so a little help would be appreciated.

Z answered 19/5, 2015 at 11:24 Comment(0)
A
3

This is what I have in my rc.lua to achieve the same result:

for s = 1, screen.count() do
    screen[s]:connect_signal("arrange", function ()
        local clients = awful.client.visible(s)
        local layout  = awful.layout.getname(awful.layout.get(s))

        -- No borders with only one visible client or in maximized layout
        if #clients > 1 and layout ~= "max" then
            for _, c in pairs(clients) do -- Floaters always have borders
                if not awful.rules.match(c, {class = "Synapse"}) and awful.client.floating.get(c) or layout == "floating" then                                     
                    c.border_width = beautiful.border_width
                    c.border_color = beautiful.border_focus
                end
            end
        end
    end)
end

I added the condition if not awful.rules.match(c, {class = "Synapse"})... to handle the synapse launcher case you specified. But it may be already covered by the other conditions (the launcher should already be floating, therefore the next condition would not allow it to get a border)

Agreement answered 9/6, 2015 at 23:35 Comment(1)
Thanks for this! It's worth mentioning that in combination with this, the default rule for clients should have border_width set to zero by some means.Ries
M
8

Here's my version for Awesome 4.2:

screen.connect_signal("arrange", function (s)
    local max = s.selected_tag.layout.name == "max"
    local only_one = #s.tiled_clients == 1 -- use tiled_clients so that other floating windows don't affect the count
    -- but iterate over clients instead of tiled_clients as tiled_clients doesn't include maximized windows
    for _, c in pairs(s.clients) do
        if (max or only_one) and not c.floating or c.maximized then
            c.border_width = 0
        else
            c.border_width = beautiful.border_width
        end
    end
end)

I believe it correctly handles maximized windows, windows that are the only visible one in the layout, and windows in the 'max' layout. It also ignores floating clients as it should.

Moquette answered 4/8, 2018 at 16:1 Comment(1)
I came across your post and really appreciate the code helped a lot to get my system working also been trying to get dynamic border colors working also but been having some trouble differentiating between focus and none focused windows wondering if you had any ideas. In particular where did you find the "s.selected_tag.layout.name" function at I have been through the docs and have had this issue before I ask a question and there is a function that does what I want already but its isn't in the docs or is poorly filed so you can't find them.Olwena
A
3

This is what I have in my rc.lua to achieve the same result:

for s = 1, screen.count() do
    screen[s]:connect_signal("arrange", function ()
        local clients = awful.client.visible(s)
        local layout  = awful.layout.getname(awful.layout.get(s))

        -- No borders with only one visible client or in maximized layout
        if #clients > 1 and layout ~= "max" then
            for _, c in pairs(clients) do -- Floaters always have borders
                if not awful.rules.match(c, {class = "Synapse"}) and awful.client.floating.get(c) or layout == "floating" then                                     
                    c.border_width = beautiful.border_width
                    c.border_color = beautiful.border_focus
                end
            end
        end
    end)
end

I added the condition if not awful.rules.match(c, {class = "Synapse"})... to handle the synapse launcher case you specified. But it may be already covered by the other conditions (the launcher should already be floating, therefore the next condition would not allow it to get a border)

Agreement answered 9/6, 2015 at 23:35 Comment(1)
Thanks for this! It's worth mentioning that in combination with this, the default rule for clients should have border_width set to zero by some means.Ries
H
2

With awesome 4.0, titlebars offer more flexibility than window borders. I use titlebars to create top and left borders. This way, I have borders to distinguish clients in tiled mode, but I can still move my mouse to the right or bottom edge of the screen and click the scrollbar. This also helps me tell which is the focused client.

Here is a piece of my theme.lua, where I define theme.bar_width:

-- {{{ Borders
theme.useless_gap   = 0
theme.border_width  = 0
theme.bar_width = 2
theme.border_normal = "#3F3F3F"
theme.border_focus  = "#6F6F6F"
theme.border_marked = "#CC9393"
-- }}}

And here are two pieces from my rc.lua, where I define the two titlebars:

client.connect_signal("request::titlebars", function(c)
    -- ...

    -- The top bar
    -- code was: awful.titlebar(c) : setup { ...
    -- code became:
    awful.titlebar(c, {
        position = "top",
        bg_normal = beautiful.border_normal,
        bg_focus  = beautiful.border_focus,
    }):setup{
        -- ...
    }

    -- The left bar
    awful.titlebar(c, {
        position = "left",
        size = beautiful.bar_width,
        bg_normal = beautiful.border_normal,
        bg_focus  = beautiful.border_focus,
    })

    -- ...
end)
Herman answered 5/11, 2017 at 4:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.