Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

osc.lua: use private options to control SUB/OSD offset #17555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking "Sign up for GitHub", you agree to our terms of service and privacy statement. We'll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
kasper93 merged 2 commits into mpv-player:master from kasper93:fix-margins
Mar 13, 2026
Merged

osc.lua: use private options to control SUB/OSD offset #17555

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions DOCS/man/options.rst
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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``).
Expand Down Expand Up @@ -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``).
Expand Down
17 changes: 7 additions & 10 deletions DOCS/man/osc.rst
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
22 changes: 5 additions & 17 deletions player/lua/osc.lua
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -543,27 +543,15 @@ 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
mp.set_property_number(mopt[2], 0.0)
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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sub/ass_mp.c
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sub/osd.c
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions sub/osd.h
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading