History

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.

nanahi committed 2 years ago

Commit e3e22de1 parent 34571e72 files · +18 −4Browse files

Unified · Split

2 files
  1. DOCS/man/lua.rst +11 −0
  2. player/lua/defaults.lua +7 −4
DOCS/man/lua.rst+11−0
@@ -323,6 +323,13 @@ The ``mp`` module is preloaded, although it can be loaded manually with · 322 unmodified lines
323323 If set to ``true``, enables key repeat for this specific binding.
324324 This option only makes sense when ``complex`` is not set to ``true``.
325325
326+ ``scalable``
327+ If set to ``true``, enables key scaling for this specific binding.
328+ This option only makes sense when ``complex`` is set to ``true``.
329+ Note that this has no effect if the key binding is invoked by
330+ ``script-binding`` command, where the scalability of the command
331+ takes precedence.
332+
326333 ``complex``
327334 If set to ``true``, then ``fn`` is called on key down, repeat and up
328335 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 · 21 unmodified lines
350357 description of ``script-binding`` command for details (this
351358 field is equivalent to the 5th argument).
352359
360+ ``scale``
361+ The scale of the key, such as the ones produced by ``WHEEL_*``
362+ keys. The scale is 1 if the key is nonscalable.
363+
353364 Internally, key bindings are dispatched via the ``script-message-to`` or
354365 ``script-binding`` input commands and ``mp.register_script_message``.
355366
player/lua/defaults.lua+7−4
@@ -60,10 +60,10 @@ local function reserve_binding() · 59 unmodified lines
6060 return "__keybinding" .. tostring(message_id)
6161 end
6262
63−local function dispatch_key_binding(name, state, key_name, key_text)
63+local function dispatch_key_binding(name, state, key_name, key_text, scale)
6464 local fn = dispatch_key_bindings[name]
6565 if fn then
66− fn(name, state, key_name, key_text)
66+ fn(name, state, key_name, key_text, scale)
6767 end
6868 end
6969
@@ -186,6 +186,7 @@ local function add_binding(attrs, key, name, fn, rp) · 116 unmodified lines
186186 name = reserve_binding()
187187 end
188188 local repeatable = rp == "repeatable" or rp["repeatable"]
189+ local scalable = rp == "scalable" or rp["scalable"]
189190 if rp["forced"] then
190191 attrs.forced = true
191192 end
@@ -200,7 +201,7 @@ local function add_binding(attrs, key, name, fn, rp) · 8 unmodified lines
200201 ["r"] = "repeat",
201202 ["p"] = "press",
202203 }
203− key_cb = function(_, state, key_name, key_text)
204+ key_cb = function(_, state, key_name, key_text, scale)
204205 if key_text == "" then
205206 key_text = nil
206207 end
@@ -210,6 +211,7 @@ local function add_binding(attrs, key, name, fn, rp) · 3 unmodified lines
210211 canceled = state:sub(3, 3) == "c",
211212 key_name = key_name,
212213 key_text = key_text,
214+ scale = tonumber(scale),
213215 })
214216 end
215217 msg_cb = function()
@@ -235,8 +237,9 @@ local function add_binding(attrs, key, name, fn, rp) · 19 unmodified lines
235237 end
236238 msg_cb = fn
237239 end
240+ local prefix = scalable and "" or " nonscalable"
238241 if key and #key > 0 then
239− attrs.bind = key .. " script-binding " .. mp.script_name .. "/" .. name
242+ attrs.bind = key .. prefix .. " script-binding " .. mp.script_name .. "/" .. name
240243 end
241244 attrs.name = name
242245 -- new bindings override old ones (but do not overwrite them)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t