我想知道当小部件被激活时,是否有可能从一个可怕的提示小部件中捕获事件,例如:
myprompt:run()
或者当用户按Enter验证他的输入或Esc离开/退出此小部件时。
我想知道当小部件被激活时,是否有可能从一个可怕的提示小部件中捕获事件,例如:
myprompt:run()
或者当用户按Enter验证他的输入或Esc离开/退出此小部件时。
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),