我使用了很棒的WM,我希望在创建/删除客户端后运行lua函数。具体来说,我想将标记的名称更改为标记上的一个客户端的名称。
我使用计时器执行此操作,但我认为执行此操作的最佳方法是向awesomeWM注册一个回调函数,它将在创建/删除客户端时调用。
我可以实现一些钩子/回调来告诉我真棒吗?
---------------------------------------------更新 - ---------------------------------------
我尝试使用这些信号,但是在创建窗口并附加到标签后,我无法找到更改的正确信号调用我的功能。我尝试使用manage / unmanage tagged / untagged和tag.new等,但没有人帮忙。
有什么想法吗?
这是代码:
override_name_char = "<"
function tag_name_from_client(c)
if string.match(c.name, "Mozilla Firefox") then
return "Firefox"
end
if string.match(c.name, "Sublime Text") then
return "Sublime"
end
if string.match(c.name, "/bin/bash") then
return "Shell"
end
return ""
end
function tag_name_from_tag(tag)
if tag.name:match(override_name_char) then
return tag.name
end
for _, c in pairs(tag:clients()) do
return " "..tostring(awful.tag.getidx(tag)).." "..tag_name_from_client(c)
end
return tostring(awful.tag.getidx(tag))
end
function refresh_tag_name()
for s = 1, screen.count() do
for _,tag in pairs(awful.tag.gettags(s)) do
tag.name = tag_name_from_tag(tag)
end
end
end
client.connect_signal("tagged", refresh_tag_name)
client.connect_signal("untagged", refresh_tag_name)
--tag_timer = timer({timeout = 0.5})
--tag_timer:connect_signal("timeout", function()
--refresh_tag_name()
--end)
--tag_timer:start()
提前感谢您提供任何帮助。
答案 0 :(得分:0)
v3.5.6的一种可能方法,在你的rc.lua
中试试local naughty = require("naughty")
client.connect_signal("manage", function (c)
--filter client by class name
if c.class:lower() == "gedit" then
-- do things on client start
naughty.notify({text = "Gedit launched!"})
-- add exit signal for this client
c:connect_signal("unmanage", function() naughty.notify({text = "Gedit closed!"}) end)
end
end)
答案 1 :(得分:0)
manage
信号。unmanage
信号。所以,类似于以下内容(未经测试):
local function choose_name_for_tag(t)
for _, c in ipairs(t:clients() do
return "has client: " .. tostring(c.name or "unknown")
end
return "has no clients"
end
local function update_state()
for _, t in pairs(root.tags()) do
t.name = choose_name_for_tag(t)
end
end
client.connect_signal("manage", update_state)
client.connect_signal("unmanage", update_state)
tag.connect_signal("tagged", function(t)
t.name = choose_name_for_tag(t)
end)
tag.connect_signal("untagged", function(t)
t.name = choose_name_for_tag(t)
end)