Skip to content

feat: add sub_margins, osd_margins and dynamic_margins options#523

Merged
Samillion merged 5 commits intomainfrom
feat_sub_osd_margins
Mar 11, 2026
Merged

feat: add sub_margins, osd_margins and dynamic_margins options#523
Samillion merged 5 commits intomainfrom
feat_sub_osd_margins

Conversation

@Samillion
Copy link
Owner

Changes:

  • Add sub_margins option: Raises subtitles above OSC if it's visible, then restores it when OSC is hidden
  • Add osd_margins option: Adjusts displayed OSD position to not overlap with OSC/WC when it is visible
  • Add dynamic_margins option: Allows subtitles and OSD to be adjusted when visibility mode is set to auto (default)
  • Reset margins and subtitle position on shutdown (mpv exit)
  • Deprecate raise_subtitles
    • Also warn user if raise_subtitles was used that both raise_subtitles and raise_subtitles_amount are deprecated, to use sub_margins and dynamic_margins instead.

Based on mpv-player/mpv#17544

Key difference:

  • We use sub-pos to adjust subtitles, they use sub-margin-y
  • sub-margin-y does not work with ASS subtitles unless sub-ass-override=strip is used, which defeats the purpose of ASS subtitles
  • Also, sub-margin-y might be affected by sub-use-margins

cc @Keith94 as I know you wanted osd_margins

@Keith94
Copy link
Contributor

Keith94 commented Mar 10, 2026

Wow that was quick. Will try it out very soon.

For subtitles, how much margin does it know to offset by? Specifically what I'm wondering is would it still overlap with title or chapter title if enabled? I personally don't use either of these, so it doesn't bother me if they overlap though.

Why sub-pos and sub-margin-y both exist but accomplish the same thing? Now I'm just thinking out loud at this point lol.

@Samillion
Copy link
Owner Author

Samillion commented Mar 10, 2026

I'm wondering is would it still overlap with title or chapter title if enabled?

It should never overlap. This method uses the margins set by OSC height. similar to how select menu (long playlist) does not overlap with OSC.

Why sub-pos and sub-margin-y both exist but accomplish the same thing?

We were joking about it on irc at one point, that mpv has so many options, a student can write their thesis on them and pass. 😆

@Samillion
Copy link
Owner Author

Also, on an unrelated note, this PR has the phrase ASS subtitles and it's completely normal. Thank you.

@Keith94
Copy link
Contributor

Keith94 commented Mar 10, 2026

We were joking about it on irc at one point, that mpv has so many options, a student can write their thesis on them and pass. 😆

You're not wrong lol. Scrolling through the documentation and you can tell it's more than bloated.

What is that shutdown event? Does it reset the script-adjusted sub pos on shutdown?

@Samillion
Copy link
Owner Author

Samillion commented Mar 10, 2026

What is that shutdown event? Does it reset the script-adjusted sub pos on shutdown?

Ensures that they're reset back to default/user config. In essence, to prevent a scenario like this: #389

@Samillion
Copy link
Owner Author

I'll update docs and modernz.conf after testing this PR for a while.

I need a break from PRs lol.

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

If WC is visible and you scroll up/down on the volume bar (which triggers OSD) it seems to be preventing the WC from timing out. However I don't know if that's expected so I'll point it out anyway.

Subtitle works well too. Maybe it raises a bit high if the title and/or chapter title is disabled. Should those options be taken into account?

Ensures that they're reset back to default/user config. In essence, to prevent a scenario like this: #389

I'm not sure if this is working as intended. When doing a quit-water-later it seems they're permanently raised on next startup.

Why not enable osd_margin by default? It's useful.

@Samillion
Copy link
Owner Author

Samillion commented Mar 11, 2026

If WC is visible and you scroll up/down on the volume bar (which triggers OSD) it seems to be preventing the WC from timing out. However I don't know if that's expected so I'll point it out anyway.

You mean while hovering WC scroll up/down? hovering WC will keep it showing, regardless of mouse actions.

Subtitle works well too. Maybe it raises a bit high if the title and/or chapter title is disabled. Should those options be taken into account?

I'm not sure if this is working as intended. When doing a quit-water-later it seems they're permanently raised on next startup.

True, we might need to document, add in mpv.conf:

watch-later-options-remove=sub-pos,osd-margin-y

Why not enable osd_margin by default? It's useful.

Fear of what you just mentioned, that especially should only be enabled by user when he's aware they should adjust watch later options.

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

Ah, it's actually seems unrelated. But I was noticing that WC hideout was not working while scrolling the volume bar, like this:

  1. Hover the WC
  2. Move your mouse to the volume bar
  3. Scroll up/down to change the volume (while hovering the volume bar)

Result is the WC stays on screen until you stop changing the volume.

Anyway,

This method uses the margins set by OSC height.

