Merge pull request #972 from Elv13/prompt_fix

prompt: Fix hooks when number or caps lock are set
This commit is contained in:
Emmanuel Lepage Vallée 2016-07-16 22:59:54 -04:00 committed by GitHub
commit 34cc04ec97
2 changed files with 15 additions and 5 deletions

View File

@ -22,9 +22,9 @@ local key = { mt = {}, hotkeys = {} }
-- By default this is initialized as { "Lock", "Mod2" } -- By default this is initialized as { "Lock", "Mod2" }
-- so the Caps Lock or Num Lock modifier are not taking into account by awesome -- so the Caps Lock or Num Lock modifier are not taking into account by awesome
-- when pressing keys. -- when pressing keys.
-- @name ignore_modifiers -- @name awful.key.ignore_modifiers
-- @class table -- @class table
local ignore_modifiers = { "Lock", "Mod2" } key.ignore_modifiers = { "Lock", "Mod2" }
--- Convert the modifiers into pc105 key names --- Convert the modifiers into pc105 key names
local conversion = { local conversion = {
@ -83,7 +83,7 @@ function key.new(mod, _key, press, release, data)
release=nil release=nil
end end
local ret = {} local ret = {}
local subsets = util.subsets(ignore_modifiers) local subsets = util.subsets(key.ignore_modifiers)
for _, set in ipairs(subsets) do for _, set in ipairs(subsets) do
ret[#ret + 1] = capi.key({ modifiers = util.table.join(mod, set), ret[#ret + 1] = capi.key({ modifiers = util.table.join(mod, set),
key = _key }) key = _key })

View File

@ -22,6 +22,7 @@ local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility
local keygrabber = require("awful.keygrabber") local keygrabber = require("awful.keygrabber")
local util = require("awful.util") local util = require("awful.util")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local akey = require("awful.key")
local prompt = {} local prompt = {}
@ -360,15 +361,24 @@ function prompt.run(args, textbox, exe_callback, completion_callback,
end end
end end
local filtered_modifiers = {}
-- User defined cases -- User defined cases
if hooks[key] then if hooks[key] then
-- Remove caps and num lock
for _, m in ipairs(modifiers) do
if not util.table.hasitem(akey.ignore_modifiers, m) then
table.insert(filtered_modifiers, m)
end
end
for _,v in ipairs(hooks[key]) do for _,v in ipairs(hooks[key]) do
if #modifiers == #v[1] then if #filtered_modifiers == #v[1] then
local match = true local match = true
for _,v2 in ipairs(v[1]) do for _,v2 in ipairs(v[1]) do
match = match and mod[v2] match = match and mod[v2]
end end
if match or #modifiers == 0 then if match or #filtered_modifiers == 0 then
local cb local cb
local ret = v[3](command) local ret = v[3](command)
if ret then if ret then