Skip to content

Commit 0867820

Browse files
committed
select.lua: populate the context menu
Add a default context menu definition in etc/menu.conf, which can be replaced in ~~/menu.conf. The format is meant to be easily readable with just 3+ spaces as separators and submenus denoted by indentation. It avoids complicating the builtin input.conf like similar scripts do. select.lua parses menu.conf, fills menu-data and opens the context menu. This is done from select.lua to reuse the code to format the data and retrieve key bindings. When a preconfigured submenu has more than 25 items, … entries are added that open the scrollable console menu when clicked. input-bindings is parsed to show the shortcuts bound to commands. Compared to associating pre-defined shortcuts in the default input.conf, this won't show wrong shortcuts when the user's input.conf changes key bindings without redefining the menu. console and stats key bindings are skipped in case the context menu is opened together with those scripts. Multimedia and numpad keys are not shown to reduce clutter. Right click and MENU are rebound to show the context menu. MENU is not added to restore-old-bindings.conf because it is uncommon. Shift+F10 is also bound since it is a standard context menu binding.
1 parent 199c491 commit 0867820

File tree

11 files changed

+704
-37
lines changed

11 files changed

+704
-37
lines changed

.luacheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ stds = { mp = { read_globals = mp_globals } }
106106
-- mp_internal seems to be merged with mp for other files too...
107107
files["player/lua/defaults.lua"] = { globals = mp_internal }
108108
files["player/lua/auto_profiles.lua"] = { globals = { "p", "get" } }
109+
files["player/lua/select.lua"] = { globals = { "p", "get" } }
109110
max_line_length = 100

DOCS/man/context_menu.rst

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
CONTEXT MENU
22
============
33

4-
This script provides a context menu for platforms without integration with a
5-
native context menu. On these platforms, it can be disabled entirely using the
4+
The context menu is a menu that pops up on the video window. By default, it is
5+
bound to right click.
6+
7+
menu.conf
8+
---------
9+
10+
The default menu is defined in ``etc/menu.conf``. You can define your own menu
11+
in ``~~/menu.conf`` (see `FILES`_), or an alternative path specified with
12+
``--script-opt=select_menu_conf_path``. It is recommended to use the default
13+
``menu.conf`` from https://github.com/mpv-player/mpv/blob/master/etc/input.conf
14+
as an example to get started.
15+
16+
Each line of ``menu.conf`` is a menu entry with fields separated by 3 or more
17+
spaces. The first field is the text shown in the menu. The second field is
18+
usually the command that is run when that entry is selected. Fields from the
19+
third onwards can specify ``checked=``, ``disabled=`` and ``hidden=`` states in
20+
the same way as `Conditional auto profiles`_.
21+
22+
When there is only one field, or the second field specifies a state, it is
23+
interpreted as the title of an entry associated with a submenu. Fields below
24+
indented with leading spaces are added to this submenu. Nested submenu items are
25+
defined by adding more leading spaces than the parent menu entry.
26+
27+
Empty lines are interpreted as separators.
28+
29+
The second field can also be one of the following tokens to make that entry a
30+
submenu with the relative items: ``$playlist``, ``$video-tracks``,
31+
``$audio-tracks``, ``$sub-tracks``, ``$secondary-sub-tracks``, ``$chapters``,
32+
``$editions``, ``$audio-devices``. These menus are automatically disabled when
33+
empty.
34+
35+
``menu.conf`` is parsed by ``select.lua`` in order to fill the ``menu-data``
36+
property. It then calls the ``context-menu`` command on platforms where
37+
integration with the native context menu is implemented, while on platforms
38+
where it is not, it opens ``context_menu.lua``.
39+
40+
On these platforms, ``context_menu.lua`` can be disabled entirely using the
641
``--load-context-menu=no`` option. On platforms where the integration is
7-
implemented, it is already disabled by default.
42+
implemented, it is already disabled by default, and ``--load-context-menu=yes``
43+
will make ``select.lua`` use it.
844

945
Script messages
1046
---------------

DOCS/man/mpv.rst

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,14 @@ g-b
351351
g-r
352352
Show the values of all properties.
353353

354-
g-m, MENU, Ctrl+p
354+
g-m, Ctrl+p
355355
Show a menu with miscellaneous entries.
356356

357357
See `SELECT`_ for more information.
358358

359+
MENU, Shift+F10
360+
Show the context menu (see `CONTEXT MENU`_).
361+
359362
(The following keys are valid if you have a keyboard with multimedia keys.)
360363

