From 19adc2d50974e4a5708e967df313855b393d77df Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Mon, 25 Aug 2025 19:54:17 +0200 Subject: [PATCH] menu.conf: add this file Add a default context menu definition in etc/menu.conf. It will be used to populate the context menu. The format is meant to be easily readable with just tabs as separators and submenus denoted by indentation. It avoids complicating the builtin input.conf like similar scripts do. By not defining the shortcut keys in the builtin input.conf, menu entries won't be associated to wrong shortcuts when the user's input.conf changes key bindings without redefining the menu. Note that external scripts don't have this issue. I used 3+ spaces as separators at first but then realized that since we have Windows users tabs will look better in editors with proportional fonts like notepad, though it still won't be perfectly aligned depending on the font. But I am still not sure what is better. On a curious note, etc/menu.conf already existed in the past as mplayer used to have a menu. git log -p etc/menu.conf will show commits from 2002 to 2011. --- .editorconfig | 3 + .pre-commit-config.yaml | 2 +- DOCS/man/context_menu.rst | 32 +++++++-- DOCS/tech-overview.txt | 5 +- etc/menu.conf | 141 ++++++++++++++++++++++++++++++++++++++ etc/meson.build | 2 +- 6 files changed, 177 insertions(+), 8 deletions(-) create mode 100644 etc/menu.conf diff --git a/.editorconfig b/.editorconfig index 36600d2a46..c69025d2d8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -21,3 +21,6 @@ indent_style = unset indent_size = unset max_line_length = unset trim_trailing_whitespace = unset + +[menu.conf] +indent_style = tab diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f3f957d615..10f3265e64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,4 +20,4 @@ repos: hooks: - id: codespell args: ["--ignore-words-list", "ALS,als,datas,DNE,enew,HDA,numer,ontop,optionA,Paeth,pathc,inout,requestor"] - exclude: ^misc/language.c$ + exclude: ^(etc/menu.conf|misc/language.c)$ diff --git a/DOCS/man/context_menu.rst b/DOCS/man/context_menu.rst index af28af851e..f6a19a5255 100644 --- a/DOCS/man/context_menu.rst +++ b/DOCS/man/context_menu.rst @@ -1,10 +1,34 @@ 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. +The context menu is a menu that pops up on the video window. By default, it is +bound to right click. + +menu.conf +--------- + +You can define your own menu in ``~~/menu.conf`` (see `FILES`_). It is +recommended to use the default ``menu.conf`` from +https://github.com/mpv-player/mpv/blob/master/etc/menu.conf as an example to get +started. + +Each line of ``menu.conf`` is a menu item with fields separated by 1 or more +tabs. The first field is the text shown in the menu. The second field is usually +the command that is run when that item is selected. Fields from the third +onwards can specify ``checked=``, ``disabled=`` and ``hidden=`` states in the +same way as `Conditional auto profiles`_. + +When there is no command, the item will open a submenu. Fields below indented +with leading whitespace are added to this submenu. Nested submenu items are +defined by adding more leading whitespace than the parent menu entry. + +Empty lines are interpreted as separators. + +The second field can also be one of the following tokens to make that entry a +submenu with the relative items: ``$playlist``, ``$tracks``, ``$video-tracks``, +``$audio-tracks``, ``$sub-tracks``, ``$secondary-sub-tracks``, ``$chapters``, +``$editions``, ``$audio-devices``, ``$profiles``. These menus are automatically +disabled when empty. Script messages --------------- diff --git a/DOCS/tech-overview.txt b/DOCS/tech-overview.txt index ca4c648004..09bd98dca7 100644 --- a/DOCS/tech-overview.txt +++ b/DOCS/tech-overview.txt @@ -272,8 +272,9 @@ sub/: sd_ass.c's internal state. etc/: - The files input.conf and builtin.conf are actually integrated into the mpv - binary by the build system. They contain the default configs and keybindings. + The files input.conf, builtin.conf and menu.conf are actually integrated + into the mpv binary by the build system. They contain the default configs + and keybindings. Best practices and Concepts within mpv ====================================== diff --git a/etc/menu.conf b/etc/menu.conf new file mode 100644 index 0000000000..0568d3a9d5 --- /dev/null +++ b/etc/menu.conf @@ -0,0 +1,141 @@ +Pla&y cycle pause hidden=not pause and not idle_active disabled=idle_active +Pa&use cycle pause hidden=idle_active or pause +&Stop stop hidden=idle ~= true disabled=idle_active + +Op&en + &Clipboard loadfile ${clipboard/text}; show-text '+ ${clipboard/text}' + &History script-binding select/select-watch-history + &Watch later script-binding select/select-watch-later +&Playlist $playlist + +&Tracks $tracks +P&layback + &Display duration hidden=not p["current-tracks/video/image"] or p["current-tracks/audio"] + 1 second set image-display-duration 1 checked=image_display_duration == 1 + 2 seconds set image-display-duration 2 checked=image_display_duration == 2 + 5 seconds set image-display-duration 5 checked=image_display_duration == 5 + 10 seconds set image-display-duration 10 checked=image_display_duration == 10 + Infinite set image-display-duration inf checked=image_display_duration == math.huge + &Speed + 25% set speed 0.25 checked=speed == 0.25 + 50% set speed 0.50 checked=speed == 0.50 + 75% set speed 0.75 checked=speed == 0.75 + &100% set speed 1 checked=speed == 1 + 1&25% set speed 1.25 checked=speed == 1.25 + 1&50% set speed 1.50 checked=speed == 1.50 + 1&75% set speed 1.75 checked=speed == 1.75 + &200% set speed 2 checked=speed == 2 + &400% set speed 4 checked=speed == 4 + &800% set speed 8 checked=speed == 8 + + Set/clear &A-B loop points ab-loop + &Loop file cycle-values loop-file inf no checked=loop_file == "inf" + L&oop playlist cycle-values loop-playlist inf no checked=loop_playlist == "inf" + + Seek &10 seconds forward seek 10 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"] + Seek 1&0 seconds backward seek -10 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"] + Seek 10 &minutes forward seek 600 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"] + Seek 10 m&inutes backward seek -600 hidden=p["current-tracks/video/image"] and not p["current-tracks/audio"] + + &Next file playlist-next disabled=playlist_count < 2 + &Previous file playlist-prev disabled=playlist_count < 2 + + N&ext sub-playlist playlist-next-playlist disabled=playlist_count < 2 + P&revious sub-playlist playlist-prev-playlist disabled=playlist_count < 2 + + &Shuffle playlist-shuffle + &Unshuffle playlist-unshuffle +&Chapters $chapters +&Editions/Titles $editions + +&Video + &Track $video-tracks + + &Fill no-osd cycle-values panscan 0 1; no-osd set video-unscaled no; no-osd set video-zoom 0 checked=panscan == 1 + &Stretch no-osd cycle keepaspect checked=not keepaspect + &Unscaled no-osd cycle-values video-unscaled yes no; no-osd set video-zoom 0; no-osd set panscan 0 checked=video_unscaled + &Zoom + &50% set video-zoom -1 checked=video_zoom == -1 + &100% set video-zoom 0 checked=video_zoom == 0 + &200% set video-zoom 1 checked=video_zoom == 1 + &Aspect ratio + &16:9 set video-aspect-override 16:9 checked=math.abs(video_aspect_override - 1.7) < 0.1 + &4:3 set video-aspect-override 4:3 checked=math.abs(video_aspect_override - 1.3) < 0.1 + &2.35:1 set video-aspect-override 2.35:1 checked=video_aspect_override == 2.35 + &Default set video-aspect-override no checked=video_aspect_override == -2 + C&enter 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 + + Rotate &clockwise cycle-values video-rotate 90 180 270 0 + Rotate c&ounterclockwise cycle-values video-rotate 270 180 90 0 + + &Deband cycle deband checked=deband + D&einterlace cycle deinterlace checked=deinterlace_active + + &Screenshot screenshot disabled=not p["current-tracks/video"] + S&creenshot without subtitles screenshot video disabled=not p["current-tracks/video"] +&Audio + &Track $audio-tracks + &Devices $audio-devices + &Channels + &Auto set audio-channels auto-safe checked=audio_channels == "auto-safe" + &Stereo set audio-channels stereo checked=audio_channels == "stereo" + &Mono set audio-channels mono checked=audio_channels == "mono" + + Increase &volume add volume 2 + Decrease v&olume add volume -2 + &Mute cycle mute checked=mute + + Increase d&elay add audio-delay 0.1 + Decrease de&lay add audio-delay -0.1 +&Subtitle + &Track $sub-tracks + &Visible cycle sub-visibility checked=sub_visibility + + Increase &delay add sub-delay 0.1 + Decrease d&elay add sub-delay -0.1 + + Scale &up add sub-scale 0.1 + Scale d&own add sub-scale -0.1 + + &Lines script-binding select/select-subtitle-line disabled=not sid or p["current-tracks/sub/codec"] == "dvb_subtitle" or p["current-tracks/sub/codec"] == "dvd_subtitle" or p["current-tracks/sub/codec"] == "hdmv_pgs_subtitle" + &Secondary subtitle + &Track $secondary-sub-tracks + &Visible cycle secondary-sub-visibility checked=secondary_sub_visibility + + Increase &delay add secondary-sub-delay 0.1 + Decrease d&elay add secondary-sub-delay -0.1 + +&Window + &Fullscreen cycle fullscreen checked=fullscreen + &Border cycle border checked=border + &Title bar cycle title-bar checked=title_bar + &Always on top cycle ontop checked=ontop + &Window scale + 50% set window-scale 0.5 checked=math.abs(get("current-window-scale", 0) - 0.5) < 0.1 + 100% set window-scale 1 checked=math.abs(get("current-window-scale", 0) - 1) < 0.1 + 200% set window-scale 2 checked=math.abs(get("current-window-scale", 0) - 2) < 0.1 + 300% set window-scale 3 checked=math.abs(get("current-window-scale", 0) - 3) < 0.1 + &Screenshot window screenshot window +V&iew + &Playback statistics script-binding stats/display-page-1-toggle + &File information script-binding stats/display-page-5-toggle + &Key bindings script-binding stats/display-page-4-toggle + &Time OSD no-osd cycle-values osd-level 3 1 checked=osd_level == 3 + &Cycle OSC visibility script-binding osc/visibility +P&rofiles $profiles +T&ools + Copy &path set clipboard/text ${path} disabled=idle_active + 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" + Copy &title set clipboard/text ${media-title} disabled=idle_active + + &Hardware decoding cycle-values hwdec no auto checked=hwdec_current ~= "no" disabled=p["current-tracks/video/image"] ~= false + &Key bindings script-binding select/select-binding + &Properties script-binding select/show-properties + &Console script-binding commands/open + + &Edit config file script-binding select/edit-config-file + Edit key &bindings script-binding select/edit-input-conf + &Online documentation script-binding select/open-docs + +&Quit quit +&Quit watch later quit-watch-later hidden=save_position_on_quit diff --git a/etc/meson.build b/etc/meson.build index ac9eec0e6f..36251b08ca 100644 --- a/etc/meson.build +++ b/etc/meson.build @@ -9,7 +9,7 @@ foreach size: icons sources += icon endforeach -etc_files = ['input.conf', 'builtin.conf'] +etc_files = ['input.conf', 'builtin.conf', 'menu.conf'] foreach file: etc_files etc_file = custom_target(file, input: file,