0

我想知道当小部件被激活时,是否有可能从一个可怕的提示小部件中捕获事件,例如:

myprompt:run()

或者当用户按Enter验证他的输入或Esc离开/退出此小部件时。

4

1 回答 1

1

There isn't a way to directly connect a signal on an awful.widget.prompt, but it is possible to specify some instructions to the prompt widget when the command has been executed:

in the awful/widget/prompt.lua the run function launch 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

with some parameters which are :

  • args A table with optional arguments: fg_cursor, bg_cursor, ul_cursor, prompt, text, selectall, font, autoexec.
  • textbox The textbox to use for the prompt.
  • exe_callback The callback function to call with command as argument when finished.
  • completion_callback The callback function to call to get completion.
  • history_path Optional parameter: file path where the history should be saved, set nil to disable history
  • history_max Optional parameter: set the maximum entries in history file, 50 by default
  • done_callback Optional parameter: the callback function to always call without arguments, regardless of whether the prompt was cancelled.
  • changed_callback Optional parameter: the callback function to call with command as argument when a command was changed.
  • keypressed_callback

So I just have to use awful.prompt.run on my prompt box and specify the done_callback

Example: a prompt box in a wibox. The wibox is shown when the Mod4 + r keys are pressed, the wibox is hidden when the command is executed:

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),
于 2015-02-19T11:45:09.747 回答