Commit Graph

795 Commits

Author SHA1 Message Date
Christoph Heinrich 91cc0d8cf6 options: transition options from OPT_FLAG to OPT_BOOL
c784820454 introduced a bool option type
as a replacement for the flag type, but didn't actually transition and
remove the flag type because it would have been too much mundane work.
2023-02-21 17:15:17 +00:00
Thomas Weißschuh 9efce6d4ae various: drop unused #include "config.h"
Most sources don't need config.h.
The inclusion only leads to lots of unneeded recompilation if the
configuration is changed.
2023-02-20 14:21:18 +00:00
Kacper Michajłow 3a28dbb711 osdep/io: add void to mp_penviron 2023-02-02 14:23:02 +00:00
Kacper Michajłow 0a4b139ddf osdep: add MP_FALLTHROUGH 2023-02-02 14:23:02 +00:00
Mia Herkt 08747c4965
osdep/terminal.h: Rename screen buffer controls
SAVE/RESTORE were a bit misleading.
2022-12-20 10:26:53 +01:00
Mia Herkt f1957ce911 osdep/terminal: Move common esc codes to terminal.h 2022-12-19 13:48:49 +01:00
Thomas Weißschuh 7a7042a4d1 w32: fix typo in F23 mapping 2022-09-03 08:46:42 -04:00
Thomas Weißschuh c4db110c8e macos: add support for F13-F20 keys 2022-09-02 14:05:46 +02:00
Thomas Weißschuh c5e5fba632 w32: add support for F13-F24 keys
Fixes #10595
2022-09-02 14:05:46 +02:00
Leo Izen 52e7269ea6 misc/random: add xoshiro random number implementation
Add xoshiro as a PRNG implementation instead of relying
on srand() and rand() from the C standard library. This,
in particular, lets us avoid platform-defined behavior with
respect to threading.
2022-08-17 10:21:55 -04:00
Cœur bb5b4b1ba6 various: fix typos 2022-04-25 09:07:18 -04:00
Aman Karmani 76b9254b8b osdep/atomic: add mp_atomic_double
Signed-off-by: Aman Karmani <aman@tmm1.net>
2022-04-02 21:41:58 +03:00
sfan5 24dcb5d167 subprocess: unblock/reset signals before running child process
During execve() ignored and blocked signals carry over to the child
process, though apparently for SIGCHLD (which the bug report was about)
this is implementation-defined.
fixes #9613
2021-12-19 15:02:18 +01:00
sfan5 632059816a libmpv: remove opengl_cb API and other deprecated symbols
Not all deprecated symbols were removed. Only three events were removed for now
since these are not used internally.
This bumps the library version to 2.0.
2021-12-15 12:29:10 +01:00
Dudemanguy ff322864f2 build: add meson build support
Adds support for the meson build system as well as a bit of
documentation. Compatibility with the existing waf build is
maintained.
2021-11-14 19:13:10 +00:00
Niklas Haas 8bd0dee531 osdep: rename MP_UNREACHABLE
It was pointed out on IRC that the name is misleading, since the actual
semantics of the macro is to assert first.
2021-11-03 15:15:20 +01:00
Niklas Haas c704824b45 osdep: add MP_UNREACHABLE
This seems to work on gcc, clang and mingw as-is, but I made it
conditional on __GNUC__ just in case, even though I can't figure out
which compilers we care about that don't export this define.

Also replace all instances of assert(0) in the code by MP_UNREACHABLE(),
which is a strict improvement.
2021-11-03 14:09:27 +01:00
Avi Halachmi (:avih) 930b483a68 win32: Windows 10: timeBeginPeriod on demand
Before this commit, timeBeginPeriod(1) was set once when mpv starts,
and the timers remained hi-res till mpv exits.

Now we do the same as before on Windows version < 10.
On Windows 10+ we now use timeBeginPeriod if needed, per timeout.

To force a mode regardless of Windows version, set env MPV_HRT:
- "always":  the old behavior - hires timers as long as mpv runs.
- "perwait": sets 1ms timer resolution if timeout <= 50ms.
- "never":   don't use timeBeginPeriod at all.

