Skip to content

Commit 97804a9

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 24500c5 commit 97804a9

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

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)},
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)