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.
This commit is contained in:
Dudemanguy committed 2025-01-28 15:47:47 +00:00
1 parent fd4aa9b533
commit 8d665ac2df
3 files changed
+25 -6

No files matched your search

+18 -6
View File
@@ -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