It was observed that on Windows 10 we lose about 0.5ms accuracy of
timeouts with "perwait" mode (acceptable), but otherwise it works
well for continuous timeouts (one after the other) and random ones.

On Windows 7 with "perwait": continous timeouts are accurate, but
random timeouts (after some time without timeouts) have bad
accuracy - roughly 16ms resolution instead of the requested 1ms.

Windows 8 was not tested, so to err on the side of caution, we keep
the legacy behavior "always" by default.
2021-09-21 00:45:08 +10:00
Avi Halachmi (:avih) 21d434d2db terminal-unix: identify and ignore unknown CSI sequences
If an unknown ESC sequence is detected where an ASCII char <X> follows
the ESC, mpv interprets it as ALT+<X>, which is the traditional
terminal encoding of ALT+letter.

However, if <X> is '[' then it's a CSI sequence which continues after
the '[', and has its own termination rules (can be many chars).

Previously, mpv interpreted unknown CSI sequences as (incorrect) ALT+[
followed by (incorrect) "keys" from the rest of the sequence.

In this commit, if a unknown CSI sequence is detected, mpv ignores
exactly the complete sequence.
2021-08-19 15:39:42 +03:00
Martin Tournoij 854404a639 terminal-unix: fix ^Z identification
When using "stty susp ''" to disable sending the TSTP signal with ^Z,
mpv didn't recognize ^Z correctly in the terminal:

  [input] No key binding found for key 'Ctrl+2'.

Because ASCII 26 (^Z) and above were incorrectly considered ^<NUMBER>.

This commit moves the cutoff between letters/numbers from 25 to 26 so
that ^Z is now detected correctly as ^<LETTER>.

Additionally, it rephrases the ^<NUMBER> formula for clarity.
2021-07-13 12:12:56 +03:00
Evgeny Zinoviev 56669fb44e mac: add ability to toggle visibility on all workspaces from menubar 2021-02-21 13:38:53 +01:00
der richter 7f8d069087 mac: only update touch bar items when necessary
the slider on the touch bar was always updated when any of the related
properties changed their value. this is partially dependent on the
refresh rate of the video, in the case of time-pos. too many updates to
touch bar impact the render performance.

to prevent this we only update the slider when necessary, when the touch
bar or the touch bar item is visible. the touch bar items only need a
granularity of seconds without any decimals, but the time-pos property
provides a granularity with decimals. we floor those values and only
update the touch bar items when we have at least a 1 second difference.
we also check for the visibility of the touch bar and its items.

Fixes #8477
2021-02-13 15:51:32 +01:00
der richter aa00ad06aa mac: use custom touch bar item and slider instead of a touch bar slider
the NSSliderTouchBarItem seem to be broken in a way it can't be fixed.
it has constraints set by default that can't be removed and lead to
warnings and render performance regressions.

instead of using the preconfigured NSSliderTouchBarItem we use a custom
touch bar item (NSCustomTouchBarItem) with a slider, which essential are
the same. this way we can configure our constraints ourselves, which
aren't needed in the first place.

Fixes: #7047
2021-02-13 15:51:32 +01:00
der richter dae9ea3fa7 mac: fix dangling pointers
initialising UnsafeMutableRawPointer the way we did won't free those
pointers and we get dangling pointers. explicitly define a scope those
pointers are alive and auto freed.
2021-01-13 16:23:47 +01:00
der richter ce1571ac01 mac: drop build support for swift versions earlier than version 4.1
this drops support for swift <4.1 and with this support for xcode <=9.2.
this was the last setup that is officially working on macOS 10.12.

our old legacy build macOS 10.12 + xcode 9.2 is replaced by macOS 10.13
+ xcode 9.4.1 with swift 4.1. the macOS 10.13 + xcode 10.1 VM is
replaced by the latest macOS 10.14 + xcode 11.3.1 VM. this is the oldest
version officially supported by Apple.

this is in preparations for the following commit.
2021-01-13 16:23:47 +01:00
der richter bc58361d86 mac: fix usage of temporary pointers
the pointer used to initialise the respective structs is only guaranteed
to be alive within this constructor. the struct itself is used later and
the data it points to, is not guaranteed to be the same.

to fix this we define a scope that pointer is definitely valid and use
it within this scope. a helper function was added to get the pointers
for several data at once. otherwise we would need to nest
withUnsafeMutableBytes several times, which would make it hard to read.
2021-01-13 16:23:47 +01:00
der richter af26402948 mac: use visible frame rectangle for window geometry calculation
currently we use the whole screen rectangle to calculate the window
geometry. this doesn't take the menu bar or the Dock into account.

by default use the visible screen rectangle instead. this is also a
change in behaviour, since the window can't be placed outside of this
rectangle anymore. also add an option to change to the old behaviour,
because it can still be useful in certain cases, like placing the window
directly underneath the menu bar when used a desktop background.

Fixes #8272
2020-12-19 21:37:55 +02:00
Guido Cella 9867f21830 terminal: process input when foregrounded
When mpv is in the background because it was started with
`mpv foo.mp3 &`, or the user did ctrl+z bg, and is then brought to the
foreground with fg, it buffers input until you press enter. This makes
it accept input almost immediately. Having a short interval isn't
important, since input is buffered until the next loop iteration.

Closes #8120.
2020-11-26 23:55:59 +02:00
Shreesh Adiga 670f23f169 osdep/terminal: Add function to get terminal pixel dimensions 2020-11-22 13:34:25 +02:00
wm4 26fc70dbfd path: do not use old_home for win32 exe dir
Apparently mpv supports loading config files from the same directory as
the mpv.exe. This is a fallback of some sort. It used the old_home
mechanism.

I want to add a warning if old_home exists, but that would always show
the warning on win32. Obviously we don't want that.

Add a separate exe_dir entry to deal with that.

Untested, but probably works.

Mistakenly reverted as part of the default configuration directory
location switch-back in aa18a8e1cd.

Separation of the mpv executable directory from old_path is a
good change now that we warn about the old_config directory also
existing.

Fixes #8232
Fixes #8244
Fixes #8262
2020-11-16 00:44:40 +02:00
Philip Langdale 949e06c86c Revert "path: switch back to using non-XDG config dir by default"
This reverts commit 269f0e743e.
2020-10-16 00:47:18 +03:00
Philip Langdale aa18a8e1cd Revert "path: do not use old_home for win32 exe dir"
This reverts commit c3694f0acb.
2020-10-16 00:47:18 +03:00
wm4 95e3a6e67e terminal: fix segfault when backgrounding
In the recent terminal commit, I "compressed" the read() error handling,
and messed it up. The return value could be -1 for other non-fatal
errors (such as EIO when trying to read while backgrounded), which
resulted in buf.len getting messed up.

Fixes: 602384348e
2020-09-21 19:31:15 +02:00
der richter 03047a0169 mac: add an option to change the App activation policy
useful to hide the app icon in the Dock if necessary.
2020-09-20 15:28:50 +02:00
wm4 602384348e terminal: attempt to handle the ESC key
Due to Unix being legacy garbage, it's not possible to safely detect the
ESC key on terminal. The key sequences are ambiguous. The code for the
ESC key also starts the sequences for other special keys.

Until now, you needed to hit ESC twice for it to be recognized.

Attempt to handle this better by using a timeout to detect the key. If
ESC is in the input buffer, but nothing else arrived after a timeout,
assume it's the ESC key. I think this is the method vim uses. Currently,
the timeout is set at 100ms. This is hardcoded and cannot be changed.
It's possible that this causes problems on slow ssh connections or so.

I'm not sure what exactly happens if you manage to get ESC + another
normal key into the input buffer. If it's a known sequence, it will be
matched and interpreted as such. If not, it'll probably be discarded.
2020-09-17 15:31:19 +02:00
wm4 f250c29403 terminal-unix: attempt to support more CTRL
Hysterically stupid inconsistent legacy garbage from the 70ies or maybe
even 60ies. What the fuck. I fucking hate computers so much.

Fixes: #8072
2020-09-10 23:03:30 +02:00
der richter 5fb0f36937 mac: use config cache und wakeup for mac option runtime changes
remove the libmpv observer for the macOS specific options and use a
config cache + change callback for runtime changes. this is also a
preparation for new backends and generalises even more, since libmpv
functions can't and shouldn't be used in usual vo backends. for feature
parity the config cache is used.
2020-08-22 14:22:49 +02:00
der richter f79a591ae4 cocoa-cb: generalisation of backend independent parts
move all backend independent code parts in their own folder and files,
to simplify adding new backends. the goal is to only extend one class
and add the backend dependent parts there. usually only the (un)init,
config and related parts need to be implemented per backend. furthermore
all needed windowing and related events are propagated and can be
overwritten. the other backend dependent part is usually the surface for
rendering, for example the opengl oder metal layer.

in the best case a new backend can be added with only a few hundred
lines.
2020-08-22 14:22:49 +02:00
Avi Halachmi (:avih) 557e9d9531 win32: scripting utils.get_env_list(): use UTF-8
lua/js utils.get_env_list() uses `environ' which was ANSI, thus
it broke any unicode names/values.

mpv already has an internal utf8_environ for win32, but it's used
only at the getenv(..) wrapper and not exposed in itself, and also it
has lazy initialization - on first getenv() call.

Now `environ' maps to a function which ensures initialization while
keeping it an l-value (like posix expects).

The cost of this fuglyness is that files should include osdep/io.h
(which now declares environ as extern) rather than declaring it
themselves, or else the build will break on mingw.
2020-08-16 12:24:19 +03:00
wm4 e27c523a10 command: extend subprocess command stdin, change behavior
Make it possible to feed a string to stdin of a subprocess. Out of
laziness, it can't be an arbitrary byte string. (Would require adding an
option type that takes in a Lua byte string.)

