From 6bf1a830574e84012c44920584fd72f7ad9a55af Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 22 Dec 2019 12:38:41 +0100 Subject: osc: cleanup boxvideo margin handling Make sure it gets properly reinitialized when needed. This is especially useful now that the OSC reacts to runtime option changes, which can change the layout too. This may call set_property_number() on the margin properties more often now, but since redundant option changes are ignored now, this shouldn't have any too bad effects. --- player/lua/osc.lua | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 8c2d93b635..8196574372 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -1677,6 +1677,8 @@ function osc_init() -- stop seeking with the slider to prevent skipping files state.active_element = nil + osc_param.video_margins = {l = 0, r = 0, t = 0, b = 0} + elements = {} -- some often needed stuff @@ -2034,21 +2036,37 @@ function osc_init() --do something with the elements prepare_elements() + update_margins() +end + +function reset_margins() + if state.using_video_margins then + for _, opt in ipairs(margins_opts) do + mp.set_property_number(opt[2], 0.0) + end + state.using_video_margins = false + end +end + +function update_margins() + local margins = osc_param.video_margins + if user_opts.boxvideo then -- check whether any margin option has a non-default value local margins_used = false - for _, opt in ipairs(margins_opts) do - if mp.get_property_number(opt[2], 0.0) ~= 0.0 then - margins_used = true + if not state.using_video_margins then + for _, opt in ipairs(margins_opts) do + if mp.get_property_number(opt[2], 0.0) ~= 0.0 then + margins_used = true + end end end if not margins_used then - local margins = osc_param.video_margins for _, opt in ipairs(margins_opts) do local v = margins[opt[1]] - if v ~= 0 then + if (v ~= 0) or state.using_video_margins then mp.set_property_number(opt[2], v) state.using_video_margins = true end @@ -2058,21 +2076,6 @@ function osc_init() reset_margins() end - update_margins() -end - -function reset_margins() - if state.using_video_margins then - for _, opt in ipairs(margins_opts) do - mp.set_property_number(opt[2], 0.0) - end - state.using_video_margins = false - end -end - -function update_margins() - local margins = osc_param.video_margins - -- Don't report margins if it's visible only temporarily. At least for -- console.lua this makes no sense. if (not state.osc_visible) or (get_hidetimeout() >= 0) then -- cgit v1.2.3