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.
Unified · Split
| @@ -323,6 +323,13 @@ The ``mp`` module is preloaded, although it can be loaded manually with · 322 unmodified lines | ||
| 323 | 323 | If set to ``true``, enables key repeat for this specific binding. |
| 324 | 324 | This option only makes sense when ``complex`` is not set to ``true``. |
| 325 | 325 | |
| 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 | + | |
| 326 | 333 | ``complex`` |
| 327 | 334 | If set to ``true``, then ``fn`` is called on key down, repeat and up |
| 328 | 335 | 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 | ||
| 350 | 357 | description of ``script-binding`` command for details (this |
| 351 | 358 | field is equivalent to the 5th argument). |
| 352 | 359 | |
| 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 | + | |
| 353 | 364 | Internally, key bindings are dispatched via the ``script-message-to`` or |
| 354 | 365 | ``script-binding`` input commands and ``mp.register_script_message``. |
| 355 | 366 | |
| @@ -60,10 +60,10 @@ local function reserve_binding() · 59 unmodified lines | ||
| 60 | 60 | return "__keybinding" .. tostring(message_id) |
| 61 | 61 | end |
| 62 | 62 | |
| 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) | |
| 64 | 64 | local fn = dispatch_key_bindings[name] |
| 65 | 65 | if fn then |
| 66 | − fn(name, state, key_name, key_text) | |
| 66 | + fn(name, state, key_name, key_text, scale) | |
| 67 | 67 | end |
| 68 | 68 | end |
| 69 | 69 | |
| @@ -186,6 +186,7 @@ local function add_binding(attrs, key, name, fn, rp) · 116 unmodified lines | ||
| 186 | 186 | name = reserve_binding() |
| 187 | 187 | end |
| 188 | 188 | local repeatable = rp == "repeatable" or rp["repeatable"] |
| 189 | + local scalable = rp == "scalable" or rp["scalable"] | |
| 189 | 190 | if rp["forced"] then |
| 190 | 191 | attrs.forced = true |
| 191 | 192 | end |
| @@ -200,7 +201,7 @@ local function add_binding(attrs, key, name, fn, rp) · 8 unmodified lines | ||
| 200 | 201 | ["r"] = "repeat", |
| 201 | 202 | ["p"] = "press", |
| 202 | 203 | } |
| 203 | − key_cb = function(_, state, key_name, key_text) | |
| 204 | + key_cb = function(_, state, key_name, key_text, scale) | |
| 204 | 205 | if key_text == "" then |
| 205 | 206 | key_text = nil |
| 206 | 207 | end |
| @@ -210,6 +211,7 @@ local function add_binding(attrs, key, name, fn, rp) · 3 unmodified lines | ||
| 210 | 211 | canceled = state:sub(3, 3) == "c", |
| 211 | 212 | key_name = key_name, |
| 212 | 213 | key_text = key_text, |
| 214 | + scale = tonumber(scale), | |
| 213 | 215 | }) |
| 214 | 216 | end |
| 215 | 217 | msg_cb = function() |
| @@ -235,8 +237,9 @@ local function add_binding(attrs, key, name, fn, rp) · 19 unmodified lines | ||
| 235 | 237 | end |
| 236 | 238 | msg_cb = fn |
| 237 | 239 | end |
| 240 | + local prefix = scalable and "" or " nonscalable" | |
| 238 | 241 | 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 | |
| 240 | 243 | end |
| 241 | 244 | attrs.name = name |
| 242 | 245 | -- new bindings override old ones (but do not overwrite them) |