Do not set stdin of a subprocess to fd 0 (i.e. mpv's stdin) anymore,
because it makes things more consistent. Enabling stdin didn't make too
much sense in the first place, so this behavior change seems
justifiable.

win32 support missing.

Fixes: #8003
2020-08-16 02:54:44 +02:00
James Ross-Gowan bb231889fd win32: request the UTF-8 code page for Windows APIs
This sets the activeCodePage property in the manifest, which forces the
ANSI code page to be UTF-8 in Windows 10 1903 and up. It shouldn't make
a difference for mpv itself, since mpv already uses the wide-char APIs
for most functions, however some of mpv's dependencies, such as Lua,
rely on the ANSI codepage. Hence this change enables support for Unicode
file names in Lua's I/O library.

Thanks @avih for finding this property.

See:
https://docs.microsoft.com/en-us/windows/uwp/design/globalizing/use-utf8-code-page
2020-08-08 15:00:25 +03:00
James Ross-Gowan 83fec9bafb subprocess-win: update to mp_subprocess2
This fixes the "run" and "subprocess" commands on Windows, including
youtube-dl support.

Unix-like FD inheritance is emulated on Windows by using an undocumented
data structure[1] that gets passed to the newly created process in
STARTUPINFO.lpReserved2. It consists of two sparse arrays listing the
HANDLE and internal CRT flags corresponding to each FD. This structure
is used and understood primarily by MSVCRT, but there are other runtimes
and frameworks that can write it, like libuv.

The code for creating asynchronous "anonymous" pipes in Windows has been
enhanced and moved into windows_utils.c. This is mainly an artifact of
an unfinished future change to support anonymous IPC clients in Windows.
Right now, it's still only used in subprocess-win.c

[1]: https://www.catch22.net/tuts/undocumented-createprocess
2020-07-20 21:02:17 +02:00
wm4 0279a44d93 command: extend subprocess command
Add env and detach arguments. This means the command.c code must use the
"new" mp_subprocess2(). So also take this as an opportunity to clean up.
win32 support gets broken by it, because it never made the switch to the
newer function.

The new detach parameter makes the "run" command fully redundant, but I
guess we'll keep it for simplicity. But change its implementation to use
mp_subprocess2() (couldn't do this earlier, because win32).

Privately, I'm going to use the "env" argument to add a key binding that
starts a shell with a FILE environment variable set to the currently
playing file, so this is very useful to me.

Note: breaks windows, so for example youtube-dl on windows will not work
anymore. mp_subprocess2() has to be implemented. The old functions are
gone, and subprocess-win.c is not built anymore. It will probably work
on Cygwin.
2020-07-20 21:02:17 +02:00
wm4 c3694f0acb path: do not use old_home for win32 exe dir
Apparently mpv supports loading config files from the same directory as
the mpv.exe. This is a fallback of some sort. It used the old_home
mechanism.

I want to add a warning if old_home exists, but that would always show
the warning on win32. Obviously we don't want that.

Add a separate exe_dir entry to deal with that.

Untested, but probably works.
2020-06-25 17:56:16 +02:00
wm4 269f0e743e path: switch back to using non-XDG config dir by default
XDG is stupid, so change back to the standard behavior. Unfortunately,
most users will now have the XDG one, so we will still need to load
this. (This is exactly the same problem as when XDG support was
introduced, just the other way around).

This should not affect any normal users. Hopefully I tested this well
enough; my intention is not to torment miserable XDG fans; they can keep
using their config dir if they want it.

This changes behavior in two cases:
- new users (now creates ~/.mpv/ instead of ~/.config/mpv/)
- users which have both directories

The latter case will behave subtly or obviously different, not sure.
Just fix your shit.

Extend the manpage with all the messy details, as far as I could reverse
engineer them from the code.
2020-06-25 17:56:16 +02:00
wm4 07b0c18bad build: change filenames of generated files
Force them into a more consistent naming schema.
2020-06-04 16:59:05 +02:00
James Ross-Gowan 102a083171 terminal-win: handle 'Change Window Title' OSC sequence
This should make --term-title work in Windows 8.1 and below.

OSC sequences are defined in ECMA-48. The 'Change Window Title' command,
as far as I can tell, is a de-facto standard defined by xterm[1]. In
either case, this code is probably still not standards-compliant.

This also changes mp_write_console_ansi to convert to UTF-16 before
parsing control sequences, because that made it easier to pass the OSC
param to SetConsoleTitleW. I think it's also more correct to do it this
way, even though it doesn't really matter much for our limited terminal
parsing. As a side-effect of this, mp_write_console_ansi no longer
mutates its argument.

[1]: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
2020-05-29 19:48:51 +10:00
sfan5 bf6afbc299 osdep: remove confstr() fallback for subprocess spawning
It doesn't exist on bionic (Android) and accurately emulating
execvpe's behaviour isn't all that important.
2020-05-25 00:30:35 +03:00
wm4 60f8cd4072 osdep: remove posix_spawn() helpers and wrappers
See previous commit. Farewell, useless shitty POSIX function.
2020-05-15 16:37:41 +02:00
wm4 5309497727 subprocess: replace posix_spawnp() with fork()
This code runs posix_spawnp() within a fork() in some cases, in order to
"disown" processes which are meant as being started detached. But
posix_spawnp() is not marked as async-signal-safe, so what we do is not
allowed. It could for example cause deadlocks, depending on
implementation and luck at runtime. Turns out posix_spawnp() is useless
crap.

Replace it with "classic" fork() to ensure correctness.

We could probably use another mechanism to start a process "disowned"
than doing a double-fork(). The only problem with "disowning" a process
is calling setsid() (which posix_spawnp() didn't support, but maybe will
in newer revisions), and removing as as parent from the child process
(the double-fork() will make PID 1 the parent). But there is no good way
to either remove us as parent, or to "reap" the PID in a way that is
safe and less of a mess than the current code. This is because
POSIX/UNIX is a miserable heap of shit. (Less shit than "alternatives"
like win32, no doubt.)

Because POSIX/UNIX is a miserable heap of shit, execvp() is also not
specified as async-signal-safe. It's funny how you can run a full
fledged HTTP server in an async-signal-safe context, but not start a
shitty damn process. Unix is really, really, really extremely bad at
this process management stuff. So we reimplement execvp() in an
async-signal-safe way.

The new code assumes that CLOEXEC is a thing. Since POSIX/UNIX is such a
heap of shit, O_CLOEXEC and FD_CLOEXEC were (probably) added at
different times, but both must be present. io.h defines them to 0 if
they don't exist, and in this case the code will error out at runtime.
Surely we could do without CLOEXEC via fallback, but I'll do that only
if at least 1 bug is reported wrt. this issue.

The idea how to report exec() failure or success is from musl. The way
as_execvpe() is also inspired by musl (for example, the list of error
codes that should make it fail is the same as in musl's code).
2020-05-15 16:37:41 +02:00