cedlemo
cedlemo

Reputation: 3334

are there any events related to awful.prompt in Awesome WM 3.5?

I would like to know if it is possible to catch events from an awful.prompt widget like an event when the widget is activated with:

myprompt:run()

or when the user press Enter to validate his entry or Esc to leave/quit this widget.

Upvotes: 0

Views: 565

Answers (1)

cedlemo
cedlemo

Reputation: 3334

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

Upvotes: 1

Related Questions