在Awesome WM 3.5中是否有与awful.prompt相关的事件?

时间:2015-02-02 17:53:14

标签: awesome-wm

我想知道是否可以从 awful.prompt 窗口小部件中捕获事件,就像使用以下命令激活窗口小部件时的事件一样:

myprompt:run()

或当用户按 Enter 以验证其条目或 Esc 离开/退出此小部件时。

1 个答案:

答案 0 :(得分:1)

没有办法直接连接awful.widget.prompt上的信号,但是当命令执行时,可以为提示小部件指定一些指令:

在糟糕的/ widget / prompt.lua中运行函数启动awful.prompt.run():

local function run(promptbox)
    return prompt.run({ prompt = promptbox.prompt },
                      promptbox.widget,
                      function (...)
                          local result = util.spawn(...)
                          if type(result) == "string" then
                              promptbox.widget:set_text(result)
                          end
                      end,
                      completion.shell,
                      util.getdir("cache") .. "/history")
end

有一些参数:

  • args包含可选参数的表:fg_cursor,bg_cursor,ul_cursor,prompt,text,selectall,font,autoexec。
  • textbox用于提示的文本框。
  • exe_callback完成后用命令作为参数调用的回调函数。
  • completion_callback要调用以完成的回调函数。
  • history_path可选参数:应保存历史记录的文件路径,将nil设置为禁用历史记录
  • history_max可选参数:设置历史文件中的最大条目,默认为50
  • done_callback可选参数:无论是否取消提示,总是不带参数调用的回调函数。
  • changed_callback可选参数:当命令发生变化时,使用命令作为参数调用的回调函数。
  • keypressed_callback

所以我只需在提示框中使用awful.prompt.run并指定done_callback

示例:wibox中的提示框。当按下Mod4 + r键时显示wibox,执行命令时隐藏wibox:

awful.key({ modkey },            "r",     function () 
--promptlist is a table that contains wibox for each screen
if promptlist[mouse.screen].visible == false then
  promptlist[mouse.screen].visible=true
  awful.prompt.run({
    prompt = promptlist.prompt[mouse.screen].prompt },
    promptlist.prompt[mouse.screen].widget,
    function (...)
      local result = awful.util.spawn(...)
      if type(result) == "string" then
        promptlist.prompt[mouse.screen].widget:set_text(result)
        --promptlist.prompt table that contains prompt widget for each screen
      end
    end,
    awful.completion.shell,
    awful.util.getdir("cache") .. "/history",
    50,
    function()
      promptlist[mouse.screen].visible = false
    end
  )
else
  promptlist[mouse.screen].visible=false
end
end),