Commit Graph

3956 Commits

Author SHA1 Message Date
Guido Cella
e549bf0dec console.lua: update completions after moving the cursor
...and after navigating the history.

I thought of making the new function accept the new cursor position and
set it, but it would not be clear that you're only supposed to call it
when handle_edit() is not already called.
2024-11-24 12:19:45 +01:00
Kacper Michajłow
5730c631fd player/video: update dynamic hdr params 2024-11-24 11:32:12 +01:00
Guido Cella
a0d416e94b console.lua: highlight the first completion suggestion before cycling
2f271a92de made it so that the first completion suggestion is
automatically selected when pressing Enter, if none was manually
selected. So automatically highlight the first completion in yellow to
show this.
2024-11-24 11:23:04 +01:00
Guido Cella
40724f81e1 console.lua: save commands in history after autocompletion
2f271a92de made it so that the first completion suggestion is
automatically selected when pressing enter, but that was done after
saving the command in the history. Save it to the history after
expanding it, so re-running the previous command actually works, e.g.
save "set vo gpu-next" instead of "set vo gn".
2024-11-24 11:23:04 +01:00
Guido Cella
2f271a92de console.lua: expand the first completion on Enter
If you run a command without manually selecting a completion, select the
first one. e.g. set vo gn runs set vo gpu-next.
2024-11-23 10:48:32 +01:00
Guido Cella
57a6f12ed3 console.lua: dont crash when typing a command prefix
Typing a command prefix crashes console because first_useful_token is
nil. This already happened before implementing autocompletion if you did
no-osd<Tab>, but autocompletion made it evident.
2024-11-23 10:48:32 +01:00
Guido Cella
57b73f1af6 console.lua: show completions as you type
Show available completion suggestions as you type without having to
press Tab.

This is fast even on a 2011 CPU, so we can get away with doing this in
the same thread that draws the console. The one case where it could make
the console hang is file completion of network drives, but in general it
is convenient for loadfile.

mp.input.get clients also get a request to complete on each character
typed, but those run in a different thread so performance is always
fine, and completions were already rejected if the input line or cursor
changed after the request. If I ever make running mpv commands an
mp.input client in the future, command completion will also benefit from
running in a different thread.
2024-11-23 10:48:32 +01:00
Guido Cella
2e265f33e3 console.lua: complete fewer properties
10k properties makes the console hang and the CPU fan spin with live
fuzzy filtering, so print fewer sub-properties. These are rarely useful
anyway.
2024-11-23 10:48:32 +01:00
Guido Cella
a0de894d4c console.lua: determine completions with fuzzy search
For example, set vo gn<Tab> will complete to gpu-next.
2024-11-23 10:48:32 +01:00
Kacper Michajłow
3e10309b62 player/loadfile: prefer non-image when selecting video track
This fixes `ytdl_hook`, which would start playback with the thumbnail
track selected. This issue occurs because the thumbnail track is added
first. If the main track is not marked as default afterward, which it
isn't for single streams, the first track (the image track) would be
selected.

