prompt: Add a key filter example

This commit is contained in:
Emmanuel Lepage Vallee 2016-12-30 01:32:07 -05:00
parent f6cce940a5
commit 928f7b04b4
2 changed files with 43 additions and 0 deletions

View File

@ -72,6 +72,16 @@
--
-- @DOC_wibox_awidget_prompt_vilike_EXAMPLE@
--
-- *[Example three] Key listener*:
--
-- The 2 previous examples were focused on changing the prompt behavior. This
-- one explains how to "spy" on the prompt events. This can be used for
--
-- * Implementing more complex mutator
-- * Synchronising other widgets
-- * Showing extra tips to the user
--
-- @DOC_wibox_awidget_prompt_keypress_EXAMPLE@
--
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2008 Julien Danjou

View File

@ -0,0 +1,33 @@
local parent = ... --DOC_NO_USAGE --DOC_HIDE
local wibox = require( "wibox" ) --DOC_HIDE
local awful = { prompt = require("awful.prompt"),--DOC_HIDE
util = require("awful.util"),--DOC_HIDE
screen = require("awful.screen")}--DOC_HIDE
local beautiful = require( "beautiful" ) --DOC_HIDE
local naughty = {} --DOC_HIDE
local atextbox = wibox.widget.textbox()
local notif = nil
awful.prompt.run {
prompt = "<b>Run: </b>",
keypressed_callback = function(mod, key, cmd) --luacheck: no unused args
if key == "Shift_L" then
notif = naughty.notify { text = "Shift pressed" }
end
end,
keyreleased_callback = function(mod, key, cmd) --luacheck: no unused args
if notif then
naughty.destroy(notif)
notif = nil
end
end,
textbox = atextbox,
history_path = awful.util.getdir("cache") .. "/history",
}
parent:add( wibox.widget { --DOC_HIDE
atextbox, --DOC_HIDE
bg = beautiful.bg_normal, --DOC_HIDE
widget = wibox.container.background --DOC_HIDE
}) --DOC_HIDE