Skip to content
Merged
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
1 change: 1 addition & 0 deletions DOCS/interface-changes/context-menu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--load-context-menu` option
98 changes: 98 additions & 0 deletions DOCS/man/context_menu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
CONTEXT MENU SCRIPT
===================

This script provides a context menu for platforms without integration with a
native context menu. On these platforms, it can be disabled entirely using the
``--load-context-menu=no`` option. On platforms where the integration is
implemented, it is already disabled by default.

Script messages
---------------

``open``
Show the context menu.

``select``
Select the focused item when there is one.

Configuration
-------------

This script can be customized through a config file
``script-opts/context_menu.conf`` placed in mpv's user directory and through
the ``--script-opts`` command-line option. The configuration syntax is
described in `mp.options functions`_.

Configurable Options
~~~~~~~~~~~~~~~~~~~~

``font_size``
Default: 14

The font size.

``gap``
Default: 3

The gap between menu items.

``padding_x``
Default: 8

The horizontal padding of the menu.

``padding_y``
Default: 4

The vertical padding of the menu.

``menu_outline_size``
Default: 0

The size of the menu's border.

``menu_outline_color``
Default: ``#FFFFFF``

The color of the menu's border.

``corner_radius``
Default: 5

The radius of the menu's corners.

``scale_with_window``
Default: auto

Whether to scale sizes with the window height. Can be ``yes``, ``no``, or
``auto``, which follows the value of ``--osd-scale-by-window``.

When sizes aren't scaled with the window, they are scaled by
``display-hidpi-scale``.

``focused_color``
Default: ``#222222``

The color of the focused item.

``focused_back_color``
Default: ``#FFFFFF``

The background color of the focused item.

``disabled_color``
Default: ``#555555``

The color of disabled items.

``seconds_to_open_submenus``
Default: 0.2

The number of seconds to open submenus after the cursor enters items
associated with one.

``seconds_to_close_submenus``
Default: 0.2

The number of seconds to close submenus after the cursor enters a parent
menu.
7 changes: 2 additions & 5 deletions DOCS/man/mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,6 @@ Ctrl+Wheel up/down
Context Menu
-------------

.. warning::

This feature is experimental. It may not work with all VOs. A libass based
fallback may be implemented in the future.

Context Menu is a menu that pops up on the video window on user interaction
(mouse right click, etc.).

Expand Down Expand Up @@ -1548,6 +1543,8 @@ works like in older mpv releases:

.. include:: select.rst

.. include:: context_menu.rst

.. include:: positioning.rst

.. include:: lua.rst
Expand Down
5 changes: 5 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,11 @@ Program Behavior
Enable the builtin script that lets you select from lists of items (default:
yes). By default, its keybindings start with the ``g`` key.

``--load-context-menu=<yes|no>``
Enable the builtin script that implements a context menu. Defaults to
``yes`` on platforms where integration with a native context menu is not
implemented, and to ``no`` on platform where it is.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be auto instead? I am not sure if some would prefer the OSD menu than GUI menu.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? It already behaves like auto by changing default value based on the platform.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the explicit value auto. Is there any reason to make the option special?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that the default value can be determined at compile time unlike every other auto option, removing the need to implement a context-menu-loaded property.

Copy link
Contributor

@hooke007 hooke007 Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it wouldn't be conflict with GUI menu. I think I will always set it to yes to use two menus together in different cases.

Copy link
Contributor Author

@guidocella guidocella Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what you mean by GUI menu.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean Windows users cannot use the ASS menu?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--load-context-menu defaults to no on Windows so that select.lua will prefer opening the native context menu, but nothing stops you from ignoring this option and opening either menu in a third party script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, the only advantage of the native context menu I see is that it can be drawn outside of mpv's window. Whereas the advantage of the ASS menu is that you can customize its appearance.


``--load-positioning=<yes|no>``
Enable the builtin script that provides various keybindings to pan videos
and images (default: yes).
Expand Down
2 changes: 2 additions & 0 deletions etc/builtin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ osd-outline-size=0
osd-shadow-offset=4
script-opt=console-border_size=0
script-opt=console-corner_radius=0
script-opt=context_menu-padding_y=0
script-opt=context_menu-corner_radius=0
script-opt=stats-border_size=0

[sub-box]
Expand Down
4 changes: 4 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ static const m_option_t mp_opts[] = {
{"load-select", OPT_BOOL(lua_load_select), .flags = UPDATE_BUILTIN_SCRIPTS},
{"load-positioning", OPT_BOOL(lua_load_positioning), .flags = UPDATE_BUILTIN_SCRIPTS},
{"load-commands", OPT_BOOL(lua_load_commands), .flags = UPDATE_BUILTIN_SCRIPTS},
{"load-context-menu", OPT_BOOL(lua_load_context_menu), .flags = UPDATE_BUILTIN_SCRIPTS},
#endif

// ------------------------- stream options --------------------
Expand Down Expand Up @@ -1000,6 +1001,9 @@ static const struct MPOpts mp_default_opts = {
.lua_load_select = true,
.lua_load_positioning = true,
.lua_load_commands = true,
#ifndef _WIN32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks iffy. What about macOS, or other possible implementations of context menu?

Copy link
Contributor Author

@guidocella guidocella Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is iffy? When the macOS context menu is implemented this needs to be updated to #if !defined(_WIN32) && !defined(HAVE_COCOA)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the macOS context menu is implemented

macOS has its own context menu implemented already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing the macOS context menu is literally listed as a goal in #13608. Only the top bar menu is implemented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal of disabling context menu script anyway? It's not bound to any key, so there is no conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just reduces the number of threads running.

.lua_load_context_menu = true,
#endif
#endif
.auto_load_scripts = true,
.loop_times = 1,
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ typedef struct MPOpts {
bool lua_load_select;
bool lua_load_positioning;
bool lua_load_commands;
bool lua_load_context_menu;

bool auto_load_scripts;

Expand Down
2 changes: 1 addition & 1 deletion player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ typedef struct MPContext {

struct mp_ipc_ctx *ipc_ctx;

int64_t builtin_script_ids[8];
int64_t builtin_script_ids[9];

mp_mutex abort_lock;

Expand Down
3 changes: 3 additions & 0 deletions player/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ static const char * const builtin_lua_scripts[][2] = {
},
{"@commands.lua",
# include "player/lua/commands.lua.inc"
},
{"@context_menu.lua",
# include "player/lua/context_menu.lua.inc"
},
{0}
};
Expand Down
Loading
Loading