361364
PAUSE
@@ -384,7 +387,7 @@ Left double click
384387
Toggle fullscreen on/off.
385388

386389
Right click
387-
Toggle pause on/off.
390+
Show the context menu (see `CONTEXT MENU`_).
388391

389392
Forward/Back button
390393
Skip to next/previous entry in playlist.
@@ -399,16 +402,6 @@ Ctrl+Wheel up/down
399402
Change video zoom keeping the part of the video hovered by the cursor under
400403
it.
401404

402-
Context Menu
403-
-------------
404-
405-
Context Menu is a menu that pops up on the video window on user interaction
406-
(mouse right click, etc.).
407-
408-
To use this feature, you need to fill the ``menu-data`` property with menu
409-
definition data, and add a keybinding to run the ``context-menu`` command,
410-
which can be done with a user script.
411-
412405
USAGE
413406
=====
414407

DOCS/man/select.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ providing script bindings that gather and format the data to be selected in the
77
console and do operations on the selected item. It can be disabled using the
88
``--load-select=no`` option.
99

10+
This script is also used to populate the context menu.
11+
1012
Key bindings
1113
------------
1214

@@ -130,6 +132,9 @@ Available script bindings are:
130132
``menu``
131133
Show a menu with miscellaneous entries.
132134

135+
``context-menu``
136+
Show the context menu.
137+
133138
Configuration
134139
-------------
135140

@@ -150,3 +155,26 @@ Configurable options
150155
Default: yes
151156

152157
Whether to show only the last of history entries with the same path.
158+
159+
``menu_conf_path``
160+
Default: ~~/menu.conf (see `FILES`_).
161+
162+
The path from which to read the custom context menu definition (see `CONTEXT
163+
MENU`_).
164+
165+
``max_submenu_items``
166+
Default: 25
167+
168+
The maximum number of items in preconfigured submenus.
169+
170+
``use_context_menu_script``
171+
Default: auto
172+
173+
Whether to use the native context menu or ``context_menu.lua``.
174+
175+
``auto`` means ``context_menu.lua`` is used with
176+
``--load-context-menu=yes``, and the native context menu is attempted to be
177+
used with ``--load-context-menu=no``.
178+
179+
``yes`` allows using a fork of ``context_menu.lua`` with
180+
``--load-context-menu=no``.

DOCS/tech-overview.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ sub/:
272272
sd_ass.c's internal state.
273273

274274
etc/:
275-
The files input.conf and builtin.conf are actually integrated into the mpv
276-
binary by the build system. They contain the default configs and keybindings.
275+
The files input.conf, builtin.conf and menu.conf are actually integrated
276+
into the mpv binary by the build system. They contain the default configs
277+
and keybindings.
277278

278279
Best practices and Concepts within mpv
279280
======================================

etc/input.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#MBTN_LEFT ignore # don't do anything
3232
#MBTN_LEFT_DBL cycle fullscreen # toggle fullscreen
33-
#MBTN_RIGHT cycle pause # toggle pause/playback mode
33+
#MBTN_RIGHT script-binding select/context-menu # show the context menu
3434
#MBTN_BACK playlist-prev # skip to the previous file
3535
#MBTN_FORWARD playlist-next # skip to the next file
3636
#Ctrl+MBTN_LEFT script-binding positioning/drag-to-pan # pan around the clicked point
@@ -196,8 +196,9 @@
196196
#g-b script-binding select/select-binding
197197
#g-r script-binding select/show-properties
198198
#g-m script-binding select/menu
199-
#MENU script-binding select/menu
200199
#ctrl+p script-binding select/menu
200+
#MENU script-binding select/context-menu
201+
#Shift+F10 script-binding select/context-menu
201202

202203
#Alt+KP1 add video-rotate -1 # rotate video counterclockwise by 1 degree
203204
#Alt+KP5 set video-rotate 0 # reset rotation

