mirror of https://github.com/mpv-player/mpv
input: add text produced by key to script key events
Particularly for "any_unicode" mappings, so they don't have to special-case keys like '#' and ' ', which are normally mapped to symbolic names for input.conf reasons. (Though admittedly, this is a pretty minor thing, since API users could map these manually.)
This commit is contained in:
parent
eab5457e47
commit
21f2468d67
|
@ -971,8 +971,13 @@ Input Commands that are Possibly Subject to Change
|
|||
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.
|
||||
|
||||
The key state consists of 2 letters:
|
||||
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
|
||||
in upper case text instead, but some backends may mess up).
|
||||
|
||||
The key state consists of 2 characters:
|
||||
|
||||
1. One of ``d`` (key was pressed down), ``u`` (was released), ``r`` (key
|
||||
is still down, and was repeated; only if key repeat is enabled for this
|
||||
|
@ -980,6 +985,9 @@ Input Commands that are Possibly Subject to Change
|
|||
2. Whether the event originates from the mouse, either ``m`` (mouse button)
|
||||
or ``-`` (something else).
|
||||
|
||||
Future versions can add more arguments and more key state characters to
|
||||
support more input peculiarities.
|
||||
|
||||
``ab-loop``
|
||||
Cycle through A-B loop states. The first command will set the ``A`` point
|
||||
(the ``ab-loop-a`` property); the second the ``B`` point, and the third
|
||||
|
|
|
@ -265,6 +265,11 @@ The ``mp`` module is preloaded, although it can be loaded manually with
|
|||
The name of they key that triggered this, or ``nil`` if invoked
|
||||
artificially. If the key name is unknown, it's an empty string.
|
||||
|
||||
``key_text``
|
||||
Text if triggered by a text key, otherwise ``nil``. See
|
||||
description of ``script-binding`` command for details (this
|
||||
field is equivalent to the 5th argument).
|
||||
|
||||
Internally, key bindings are dispatched via the ``script-message-to`` or
|
||||
``script-binding`` input commands and ``mp.register_script_message``.
|
||||
|
||||
|
|
|
@ -511,6 +511,7 @@ mp_cmd_t *mp_cmd_clone(mp_cmd_t *cmd)
|
|||
}
|
||||
ret->original = bstrdup(ret, cmd->original);
|
||||
ret->key_name = talloc_strdup(ret, ret->key_name);
|
||||
ret->key_text = talloc_strdup(ret, ret->key_text);
|
||||
|
||||
if (cmd->def == &mp_cmd_list) {
|
||||
struct mp_cmd *prev = NULL;
|
||||
|
|
|
@ -114,6 +114,7 @@ typedef struct mp_cmd {
|
|||
const struct mp_cmd_def *def;
|
||||
char *sender; // name of the client API user which sent this
|
||||
char *key_name; // string representation of the key binding
|
||||
char *key_text; // text if key is a text key
|
||||
} mp_cmd_t;
|
||||
|
||||
extern const struct mp_cmd_def mp_cmds[];
|
||||
|
|
|
@ -481,6 +481,11 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, char *force_section,
|
|||
ret->key_name = talloc_steal(ret, mp_input_get_key_combo_name(&code, 1));
|
||||
MP_TRACE(ictx, "key '%s' -> '%s' in '%s'\n",
|
||||
ret->key_name, cmd->cmd, ret->input_section);
|
||||
if (MP_KEY_IS_UNICODE(code)) {
|
||||
bstr text = {0};
|
||||
mp_append_utf8_bstr(ret, &text, code);
|
||||
ret->key_text = text.start;
|
||||
}
|
||||
ret->is_mouse_button = code & MP_KEY_EMIT_ON_UP;
|
||||
} else {
|
||||
char *key_buf = mp_input_get_key_combo_name(&code, 1);
|
||||
|
|
|
@ -5516,9 +5516,10 @@ static void cmd_script_binding(void *p)
|
|||
char state[3] = {'p', incmd->is_mouse_button ? 'm' : '-'};
|
||||
if (incmd->is_up_down)
|
||||
state[0] = incmd->repeated ? 'r' : (incmd->is_up ? 'u' : 'd');
|
||||
event.num_args = 4;
|
||||
event.args = (const char*[4]){"key-binding", name, state,
|
||||
incmd->key_name ? incmd->key_name : ""};
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -54,10 +54,10 @@ local function reserve_binding()
|
|||
return "__keybinding" .. tostring(message_id)
|
||||
end
|
||||
|
||||
local function dispatch_key_binding(name, state, key_name)
|
||||
local function dispatch_key_binding(name, state, key_name, key_text)
|
||||
local fn = dispatch_key_bindings[name]
|
||||
if fn then
|
||||
fn(name, state, key_name)
|
||||
fn(name, state, key_name, key_text)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -176,11 +176,15 @@ local function add_binding(attrs, key, name, fn, rp)
|
|||
["r"] = "repeat",
|
||||
["p"] = "press",
|
||||
}
|
||||
key_cb = function(name, state, key_name)
|
||||
key_cb = function(name, state, key_name, key_text)
|
||||
if key_text == "" then
|
||||
key_text = nil
|
||||
end
|
||||
fn({
|
||||
event = key_states[state:sub(1, 1)] or "unknown",
|
||||
is_mouse = state:sub(2, 2) == "m",
|
||||
key_name = key_name,
|
||||
key_text = key_text,
|
||||
})
|
||||
end
|
||||
msg_cb = function()
|
||||
|
|
Loading…
Reference in New Issue