osc: add options: chapters/playlist OSD, hover chapter format

Previously OSD was always displayed on {ch,pl}_{next,prev} left-click,
and seekbar-hover-chapter was always enabled and with fixed format.

Now it can be controlled with:
- chapters_osd, playlist_osd: yes/no (only affects left-click).
- chapter_fmt: lua string.format template, or "no" to disable.

Fixes #4675
This commit is contained in:
Avi Halachmi (:avih) 2021-11-25 10:19:34 +02:00 committed by avih
parent 1ab9119817
commit b8926dd484
2 changed files with 31 additions and 6 deletions

View File

@ -382,6 +382,20 @@ Configurable Options
Update chapter markers positions on duration changes, e.g. live streams.
The updates are unoptimized - consider disabling it on very low-end systems.
``chapters_osd``, ``playlist_osd``
Default: yes
Whether to display the chapters/playlist at the OSD when left-clicking the
next/previous OSC buttons, respectively.
``chapter_fmt``
Default: ``Chapter: %s``
Template for the chapter-name display when hovering the seekbar.
Use ``no`` to disable chapter display on hover. Otherwise it's a lua
``string.format`` template and ``%s`` is replaced with the actual name.
Script Commands
~~~~~~~~~~~~~~~

View File

@ -49,6 +49,9 @@ local user_opts = {
windowcontrols_alignment = "right", -- which side to show window controls on
greenandgrumpy = false, -- disable santa hat
livemarkers = true, -- update seekbar chapter markers on duration change
chapters_osd = true, -- whether to show chapters OSD on next/prev
playlist_osd = true, -- whether to show playlist OSD on next/prev
chapter_fmt = "Chapter: %s", -- chapter print format for seekbar-hover. "no" to disable
}
-- read options from config and command-line
@ -620,13 +623,13 @@ function render_elements(master_ass)
-- render iterations because the title may be rendered before the slider.
state.forced_title = nil
local se, ae = state.slider_element, elements[state.active_element]
if se and (ae == se or (not ae and mouse_hit(se))) then
if user_opts.chapter_fmt ~= "no" and se and (ae == se or (not ae and mouse_hit(se))) then
local dur = mp.get_property_number("duration", 0)
if dur > 0 then
local possec = get_slider_value(se) * dur / 100 -- of mouse pos
local ch = get_chapter(possec)
if ch and ch.title and ch.title ~= "" then
state.forced_title = "Chapter: " .. ch.title
state.forced_title = string.format(user_opts.chapter_fmt, ch.title)
end
end
end
@ -1806,7 +1809,9 @@ function osc_init()
ne.eventresponder["mbtn_left_up"] =
function ()
mp.commandv("playlist-prev", "weak")
show_message(get_playlist(), 3)
if user_opts.playlist_osd then
show_message(get_playlist(), 3)
end
end
ne.eventresponder["shift+mbtn_left_up"] =
function () show_message(get_playlist(), 3) end
@ -1821,7 +1826,9 @@ function osc_init()
ne.eventresponder["mbtn_left_up"] =
function ()
mp.commandv("playlist-next", "weak")
show_message(get_playlist(), 3)
if user_opts.playlist_osd then
show_message(get_playlist(), 3)
end
end
ne.eventresponder["shift+mbtn_left_up"] =
function () show_message(get_playlist(), 3) end
@ -1876,7 +1883,9 @@ function osc_init()
ne.eventresponder["mbtn_left_up"] =
function ()
mp.commandv("add", "chapter", -1)
show_message(get_chapterlist(), 3)
if user_opts.chapters_osd then
show_message(get_chapterlist(), 3)
end
end
ne.eventresponder["shift+mbtn_left_up"] =
function () show_message(get_chapterlist(), 3) end
@ -1891,7 +1900,9 @@ function osc_init()
ne.eventresponder["mbtn_left_up"] =
function ()
mp.commandv("add", "chapter", 1)
show_message(get_chapterlist(), 3)
if user_opts.chapters_osd then
show_message(get_chapterlist(), 3)
end
end
ne.eventresponder["shift+mbtn_left_up"] =
function () show_message(get_chapterlist(), 3) end