etc/menu.conf

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Play cycle pause hidden=not pause and not idle_active disabled=idle_active
2+
Pause cycle pause hidden=idle_active or pause
3+
Stop stop hidden=idle ~= true disabled=idle_active
4+
5+
Open
6+
Clipboard loadfile ${clipboard/text} append-play; show-text '+ ${clipboard/text}'
7+
History script-binding select/select-watch-history
8+
Watch later script-binding select/select-watch-later
9+
Playlist $playlist disabled=playlist_count < 2
10+
11+
Video
12+
Track $video-tracks
13+
14+
Fill no-osd cycle-values panscan 0 1; no-osd set video-unscaled no; no-osd set video-zoom 0 checked=panscan == 1
15+
Unscaled no-osd cycle-values video-unscaled yes no; no-osd set video-zoom 0; no-osd set panscan 0 checked=video_unscaled
16+
Zoom
17+
50% set video-zoom -1 checked=video_zoom == -1
18+
100% set video-zoom 0 checked=video_zoom == 0
19+
200% set video-zoom 1 checked=video_zoom == 1
20+
Aspect ratio
21+
16:9 set video-aspect-override 16:9 checked=math.abs(video_aspect_override - 1.7) < 0.1
22+
4:3 set video-aspect-override 4:3 checked=math.abs(video_aspect_override - 1.3) < 0.1
23+
2.35:1 set video-aspect-override 2.35:1 checked=video_aspect_override == 2.35
24+
Default set video-aspect-override no checked=video_aspect_override == -2
25+
Center no-osd set video-pan-x 0; no-osd set video-pan-y 0; no-osd set video-align-x 0; no-osd set video-align-y 0 disabled=video_pan_x == 0 and video_pan_y == 0 and video_align_x == 0 and video_align_y == 0
26+
27+
Rotate clockwise cycle-values video-rotate 90 180 270 0
28+
Rotate counterclockwise cycle-values video-rotate 270 180 90 0
29+
30+
Deband cycle deband checked=deband
31+
Deinterlace cycle deinterlace checked=deinterlace_active
32+
33+
Screenshot screenshot disabled=not p["current-tracks/video"]
34+
Screenshot without subtitles screenshot video disabled=not p["current-tracks/video"]
35+
Audio
36+
Track $audio-tracks
37+
Devices $audio-devices
38+
Channels
39+
Auto set audio-channels auto-safe checked=audio_channels == "auto-safe"
40+
Stereo set audio-channels stereo checked=audio_channels == "stereo"
41+
Mono set audio-channels mono checked=audio_channels == "mono"
42+
43+
Increase volume add volume 5
44+
Decrease volume add volume -5
45+
Mute cycle mute checked=mute
46+
47+
Increase delay add audio-delay 0.1
48+
Decrease delay add audio-delay -0.1
49+
Subtitle
50+
Track $sub-tracks
51+
Visible cycle sub-visibility checked=sub_visibility
52+
53+
Increase delay add sub-delay 0.1
54+
Decrease delay add sub-delay -0.1
55+
56+
Scale up add sub-scale 0.1
57+
Scale down add sub-scale -0.1
58+
59+
Lines script-binding select/select-subtitle-line disabled=not sid or p["current-tracks/sub/codec"] == "dvd_subtitle" or p["current-tracks/sub/codec"] == "hdmv_pgs_subtitle"
60+
Secondary subtitle
61+
Track $secondary-sub-tracks
62+
Visible cycle secondary-sub-visibility checked=secondary_sub_visibility
63+
64+
Increase delay add secondary-sub-delay 0.1
65+
Decrease delay add secondary-sub-delay -0.1
66+
67+
Playback
68+
Display duration hidden=not p["current-tracks/video/image"] or p["current-tracks/audio"]
69+
1 second set image-display-duration 1 checked=image_display_duration == 1
70+
2 seconds set image-display-duration 2 checked=image_display_duration == 2
71+
5 seconds set image-display-duration 5 checked=image_display_duration == 5
72+
10 seconds set image-display-duration 10 checked=image_display_duration == 10
73+
Infinite set image-display-duration inf checked=image_display_duration == math.huge
74+
Speed hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"]
75+
25% set speed 0.25 checked=speed == 0.25
76+
50% set speed 0.50 checked=speed == 0.50
77+
75% set speed 0.75 checked=speed == 0.75
78+
100% set speed 1 checked=speed == 1
79+
125% set speed 1.25 checked=speed == 1.25
80+
150% set speed 1.50 checked=speed == 1.50
81+
175% set speed 1.75 checked=speed == 1.75
82+
200% set speed 2 checked=speed == 2
83+
400% set speed 4 checked=speed == 4
84+
800% set speed 8 checked=speed == 8
85+
86+
Seek 10 seconds forward seek 10 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"]
87+
Seek 10 seconds backward seek -10 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"]
88+
Seek 10 minutes forward seek 600 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"]
89+
Seek 10 minutes backward seek -600 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"]
90+
91+
Next file playlist-next disabled=playlist_count < 2
92+
Previous file playlist-prev disabled=playlist_count < 2
93+
94+
Next sub-playlist playlist-next-playlist disabled=playlist_count < 2
95+
Previous sub-playlist playlist-prev-playlist disabled=playlist_count < 2
96+
Chapters $chapters
97+
Editions/Titles $editions disabled=get("edition-list/count", 0) < 2
98+
99+
Window
100+
Fullscreen cycle fullscreen checked=fullscreen
101+
Border cycle border checked=border
102+
Always on top cycle ontop checked=ontop
103+
Window scale
104+
50% set window-scale 0.5 checked=math.abs(get(current_window_scale, 0) - 0.5) < 0.1
105+
100% set window-scale 1 checked=math.abs(get(current_window_scale, 0) - 1) < 0.1
106+
200% set window-scale 2 checked=math.abs(get(current_window_scale, 0) - 2) < 0.1
107+
300% set window-scale 3 checked=math.abs(get(current_window_scale, 0) - 3) < 0.1
108+
Screenshot window screenshot window
109+
View
110+
Stats script-binding stats/display-page-1-toggle
111+
File info script-binding stats/display-page-5-toggle
112+
Key bindings script-binding stats/display-page-4-toggle
113+
Time OSD no-osd cycle-values osd-level 3 1 checked=osd_level == 3
114+
Cycle OSC visibility script-binding osc/visibility
115+
Tools
116+
Set/clear A-B loop points ab-loop
117+
Loop file cycle-values loop-file inf no checked=loop_file == "inf"
118+
Loop playlist cycle-values loop-playlist inf no checked=loop_playlist == "inf"
119+
120+
Copy path set clipboard/text ${path} disabled=idle_active
121+
Copy subtitle set clipboard/text ${sub-text} disabled=not sid or p["current-tracks/sub/codec"] == "dvd_subtitle" or p["current-tracks/sub/codec"] == "hdmv_pgs_subtitle"
122+
Copy title set clipboard/text ${media-title} disabled=idle_active
123+
124+
Shuffle playlist-shuffle
125+
Unshuffle playlist-unshuffle
126+
127+
Hardware decoding cycle-values hwdec no auto checked=hwdec_current ~= "no" disabled=p["current-tracks/video/image"] ~= false
128+
Key bindings script-binding select/select-binding
129+
Properties script-binding select/show-properties
130+
Console script-binding commands/open
131+
132+
Quit quit
133+
Quit watch later quit-watch-later hidden=save_position_on_quit

