Commit Graph
1109 Commits
Author SHA1 Message Date
MarieVelter42 89427a4201 osc.lua: fix volume icon not updating while paused
Volume icon in the OSC did not update when mute toggled or
volume changed while playback was paused and mouse was idle.

This commit adds observers for mute and volume properties to
request_tick(), ensuring OSC updates immediately on mute or
volume changes, even if playback is paused and mouse is idle.
2025-07-04 10:17:04 +02:00
nanahi a043624ea6 osc.lua: fix element touch handling
On some compositors, when all touch points disappear the compositors
reset the mouse position, which moves the mouse out of the osc element
trigger area so mouse up events do not happen.

Fix this by tracking the last touch position and use that as the virt
mouse position if the screen is recently touched.
2025-06-29 18:16:54 +02:00
nanahi 18defc8530 stats.lua: fix append_property exclusions
f676a9ff20 changed some append_property
calls to append, but append does not support the exclusion feature
which results in "HW: no" shown when no hwdec is active when this
was not displayed before.

Fix this by adding option to append_property to use get_property_cached.

Fixes: f676a9ff20
2025-06-20 16:13:14 +02:00
Kacper Michajłow 47bc7b2a07 ytdl_hook.lua: add support for HEVC 2025-06-10 17:52:25 +02:00
Guido Cella d702e5fec8 console.lua: set compute_bounds and hidden at startup
There is no need to set them every time the width is calculated.
2025-05-03 22:45:10 +02:00
Guido Cella 4194522344 console.lua: rename option_color_to_ass to color_option_to_ass
It is more correct English.
2025-05-03 22:45:10 +02:00
Guido Cella 3600c716ea console.lua: fix crash when pressing Ctrl+l
Pressing Ctrl+l with selectable items without having called input.get()
earlier caused a crash.

Fixes a6024b562a.
2025-04-18 12:02:47 +02:00
yumcookiez df1e71a7cc ytdl_hook: add option to extract chapters 2025-04-17 00:37:13 +02:00
Guido Cella 498a9bf464 console.lua: center correctly within OSC margins
Center in the middle of the rectangle surrounded by the OSC instead of
in the center of the window.
2025-04-17 00:17:01 +02:00
Guido Cella 4dfe92fa27 console.lua: replace font script-opt with monospace_font
Allow configuring the monospace font without also changing the
proportional font. The proportional font is configured with the standard
--osd-font.
2025-04-17 00:13:19 +02:00
Guido Cella 42660a8c23 console.lua: say focused instead of selected
The selected term was causing confusion e.g. in
https://github.com/mpv-player/mpv/pull/15711#issuecomment-2676060139.
Saying either focused or current makes more sense since the item is not
actually selected until you click or press Enter.
2025-04-17 00:08:16 +02:00
Guido Cella b554d43cde select.lua: display editions when before the first edition
When the first edition is not at the start of the file but after the
current time position, the current-edition property is -1, which
prevented displaying any edition.

Fixes https://github.com/mpv-player/mpv/issues/16073#issuecomment-2787316609
2025-04-17 00:07:22 +02:00
Guido Cella d059f648fa console.lua: repurpose case_sensitive to only affect exact searches
case_sensitive originally only affected Tab completion. It defaulted to
yes outside of Windows just to emulate the bad defaults of bash and zsh
(not fish, which has better defaults and defaults to case-insensitive
completion). This was already silly, but then it affected the fuzzy
autocompletion and case-sensitive fuzzy completion is even more silly.
And since 0b3cc3a167, it accidentally stopped affecting even that,
because the completion via script message never checked for the option.
Nobody even noticed this, meaning that nobody was relying on fuzzy
autocompletion being case-sensitive.

Just make case_sensitive only affect the new exact search, and make it
default to no on all platforms. Though IMO the search could just always
be case-insensitive.
2025-04-17 00:01:27 +02:00
Guido Cella 4cb5f7aa1f console.lua: implement exact matching
Allow matching items exactly instead of fuzzily when prefixing the
search with ' (like in fzf) or with
--script-opt=console-exact_match=yes.

This is mainly useful to filter history entries chronologically.

You can also specify multiple search terms delimited by spaces. But '
makes every term an exact match, unlike fzf where you need to place it
before every word, since we can't hook into fzy's algorithm.

Closes #14587.
2025-04-17 00:01:27 +02:00
Kacper Michajłow bff0d59cbe stats.lua: set plot_{perfdata,vsync_ratio,vsync_jitter} to no
Disables perf graphs from stats.lua. They are relatively expensive to
render, causes a lot of memory to be used for caches which are never
reused because graph is rarely the same. And most importantly those
graphs are not that useful beyond quick visual inspection of jitter.

Can be enable in script-opt if needed. Cache graph is left enabled,
because it shows if cache readhead grows or not nicely.
2025-04-16 23:58:46 +02:00
Kacper Michajłow fd1007260c stats.lua: add stats-plot_cache script-opt
Allows to disable cache graphs on page 3 of stats.lua.

Fixes: #13894
2025-04-16 23:58:46 +02:00
Mike Will d1d2d9a0bb osc.lua: update OSC on playlist position changes
Fixes: 168fb56fe8
2025-04-16 23:58:28 +02:00
showergum 44816ef8ff console.lua: default prompt to an empty string
Calling input.select() without a prompt argument was failing due to
attempting to concatenate a nil value.

Before mpv 0.40 the prompt defaulted to ">" so this is expected to
work as evident from the example code.
2025-04-12 20:55:34 +02:00
Guido Cella 52a95d91bd positioning.lua: validate that an amount is passed
Instead of crashing, show the correct usage when running pan-x, pan-y or
cursor-centric with script-message, or with script-binding but no
argument.
2025-03-31 12:04:37 +02:00
verygoodlee f837e951af select.lua: simplify the time formatting function
The C version of time formatting function has been exposed to lua,
so why not use it, `osc.lua` and `stats.lua` are already using it.
2025-03-31 11:57:06 +02:00
Guido Cella e88864aef3 commands.lua: add remember_input script-opt
Allow clearing the input line on close. Fixes #16104.
2025-03-26 14:56:48 +01:00
Guido Cella ba80e447a6 console.lua: use a variadic function 2025-03-26 14:48:37 +01:00
Guido Cella 6ec0d06aa9 console.lua: use double quotes
Make it consistent with other scripts.
2025-03-26 02:53:01 +01:00
nanahi f676a9ff20 stats.lua: cache some properties
Some properties can take a long time to query, especially those which
require voctrl like current-window-scale and display-names.

Similar to d37521b5ef, make the script
observe these properties and cache the values to avoid querying them
on every refresh. This alleviates the issue when holding down "i" key
for a while and releasing it results in stats being stuck on display
for a long time because of the time required to query there properties.
2025-03-26 01:30:46 +01:00
Guido Cella b31c3d80ab commands.lua: prevent infinite logging with debug log level
With -v -v there was an infinite loop of log messages, because every new
logged script message to console triggers a new script message, which
gets logged again.
2025-03-23 22:56:39 +01:00
Christoph Heinrich 958fee6895 ytdl_hook.lua: fix duplicated chapters
Sometimes when opening a YouTube video with chapters, the chapter-list
ended up having all the chapters twice, despite the json from yt-dlp only
containing them once. That must mean that sometimes add_single_video()
runs twice before the chapter_list table gets cleared in the
on_preloaded hook.

This can be avoided by replacing chapter_list with a new table before
adding entries to it.
2025-03-23 22:52:12 +01:00
Guido Cella 6171e4800c select.lua: display chapters when before the first chapter
When the first chapter is not at the start of the file but after the
current time position, the chapter property is -1, which prevented
displaying any chapter.

Fixes #16073.
2025-03-19 12:28:44 +01:00
Dudemanguy 6c42182522 Revert "console.lua: disable cursor autohide while selector is open"
In retrospect, this isn't so great because not neccesarily everyone
would want the mouse to show with the menu and said menu can be
navigated with the keyboard anyway.

This reverts commit a8f5beb5a3.
2025-03-15 05:19:43 +00:00
verygoodlee a8f5beb5a3 console.lua: disable cursor autohide while selector is open
This is an improvement on #15145 .
If the cursor is automatically hidden, users may not know whether
they are clicking on the inside or outside of selectable items,
the result after clicking is unclear to them.
2025-03-14 15:55:55 +00:00
verygoodlee ae3420fe66 DOCS/man/input: correct the mode flag of apply-profile command
The default mode actually named `apply` instead of `default`,
it's a mistake that has existed for a long time.
2025-03-12 10:50:32 +01:00
Guido Cella 4c26e7d2ed console.lua: fix crash when pressing Ctrl+c with select
Pressing ctrl+c in select mode crashes if console wasn't opened in
free-form text mode before.

This also makes the type of the history variable clear.

Fixes a6024b562a.
2025-03-10 17:06:02 +01:00
llyyr edf4fdfb1f positioning.lua: clamp values within {-1, 1} for video-align-{x,y}
Otherwise you can move your cursor outside the mpv window while having
align-to-cursor "held" and make the script send illegal values
2025-03-09 12:06:54 +01:00
Kacper Michajłow f751f218bc commands.lua: add cache for often queried constant properties
commands, properties, options, options info, never changes during
runtime, so we can cache them to make the value instantly available.
2025-03-09 11:45:30 +01:00
Kacper MichajłowandGuido Cella d37521b5ef console.lua: cache observed properties to avoid unnecessary fetching
Those properties are already observed and trigger update, remember the
value to avoid re-fetching them.

This fixes delay caused by properties that synchronize GUI thread like
`focused` which takes 30+ ms in certain cases.

Co-authored-by: Guido Cella <guido@guidocella.xyz>
2025-03-09 11:45:30 +01:00
Guido Cella 8385c2b5e8 console.lua: convert cursor_position to number
script-message-to commands type was passing cursor_position as a string,
which caused a crash if you e.g. moved the cursor afterwards. Convert it
to number in console so commands.lua and similar clients don't have to
manually convert it.
2025-03-08 19:09:23 +00:00
Guido Cella 061b83d479 commands.lua: complete filesystem paths for run
Complete file paths after e.g. run mv ${path}. This is similar to how
shells complete file paths for all commands without known completions.
2025-03-08 19:09:23 +00:00
Guido Cella e28c6ceea3 console.lua: default to --osd-font without completions
Currently --osd-font is the default for select, and a monospace font is
the default for free-form text mode. We can also default to the
proportional --osd-font for mp.input.get clients that don't specify
completions and thus don't need alignment, which is most clients.

In builtin scripts, this is the case for filtering stats key bindings.
2025-03-08 19:09:23 +00:00
Guido Cella d738e787a0 console.lua: instantly show completions with the type script message
With script-message-to commands type, instantly show completions if
available. Useful e.g. with loadfile or apply-profile.

This also shows completions if you just close the console with a filled
line and reopen it.
2025-03-08 19:09:23 +00:00
Guido Cella 415078ba2d console.lua: fix the line end position to filter completions
Completions were not being shown if a character in front of the cursor
was not in the completions, e.g. with loadfile '...'
2025-03-08 19:09:23 +00:00
Guido Cella 10bb083ab4 console.lua: don't retrieve --input-ime at startup
This is already retrieved when opening the console.
2025-03-08 19:09:23 +00:00
Guido Cella a839738d1c console.lua: reduce indentation in 2 functions
Nest the shorter blocks instead of the longer ones.
2025-03-08 19:09:23 +00:00
Guido Cella b23bd34921 console.lua: inline log_add()
As it's now used in a single place.
2025-03-08 19:09:23 +00:00
Guido Cella 686eb160e4 console.lua: clear the default item on input.get()
Clear the default item of the last input.select() call to prevent
command history search from highlighting that same default item.
2025-03-08 19:09:23 +00:00
Guido Cella a6024b562a console.lua: declare various variables only in free-form text mode
These are no longer used anywhere in select mode, except for 1 instance
of log_buffers[id].
2025-03-08 19:09:23 +00:00
Guido Cella 6f2ce8aac1 console.lua: don't duplicate the check to add to history 2025-03-08 19:09:23 +00:00
Guido Cella 0b3cc3a167 commands.lua: split this script out of console.lua
It was suggested by CogentRedTester in
https://github.com/mpv-player/mpv/pull/10282#issuecomment-1858727729 and
https://github.com/mpv-player/mpv/pull/10282#issuecomment-1858809580 and
by avih that making running commands an mp.input client is a better
architecture.

A practical advantage is that completions are calculated in a different
thread, which prevents hanging when completing slow/network filesystems.

script-binding console/enable becomes script-binding commands/open,
though the console one is kept as an alias. I took the opportunity to
rename this because open makes more sense for a graphical modal, and it
is the word used in mp.input and user-data.

script-message-to console type becomes script-message-to commands type,
though the console one is kept as an alias. It is also changed to
automatically close on submit without having to append '; keypress ESC'
as you don't need to keep the console open after running prefilled
commands.

Also convert to double quotes like other scripts and rename some
inconsistent functions.
2025-03-08 19:09:23 +00:00
Guido Cella ce6a52d40a console.lua: add history_path field to mp.input.get
This allows saving the history to all mp.input.get clients.

Needed to split running commands out of console.lua.
2025-03-08 19:09:23 +00:00
Guido Cella 05438fc081 console.lua: add autoselect_completion field to mp.input.get
This selects the first completion when pressing Enter when one wasn't
already manually selected.

Needed to split running commands out of console.lua.
2025-03-08 19:09:23 +00:00
Guido Cella 3c175f0114 console.lua: let the complete callback return a character to append
Let the complete callback return the character to append to the selected
completion.

I didn't want to document this because it's specifically meant for
properties and unlikely to be needed by other scripts, but silently
interpreting the 3rd return value can screw you over if you do something
like

return candidates, code:find('[%w_]*$')

I was doing this in my lua-repl script, and find() returns the end
position as the 2rd argument, this becomes the 3rd return value and gets
appended to completions. So you have to do

return candidates, code:find('[%w_]*$'), nil

Needed to split running commands out of console.lua.
2025-03-08 19:09:23 +00:00
Kacper Michajłow d2e3fd9383 auto_profiles.lua: make profiles apply with higher priority
This increases the priority from 50 (which is neutral) to ensure that
profiles are applied before other scripts.

In general, applying profiles before other scripts makes sense. This was
already the case for external scripts with default priority because they
would load after auto_profiles.

This commit primarily fixes ytdl_hook.lua to respond to profile changes.
In most cases, profile conditions are triggered by external conditions,
not the output from the ytdl hook, so this is fine.

I acknowledge that this will change the order if a script previously had
a priority lower than 50. However, injecting itself before profiles are
evaluated is a very obscure use case, if there is even a valid one.
2025-03-07 00:08:10 +01:00