From 4787eb594a879619b9acd266bac015bfd0032c50 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 18 Dec 2019 09:03:32 +0100 Subject: osc: make margins available This is for console.lua (see next commit). The idea is that console.lua can adjust its offset to the bottom of the window by the height of the OSC. If the OSC is not set to permanently visible, export no margins, because it would look weird to move the console depending on the mouse movement. --- player/lua/osc.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 9047db45bb..872eead52d 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -2058,6 +2058,7 @@ function osc_init() reset_margins() end + update_margins() end function reset_margins() @@ -2069,6 +2070,24 @@ function reset_margins() 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 (user_opts.hidetimeout >= 0) then + margins = {l = 0, r = 0, t = 0, b = 0} + end + + utils.shared_script_property_set("osc-margins", + string.format("%f,%f,%f,%f", margins.l, margins.r, margins.t, margins.b)) +end + +function shutdown() + reset_margins() + utils.shared_script_property_set("osc-margins", nil) +end + -- -- Other important stuff -- @@ -2110,6 +2129,7 @@ end function osc_visible(visible) state.osc_visible = visible control_timer() + update_margins() end function pause_state(name, enabled) @@ -2478,7 +2498,7 @@ end validate_user_opts() -mp.register_event("shutdown", reset_margins) +mp.register_event("shutdown", shutdown) mp.register_event("start-file", request_init) mp.register_event("tracks-changed", request_init) mp.observe_property("playlist", nil, request_init) @@ -2609,6 +2629,8 @@ function visibility_mode(mode, no_osd) if not no_osd and tonumber(mp.get_property("osd-level")) >= 1 then mp.osd_message("OSC visibility: " .. mode) end + + update_margins() end visibility_mode(user_opts.visibility, true) -- cgit v1.2.3