etc/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ foreach size: icons
99
sources += icon
1010
endforeach
1111

12-
etc_files = ['input.conf', 'builtin.conf']
12+
etc_files = ['input.conf', 'builtin.conf', 'menu.conf']
1313
foreach file: etc_files
1414
etc_file = custom_target(file,
1515
input: file,

etc/restore-old-bindings.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#
1010
# Older installations use ~/.mpv/input.conf instead.
1111

12+
# changed in mpv 0.41.0
13+
14+
MBTN_RIGHT cycle pause
15+
1216
# changed in mpv 0.37.0
1317

1418
WHEEL_UP seek 10 # seek 10 seconds forward

player/command.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4039,6 +4039,22 @@ static int mp_property_mdata(void *ctx, struct m_property *prop,
40394039
return M_PROPERTY_NOT_IMPLEMENTED;
40404040
}
40414041

4042+
static int mp_property_default_menu(void *ctx, struct m_property *prop,
4043+
int action, void *arg)
4044+
{
4045+
switch (action) {
4046+
case M_PROPERTY_GET:
4047+
*(char **)arg = talloc_strdup(NULL,
4048+
#include "etc/menu.conf.inc"
4049+
);
4050+
return M_PROPERTY_OK;
4051+
case M_PROPERTY_GET_TYPE:
4052+
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING};
4053+
return M_PROPERTY_OK;
4054+
}
4055+
return M_PROPERTY_NOT_IMPLEMENTED;
4056+
}
4057+
40424058
static int do_list_udata(int item, int action, void *arg, void *ctx);
40434059

40444060
struct udata_ctx {
@@ -4542,6 +4558,7 @@ static const struct m_property mp_properties_base[] = {
45424558
{"input-bindings", mp_property_bindings},
45434559

45444560
{"menu-data", mp_property_mdata},
4561+
{"default-menu", mp_property_default_menu},
45454562

45464563
{"user-data", mp_property_udata},
45474564
{"term-size", mp_property_term_size},

0 commit comments

Comments
 (0)