Skip to content

Commit a44744d

Browse files
committed
select.lua: populate the context menu
Make select.lua parse menu.conf, fill menu-data and open the context menu. This is done from select.lua to reuse the code to format the data and retrieve key bindings. The first time the context menu is opened, menu-data is filled initially, and the referenced properties are observed so that menu-data is already updated by the next time you open the context menu. So if you never use the context menu there is no extra overhead. While the context menu is scrollable, for the playlist it is better to start from around the current entry rather than from the beginning, and since menu-data has no way to specify where to start, when there are more than 25 items playlist items this adds … entries that open the scrollable console menu when clicked. input-bindings is parsed to show the shortcuts bound to commands. Since it is not observable, it just uses the bindings from the first time the context menu is opened. 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. The old Context Menu section of the docs is merged in the more detailed context_menu.rst to not repeat the same information.
1 parent 52edbc4 commit a44744d

File tree

5 files changed

+607
-32
lines changed

5 files changed

+607
-32
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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
CONTEXT MENU SCRIPT
2-
===================
1+
CONTEXT MENU
2+
============
33

44
The context menu is a menu that pops up on the video window. By default, it is
55
bound to right click.
66

77
menu.conf
88
---------
99

10-
You can define your own menu in ``~~/menu.conf`` (see `FILES`_). It is
10+
You can define your own menu in ``~~/menu.conf`` (see `FILES`_), or an
11+
alternative path specified with ``--script-opt=select-menu_conf_path``. It is
1112
recommended to use the default ``menu.conf`` from
1213
https://github.com/mpv-player/mpv/blob/master/etc/menu.conf as an example to get
1314
started.
@@ -30,6 +31,19 @@ submenu with the relative items: ``$playlist``, ``$video-tracks``,
3031
``$editions``, ``$audio-devices``. These menus are automatically disabled when
3132
empty.
3233

34+
To use the native context menu, you need to fill the ``menu-data`` property with
35+
menu definition data, and call the ``context-menu`` command. In builtin scripts,
36+
this is done by ``select.lua``, which parses ``menu.conf`` to populate
37+
``menu-data``. It then calls the ``context-menu`` command on platforms where
38+
integration with the native context menu is implemented, while on platforms
39+
where it is not, it opens ``context_menu.lua``.
40+
41+
On platforms without integration with the native context menu,
42+
``context_menu.lua`` can be disabled entirely using the
43+
``--load-context-menu=no`` option. On platforms where the integration is
44+
implemented, it is already disabled by default, and ``--load-context-menu=yes``
45+
will make ``select.lua`` use it.
46+
3347
Script messages
3448
---------------
3549

DOCS/man/mpv.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,6 @@ Ctrl+Wheel up/down
399399
Change video zoom keeping the part of the video hovered by the cursor under
400400
it.
401401

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-
412402
USAGE
413403
=====
414404

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

@@ -141,6 +143,9 @@ Available script bindings are:
141143
``menu``
142144
Show a menu with miscellaneous entries.
143145

146+
``context-menu``
147+
Show the context menu.
148+
144149
Configuration
145150
-------------
146151

@@ -161,3 +166,26 @@ Configurable options
161166
Default: yes
162167

163168
Whether to show only the last of history entries with the same path.
169+
170+
``menu_conf_path``
171+
Default: ~~/menu.conf (see `FILES`_).
172+
173+
The path from which to read the custom context menu definition (see `CONTEXT
174+
MENU`_).
175+
176+
``max_playlist_items``
177+
Default: 25
178+
179+
The maximum number of playlist entries in the context menu.
180+
181+
``use_context_menu_script``
182+
Default: auto
183+
184+
Whether to use the native context menu or ``context_menu.lua``.
185+
186+
``auto`` means ``context_menu.lua`` is used with
187+
``--load-context-menu=yes``, and the native context menu is attempted to be
188+
used with ``--load-context-menu=no``.
189+
190+
``yes`` allows using a fork of ``context_menu.lua`` with
191+
``--load-context-menu=no``.

0 commit comments

Comments
 (0)