diff --git a/DOCS/interface-changes/script-binding-scalable.txt b/DOCS/interface-changes/script-binding-scalable.txt new file mode 100644 index 0000000000..bbd8c5d64e --- /dev/null +++ b/DOCS/interface-changes/script-binding-scalable.txt @@ -0,0 +1 @@ +make `script-binding` command scalable; add `nonscalable` command prefix to restore the old behavior diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 6b91c14183..fc878f2834 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1274,13 +1274,15 @@ Scripting Commands For completeness, here is how this command works internally. The details could change any time. On any matching key event, ``script-message-to`` or ``script-message`` is called (depending on whether the script name is - included), with the following arguments: + included), with the following arguments in string format: 1. The string ``key-binding``. 2. The name of the binding (as established above). 3. The key state as string (see below). 4. The key name (since mpv 0.15.0). 5. The text the key would produce, or empty string if not applicable. + 6. The scale of the key, such as the ones produced by ``WHEEL_*`` keys. + The scale is 1 if the key is nonscalable. The 5th argument is only set if no modifiers are present (using the shift key with a letter is normally not emitted as having a modifier, and results diff --git a/player/command.c b/player/command.c index 26a45870b9..6f2349f3d7 100644 --- a/player/command.c +++ b/player/command.c @@ -6561,17 +6561,31 @@ static void cmd_script_binding(void *p) incmd->canceled ? 'c' : '-'}; if (incmd->is_up_down) state[0] = incmd->repeated ? 'r' : (incmd->is_up ? 'u' : 'd'); - event.num_args = 5; - event.args = (const char*[5]){"key-binding", name, state, - incmd->key_name ? incmd->key_name : "", - incmd->key_text ? incmd->key_text : ""}; - if (mp_client_send_event_dup(mpctx, target, - MPV_EVENT_CLIENT_MESSAGE, &event) < 0) - { - MP_VERBOSE(mpctx, "Can't find script '%s' when handling input.\n", - target ? target : "-"); - cmd->success = false; + + double scale = 1; + int scale_units = incmd->scale_units; + if (mp_input_is_scalable_cmd(incmd)) { + scale = incmd->scale; + scale_units = 1; } + char *scale_s = mp_format_double(NULL, scale, 6, false, false, false); + + for (int i = 0; i < scale_units; i++) { + event.num_args = 6; + event.args = (const char*[6]){"key-binding", name, state, + incmd->key_name ? incmd->key_name : "", + incmd->key_text ? incmd->key_text : "", + scale_s}; + if (mp_client_send_event_dup(mpctx, target, + MPV_EVENT_CLIENT_MESSAGE, &event) < 0) + { + MP_VERBOSE(mpctx, "Can't find script '%s' when handling input.\n", + target ? target : "-"); + cmd->success = false; + break; + } + } + talloc_free(scale_s); } static void cmd_script_message_to(void *p) @@ -7283,7 +7297,7 @@ const struct mp_cmd_def mp_cmds[] = { { "ao-reload", cmd_ao_reload }, { "script-binding", cmd_script_binding, { {"name", OPT_STRING(v.s)} }, - .allow_auto_repeat = true, .on_updown = true}, + .allow_auto_repeat = true, .on_updown = true, .scalable = true }, { "script-message", cmd_script_message, { {"args", OPT_STRING(v.s)} }, .vararg = true },