lua: don't require key for mp.add_key_binding()

Requested. The intention is that scripts can provide mappable actions
for key bindings without setting a default key.
This commit is contained in:
wm4 2016-03-26 10:44:57 +01:00
parent 5843392db5
commit 32fde273d3
2 changed files with 6 additions and 4 deletions

View File

@ -192,7 +192,8 @@ The ``mp`` module is preloaded, although it can be loaded manually with
Register callback to be run on a key binding. The binding will be mapped to
the given ``key``, which is a string describing the physical key. This uses
the same key names as in input.conf, and also allows combinations
(e.g. ``ctrl+a``).
(e.g. ``ctrl+a``). If the key is empty or ``nil``, no physical key is
registered, but the user still can create own bindings (see below).
After calling this function, key presses will cause the function ``fn`` to
be called (unless the user remapped the key with another binding).

View File

@ -145,7 +145,7 @@ local function update_key_bindings()
end
local cfg = ""
for k, v in pairs(key_bindings) do
if v.forced ~= def then
if v.bind and v.forced ~= def then
cfg = cfg .. v.bind .. "\n"
end
end
@ -161,7 +161,6 @@ local function add_binding(attrs, key, name, fn, rp)
fn = name
name = reserve_binding()
end
local bind = key
local repeatable = rp == "repeatable" or rp["repeatable"]
if rp["forced"] then
attrs.forced = true
@ -205,7 +204,9 @@ local function add_binding(attrs, key, name, fn, rp)
end
msg_cb = fn
end
attrs.bind = bind .. " script-binding " .. mp.script_name .. "/" .. name
if key and #key > 0 then
attrs.bind = key .. " script-binding " .. mp.script_name .. "/" .. name
end
attrs.name = name
key_bindings[name] = attrs
update_key_bindings()