Skip to content

Commit 63c6921

Browse files
committed
osc.lua: use private options to control SUB/OSD offset
There is concern that with certain user options or script the value of `{sub,osd}-margin-y` value may be persisted or overwrite user option when it's changed while OSD is visible and offset is applied. Fix this by using dedicated private option only for OSC use.
1 parent 400acc5 commit 63c6921

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

DOCS/man/osc.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,9 @@ Configurable Options
411411
``sub_margins``
412412
Default: yes
413413

414-
Whether to adjust ``--sub-margin-y`` so that subtitles do not overlap
415-
with the OSC. The offset is derived from the bottom OSC margin and added
416-
on top of the current ``--sub-margin-y`` value. Requires
417-
``dynamic_margins`` or ``visibility=always`` to take effect.
414+
Whether to adjust the subtitle margin so that subtitles do not overlap
415+
with the OSC. Requires ``dynamic_margins`` or ``visibility=always`` to
416+
take effect.
418417

419418
With ``boxvideo`` enabled and ``--sub-use-margins=no``, subtitles are
420419
already confined to the video area and this option has no additional
@@ -423,11 +422,9 @@ Configurable Options
423422
``osd_margins``
424423
Default: yes
425424

426-
Whether to adjust ``--osd-margin-y`` so that OSD text does not overlap
427-
with the OSC. The offset is derived from the top OSC margin (including
428-
window controls when present) and added on top of the current
429-
``--osd-margin-y`` value. Requires ``dynamic_margins`` or
430-
``visibility=always`` to take effect.
425+
Whether to adjust the OSD margin so that OSD text does not overlap
426+
with the OSC. Requires ``dynamic_margins`` or ``visibility=always`` to
427+
take effect.
431428

432429
``windowcontrols``
433430
Default: auto (Show window controls if there is no window border)

player/lua/osc.lua

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -543,27 +543,15 @@ local function cache_enabled()
543543
return state.cache_state and #state.cache_state["seekable-ranges"] > 0
544544
end
545545

546-
local function set_margin_offset(prop, offset)
547-
if offset > 0 then
548-
if not state[prop] then
549-
state[prop] = mp.get_property_number(prop)
550-
end
551-
mp.set_property_number(prop, state[prop] + offset)
552-
elseif state[prop] then
553-
mp.set_property_number(prop, state[prop])
554-
state[prop] = nil
555-
end
556-
end
557-
558546
local function reset_margins()
559547
if state.using_video_margins then
560548
for _, mopt in ipairs(margins_opts) do
561549
mp.set_property_number(mopt[2], 0.0)
562550
end
563551
state.using_video_margins = false
564552
end
565-
set_margin_offset("sub-margin-y", 0)
566-
set_margin_offset("osd-margin-y", 0)
553+
mp.set_property_number("sub-margin-y-offset", 0)
554+
mp.set_property_number("osd-margin-y-offset", 0)
567555
end
568556

569557
local function update_margins()
@@ -617,8 +605,8 @@ local function update_margins()
617605
end
618606
return margin * osc_param.playresy
619607
end
620-
set_margin_offset("sub-margin-y", get_margin("sub"))
621-
set_margin_offset("osd-margin-y", get_margin("osd"))
608+
mp.set_property_number("sub-margin-y-offset", get_margin("sub"))
609+
mp.set_property_number("osd-margin-y-offset", get_margin("osd"))
622610

623611
mp.set_property_native("user-data/osc/margins", margins)
624612
end

sub/ass_mp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void mp_ass_set_style(ASS_Style *style, double res_y,
6464
style->Spacing = opts->spacing * scale;
6565
style->MarginL = opts->margin_x * scale;
6666
style->MarginR = style->MarginL;
67-
style->MarginV = opts->margin_y * scale;
67+
style->MarginV = (opts->margin_y + opts->margin_y_offset) * scale;
6868
style->ScaleX = 1.;
6969
style->ScaleY = 1.;
7070
style->Alignment = 1 + (opts->align_x + 1) + (opts->align_y + 2) % 3 * 4;

sub/osd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static const m_option_t style_opts[] = {
6060
{"spacing", OPT_FLOAT(spacing), M_RANGE(-10, 10)},
6161
{"margin-x", OPT_INT(margin_x), M_RANGE(0, INT_MAX)},
6262
{"margin-y", OPT_INT(margin_y), M_RANGE(0, INT_MAX)},
63+
{"margin-y-offset", OPT_INT(margin_y_offset), .flags = M_OPT_PRIVATE},
6364
{"align-x", OPT_CHOICE(align_x,
6465
{"left", -1}, {"center", 0}, {"right", +1})},
6566
{"align-y", OPT_CHOICE(align_y,

sub/osd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct osd_style_opts {
155155
float spacing;
156156
int margin_x;
157157
int margin_y;
158+
int margin_y_offset;
158159
int align_x;
159160
int align_y;
160161
float blur;

0 commit comments

Comments
 (0)