Skip to content

Commit a4ba37f

Browse files
committed
osc.lua: add sub-margin option
1 parent 8adf359 commit a4ba37f

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add `osc-dynamic_margins` option
2+
add `osc-sub-margin` option

DOCS/man/osc.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,18 @@ Configurable Options
408408
applied when the OSC appears and removed when it hides. Without this
409409
option, margins are only applied when ``visibility`` is set to ``always``.
410410

411+
``sub_margins``
412+
Default: yes
413+
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.
418+
419+
With ``boxvideo`` enabled and ``--sub-use-margins=no``, subtitles are
420+
already confined to the video area and this option has no additional
421+
effect.
422+
411423
``windowcontrols``
412424
Default: auto (Show window controls if there is no window border)
413425

player/lua/osc.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ local user_opts = {
4949
boxmaxchars = 80, -- title crop threshold for box layout
5050
boxvideo = false, -- apply osc_param.video_margins to video
5151
dynamic_margins = false, -- update margins dynamically with OSC visibility
52+
sub_margins = true, -- adjust sub-margin-y to not overlap with OSC
5253
windowcontrols = "auto", -- whether to show window controls
5354
windowcontrols_alignment = "right", -- which side to show window controls on
5455
windowcontrols_title = "${media-title}", -- same as title but for windowcontrols
@@ -184,6 +185,7 @@ local margins_opts = {
184185
{"t", "video-margin-ratio-top"},
185186
{"b", "video-margin-ratio-bottom"},
186187
}
188+
local sub_margin_opt = "file-local-options/sub-margin-y"
187189

188190
local tick_delay = 1 / 60
189191
local audio_track_count = 0
@@ -541,13 +543,26 @@ local function cache_enabled()
541543
return state.cache_state and #state.cache_state["seekable-ranges"] > 0
542544
end
543545

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+
544558
local function reset_margins()
545559
if state.using_video_margins then
546560
for _, mopt in ipairs(margins_opts) do
547561
mp.set_property_number(mopt[2], 0.0)
548562
end
549563
state.using_video_margins = false
550564
end
565+
set_margin_offset(sub_margin_opt, 0)
551566
end
552567

553568
local function update_margins()
@@ -586,6 +601,23 @@ local function update_margins()
586601
reset_margins()
587602
end
588603

604+
local function get_margin(ent)
605+
local margin = 0
606+
if user_opts[ent .. "_margins"] then
607+
local align = mp.get_property(ent .. "-align-y")
608+
if align == "top" and top_vis then
609+
margin = margins.t
610+
elseif align == "bottom" and bottom_vis then
611+
margin = margins.b
612+
end
613+
end
614+
if ent == "sub" and user_opts.boxvideo and mp.get_property_bool("sub-use-margins") then
615+
margin = 0
616+
end
617+
return margin * osc_param.playresy
618+
end
619+
set_margin_offset("sub-margin-y", get_margin("sub"))
620+
589621
mp.set_property_native("user-data/osc/margins", margins)
590622
end
591623

0 commit comments

Comments
 (0)