Commit Graph

212 Commits

Author SHA1 Message Date
Christoph Heinrich 9c22d6b438 osc: move the idle logo behind other overlays
The default `z` of an overlay is 0, which is used by e.g. console.lua.
Having the idle logo at a `z` of 1000 means that it ends up above the
console (and anything that don't set a value higher then 1000).
It doesn't make sense for the idle logo to overshadow other things, so
put it at -1000 instead to prevent that.
2023-09-27 23:05:53 +00:00
Dudemanguy c0c595b588 osc: remove shared-script-properties usage
0b4860248b added user-data which is
completely superior and makes this property obsolete. We've already had
one mpv release with the osc using user-data so drop this.
2023-09-27 14:04:59 +00:00
Mike Will 9cd2a9fc48 osc.lua: fix calculation for slider's min-max average
Average of two numbers is given by the sum of the two numbers
divided by two. It's gone unnoticed because `s_min` is
basically always zero.
2023-09-25 16:07:34 +00:00
llyyr 181eddc80e osc: add scrolling to audio/sub buttons
Consistent with other osc buttons now
2023-09-17 00:03:45 +02:00
NRK 022dbfc977 osc: add scrolling to the seekbar
the osc currently allows for changing volume via scrolling when on top
of the volume icon. this does the same thing for the seekbar by allowing
seeking via scroll.
2023-09-02 18:14:02 +02:00
llyyr 998c3a163c osc: remove toggle for forced only subpictures
DVD/PGS are definitely not common, and ones that make use of the forced
subpictures flag even less so. For this button to be useful, the
subtitle track would need to be DVD or PGS, the track would need to make
use of the forced flag, the user would have to know what forced
subpictures are, and the user would need to have the preference of only
viewing forced subpictures on a subtitle. The function of this button is
too niche to be on the osc, if this behavior is desired the user can
simply bind a key in their input.conf. Moreover, this button only adds
confusion because there's no intuitive way to show what it does, and
there's no explanation for it anywhere in the manuals. osc real-estate
is quite limited as it is, so let's not waste any space on buttons with
highly questionable utility at best and confusing or bad UX at worst.
2023-08-31 17:38:08 +00:00
Dudemanguy 92fe8f1a4e osc: replace sub-forced-only with sub-forced-events-only 2023-08-29 16:39:00 +00:00
llyyr a19aefac37 osc: fix margin for forced-only subs toggle in bar layout
This ensures the spacing between forced-only sub toggle button and the
volume button matches the spacing between the volume and the fullscreen
button on bottombar/topbar layouts
2023-08-27 16:28:24 +00:00
llyyr d0bc907806 osc: only add sub forced-only toggle to layout for DVD/PGS subs
Fixes: 945d7c1eda

Previously, we would have a button with empty string added to the layout
for non DVD/PGS subtitles. This would cause there to be an invisible
button present that would take up space and could still be clicked
despite being invisible when the current subtitle track was not DVD/PGS.
The idea was that the button would be invisible for regular subtitle
tracks, and be visible as "[ ]"/"[F]" for DVD/PGS subtitle tracks.

This commit modifies the bar and box layouts to only add this button if
the current subtitle track is DVD/PGS. This results in there no longer
being an invisible button, and also prevents it from taking up space.
The button is added to layout as before when the current subtitle track
is DVD/PGS, matching the same logic as before.
2023-08-27 16:28:24 +00:00
Dave dfbdf75165 osc: support speed-independent time-remaiing display
The new OSC config option "remaining_playtime" controls whether the
time-remaining display considers speed (yes - default) or ignores it.
2023-08-11 14:30:42 +03:00
llyyr 4198e6f35f osc: don't add margins to osc-deadzonesize
Currently, the osc will add a margin of (osc_height / 2) to the
deadzonesize for the window controls, the topbar and the bottombar,
i.e. when osc-deadzonesize=1, the osc will show up even if the cursor
is only hovering (osc_height / 2) pixels above or below it. This is not
what this option is supposed to do according to the manual, instead
osc-deadzonesize=1 should result in the osc only appearing when it is
directly hovered. The user can simply set osc-deadzonesize=0.9 or so if
such a margin is desired, instead make the option work as advertised by
removing this margin.

It should be noted that osc-layout=box does not share this behavior,
and it already works as advertised in the manual.
2023-07-21 20:24:18 +02:00
rcombs 945d7c1eda osc: add toggle for forced-only subs 2023-06-25 11:01:58 +02:00
Christoph Heinrich b7ffe0d16e osc: skip rendering when osd_dimensions are 0
The idle logo could appear on the left side of the window for a split
second after starting.
That is because when osd dimensions can be reported as 0 at the very beginning.
Since the width gets calculated based on a fixed height and the aspect ratio,
which is 0, that results in a width of 0 until the next update.
2023-04-05 17:14:43 +00:00
Harri Nieminen 292a5868cb various: fix typos
Found by codespell
2023-03-28 19:29:44 +00:00
rcombs 894f0c28eb osc: set values in user-data in addition to shared-script-properties 2023-02-26 17:54:09 -06:00
Dudemanguy bca516bd2c osc: don't spam window-controls bindings on every render
Not sure when this actually started happening, but it's probably been
like this for years. Currently, the logic for the window-controls works
by simply checking if the osc is visible and then either enabling or
disabling the associated keybindings. The problem is that this can just
constantly spam mp.enable_keybindings/disable_key_bindings on every
single render call if the user disables the border at any point in time.
This does a lot of pointless work and also results in the logs being
spammed with lines like "disable-section". Clearly, this should just
work like the code for checking the input keybindings just above it.
Keep track of an internal state variable and check when it doesn't match
the osc visibility. In that case, we can then either enable or disable
the key bindings and just update the variable.
2022-11-29 16:40:36 +00:00
Christoph Heinrich cc65b3892d osc: scale rendered aspect ratio with window aspect ratio
The logo stays centered better and it doesn't distort anymore due to a
recent change in libass https://github.com/libass/libass/pull/645
2022-10-06 14:34:56 -04:00
Ryan Hendrickson ad5a1ac873 osc.lua: add osc-tcspace script option
Generally, the hard-coded sizes used for the OSC elements are
comfortable regardless of the font used, but the timecode fields have
relatively many characters, and so are affected to a greater degree by
fonts with a wider or narrower average character width than expected.

This allow users to adjust the space reserved for the timecode fields to
compensate.
2022-07-19 23:19:45 +03:00
Ryan Hendrickson ff25a8c65a osc.lua: add osc-unicodeminus script option
This option enables the use of the Unicode U+2212 Minus Sign character
when displaying the time remaining, instead of "-" (U+002D
Hyphen-Minus).
2022-07-19 23:19:45 +03:00
Dudemanguy ec236f7a99 osc.lua: add idlescreen and osc-idlescreen
This is mainly for other user scripts that may conflict with the osc
logo in some way. Although it is possible to listen for
shared-script-properties, this has many edge cases that could easily pop
up. A user could want other OSC things to happen at the same time (say
osc-message). They just don't want the logo. The idlescreen option
disables all idlescreen related things (including the santa hat) if it
is set to "no". A new script message (osc-idlescreen) is also added so
users can easily toggle the value (passing "cycle" or just explictly
setting "yes" or "no"). Some more discussion on this is found in the
below github issues.
https://github.com/mpv-player/mpv/issues/10201
https://github.com/CogentRedTester/mpv-file-browser/issues/55
2022-06-04 14:48:32 +00:00
CogentRedTester b4c73ed105 osc.lua: fix crash when calling osc-tracklist while idle
If the player is started with --idle  and the osc-tracklist script-message
is called then the tracks_osc table will be nil,
which caused the OSC to crash due to attempting to index a nil value.

This appears to be because the osc_tracklist variable is both
initialised and updated by (ultimately) the render() function, which
is not run when the player is idling.

Rather than mess with the existing OSC logic it's easier to either
add this single check, or alternatively to initialise the the tracks_osc
table somewhere before this.
2022-05-19 13:54:31 +00:00
Cœur bb5b4b1ba6 various: fix typos 2022-04-25 09:07:18 -04:00
Avi Halachmi (:avih) 0197729949 osc.lua: seekbar hover: speed-up chapter access
This speeds up chapter name access while hovering the seekbar:

- Fetch the chapter-list property using observation rather than on
  every render while hovering the bar. Property access, especially
  with potentially lots of values (chapters), can be expensive-ish,
  and can involve locking, so the less per-render the better.

- Sort the list once (on change) to simplify the iteration logic when
  searching the chapter which matches the mouse position. It's still
  O(N) (no binary search currently), but with less work.

The cached sorted list is stored at the state. While there are other
places which access this property and could use this cache, for now we
don't touch them, because they're not performance-critical (on init
for the chapter markers, on ch_{prev,next} button click for OSD).

Caching properties using observation instead of using mp.get_property
can indeed speedup other places too, but it should be part of a system
rather than implemented per-property. Maybe some day.
2022-02-06 11:02:39 +02:00
Funami580 448fe0226b osc: fix cache displaying 60s in some cases
It was caused by string.format rounding e.g. 59.9 to 60.
2021-11-27 21:37:24 +02:00
Avi Halachmi (:avih) b8926dd484 osc: add options: chapters/playlist OSD, hover chapter format
Previously OSD was always displayed on {ch,pl}_{next,prev} left-click,
and seekbar-hover-chapter was always enabled and with fixed format.

Now it can be controlled with:
- chapters_osd, playlist_osd: yes/no (only affects left-click).
- chapter_fmt: lua string.format template, or "no" to disable.

Fixes #4675
2021-11-25 21:20:48 +02:00
Avi Halachmi (:avih) ca6108baf4 osc.lua: avoid infinite ticks loop on idle
Before this commit, animation-end was handled at render(), however,
it's not called on idle, which resulted in state.anitype ~= nil, with
nothing to reset it during idle, which caused in an infinite tick()
loop (starts on first mouse move).

Now tick resets the animation on idle, and also, as a safety measure,
if we're past 1s after the animation deadline.

The safety measure is because the osc states are complex, and it's
easier to detect a "we really shouldn't be animating now" at tick()
itself rather than detecting the exact states where animation should
be reset. Generally, the safety mmeasure is not needed.
2021-10-03 19:52:58 +03:00
Avi Halachmi (:avih) bc6dab6d92 osc.lua: unify animation reset function (no-op) 2021-10-03 19:52:58 +03:00
Avi Halachmi (:avih) d2dd4cacb8 osc: expose osc-visibility via shared-script-properties
osc-visibility can already be changed at runtime via script-message
or other means, but until now there was no way to tell what the
current state is.

Now shared-script-properties/osc-visibility reflects this state.
It's output-only by the osc - changing it does not affect the osc.

Useful if a script wants to change osc-visibility temporarily, and
later restore to its original state.

There's no way to coordinate if more than one script wants to change
it, but that would be a hard problem to solve anyway, even if the
osc itself tried to coordinate such requests from different sources.
2021-07-06 16:12:36 +03:00
Avi Halachmi (:avih) 76b1ac57a4 osc: seekbar hover/drag: display target chapter at the title
Fixes #8925
2021-06-22 18:12:29 +03:00
Avi Halachmi (:avih) 48f3a26746 osc: ensure tick after any mouse-event
Previously tick() was ensured unconditionally only after mouse-move,
but there are other mouse-events which need re-rendering (tick), like
mouse-down (icons may get grayed-out) or mouse-up (icons may change).

For instance: mpv --pause --myclip.mkv

then move the mouse over the volume/mute OSC button, then - without
moving the mouse - press and release the left mouse button.

The osc was not re-rendered because it's paused and the mouse didn't
move, so the volume icon didn't get grayed-out when held down, and the
icon doesn't change on mouse-up (to reflect the new mute state).

Now both these changes are rendered correctly.
2021-06-20 17:37:47 +03:00
Avi Halachmi (:avih) 89efe820a8 osc: don't initialize while mouse-down over an element
This is not a new issue, however, until the last commit - 96b246d
init probably didn't happen much (or at all) between mouse-down and
mouse-up, but after this commit, if there are chapters in a live-stream
then osc_init() is used to re-render the markers at the adjusted
position - which breaks the OSC buttons functionality if init happened
between mouse-down and mouse-up.
2021-06-20 17:37:47 +03:00
Sagnac 96b246d928 osc: update chapter marker positions when duration changes
Commit 6abb7e3 updates the markers when the chapters change, but it
doesn't update their relative position at the bar when the duration
changes.

This means that adding chapters to a live stream would result in
corresponding chapter markers which were static while the duration
changed and thus their positions became incorrect over time until the
OSC was reinitialized.

This is fixed by observing the duration property if chapters are present
and reinitializing the OSC when the duration changes.

The live_markers user option, which determines whether the duration
property is observed when there are chapters, has been added in order to
allow disabling this behaviour as calling request_init() frequently
might have some impact on low-end systems.

The impact of request_init() on render() was measured to increase from
1-1.5 ms to 2-3 ms on a 2010 MacBook Air, while the impact was neglible
on a 2016 Surface Book (increasing only to an average of 1.4 ms from
1.3 ms for n=1500 render cycles).

The live_markers option is enabled by default.
2021-06-16 02:04:28 +03:00
Retusthese 6abb7e385f osc: re-initialize when chapter list changes
When the OSC initializes, it checks whether the current video has
chapters, and if it does not, it disables its chapter functionality
(chapter buttons are grayed out and unusable, chapter indicators don't
show on the seek bar). If another script changed the chapter list
after the video has loaded, those changes would be ignored by the OSC
until some other event causes it to re-initialize, because it did not
observe the chapter list property. This is fixed by adding
observation of chapter-list alongside the other properties that
trigger re-initialization.
2021-05-27 09:12:38 +03:00
ossifrage 0d384592c5 osc: reset margins when using boxvideo with showfullscreen/showwindowed
This fixes a bug where using boxvideo with showfullscreen=no or
showwindowed=no resulted in the margins not resetting when the OSC
wasn't visible.

For example, using:

script-opts=osc-visibility=always,osc-boxvideo=yes,osc-showfullscreen=no

and then going fullscreen would make the OSC disappear but the video
margins would remain. This is because boxvideo was missing a dependence
on the showfullscreen and showwindowed user options.

This is fixed by adding the corresponding conditions to update_margins()
and setting state.marginsREQ on fullscreen changes. update_margins() is
called on tick() if there's a margins update pending, which guarantees
the boxvideo margins are reset appropriately.
2021-04-27 14:12:05 +03:00
ossifrage c1568a3a6c osc: display immediately when visibility changes from never to always
Clearing state.osd.data with an empty string at render_wipe() fixes an
issue where changing the OSC visibility from "never" directly to
"always" didn't immediately update the display when the player was
paused. This could be verified by starting the player with
`--script-opts=osc-visibility=always --pause` and then running
`script-message osc-visibility never` followed by
`script-message osc-visibility always`.

Removing the overlay without changing the contents meant the overlay
wouldn't update and display when enabled again until the fields changed
in some way (e.g. seeking, mousing over the OSC area, etc.). Clearing
state.osd.data before removal of the OSC makes sure set_osd doesn't
return on re-enable and instead displays the OSC immediately as the data
is now different.

render_wipe() is now also used when the OSC needs to be cleared at
tick() as using set_osd to clear it with an empty string did not call
state.osd:remove() which can allow cleanups related to bitmap memory
allocations etc.
2021-04-25 19:24:46 +03:00
wm4 152b0e2a8c osc: fix hovering timestamp sticking around when moving mouse away
The OSC calls this "tooltip" (and although a general mechanism, there's
only one instance using it). One particular problem was that with the
default OSC layout, moving the mouse down and out of the window, the
tooltip stuck around, because the returned mouse position was the last
pixel row in the window, which still overlaps with the seek bar.

Instead of introducing mouse_in_window, you could check last_mouse_X for
nil, but I think this is clearer.

This returns (-1, -1) to the caller if the mouse is outside. Kind of
random, but works.
2020-05-16 13:45:16 +02:00
wm4 9815887435 osc: avoid using a deprecated event
The new code is pretty much equivalent.
2020-03-21 19:32:50 +01:00
wm4 cb2b5553bf osc: fix updating message when paused
The message_timeout field was basically polled. But ever since the OSC
was changed to work more event based, this didn't quite work. It was
quite visible when switching subtitle or audio tracks while paused (and
with caching disabled, since the cache update triggered some extra
redrawing).

Fix by using a proper timer.

I noticed that changing tracks with the message call commented didn't
redraw properly either, but, uh, I guess the message is always triggered
anyway, and happens to take care of this.
2020-03-14 15:15:44 +01:00
wm4 7e2bb7b439 osc: use default hr-seek when dragging progress bar to seek
The "seekbarkeyframes" option is now interpreted such if it's true, the
player default is used. Too lazy to make this a choice option or
whatever; the Lua option parser doesn't have support for that anyway.
Someone who cares can adjust this.
2020-02-28 17:17:42 +01:00
wm4 10a97f7cc3 osc: use cache state cache-duration field
Avoids an additional property access; see previous commit.
2020-02-07 16:16:18 +01:00
Avi Halachmi (:avih) 40832773c1 osc: more frequent cache updates: from 10% diff to 5% or 5s
Cache display updates, especially when it's bigger than few minute,
could have been be very infrequent to the point that one is not sure
if it updates at all.

Reduce the 10% change-threshold to 5% and add another threshold of 5s.
2020-01-14 13:15:48 +02:00
Philip Langdale 4d51660195 osc: usability improvements for pseudo-csd title bar
There are two improvements here:

1) Correct the right-side padding on the title box. This was messed
   up previously because I was passing the title box width when I
   should be passing the x coordinate. I've also increased the
   spacing to separate the title from the window controls more
   clearly.

2) I'ved added a mouse tracking area over the title bar so that the
   osc doesn't disappear if you hover over the title box. This didn't
   work previously because the input area only covers the actual
   window controls. The implementation here is simplified in that
   it's only a mouse area and not an input area. This is enough to
   keep the osc visible, but it won't stop the mouse pointer
   disappearing. Fixing that requires a full input area which, for
   now, I will say isn't worth the effort.
2020-01-13 16:25:34 -08:00
Philip Langdale 9f7c271087 osc: when fullscreened, un-maximise window control should un-fullscreen
It's a bit unintuitive today when you use the un-maximise control
while fullscreened. Depending on the VO in use, this might silently
change the maximise state without any visible effect, or it might
do nothing. It's less surprising if the control exits the fullscreen
state.

Note that the exact behaviour is still VO dependent. If the window
was maximised before being fullscreened, it might exit fullscreen
back to maximised or back to regular window mode.

I thought about trying to explicitly control that behaviour but
it makes the osc code weird and probably wouldn't work all the time.
2020-01-12 08:43:19 -08:00
wm4 1c83ded3b0 osc: don't delay updates on resize
The idea is that if the player is resized, we do not delay redrawing
(which is normally done to limit the redraw rate to something
reasonable).

Not sure if this even does anything. For one, reacting to osd-dimensions
changes is cleaner than just polling the screen size with the next tick
event, and hoping that resizes generate tick events for whatever
logically unrelated reasons.
2020-01-08 02:37:12 +01:00
Philip Langdale daa125cb45 osc: reset input handling state on a change in visibility mode
Currently, the activation and deactivation of input handling is done
inside the render() loop, but this does not run when the osc mode is
`never` - which does make sense.

That means that if you are cycling the visibility mode, the input
state will be whatever it was at the time of the mode change. And,
as our modes are ordered `auto` -> `always` -> `never`, the input
state will be enabled when you cycle to `never`.

There are various ways you can imagine fixing this, and in this
change I propose we reset the input state to disabled on a mode
change, and then let render() re-enable input if that's appropriate.

Fixes #7298.
2020-01-02 07:32:57 -08:00
wm4 2636bbbf33 osc: redraw on visibility option runtime changes
This affects behavior when using the "del" default key binding.
Sometimes, setting visibility to always did not draw it correctly. This
probably fixes it.
2019-12-24 09:50:08 +01:00
Nicolas F 7ed70f925b osc: add option to disable santa hat
A minority of users have expressed a dislike of hats, calling them
"cancer [that] don't belong in software" describing the people who add
them as "shitty circlejerks" and "chucklefuck."

While I personally disagree with those opinions, it's probably easier
to let them have it their way. For that reason this adds the option
`greenandgrumpy` to the osc, which allows users to disable the hat.
2019-12-23 16:38:41 +01:00
wm4 86d24b069b osc: set an arbitrary high Z-order
The main reason for this is just to make show the OSC always above
console.lua, instead of a random order.

(And this is also the only reason osc.lua was changed to the new API.
The old API could have been extended, but lets not.)
2019-12-23 12:06:33 +01:00
wm4 490b3ba007 osc: use new overlay API
This tries to avoid the update() call if nothing changed. This brings it
more into line with the old code (the osd-overlay command simply does
not skip the update if nothing changed). I don't know whether this
matters; most likely not. Normally, code should try to avoid redundant
updates on its own, so it's not the job of the command. However, for the
OSC we simply want to reduce the differences.
2019-12-23 11:48:16 +01:00
TheAMM 6d93e4cb22 osc: display Santa hat for idle logo in December
During the 12th month (checked during script initialization), draw a Santa hat
on top of the idle message's logo.
Slightly refactors and optimizes the drawing process as well: reorder original
logo layers and remove redundant holes in them, use a shared line prefix
to clear the style and set start position.

Signed-off-by: wm4 <wm4@nowhere>
2019-12-23 01:45:34 +01:00