diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index c4e9e18f3e01c..dec15c6942449 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3134,6 +3134,16 @@ Subtitles Default: 34 +``--sub-margin-y-offset=`` + Additional vertical offset added to the subtitle margin, in scaled pixels. + This is added on top of ``--sub-margin-y``. + + This is intended for dynamic margin adjustments at runtime (e.g. by + scripts like the OSC to avoid subtitle/UI overlap). For persistent + settings, use ``--sub-margin-y`` instead. + + Default: 0 + ``--sub-align-x=`` Control to which corner of the screen text subtitles should be aligned to (default: ``center``). @@ -4816,6 +4826,16 @@ OSD Default: 16 +``--osd-margin-y-offset=`` + Additional vertical offset added to the OSD margin, in scaled pixels. + This is added on top of ``--osd-margin-y``. + + This is intended for dynamic margin adjustments at runtime (e.g. by + scripts like the OSC to avoid OSD/UI overlap). For persistent settings, + use ``--osd-margin-y`` instead. + + Default: 0 + ``--osd-align-x=`` Control to which corner of the screen OSD should be aligned to (default: ``left``). diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index 5981416761916..cdcd3c27293d5 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -409,12 +409,11 @@ Configurable Options option, margins are only applied when ``visibility`` is set to ``always``. ``sub_margins`` - Default: yes + Default: no - 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. + Whether to adjust the subtitle margin so that subtitles do not overlap + with the OSC. Requires ``dynamic_margins`` or ``visibility=always`` to + take effect. Uses ``--sub-margin-y-offset`` to apply the adjustment. With ``boxvideo`` enabled and ``--sub-use-margins=no``, subtitles are already confined to the video area and this option has no additional @@ -423,11 +422,9 @@ Configurable Options ``osd_margins`` Default: yes - Whether to adjust ``--osd-margin-y`` so that OSD text does not overlap - with the OSC. The offset is derived from the top OSC margin (including - window controls when present) and added on top of the current - ``--osd-margin-y`` value. Requires ``dynamic_margins`` or - ``visibility=always`` to take effect. + Whether to adjust the OSD margin so that OSD text does not overlap + with the OSC. Requires ``dynamic_margins`` or ``visibility=always`` to + take effect. Uses ``--osd-margin-y-offset`` to apply the adjustment. ``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 50e043f7c958c..b5272007232b9 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -49,7 +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 + sub_margins = false, -- adjust sub-margin-y to not overlap with OSC osd_margins = true, -- adjust osd-margin-y to not overlap with OSC windowcontrols = "auto", -- whether to show window controls windowcontrols_alignment = "right", -- which side to show window controls on @@ -543,18 +543,6 @@ 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 @@ -562,8 +550,8 @@ local function reset_margins() end state.using_video_margins = false end - set_margin_offset("sub-margin-y", 0) - set_margin_offset("osd-margin-y", 0) + mp.set_property_number("sub-margin-y-offset", 0) + mp.set_property_number("osd-margin-y-offset", 0) end local function update_margins() @@ -617,8 +605,8 @@ local function update_margins() end return margin * osc_param.playresy end - set_margin_offset("sub-margin-y", get_margin("sub")) - set_margin_offset("osd-margin-y", get_margin("osd")) + mp.set_property_number("sub-margin-y-offset", get_margin("sub")) + mp.set_property_number("osd-margin-y-offset", get_margin("osd")) mp.set_property_native("user-data/osc/margins", margins) end diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 7e81bb266dd45..b8e9e5aeabcc9 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -64,7 +64,7 @@ void mp_ass_set_style(ASS_Style *style, double res_y, style->Spacing = opts->spacing * scale; style->MarginL = opts->margin_x * scale; style->MarginR = style->MarginL; - style->MarginV = opts->margin_y * scale; + style->MarginV = (opts->margin_y + opts->margin_y_offset) * scale; style->ScaleX = 1.; style->ScaleY = 1.; style->Alignment = 1 + (opts->align_x + 1) + (opts->align_y + 2) % 3 * 4; diff --git a/sub/osd.c b/sub/osd.c index 278889739692e..ef646b6775f42 100644 --- a/sub/osd.c +++ b/sub/osd.c @@ -60,6 +60,7 @@ static const m_option_t style_opts[] = { {"spacing", OPT_FLOAT(spacing), M_RANGE(-10, 10)}, {"margin-x", OPT_INT(margin_x), M_RANGE(0, INT_MAX)}, {"margin-y", OPT_INT(margin_y), M_RANGE(0, INT_MAX)}, + {"margin-y-offset", OPT_INT(margin_y_offset)}, {"align-x", OPT_CHOICE(align_x, {"left", -1}, {"center", 0}, {"right", +1})}, {"align-y", OPT_CHOICE(align_y, diff --git a/sub/osd.h b/sub/osd.h index 076187573ad80..44cf2edc1a3db 100644 --- a/sub/osd.h +++ b/sub/osd.h @@ -155,6 +155,7 @@ struct osd_style_opts { float spacing; int margin_x; int margin_y; + int margin_y_offset; int align_x; int align_y; float blur;