From 2a183c5ca7c624421e3ccf9c72d7a129609e98b1 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Thu, 7 Oct 2021 02:18:19 +0300 Subject: [PATCH] input: new option: --no-input-builtin-bindings This is similar to [no-]input-default-bindings, but affects only builtin bindings (while input-default-bindings affects anything which config files can override, like scripting mp.add_key_binding). Arguably, this is what input-default-binding should have always done, however, it does not. The reason we add a new option rather than repurpose/modify the existing option is that it behaves differently enough to raise concerns that it will break some use cases for existing users: - The new option is only applied once on startup, while input-default-bindings can be modified effectively at runtime. - They affects different sets of bindings, and it's possible that the set of input-default-bindings is useful enough to keep. Implementation-wise, both options are trivial, so keeping one or the other or both doesn't affect code complexity. It could be argued that it would be useful to make the new option also effective for runtime changes, however, this opens a can of worms of how the bindings are stored beyond the initial setup. TL;DR: it's impossible to differentiate correctly at runtime between builtin bindings, and those added with mp.add_key_bindings. The gist is that technically mpv needs/uses two binding "classes": - weak/builtin bindings - lower priority than config files. - "user" bindings - config files and "forced" runtime bindings. input-default-bindings affects the first class trivially, but input-builtin-bindings would not be able split this class further at runtime without meaningful changes to a lot of delicate code. So a new option it is. It should be useful to some libmpv clients (players) which want to disable mpv's builtin bindings without breaking mp.add_key_bindings for scripts. Fixes #8809 (again. the previous fix 8edfe70b only improved the docs, while now we're actually making the requested behavior possible) --- DOCS/interface-changes.rst | 3 +++ DOCS/man/options.rst | 5 +++++ input/input.c | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index ee84bc8f1c..759d5fa9ea 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -43,6 +43,9 @@ Interface changes - add a `--watch-later-options` option to allow configuring which options quit-watch-later saves - make `current-window-scale` writeable and use it in the default input.conf + - add `--input-builtin-bindings` flag to control loading of built-in key + bindings during start-up (default: yes). + --- mpv 0.33.0 --- - add `--d3d11-exclusive-fs` flag to enable D3D11 exclusive fullscreen mode when the player enters fullscreen. diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 34d29db083..812b66639f 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3842,6 +3842,11 @@ Input using ``mp.add_key_binding`` (but not ``mp.add_forced_key_binding``). This might change in the future to exclude ``mp.add_key_binding``. +``--no-input-builtin-bindings`` + Disable loading of built-in key bindings during start-up. This option is + applied only during (lib)mpv initialization, and if used then it will not + be not possible to enable them later. May be useful to libmpv clients. + ``--input-cmdlist`` Prints all commands that can be bound to keys. diff --git a/input/input.c b/input/input.c index 40abd7d0fa..f69517f748 100644 --- a/input/input.c +++ b/input/input.c @@ -176,6 +176,7 @@ struct input_opts { int use_gamepad; int use_media_keys; int default_bindings; + int builtin_bindings; int enable_mouse_movements; int vo_key_input; int test; @@ -190,6 +191,7 @@ const struct m_sub_options input_config = { {"input-keylist", OPT_PRINT(mp_print_key_list)}, {"input-cmdlist", OPT_PRINT(mp_print_cmd_list)}, {"input-default-bindings", OPT_FLAG(default_bindings)}, + {"input-builtin-bindings", OPT_FLAG(builtin_bindings)}, {"input-test", OPT_FLAG(test)}, {"input-doubleclick-time", OPT_INT(doubleclick_time), M_RANGE(0, 1000)}, @@ -218,6 +220,7 @@ const struct m_sub_options input_config = { .enable_mouse_movements = 1, .use_media_keys = 1, .default_bindings = 1, + .builtin_bindings = 1, .vo_key_input = 1, .allow_win_drag = 1, }, @@ -1367,7 +1370,7 @@ void mp_input_load_config(struct input_ctx *ictx) // "Uncomment" the default key bindings in etc/input.conf and add them. // All lines that do not start with '# ' are parsed. bstr builtin = bstr0(builtin_input_conf); - while (builtin.len) { + while (ictx->opts->builtin_bindings && builtin.len) { bstr line = bstr_getline(builtin, &builtin); bstr_eatstart0(&line, "#"); if (!bstr_startswith0(line, " "))