defaults.lua: support scalable mp.add_key_binding()
For complex key bindings, the table now contains a new member of the current key scale. mp.add_key_binding() now accepts the scalable flag to make the binding scalable.
This commit is contained in:
1 parent
34571e7882
commit
e3e22de2ca
2 files changed
+18
-4
No files matched your search
@@ -323,6 +323,13 @@ The ``mp`` module is preloaded, although it can be loaded manually with
|
||||
If set to ``true``, enables key repeat for this specific binding.
|
||||
This option only makes sense when ``complex`` is not set to ``true``.
|
||||
|
||||
``scalable``
|
||||
If set to ``true``, enables key scaling for this specific binding.
|
||||
This option only makes sense when ``complex`` is set to ``true``.
|
||||
Note that this has no effect if the key binding is invoked by
|
||||
``script-binding`` command, where the scalability of the command
|
||||
takes precedence.
|
||||
|
||||
``complex``
|
||||
If set to ``true``, then ``fn`` is called on key down, repeat and up
|
||||
events, with the first argument being a table. This table has the
|
||||
@@ -350,6 +357,10 @@ The ``mp`` module is preloaded, although it can be loaded manually with
|
||||
description of ``script-binding`` command for details (this
|
||||
field is equivalent to the 5th argument).
|
||||
|
||||
``scale``
|
||||
The scale of the key, such as the ones produced by ``WHEEL_*``
|
||||
keys. The scale is 1 if the key is nonscalable.
|
||||
|
||||
Internally, key bindings are dispatched via the ``script-message-to`` or
|
||||
``script-binding`` input commands and ``mp.register_script_message``.
|
||||
|
||||
|
||||
@@ -60,10 +60,10 @@ local function reserve_binding()
|
||||
return "__keybinding" .. tostring(message_id)
|
||||
end
|
||||
|
||||
local function dispatch_key_binding(name, state, key_name, key_text)
|
||||
local function dispatch_key_binding(name, state, key_name, key_text, scale)
|
||||
local fn = dispatch_key_bindings[name]
|
||||
if fn then
|
||||
fn(name, state, key_name, key_text)
|
||||
fn(name, state, key_name, key_text, scale)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -186,6 +186,7 @@ local function add_binding(attrs, key, name, fn, rp)
|
||||
name = reserve_binding()
|
||||
end
|
||||
local repeatable = rp == "repeatable" or rp["repeatable"]
|
||||
local scalable = rp == "scalable" or rp["scalable"]
|
||||
if rp["forced"] then
|
||||
attrs.forced = true
|
||||
end
|
||||
@@ -200,7 +201,7 @@ local function add_binding(attrs, key, name, fn, rp)
|
||||
["r"] = "repeat",
|
||||
["p"] = "press",
|
||||
}
|
||||
key_cb = function(_, state, key_name, key_text)
|
||||
key_cb = function(_, state, key_name, key_text, scale)
|
||||
if key_text == "" then
|
||||
key_text = nil
|
||||
end
|
||||
@@ -210,6 +211,7 @@ local function add_binding(attrs, key, name, fn, rp)
|
||||
canceled = state:sub(3, 3) == "c",
|
||||
key_name = key_name,
|
||||
key_text = key_text,
|
||||
scale = tonumber(scale),
|
||||
})
|
||||
end
|
||||
msg_cb = function()
|
||||
@@ -235,8 +237,9 @@ local function add_binding(attrs, key, name, fn, rp)
|
||||
end
|
||||
msg_cb = fn
|
||||
end
|
||||
local prefix = scalable and "" or " nonscalable"
|
||||
if key and #key > 0 then
|
||||
attrs.bind = key .. " script-binding " .. mp.script_name .. "/" .. name
|
||||
attrs.bind = key .. prefix .. " script-binding " .. mp.script_name .. "/" .. name
|
||||
end
|
||||
attrs.name = name
|
||||
-- new bindings override old ones (but do not overwrite them)
|
||||
|
||||
Reference in new issue
Block a user