From 8d665ac2dfc9ff8ee1749ef3be59dd5e10aad537 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sat, 25 Jan 2025 11:56:11 -0600 Subject: [PATCH] osc.lua: add visibility_modes script opt This allows users to choose what visibility modes they want to cycle through when calling the osc-visibilty cycle script binding. --- .../interface-changes/osc-script-messages.txt | 1 + DOCS/man/osc.rst | 6 +++++ player/lua/osc.lua | 24 ++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/DOCS/interface-changes/osc-script-messages.txt b/DOCS/interface-changes/osc-script-messages.txt index bfa9df1073..b7ea60ff02 100644 --- a/DOCS/interface-changes/osc-script-messages.txt +++ b/DOCS/interface-changes/osc-script-messages.txt @@ -2,3 +2,4 @@ deprecate `osc-message` script message in favor of `show-text` command deprecate `osc-chapterlist` script message in favor of `show-text ${chapter-list}` deprecate `osc-playlist` script message in favor of `show-text ${playlist}` deprecate `osc-tracklist` script message in favor of `show-text ${track-list}` +add `visibility_modes` script-opt to osc diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index 227cdfe355..2a0c14fe29 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -358,6 +358,12 @@ Configurable Options Also supports ``never`` and ``always`` +``visibility_modes`` + Default: never_auto_always + + The list of visibility modes to cycle through when calling the + osc-visibility cycle script message. Modes are separated by ``_``. + ``boxmaxchars`` Default: 80 diff --git a/player/lua/osc.lua b/player/lua/osc.lua index c618f0ce31..c515baf146 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -44,6 +44,7 @@ local user_opts = { timems = false, -- display timecodes with milliseconds? tcspace = 100, -- timecode spacing (compensate font size estimation) visibility = "auto", -- only used at init to set visibility_mode(...) + visibility_modes = "never_auto_always", -- visibility modes to cycle through boxmaxchars = 80, -- title crop threshold for box layout boxvideo = false, -- apply osc_param.video_margins to video windowcontrols = "auto", -- whether to show window controls @@ -255,6 +256,7 @@ local state = { maximized = false, osd = mp.create_osd_overlay("ass-events"), chapter_list = {}, -- sorted by time + visibility_modes = {}, -- visibility_modes to cycle through osc_message_warned = false, -- deprecation warnings osc_chapterlist_warned = false, osc_playlist_warned = false, @@ -2774,12 +2776,14 @@ end -- the modes only affect internal variables and not stored on its own. local function visibility_mode(mode, no_osd) if mode == "cycle" then - if not state.enabled then - mode = "auto" - elseif user_opts.visibility ~= "always" then - mode = "always" - else - mode = "never" + for i, allowed_mode in ipairs(state.visibility_modes) do + if i == #state.visibility_modes then + mode = state.visibility_modes[1] + break + elseif user_opts.visibility == allowed_mode then + mode = state.visibility_modes[i + 1] + break + end end end @@ -2907,6 +2911,14 @@ local function validate_user_opts() msg.warn("'" .. color .. "' is not a valid color") end end + + for str in string.gmatch(user_opts.visibility_modes, "([^_]+)") do + if str ~= "auto" and str ~= "always" and str ~= "never" then + msg.warn("Ignoring unknown visibility mode '" .. str .."' in list") + else + table.insert(state.visibility_modes, str) + end + end end -- read options from config and command-line