1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2009 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
8 local setmetatable
= setmetatable
11 local capi
= { key
= key
}
12 local util
= require("awful.util")
14 --- Key helper for awful
17 --- Modifiers to ignore
18 ignore_modifiers
= { "Lock", "Mod2" }
20 --- Create a new key to use as binding.
21 -- This function is useful to create several keys from one, because it will use
22 -- the ignore_modifier variable to create more key with or without the ignored
23 -- modifiers activated.
24 -- For example if you want to ignore CapsLock in your keybinding (which is
25 -- ignored by default by this function), creatina key binding with this function
26 -- will return 2 key objects: one with CapsLock on, and the other one with
28 -- @see C api key() function for parameters.
29 -- @return A table with one or several key objects.
30 function new(mod, ...)
32 local subsets
= util
.subsets(ignore_modifiers
)
33 for _
, set
in ipairs(subsets
) do
34 ret
[#ret
+ 1] = capi
.key(util
.table.join(mod, set
), unpack(arg
))
39 --- Compare a key object with modifiers and key.
40 -- @param key The key object.
41 -- @param pressed_mod The modifiers to compare with.
42 -- @param pressed_key The key to compare with.
43 function match(key
, pressed_mod
, pressed_key
)
44 -- First, compare key.
45 if pressed_key
~= key
.key
then return false end
47 local mod = key
.modifiers
49 -- For each modifier of the key object, check that the modifier has been
51 for _
, m
in ipairs(mod) do
52 -- Has it been pressed?
53 if util
.table.hasitem(pressed_mod
, m
) then
54 -- Yes, the number of modifier correctly pressed++
57 -- No, so this is failure!
61 -- If the number of pressed modifier is ~=, it is probably >, so this is not
62 -- the same, return false.
69 setmetatable(_M
, { __call
= function(_
, ...) return new(unpack(arg
)) end })
71 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80