From e1e6eb8b6ee5d4697c33c0b463de5cba8c96c745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 10 Mar 2026 13:29:43 +0100 Subject: [PATCH] osc.lua: add `sub-margin` option --- DOCS/interface-changes/osc-margins.txt | 1 + DOCS/man/osc.rst | 12 ++++++++++ player/lua/osc.lua | 31 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/DOCS/interface-changes/osc-margins.txt b/DOCS/interface-changes/osc-margins.txt index 1f73b171d7..64f7a36038 100644 --- a/DOCS/interface-changes/osc-margins.txt +++ b/DOCS/interface-changes/osc-margins.txt @@ -1 +1,2 @@ add `osc-dynamic_margins` option +add `osc-sub-margin` option diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index e75b281b5a..bd32443f7c 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -408,6 +408,18 @@ Configurable Options applied when the OSC appears and removed when it hides. Without this option, margins are only applied when ``visibility`` is set to ``always``. +``sub_margins`` + Default: yes + + Whether to adjust ``--sub-margin-y`` so that subtitles do not overlap + with the OSC. The offset is derived from the bottom OSC margin and added + on top of the current ``--sub-margin-y`` value. Requires + ``dynamic_margins`` or ``visibility=always`` to take effect. + + With ``boxvideo`` enabled and ``--sub-use-margins=no``, subtitles are + already confined to the video area and this option has no additional + effect. + ``windowcontrols`` Default: auto (Show window controls if there is no window border) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index ffbf85248f..ace10c384f 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -49,6 +49,7 @@ local user_opts = { boxmaxchars = 80, -- title crop threshold for box layout boxvideo = false, -- apply osc_param.video_margins to video dynamic_margins = false, -- update margins dynamically with OSC visibility + sub_margins = true, -- adjust sub-margin-y to not overlap with OSC windowcontrols = "auto", -- whether to show window controls windowcontrols_alignment = "right", -- which side to show window controls on windowcontrols_title = "${media-title}", -- same as title but for windowcontrols @@ -541,6 +542,18 @@ local function cache_enabled() return state.cache_state and #state.cache_state["seekable-ranges"] > 0 end +local function set_margin_offset(prop, offset) + if offset > 0 then + if not state[prop] then + state[prop] = mp.get_property_number(prop) + end + mp.set_property_number(prop, state[prop] + offset) + elseif state[prop] then + mp.set_property_number(prop, state[prop]) + state[prop] = nil + end +end + local function reset_margins() if state.using_video_margins then for _, mopt in ipairs(margins_opts) do @@ -548,6 +561,7 @@ local function reset_margins() end state.using_video_margins = false end + set_margin_offset("sub-margin-y", 0) end local function update_margins() @@ -586,6 +600,23 @@ local function update_margins() reset_margins() end + local function get_margin(ent) + local margin = 0 + if user_opts[ent .. "_margins"] then + local align = mp.get_property(ent .. "-align-y") + if align == "top" and top_vis then + margin = margins.t + elseif align == "bottom" and bottom_vis then + margin = margins.b + end + end + if ent == "sub" and user_opts.boxvideo and mp.get_property_bool("sub-use-margins") then + margin = 0 + end + return margin * osc_param.playresy + end + set_margin_offset("sub-margin-y", get_margin("sub")) + mp.set_property_native("user-data/osc/margins", margins) end