awesome-wm

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.


Solution

  • 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 :

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