Skip to content

Commit 06de1c1

Browse files
committed
context_menu.lua: add this script
This implements a ASS context menu to be used on platforms other than Windows. The select script message will allow selecting an item with a single click when releasing a mouse button, like in native context menus. This is mainly useful to cycle pause with one click.
1 parent 194ce88 commit 06de1c1

File tree

12 files changed

+724
-7
lines changed

12 files changed

+724
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add `--load-context-menu` option

DOCS/man/context_menu.rst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
CONTEXT MENU SCRIPT
2+
===================
3+
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
6+
``--load-context-menu=no`` option. On platforms where the integration is
7+
implemented, it is already disabled by default.
8+
9+
Script messages
10+
---------------
11+
12+
``open``
13+
Show the context menu.
14+
15+
``select``
16+
Select the focused item when there is one.
17+
18+
Configuration
19+
-------------
20+
21+
This script can be customized through a config file
22+
``script-opts/context_menu.conf`` placed in mpv's user directory and through
23+
the ``--script-opts`` command-line option. The configuration syntax is
24+
described in `mp.options functions`_.
25+
26+
Configurable Options
27+
~~~~~~~~~~~~~~~~~~~~
28+
29+
``font_size``
30+
Default: 20
31+
32+
The font size.
33+
34+
``gap``
35+
Default: 5
36+
37+
The gap between menu items.
38+
39+
``padding_x``
40+
Default: 10
41+
42+
The horizontal padding of the menu.
43+
44+
``padding_y``
45+
Default: 5
46+
47+
The vertical padding of the menu.
48+
49+
``menu_outline_size``
50+
Default: 0
51+
52+
The size of the menu's border.
53+
54+
``menu_outline_color``
55+
Default: ``#FFFFFF``
56+
57+
The color of the menu's border.
58+
59+
``corner_radius``
60+
Default: 8
61+
62+
The radius of the menu's corners.
63+
64+
``scale_with_window``
65+
Default: auto
66+
67+
Whether to scale sizes with the window height. Can be ``yes``, ``no``, or
68+
``auto``, which follows the value of ``--osd-scale-by-window``.
69+
70+
When sizes aren't scaled with the window, they are scaled by
71+
``display-hidpi-scale``.
72+
73+
``focused_color``
74+
Default: ``#222222``
75+
76+
The color of the focused item.
77+
78+
``focused_back_color``
79+
Default: ``#FFFFFF``
80+
81+
The background color of the focused item.
82+
83+
``disabled_color``
84+
Default: ``#555555``
85+
86+
The color of disabled items.
87+
88+
``seconds_to_open_submenus``
89+
Default: 0.2
90+
91+
The number of seconds to open submenus after the cursor enters items
92+
associated with one.
93+
94+
``seconds_to_close_submenus``
95+
Default: 0.2
96+
97+
The number of seconds to close submenus after the cursor enters a parent
98+
menu.

DOCS/man/mpv.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,6 @@ Ctrl+Wheel up/down
402402
Context Menu
403403
-------------
404404

405-
.. warning::
406-
407-
This feature is experimental. It may not work with all VOs. A libass based
408-
fallback may be implemented in the future.
409-
410405
Context Menu is a menu that pops up on the video window on user interaction
411406
(mouse right click, etc.).
412407

@@ -1548,6 +1543,8 @@ works like in older mpv releases:
15481543

15491544
.. include:: select.rst
15501545

1546+
.. include:: context_menu.rst
1547+
15511548
.. include:: positioning.rst
15521549

15531550
.. include:: lua.rst

DOCS/man/options.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,11 @@ Program Behavior
10661066
Enable the builtin script that lets you select from lists of items (default:
10671067
yes). By default, its keybindings start with the ``g`` key.
10681068

1069+
``--load-context-menu=<yes|no>``
1070+
Enable the builtin script that implements a context menu. Defaults to
1071+
``yes`` on platforms where integration with a native context menu is not
1072+
implemented, and to ``no`` on platform where it is.
1073+
10691074
``--load-positioning=<yes|no>``
10701075
Enable the builtin script that provides various keybindings to pan videos
10711076
and images (default: yes).

etc/builtin.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ osd-outline-size=0
8585
osd-shadow-offset=4
8686
script-opt=console-border_size=0
8787
script-opt=console-corner_radius=0
88+
script-opt=context_menu-padding_y=0
89+
script-opt=context_menu-corner_radius=0
8890
script-opt=stats-border_size=0
8991

9092
[sub-box]

options/options.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ static const m_option_t mp_opts[] = {
565565
{"load-select", OPT_BOOL(lua_load_select), .flags = UPDATE_BUILTIN_SCRIPTS},
566566
{"load-positioning", OPT_BOOL(lua_load_positioning), .flags = UPDATE_BUILTIN_SCRIPTS},
567567
{"load-commands", OPT_BOOL(lua_load_commands), .flags = UPDATE_BUILTIN_SCRIPTS},
568+
{"load-context-menu", OPT_BOOL(lua_load_context_menu), .flags = UPDATE_BUILTIN_SCRIPTS},
568569
#endif
569570

570571
// ------------------------- stream options --------------------
@@ -1000,6 +1001,9 @@ static const struct MPOpts mp_default_opts = {
10001001
.lua_load_select = true,
10011002
.lua_load_positioning = true,
10021003
.lua_load_commands = true,
1004+
#ifndef _WIN32
1005+
.lua_load_context_menu = true,
1006+
#endif
10031007
#endif
10041008
.auto_load_scripts = true,
10051009
.loop_times = 1,

options/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ typedef struct MPOpts {
183183
bool lua_load_select;
184184
bool lua_load_positioning;
185185
bool lua_load_commands;
186+
bool lua_load_context_menu;
186187

187188
bool auto_load_scripts;
188189

player/core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ typedef struct MPContext {
444444

445445
struct mp_ipc_ctx *ipc_ctx;
446446

447-
int64_t builtin_script_ids[8];
447+
int64_t builtin_script_ids[9];
448448

449449
mp_mutex abort_lock;
450450

player/lua.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ static const char * const builtin_lua_scripts[][2] = {
9090
},
9191
{"@commands.lua",
9292
# include "player/lua/commands.lua.inc"
93+
},
94+
{"@context_menu.lua",
95+
# include "player/lua/context_menu.lua.inc"
9396
},
9497
{0}
9598
};

0 commit comments

Comments
 (0)