【发布时间】:2021-08-04 07:57:44
【问题描述】:
在awesome 4.0 中,有没有办法只在浮动窗口上显示标题栏?
查看文档,似乎没有开箱即用的选项。
指定;我正在寻找一种在平铺和浮动之间动态切换窗口时有效的解决方案。
【问题讨论】:
标签: lua awesome-wm
在awesome 4.0 中,有没有办法只在浮动窗口上显示标题栏?
查看文档,似乎没有开箱即用的选项。
指定;我正在寻找一种在平铺和浮动之间动态切换窗口时有效的解决方案。
【问题讨论】:
标签: lua awesome-wm
有点晚了,但我也想这样做,而且大部分时间都在工作。当您希望客户端显示或隐藏其标题栏时,它并没有涵盖所有情况,但它对于我的用例来说已经足够接近了。
这很简单,首先你需要为每个客户端禁用标题栏,所以在匹配所有客户端的默认规则的属性中添加titlebars_enabled = false。
然后,当客户浮动时,您需要在其标题栏上进行切换,并在其停止浮动时将其关闭。
我写了这个小辅助函数来使代码更清晰。这很简单,如果s 是true 则显示栏,否则隐藏。但是有一个问题,在我们的例子中,窗口从来没有标题栏,所以它还没有被创建。如果当前为空,我们会发送信号为我们构建一个。
-- 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)
我不想花太多时间在这上面,所以它不包括客户端在浮动布局中被标记的情况,或者客户端被多次标记并且其中一个标记是浮动的情况。
【讨论】:
改变
{ rule_any = {type = { "normal", "dialog" }
}, properties = { titlebars_enabled = true }
},
到
{ rule_any = {type = { "dialog" }
}, properties = { titlebars_enabled = true }
},
【讨论】:
property::floating (client.connec_signal("property::floating", function(c) ... end) 和标签property::layout(以及所有可见客户端)。然后在它们上切换标题栏。但请注意,您会点击github.com/awesomeWM/awesome/issues/1588,它不会破坏该功能,但只有在客户端在某个时候有标题栏时才会起作用。
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 提出的函数和一些短路逻辑简化了代码。
【讨论】: