I'm trying to add a keybinding to my rc.lua
for shutting down my computer, which will display a prompt like "Shutdown (y/n)? ", and will call a shutdown if "y" is pressed, but will close if anything else is pressed. Here's my attempt so far:
...
awful.key({ modkey, "Control", "Shift" }, "q",
function ()
awful.prompt.run {
prompt = "Shutdown? (y/n) ",
textbox = awful.screen.focused().mypromptbox.widget,
keypressed_callback = function (_, key, _)
if key == "y" then
naughty.notify {
text = "Shutting down!"
}
else
naughty.notify {
text = "Not shutting down!"
}
end
return
end,
}
end,
{description = "shutdown", group = "awesome"}),
...
However, the prompt remains active after keys are pressed - the keypressed_callback
will continue to trigger every another key is pressed, until I press either Return or Escape.
This is sensible default behaviour, but in my case I want the prompt to close after the first keypressed_callback
event. My first thought was to use a return
within the keypressed_callback
to try to escape/cancel/destroy the prompt, but that isn't doing anything.
Is there anyway to achieve this?