What happens if we lower the value of osc_height user option? Should the subtitle margin adapt to the new height?

@Samillion
Copy link
Owner Author

Maybe both sub_margins and osd_margins should be disabled by default? That way those that enable it, would have read the documented watch later options and know how to deal with it.

What happens if we lower the value of osc_height user option? Should the subtitle margin adapt to the new height?

It does, yes. OSC margins use osc_height and fade_alpha value. Whichever is highest, is the OSC boundary.

osc_param.video_margins.b = math.max(user_opts.osc_height, user_opts.fade_alpha) / osc_param.playresy

Result is the WC stays on screen until you stop changing the volume.

Nice catch.

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

watch-later-options-remove=sub-pos

Unless I messed something up, this option doesn't fix the issue. They are still raised on startup.

  1. input.conf -> q quit-watch-later
  2. Hover the OSC at bottom while subtitles raised.
  3. Press q
  4. Open the same file again.

@Samillion
Copy link
Owner Author

Unless I messed something up, this option doesn't fix the issue. They are still raised on startup.

With watch-later-options-remove=sub-pos:

# E:\test\Bleach- Sennen Kessen-hen - 38.mkv
start=581.247000

Without watch-later-options-remove=sub-pos:

# E:\test\Bleach- Sennen Kessen-hen - 38.mkv
start=555.138000
sub-pos=81.000000

My mpv.conf watch later:

watch-later-dir="~~/cache/watch_later"
write-filename-in-watch-later-config=yes
watch-later-options-remove=sub-pos

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

It does, yes. OSC margins use osc_height and fade_alpha value. Whichever is highest, is the OSC boundary.

Then it's working as intended. This would be good to document about the fade_alpha. I personally found the lower limit for osc_height is around 115 otherwise it messed up clicking on OSC elements.

watch-later-options-remove=sub-pos

Ok, sorry, it works with just this line. However if you add ,osd-margin-y to the line then it doesn't work (it doesn't reset the sub-pos properly?)

True, we might need to document, add in mpv.conf:
watch-later-options-remove=sub-pos,osd-margin-y

@Samillion
Copy link
Owner Author

Ok, sorry, it works with just this line. However if you add osd-margin-y to the line then it doesn't work (it doesn't reset the sub-pos properly?)

True, turns out -remove accepts one option at a time. So it would be:

watch-later-options-remove=sub-pos
watch-later-options-remove=osd-margin-y

But, from my testing, osd-margin-y is never saved. so probably only sub-pos one is needed for it.

@Samillion
Copy link
Owner Author

By the way, the whole watch-later-options-remove=sub-pos isn't just this feature PR, before with raise_subtitles it had the same behavior. Since they both adjust sub-pos

But at least now we should document and tell users what to do.

Then it's working as intended. This would be good to document about the fade_alpha

I will document this as well.

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

Can we force enable that option? Or just rely on the user to set up their mpv.conf properly.

Either way, the PR works really well. I'm impressed. Thanks for getting it in so quick.

@Samillion
Copy link
Owner Author

Can we force enable that option? Or just rely on the user to set up their mpv.conf properly.

I thought about it, but I don't know if we should. We'd be altering the user's configuration without their knowledge. Even if we tie it to an option that could be disabled.

I'm not saying no, I just don't know if yes is ok lol.

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

That's fair.

Side note, is user_opts.md even needed? Since modernz.conf has the same content and updating so many files gets a bit too much.

@Samillion
Copy link
Owner Author

so many files gets a bit too much.

It is a pain in the ass and probably is read by 1% of users.

However, it makes readability easier and we're able to add more detailed notes like the ones I just added about OSC boundary, watch later and so on.

@Samillion
Copy link
Owner Author

All done. I think this PR is ready to merge, let me know if I missed something please. If it's not a bother.

Result is the WC stays on screen until you stop changing the volume.

I'll try to fix this in another PR.

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

Looks good to me too.

@Samillion Samillion merged commit 0996284 into main Mar 11, 2026
@Samillion Samillion deleted the feat_sub_osd_margins branch March 11, 2026 02:19
@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

Maybe both sub_margins and osd_margins should be disabled by default? That way those that enable it, would have read the documented watch later options and know how to deal with it.

Forgot to reply sorry. I agree they should be disabled by default to avoid issues or just disable dynamic_margins and keep the other two enabled by default. Then users can turn it on after reading the warning.

@Samillion
Copy link
Owner Author

Samillion commented Mar 11, 2026

I was discussing it on irc, and guido suggested a great solution:
Read watch later options, if they include OSD margin/sub position, disable ModernZ sub/osd options, then warn they need to do X to enable them.

What do you think?

At least then we can enable it all by default.

Edit:
We don't even need to disable them if they're included in watch later options, we can just warn users about it.

@Keith94
Copy link
Contributor

Keith94 commented Mar 11, 2026

Yeah that seems like a good solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants