我想知道是否可以从 awful.prompt 窗口小部件中捕获事件,就像使用以下命令激活窗口小部件时的事件一样:
myprompt:run()
或当用户按 Enter 以验证其条目或 Esc 离开/退出此小部件时。
答案 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
有一些参数:
所以我只需在提示框中使用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),