Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various: define builtin options and key bindings for images #15346

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ defined here::

https://github.com/mpv-player/mpv/blob/master/etc/input.conf

Additionally, ``image-input.conf`` can be placed in mpv's configuration
directory to enable key bindings exclusively for images. The default image
bindings are defined here::

https://github.com/mpv-player/mpv/blob/master/etc/image-input.conf

A list of special keys can be obtained with

``mpv --input-keylist``
Expand Down
32 changes: 32 additions & 0 deletions DOCS/man/mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ To use this feature, you need to fill the ``menu-data`` property with menu
definition data, and add a keybinding to run the ``context-menu`` command,
which can be done with a user script.

Image Bindings
--------------

Several key bindings are changed when viewing images:

TODO

USAGE
=====

Expand Down Expand Up @@ -1008,6 +1015,28 @@ example, ``math`` is defined and gives access to the Lua standard math library.
This feature is subject to change indefinitely. You might be forced to
adjust your profiles on mpv updates.

Image profile
-------------------

mpv has a builtin conditional profile that is automatically applied to images
and restored when switching to a video or audio file. Its options are:

.. admonition:: Builtin profile definition

::

[image]
# TODO: update this with the options only

It can be extended in mpv.conf without overwriting it completely:

.. admonition:: Example to reset the zoom between files

::

[image]
reset-on-next-file=video-rotate,video-zoom,panscan,video-unscaled

Legacy auto profiles
--------------------

Expand Down Expand Up @@ -1653,6 +1682,9 @@ All configuration files should be encoded in UTF-8.
``~/.config/mpv/input.conf``
key bindings (see `INPUT.CONF`_ section)

``~/.config/mpv/image-input.conf``
key bindings for images (see `INPUT.CONF`_ section)

``~/.config/mpv/fonts.conf``
Fontconfig fonts.conf that is customized for mpv. You should include system
fonts.conf in this file or mpv would not know about fonts that you already
Expand Down
10 changes: 10 additions & 0 deletions etc/builtin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ sub-shadow-offset=4
[box]
profile=osd-box
profile=sub-box

[image]
profile-cond=(get('current-tracks/video', {}).image and not get('current-tracks/video', {}).albumart) or (not get('current-tracks/video') and get('user-data/mpv/image'))
profile-restore=copy
input-commands=no-osd set user-data/mpv/image 1; enable-section image allow-hide-cursor+allow-vo-dragging
# TODO: decide the options, this is just to test the approach

[non-image]
profile-cond=get('user-data/mpv/image') and (not get('current-tracks/video', {}).image or get('current-tracks/video', {}).albumart)
input-commands=no-osd del user-data/mpv/image; disable-section image
24 changes: 24 additions & 0 deletions etc/image-input.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Image key bindings
#
# Location of user-defined bindings: ~/.config/mpv/image-input.conf
#
# Lines starting with # are comments. Use SHARP to assign the # key.
# Copy this file and uncomment and edit the bindings you want to change.
#
# List of commands and further details: DOCS/man/input.rst
# List of special keys: --input-keylist
# Keybindings testing mode: mpv --input-test --force-window --idle
#
# Use 'ignore' to unbind a key fully (e.g. 'ctrl+a ignore').
#
# Strings need to be quoted and escaped:
# KEY show-text "This is a single backslash: \\ and a quote: \" !"
#
# You can use modifier-key combinations like Shift+Left or Ctrl+Alt+x with
# the modifiers Shift, Ctrl, Alt and Meta (may not work on the terminal).
#
# The default keybindings are hardcoded into the mpv binary.
# You can disable them completely with: --no-input-default-bindings

# TODO: decide the bindings, this is just to test the approach
#F1 show-text foo
2 changes: 1 addition & 1 deletion etc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ foreach size: icons
sources += icon
endforeach

etc_files = ['input.conf', 'builtin.conf']
etc_files = ['input.conf', 'builtin.conf', 'image-input.conf']
foreach file: etc_files
etc_file = custom_target(file,
input: file,
Expand Down
21 changes: 20 additions & 1 deletion input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ static const char builtin_input_conf[] =
#include "etc/input.conf.inc"
;

static const char builtin_image_input_conf[] =
#include "etc/image-input.conf.inc"
;

static bool test_rect(struct mp_rect *rc, int x, int y)
{
return x >= rc->x0 && y >= rc->y0 && x < rc->x1 && y < rc->y1;
Expand Down Expand Up @@ -1477,9 +1481,13 @@ static bool parse_config_file(struct input_ctx *ictx, char *file)
bstr data = stream_read_file2(file, tmp, STREAM_ORIGIN_DIRECT | STREAM_READ,
ictx->global, 1000000);
if (data.start) {
bstr section = (bstr){0};
if (!strcmp(mp_basename(file), "image-input.conf"))
section = bstr0("image");

MP_VERBOSE(ictx, "Parsing input config file %s\n", file);
bstr_eatstart0(&data, "\xEF\xBB\xBF"); // skip BOM
int num = parse_config(ictx, false, data, file, (bstr){0});
int num = parse_config(ictx, false, data, file, section);
MP_VERBOSE(ictx, "Input config file %s parsed: %d binds\n", file, num);
r = true;
} else {
Expand Down Expand Up @@ -1560,13 +1568,24 @@ void mp_input_load_config(struct input_ctx *ictx)
parse_config(ictx, true, line, "<builtin>", (bstr){0});
}

builtin = bstr0(builtin_image_input_conf);
while (ictx->opts->builtin_bindings && builtin.len) {
bstr line = bstr_getline(builtin, &builtin);
bstr_eatstart0(&line, "#");
if (!bstr_startswith0(line, " "))
parse_config(ictx, true, line, "<builtin-image>", bstr0("image"));
}

bool config_ok = false;
if (ictx->opts->config_file && ictx->opts->config_file[0])
config_ok = parse_config_file(ictx, ictx->opts->config_file);
if (!config_ok) {
// Try global conf dir
void *tmp = talloc_new(NULL);
char **files = mp_find_all_config_files(tmp, ictx->global, "input.conf");
for (int n = 0; files && files[n]; n++)
parse_config_file(ictx, files[n]);
files = mp_find_all_config_files(tmp, ictx->global, "image-input.conf");
for (int n = 0; files && files[n]; n++)
parse_config_file(ictx, files[n]);
talloc_free(tmp);
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ if get_option('cplayer')
datadir = get_option('datadir')
confdir = get_option('sysconfdir')

conf_files = ['etc/mpv.conf', 'etc/input.conf',
conf_files = ['etc/mpv.conf', 'etc/input.conf', 'etc/image-input.conf',
'etc/mplayer-input.conf', 'etc/restore-old-bindings.conf',
'etc/restore-osc-bindings.conf']
install_data(conf_files, install_dir: join_paths(datadir, 'doc', 'mpv'))
Expand Down
Loading