In general, if a non-image track is available, it should be preferred.
2024-11-22 21:14:52 +01:00
Guido Cella
cf3bc0a722 console.lua: limit the length of selectable items
Giving very long lines to libass freezes mpv and makes the CPU spin
(though it's fine with terminal output). This is often the case
user-data/mpv/ytdl/json-subprocess-result in the property list. So limit
the length of selectable items to 300 characters (not Unicode aware).
This is enough to fill a 1920x1080 window with font_size=16 and Japanese
text.
2024-11-22 19:04:51 +01:00
Guido Cella
5ec569d073 console.lua: strip multiple lines in selectable items
If an item contains newlines, it hides the top items. This is often the
case for sub-ass-extradata and metadata/ytdl_description in the property
list. So keep only the first line.
2024-11-22 19:04:51 +01:00
M Stoeckl
46574d479d console.lua,wayland_common: also detect Wayland if WAYLAND_SOCKET set
While most Wayland compositors provide a socket path indicated by
environment variable WAYLAND_DISPLAY, others may sometimes bequeath a
socket file descriptor specified by WAYLAND_SOCKET.
2024-11-18 16:35:57 +00:00
Guido Cella
2e31502cb1 console.lua: don't override the offset of opaque boxes
With --osd-border-style=opaque-box and background-box, respect
--osd-shadow-offset.

I am not sure if --osd-shadow-offset should be inherited with
--osd-border-style=outline-and-shadow, especially since it doesn't let
you specify different x and y offsets.
2024-11-18 17:10:19 +01:00
Guido Cella
b71ab51996 console.lua: use OSD margins
Now that default OSD margins have been decreased to 15 it is reasonable
to let console.lua inherit them for consistency.
2024-11-18 10:36:43 +01:00
Kacper Michajłow
a0d7265ce9 sub/osd/console/stats: use the same 1.65 outline size 2024-11-18 09:50:22 +01:00
Kacper Michajłow
fedd34e83c stats.lua: set border size to have similar relative thickness as OSD
It is 6% of font size. Little bit more relativelly to OSD, but stats has
smaller text, so we need to compensate for that.
2024-11-18 09:50:22 +01:00
Kacper Michajłow
8c3a7da619 sub/osd/console: adjust font sizes
The current OSD font size is excessively large, causing most
messages—except for very short ones to overflow horizontally.

I conducted testing across multiple devices of varying screen sizes and
under different scenarios. The adjusted font size strikes a good balance
for readability on non-high-DPI displays, while high-DPI displays should
utilize DPI scaling as needed.

Additionally, I compared the font sizes of subtitles and UI elements
across various VOD platforms, which generally use smaller font in most
cases.

The current sub font size was significantly larger than even PGS
subtitles, which are quite large on their own. Now, they are comparable.

The subtitle font size was chosen based on recommendations from the BBC
Subtitle Guidelines. It is set to 8% of the video height with a
recommended scaling factor of 0.67. Therefore, at 720p (the reference
size for mpv font scaling), the calculation is 8% * 0.67 * 720 = 38.592,
rounded down to 38. This value falls within the recommended scaling
range of x0.5–x1 for desktop PCs/Laptops and TVs (32"–42"). For more
information, see
https://www.bbc.co.uk/accessibility/forproducts/guides/subtitles/#Presentation-font-size.

OSD font size is smaller than font as those elements shouldn't be
distractful and only noticable when the user wants to look at them.

Outline size is set to 5.5% of font size.
2024-11-18 09:50:22 +01:00
Guido Cella
dd5f2069b8 loadfile: move mp_format_track_metadata to misc.c
Move the function added in 3ea8d751f5 to misc.c because command.c is too
big. The circle definitions are also moved to core.h
2024-11-16 16:59:11 +01:00
Kacper Michajłow
70aaba71d6 player/command: remove /100 from sub-pos print
It already prints %, so there's no need for '/100'. Also, use the print
helper while at it.

6ea08be59a added a percent sign but didn't
remove '/100', so we ended up with both, which is redundant.
2024-11-14 18:56:04 +01:00
Guido Cella
1c3f09270f defaults.js: send the right number of arguments to input.get callbacks
Only send how many arguments were actually passed by console.lua instead
of sending extra undefined arguments.
2024-11-14 11:09:08 +01:00
Guido Cella
ea6b1119d3 defaults.js: fix the opened event with mp.input.get
The opened event doesn't send any arguments. Don't call
JSON.parse(undefined) in that case because it errors.

Fixes eb4c6be630, fixes #15301.
2024-11-14 11:09:08 +01:00
llyyr
168fb56fe8 osc.lua: observe playlist-count instead of playlist property
Observing playlist property with "native" type is too expensive for
larger playlists, and we only observe this property to
activate/deactivate next/prev buttons on the osc. We actually only need
to know if the playlist-count has changed, nothing else.

Fixes: https://github.com/mpv-player/mpv/issues/15264
2024-11-06 18:00:09 +01:00
Guido Cella
a61518db98 player/client: reduce log level for hooks not sent to clients
If a hook event can't be sent to a client because it no longer exists,
stop logging it as a warning, as there is no way for a client to remove
hooks, so it is expected that the hook can't be sent. This is documented
in libmpv/client.h.

If the hook event can't be sent for other reasons, like the event queue
being full (currently the only other possible reason), keep logging as
warning.

Also add the client and hook type to the message. They are also logged
just above, but only in verbose mode, so when only the warning is logged
you didn't see the client before.

auto_profiles.lua logs these warning since 5dc4047415, and this commit
fixes that.

Fixes #15244.
2024-11-03 20:03:49 +02:00
Guido Cella
5dc4047415 auto_profiles.lua: actually exit when no auto profiles are defined
Unsetting _G.mp_event_loop at the top level quits the script, but not
within callbacks. Use the new exit() function instead. Fixes e2284fba18.

This actually has an edge case since e2284fba18 where you can add auto
profiles only later with load-config-file and the script stays unloaded,
but it's still reasonable to quit if mpv.conf has no conditional
profiles. You could always explicitly set --load-auto-profiles=yes in
this case.
2024-11-02 14:03:02 +02:00
Guido Cella
bb0b9f4cc8 defaults.lua: add an exit() function
Scripts can terminate execution by setting mp.keep_running = false. Add
an exit() function to wrap setting mp.keep_running and properly expose
this feature. It can be used e.g. by a thumbnail script to spawn workers
with load-script and then let them quit.

It is not added to the mp namespace as mp.exit because that would make
it look like it terminates mpv.

This mirrors the exit() function which already exists in js.

The note in javascript.rst about having to remove key bindings before
exit is not kept because they are actually removed automatically since
bf385e1140 (though it was accurate when the JS backend was developed
before upstreaming it).
2024-11-02 14:03:02 +02:00
Kacper Michajłow
e96bffe7a8 player/loadfile: limit playlist size to 10 for fuzzing
Fixes timeout on huge generated playlists, 10 is enough to test if it
works.
2024-11-02 01:40:41 +01:00
nanahi
1a522b4a72 command: quote input key names in log 2024-11-02 01:39:15 +01:00
nanahi
c5da7beaa6 command: use array index for checking first character 2024-11-02 01:39:15 +01:00
nanahi
1b9d070786 command: fix keybind command with sequence keys
The command is documented to use the same syntax as input.conf, but
it doesn't work with sequence keys because it uses
mp_input_get_key_from_name for checking key names, when it should
use mp_input_get_keys_from_string instead.

Fix this by using the correct function.
2024-11-02 01:39:15 +01:00
nanahi
56e2689894 command: add the ability to set comment for keybind command
This allows the keybind to have a comment field which can be
read from input-bindings, and displayed by e.g. stats.lua.
2024-11-02 01:39:15 +01:00
llyyr
5b946ac360 player: don't load encoding mode profile twice
Also move the loading of profiles and input section activation in one
place. Leaving this in mp_initialize has the drawback that encoding
section profile will overwrite options set by the user in the command
line, since it's set after the CLI options are parsed and processed.
mp_parse_cfgfiles happens before parsing the CLI, so loading the profile
there is better.
2024-10-31 16:43:25 +01:00
llyyr
e28bfadbea options: remove stale comment about encoding mode being compiled-in
Encoding mode used to be a compile time option, but now it's always
compiled in.
2024-10-31 16:43:25 +01:00
Guido Cella
00e223ccb6 console.lua: refine the hovered item calculation
Calculate the hovered item from the bottom of the screen where the
console is anchored. This is simpler and accurate because it accounts
for the fact that the empty line between the log and the input line
isn't as tall as a full line, for the exact height of an always visible
OSC bottombar, and for the empty top pixels present because the height
isn't an integer multiple of the font size.
2024-10-31 16:40:56 +01:00
Guido Cella
e1680167fd console.lua: factor OSC margins before the bottom margin
OSC margins are relative to the whole height before subtracting the
bottom left margin.
2024-10-31 16:40:56 +01:00
Guido Cella
b40241889b console.lua: use math.ceil in determine_hovered_item()
Replace the rounding to calculate the hovered line with ceil which is
what you would expect to work. Rounding worked better before because it
compensated for the errors fixed by the previous 2 commits.
2024-10-29 22:13:40 +01:00
Guido Cella
ce4a804a7d console.lua: factor the bottom margin in line calculations
This is more important now that the margin is bigger due to the scaling
with the window.
2024-10-29 22:13:40 +01:00
Guido Cella
10789fae1f Revert "console.lua: fix the max log lines calculation"
This reverts commit 5e65999eb2.

This was wrong because an empty line doesn't occupy as much height as a
filled line. But update the comment so it is not unclear like before why
1.5 is subtracted.
2024-10-29 22:13:40 +01:00
Guido Cella
3986f34e2a stats.lua: calculate sizes like --osd-*-size options
Currently --script-opt=stats-font_size=n is much bigger than
--osd-font-size=n, which can confuse users, so calculate sizes the same
way.

The \fs value to replicate --osd-font-size is
${osd-font-size} * 288 / 720 with --osd-scale-by-window, and
\fs${osd-font-size} * 288 / ${osd-height}
with --osd-scale-by-window=no. This is because
sub/osd_libass.c:update_playres() sets
track->PlayResY = ass->res_y ? ass->res_y : MP_ASS_FONT_PLAYRESY,
where MP_ASS_FONT_PLAYRESY is 288.

This also works with persistent_overlay=yes.

{\fscx100}{\fscy100} would also replicate --osd-font-size with show-text
and with osd-verlay + --osd-scale-by-window, but not with osd-overlay +
--osd-scale-by-window=no.

The default sizes are multiplied by 720/288 = 2.5 to keep them the same
as before.
2024-10-29 20:35:35 +01:00
Kacper Michajłow
0c5420b412 console.lua: update selected item under the cursor on mouse wheel action 2024-10-29 16:23:21 +01:00
Guido Cella
934bfd2b7e console.lua: restore the bigger default font size
Fixes aa66f0dced.
2024-10-29 00:13:32 +01:00
Guido Cella
aa66f0dced console.lua: default to a proportional font for select
In the select menu there are no completions to align in a grid, so the
better looking proportional font of --osd-font can be used by default.
It is also easier to read for the visually impaired.

The text width calculation is no longer performed if the console is only
opened through select, it is only performed the first time something is
completed. This avoids having to pass an argument to get_font() to make
it use the monospace font regardless of selectable_items.

Fixes #15176.
2024-10-28 23:30:34 +01:00
Guido Cella
cb8e3ba959 osc.lua: hide immediately without animation for select.lua
Requested by llyyr.
2024-10-28 23:28:50 +01:00
Guido Cella
bf3382b083 console.lua: fix the hovered line calculation without scale with window
If not scaling with the window the hidpi scale needs to be factored into
mouse-pos. Follow up to a670f75679 and a2106396bc.
2024-10-28 23:17:21 +01:00
Guido Cella
940ab99055 osc.lua: make shift+mbtn_left an alias of mbtn_mid
...instead of the opposite. This simplifies bind_mouse_buttons().
2024-10-28 23:16:54 +01:00
Guido Cella
dc85266aff osc.lua: remove code repetition for mouse bindings 2024-10-28 23:16:54 +01:00
Guido Cella
4b97e723d6 osc.lua: rename the tog_fs button
Make it consistent with the command script-opt names.
2024-10-28 23:16:54 +01:00
Guido Cella
a2106396bc console.lua: fix the clicked line calculation
e00d8dcb03 factored hidpi-scale in get_scaled_osd_dimensions(), so
max_lines was dividing by it a second time.
2024-10-27 21:36:32 +00:00
nanahi
a670f75679 console.lua: don't scale with display dpi if scaling with window size
Fixes overly large text on hidpi displays.
2024-10-27 21:43:36 +01:00
Guido Cella
423e8f2711 osc.lua: increase the title font size in box layout
It is too small.
2024-10-27 21:10:36 +01:00