From c0c3b4b56bcfaa552795a5334203571c72b37ad2 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Wed, 8 Jan 2025 11:56:13 +0100 Subject: [PATCH 1/4] select.lua: add a miscellaneous menu --- DOCS/man/mpv.rst | 3 +++ etc/input.conf | 1 + player/lua/select.lua | 57 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/DOCS/man/mpv.rst b/DOCS/man/mpv.rst index 7c67cf0d96d18..bf0d8e0d73ebb 100644 --- a/DOCS/man/mpv.rst +++ b/DOCS/man/mpv.rst @@ -339,6 +339,9 @@ g-b g-r Show the values of all properties. +MENU + Show a menu with miscellaneous entries. + (The following keys are valid if you have a keyboard with multimedia keys.) PAUSE diff --git a/etc/input.conf b/etc/input.conf index 2faa88c233b28..88f20e266bddf 100644 --- a/etc/input.conf +++ b/etc/input.conf @@ -190,6 +190,7 @@ #g-w script-binding select/select-watch-later #g-b script-binding select/select-binding #g-r script-binding select/show-properties +#MENU script-binding select/menu #Alt+KP1 add video-rotate -1 # rotate video counterclockwise by 1 degree #Alt+KP5 set video-rotate 0 # reset rotation diff --git a/player/lua/select.lua b/player/lua/select.lua index 7f20602aff098..d5767d5164aea 100644 --- a/player/lua/select.lua +++ b/player/lua/select.lua @@ -491,3 +491,60 @@ mp.add_key_binding(nil, "show-properties", function () end, }) end) + +mp.add_key_binding(nil, "menu", function () + local sub_track_count = 0 + local audio_track_count = 0 + local video_track_count = 0 + local text_sub_selected = false + + local image_sub_codecs = {["dvd_subtitle"] = true, ["hdmv_pgs_subtitle"] = true} + + for _, track in pairs(mp.get_property_native("track-list")) do + if track.type == "sub" then + sub_track_count = sub_track_count + 1 + if track["main-selection"] == 0 and not image_sub_codecs[track.codec] then + text_sub_selected = true + end + elseif track.type == "audio" then + audio_track_count = audio_track_count + 1 + elseif track.type == "video" then + video_track_count = video_track_count + 1 + end + end + + local menu = { + {"Subtitles", "script-binding select/select-sid", sub_track_count > 0}, + {"Secondary subtitles", "script-binding select/select-secondary-sid", sub_track_count > 1}, + {"Subtitle lines", "script-binding select/select-subtitle-line", text_sub_selected}, + {"Audio tracks", "script-binding select/select-aid", audio_track_count > 1}, + {"Video tracks", "script-binding select/select-vid", video_track_count > 1}, + {"Playlist", "script-binding select/select-playlist", + mp.get_property_native("playlist-count") > 1}, + {"Chapters", "script-binding select/select-chapter", mp.get_property("chapter")}, + {"Editions/Titles", "script-binding select/select-edition", + mp.get_property_native("edition-list/count", 0) > 1}, + {"Audio devices", "script-binding select/select-audio-device", audio_track_count > 0}, + {"Key bindings", "script-binding select/select-binding", true}, + -- {"History", "script-binding select/select-watch-history", true}, + {"Watch later", "script-binding select/select-watch-later", true}, + } + + local labels = {} + local commands = {} + + for _, entry in ipairs(menu) do + if entry[3] then + labels[#labels + 1] = entry[1] + commands[#commands + 1] = entry[2] + end + end + + input.select({ + prompt = "", + items = labels, + submit = function (i) + mp.command(commands[i]) + end, + }) +end) From 2ac1ab11dfcd10b0cf9458d523c222ea74e68dea Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 28 Dec 2024 22:37:19 +0100 Subject: [PATCH 2/4] TOOLS/mpv-osd-symbols.sfdir: document how to add icons --- TOOLS/mpv-osd-symbols.sfdir/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 TOOLS/mpv-osd-symbols.sfdir/README.md diff --git a/TOOLS/mpv-osd-symbols.sfdir/README.md b/TOOLS/mpv-osd-symbols.sfdir/README.md new file mode 100644 index 0000000000000..2186070403b46 --- /dev/null +++ b/TOOLS/mpv-osd-symbols.sfdir/README.md @@ -0,0 +1,16 @@ +Steps to add new icons: + +- Install [FontForge](https://fontforge.org/en-US/) +- Load a freely licensed font and mpv's glyph directory, for example: + `fontforge Symbola.ttf TOOLS/mpv-osd-symbols.sfdir` +- Check the Unicode hex value of the desired character (`g-a` in vim) +- Scroll until that value in the font window and click it +- Copy the selected glyph (Ctrl+c) +- Focus the window with TOOLS/mpv-osd-symbols.sfdir +- Click an unused character slot +- Paste the glyph (Ctrl+v) +- Save (Ctrl+s) +- Edit the numbers in the glyph file to match the size and position of adjacent + icons (TODO: find a better way) +- Run `sh TOOLS/gen-osd-font.sh` +- Add the icon to osc.lua following the instructions there From 842bb483106e238bbde829903e251abea1aebd96 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 28 Dec 2024 22:28:03 +0100 Subject: [PATCH 3/4] TOOLS/mpv-osd-symbols.sfdir: add a menu icon Taken from the last freely licensed version of Symbola and manually adjusted the number in the glyph file to match the adjacent arrows. Saving sfdir with fontforge also automatically removed the O flag from 2 existing glyphs. According to https://fontforge.org/docs/techref/sfdformat.html "O" just meant "the character was open when last saved", so it doesn't change anything visible. --- TOOLS/mpv-osd-symbols.sfdir/font.props | 6 +++--- TOOLS/mpv-osd-symbols.sfdir/uniE00D.glyph | 2 +- TOOLS/mpv-osd-symbols.sfdir/uniE102.glyph | 25 ++++++++++++++++++++++ TOOLS/mpv-osd-symbols.sfdir/uniE10A.glyph | 2 +- sub/osd_font.otf | Bin 4504 -> 4616 bytes 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 TOOLS/mpv-osd-symbols.sfdir/uniE102.glyph diff --git a/TOOLS/mpv-osd-symbols.sfdir/font.props b/TOOLS/mpv-osd-symbols.sfdir/font.props index 8198d27e62e80..ae2cec146e990 100644 --- a/TOOLS/mpv-osd-symbols.sfdir/font.props +++ b/TOOLS/mpv-osd-symbols.sfdir/font.props @@ -1,4 +1,4 @@ -SplineFontDB: 3.0 +SplineFontDB: 3.2 FontName: mpv-osd-symbols-Regular FullName: mpv-osd-symbols Regular FamilyName: mpv-osd-symbols @@ -22,7 +22,7 @@ OS2Version: 3 OS2_WeightWidthSlopeOnly: 0 OS2_UseTypoMetrics: 0 CreationTime: 1408646554 -ModificationTime: 1576096543 +ModificationTime: 1735420479 PfmFamily: 81 TTFWeight: 400 TTFWidth: 5 @@ -63,7 +63,7 @@ NameList: AGL For New Fonts DisplaySize: -72 AntiAlias: 1 FitToEm: 0 -WinInfo: 57600 8 2 +WinInfo: 57540 14 11 BeginPrivate: 8 BlueValues 31 [-10 0 640 650 720 730 800 810] BlueScale 5 0.037 diff --git a/TOOLS/mpv-osd-symbols.sfdir/uniE00D.glyph b/TOOLS/mpv-osd-symbols.sfdir/uniE00D.glyph index 237825c17feed..1e2a3377d0b21 100644 --- a/TOOLS/mpv-osd-symbols.sfdir/uniE00D.glyph +++ b/TOOLS/mpv-osd-symbols.sfdir/uniE00D.glyph @@ -1,7 +1,7 @@ StartChar: uniE00D Encoding: 57357 57357 34 Width: 880 -Flags: HWO +Flags: HW HStem: 780 20G<200 200> VStem: 200 375<400 400 400 800> LayerCount: 2 diff --git a/TOOLS/mpv-osd-symbols.sfdir/uniE102.glyph b/TOOLS/mpv-osd-symbols.sfdir/uniE102.glyph new file mode 100644 index 0000000000000..d3ba651acfec7 --- /dev/null +++ b/TOOLS/mpv-osd-symbols.sfdir/uniE102.glyph @@ -0,0 +1,25 @@ +StartChar: uniE102 +Encoding: 57602 57602 35 +Width: 880 +VWidth: 880 +Flags: HW +LayerCount: 2 +Fore +SplineSet +880 640 m 1 + 0 640 l 1 + 0 800 l 1 + 880 800 l 1 + 880 640 l 1 +880 320 m 1 + 0 320 l 1 + 0 480 l 1 + 880 480 l 1 + 880 320 l 1 +880 0 m 1 + 0 0 l 1 + 0 160 l 1 + 880 160 l 1 + 880 0 l 1 +EndSplineSet +EndChar diff --git a/TOOLS/mpv-osd-symbols.sfdir/uniE10A.glyph b/TOOLS/mpv-osd-symbols.sfdir/uniE10A.glyph index 029bf74d015fb..6ebbfc58b8c48 100644 --- a/TOOLS/mpv-osd-symbols.sfdir/uniE10A.glyph +++ b/TOOLS/mpv-osd-symbols.sfdir/uniE10A.glyph @@ -2,7 +2,7 @@ StartChar: uniE10A Encoding: 57610 57610 23 Width: 1977 GlyphClass: 2 -Flags: HMWO +Flags: HMW HStem: 242 248<2 155 2 156> LayerCount: 2 Fore diff --git a/sub/osd_font.ot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?Y*M%;rK}Gvx$@r7u+#=!(0QV_%>GFUc2Mr%MhjA|uBNbrK-E`=j?eGd%_;1KS ze*2GYhW#=D?`{VN< zGrKOVy%bgQ*{0$IRj$^d!alWXX$u5c9}SraCADNP(bx-mm9?769Qas^xnbuO{u#d^ zB!s8Jve+YD6Ca8zbcEiaujm3To4QP+xf|wg{ASo)HSRGv*Bc-1+A7=Qq@e=21kjm7(nZb@LVflaNfl^ap zdW|k@P8r_3DA#GLCe|uKBxiH@Vt?k*8 Date: Wed, 8 Jan 2025 11:56:24 +0100 Subject: [PATCH 4/4] osc.lua: add an icon for the miscellaneous menu Add the generic menu to bar layouts to provide discoverability for the select menus to users who don't realize you can right click OSC buttons. There's no space to add it in box layout. --- DOCS/man/osc.rst | 13 ++++++++++++- player/lua/osc.lua | 25 ++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index 66f0b78d4bc15..f1370782a3baf 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -21,7 +21,7 @@ The Interface :: +---------+----------+------------------------------------------+----------+ - | pl prev | pl next | title | cache | + | pl prev | menu | pl next | title cache | +------+--+---+------+---------+-----------+------+-------+-----+-----+----+ | play | skip | skip | time | seekbar | time | audio | sub | vol | fs | | | back | frwd | elapsed | | left | | | | | @@ -36,6 +36,11 @@ pl prev right-click open the playlist selector ============= ================================================ +menu + ============= ================================================ + left-click open the menu + ============= ================================================ + pl next ============= ================================================ left-click play next file in playlist @@ -514,6 +519,12 @@ clicked. ``mbtn_mid`` commands are also triggered with ``shift+mbtn_left``. ``playlist_prev_mbtn_right_command=script-binding select/select-playlist; script-message-to osc osc-hide`` +``menu_mbtn_left_command=script-binding select/menu; script-message-to osc osc-hide`` + +``menu_mbtn_mid_command=`` + +``menu_mbtn_right_command=`` + ``playlist_next_mbtn_left_command=playlist-next; show-text ${playlist} 3000`` ``playlist_next_mbtn_mid_command=show-text ${playlist} 3000`` diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 0e023aef7685d..f1997550dd8c5 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -75,6 +75,10 @@ local user_opts = { playlist_prev_mbtn_mid_command = "show-text ${playlist} 3000", playlist_prev_mbtn_right_command = "script-binding select/select-playlist; script-message-to osc osc-hide", + menu_mbtn_left_command = "script-binding select/menu; script-message-to osc osc-hide", + menu_mbtn_mid_command = "", + menu_mbtn_right_command = "", + playlist_next_mbtn_left_command = "playlist-next", playlist_next_mbtn_mid_command = "show-text ${playlist} 3000", playlist_next_mbtn_right_command = "script-binding select/select-playlist; script-message-to osc osc-hide", @@ -135,6 +139,7 @@ local icon_font = "mpv-osd-symbols" -- print(output) local icons = { prev = "\238\132\144", -- E110 + menu = "\238\132\130", -- E102 next = "\238\132\129", -- E101 pause = "\238\128\130", -- E002 play = "\238\132\129", -- E101 @@ -1603,13 +1608,20 @@ local function bar_layout(direction, slim) lo.alpha[1] = user_opts.boxalpha - -- Playlist prev/next + -- Playlist prev geo = { x = osc_geo.x + padX, y = line1, an = 4, w = 18, h = 18 - padY } lo = add_layout("playlist_prev") lo.geometry = geo lo.style = osc_styles.topButtonsBar + -- Menu + geo = { x = geo.x + geo.w + padX, y = geo.y, an = geo.an, w = geo.w, h = geo.h } + lo = add_layout("menu") + lo.geometry = geo + lo.style = osc_styles.topButtonsBar + + -- Playlist next geo = { x = geo.x + geo.w + padX, y = geo.y, an = geo.an, w = geo.w, h = geo.h } lo = add_layout("playlist_next") lo.geometry = geo @@ -1848,16 +1860,19 @@ local function osc_init() end bind_mouse_buttons("title") - -- playlist buttons - - -- prev + -- playlist prev ne = new_element("playlist_prev", "button") ne.content = icons.prev ne.enabled = (pl_pos > 1) or (loop ~= "no") bind_mouse_buttons("playlist_prev") - --next + -- menu + ne = new_element("menu", "button") + ne.content = icons.menu + bind_mouse_buttons("menu") + + -- playlist next ne = new_element("playlist_next", "button") ne.content = icons.next