本文介绍了AwesomeWM客户端创建/删除了回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用很棒的WM,并且我想在创建/删除客户端后运行lua函数.具体来说,我想将标签的名称更改为标签上客户端之一的名称.

I am using awesome WM and I want to run a lua function after a client is created/deleted. Specifically, I want to change the name of a tag to the name of one of the clients that are on the tag.

我使用计时器来执行此操作,但是我认为做到这一点的最佳方法是将一个回调函数注册到awesomeWM中,该回调函数将在创建/删除客户端时调用.

I do this with a timer, but I think the best way to do this would be to register a callback function to awesomeWM that it will invoke when a client is created/removed.

我可以实现一些钩子/回调来告诉我很棒吗?

Are there some hooks/callbacks that I can implement to tell awesome to do this for me?

------------------------------------------------- UPDATE- ---------------------------------------

---------------------------------------------UPDATE----------------------------------------

我尝试使用信号,但是在创建窗口并将其附加到标签后,我找不到正确的信号来调用我的函数.我尝试使用管理/取消管理已标记/未标记以及tag.new等进行此操作,但没有人帮助.

I tried using the signals, but i cant find the correct signal that changes calls my function AFTER the window is created and attached to the tag. I tried this with manage/unmanage tagged/untagged, and tag.new, etc, but no one helps.

有什么想法吗?

下面是代码:

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

在此先感谢您的帮助.

推荐答案

  • 创建新客户端"是manage信号.
  • 新客户端被销毁"是unmanage信号.
    • "A new client is created" is the manage signal.
    • "A new client was destroyed" is the unmanage signal.
    • 因此,类似以下内容(未经测试):

      So, something like the following (untested):

      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)
      

      这篇关于AwesomeWM客户端创建/删除了回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:48