From ef50f75551b6f117bbc081b53130615f137a790e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 29 Sep 2016 02:46:04 -0400 Subject: [PATCH] prompt: Add a key release callback. A possible use case is to highlight something when a key is pressed and un-highlight it when the key is released. --- lib/awful/prompt.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index 3c49a56f..279d9248 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -248,6 +248,8 @@ end -- with command as argument when a command was changed. -- @tparam[opt] function args.keypressed_callback The callback function to call -- with mod table, key and command as arguments when a key was pressed. +-- @tparam[opt] function args.keyreleased_callback The callback function to call +-- with mod table, key and command as arguments when a key was pressed. -- @tparam[opt] table args.hooks The "hooks" argument uses a syntax similar to -- `awful.key`. It will call a function for the matching modifiers + key. -- It receives the command (widget text/input) as an argument. @@ -407,11 +409,18 @@ function prompt.run(args, textbox, exe_callback, completion_callback, grabber = keygrabber.run( function (modifiers, key, event) - if event ~= "press" then return end -- Convert index array to hash table local mod = {} for _, v in ipairs(modifiers) do mod[v] = true end + if event ~= "press" then + if args.keyreleased_callback then + args.keyreleased_callback(mod, key, command) + end + + return + end + -- Call the user specified callback. If it returns true as -- the first result then return from the function. Treat the -- second and third results as a new command and new prompt