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.
This commit is contained in:
parent
11644f4582
commit
ef50f75551
|
@ -248,6 +248,8 @@ end
|
||||||
-- with command as argument when a command was changed.
|
-- with command as argument when a command was changed.
|
||||||
-- @tparam[opt] function args.keypressed_callback The callback function to call
|
-- @tparam[opt] function args.keypressed_callback The callback function to call
|
||||||
-- with mod table, key and command as arguments when a key was pressed.
|
-- 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
|
-- @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.
|
-- `awful.key`. It will call a function for the matching modifiers + key.
|
||||||
-- It receives the command (widget text/input) as an argument.
|
-- 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(
|
grabber = keygrabber.run(
|
||||||
function (modifiers, key, event)
|
function (modifiers, key, event)
|
||||||
if event ~= "press" then return end
|
|
||||||
-- Convert index array to hash table
|
-- Convert index array to hash table
|
||||||
local mod = {}
|
local mod = {}
|
||||||
for _, v in ipairs(modifiers) do mod[v] = true end
|
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
|
-- Call the user specified callback. If it returns true as
|
||||||
-- the first result then return from the function. Treat the
|
-- the first result then return from the function. Treat the
|
||||||
-- second and third results as a new command and new prompt
|
-- second and third results as a new command and new prompt
|
||||||
|
|
Loading…
Reference in New Issue