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