仅在浮动窗口上显示标题栏

awesome 4.0中,有没有一种方法仅在浮动窗口上显示标题栏?

查看文档,似乎没有开箱即用的选项。

要指定的是,我正在寻找一个可以在我动态切换窗口的平铺和浮动之间正常工作的解决方案。

点赞
用户1672598
用户1672598

将以下内容更改为:

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

更改为:

{ rule_any = {type = { "dialog" }
  }, properties = { titlebars_enabled = true }
},
2017-02-21 19:47:00
用户7735794
用户7735794

有点晚了,但我也想做这个并且我基本上弄好了。它没有涵盖所有情况,当您期望客户端显示或隐藏标题栏时,但对于我的用例来说足够接近了。

这相当简单,首先,您需要对所有客户端禁用标题栏,因此在匹配所有客户端的默认规则的属性中添加titlebars_enabled=false

然后,当客户端变为浮动时,您需要切换标题栏,并在停止浮动时将其切换掉。

我编写了这个小助手函数以使代码更清晰。它相当简单,如果strue,则显示栏,在其他情况下隐藏它。但是有一个注意点,在我们的情况下,窗口从未有过标题栏,因此它尚未创建。我们发送信号以请求为我们构建一个标题栏,如果当前标题栏为空。

-- 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

现在,我们可以连接属性更改:

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

但是这仅适用于在创建后更改状态的客户端。我们需要钩子来处理新的客户端,这些客户端在浮动或在浮动标签中诞生:

-- 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)

最后,如果当前布局是浮动的,则客户端没有设置浮动属性,因此我们需要在布局更改时添加挂钩以在内部为客户端添加标题栏。

-- 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)

我不想花费太多时间在这上面,因此它不涵盖将客户端标记为浮动布局的情况,或者当客户端被多次标记并且其中一个标记是浮动的情况。

2017-05-22 19:21:51
用户16588915
用户16588915

Niverton的解决方案非常适用于简单地从平铺模式切换到浮动模式;然而,当窗口最大化然后再次取消最大化,浮动窗口将失去它们的标题栏。为了解决这个问题,更好的解决方案是将

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

替换为

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

这应该解决这个问题,这样窗口就可以正确地最大化,而不需要切换到平铺模式,然后再次切回来以获得标题栏。

我在由u / Ham5andw1ch提供的Reddit帖子中发现了这个总体想法。我只是使用Niverton提出的函数和一些短路逻辑来简化了代码。

2021-08-03 23:57:44