Skip to content

Commit

Permalink
defaults.lua: support custom arg in mp.add_key_binding()
Browse files Browse the repository at this point in the history
The information is available in the table.
  • Loading branch information
na-na-hi committed Nov 18, 2024
1 parent 66a8a2c commit 6d880a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions DOCS/man/lua.rst
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ The ``mp`` module is preloaded, although it can be loaded manually with
or pass the ``fn`` argument in place of the name. The latter is not
recommended and is handled for compatibility only.)

The last argument is used for optional flags. This is a table, which can
have the following entries:
The ``flags`` argument is used for optional parameters. This is a table,
which can have the following entries:

``repeatable``
If set to ``true``, enables key repeat for this specific binding.
Expand Down Expand Up @@ -361,6 +361,11 @@ The ``mp`` module is preloaded, although it can be loaded manually with
The scale of the key, such as the ones produced by ``WHEEL_*``
keys. The scale is 1 if the key is nonscalable.

``arg``
User-provided string in the ``arg`` argument in the
``script-binding`` command if the key binding is invoked
by that command.

Internally, key bindings are dispatched via the ``script-message-to`` or
``script-binding`` input commands and ``mp.register_script_message``.

Expand Down
7 changes: 4 additions & 3 deletions player/lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, scale)
local function dispatch_key_binding(name, state, key_name, key_text, scale, arg)
local fn = dispatch_key_bindings[name]
if fn then
fn(name, state, key_name, key_text, scale)
fn(name, state, key_name, key_text, scale, arg)
end
end

Expand Down Expand Up @@ -201,7 +201,7 @@ local function add_binding(attrs, key, name, fn, rp)
["r"] = "repeat",
["p"] = "press",
}
key_cb = function(_, state, key_name, key_text, scale)
key_cb = function(_, state, key_name, key_text, scale, arg)
if key_text == "" then
key_text = nil
end
Expand All @@ -212,6 +212,7 @@ local function add_binding(attrs, key, name, fn, rp)
key_name = key_name,
key_text = key_text,
scale = tonumber(scale),
arg = arg,
})
end
msg_cb = function()
Expand Down

0 comments on commit 6d880a6

Please sign in to comment.