From 1e7831070f6ae1af0a1a29b0d680ef2907bf8cf6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 2 May 2015 18:47:57 +0200 Subject: build: move main-fn files to osdep And split the Cocoa and Unix cases. Simplify the Cocoa case slightly by calling mpv_main directly, instead of passing a function pointer. Also add a comment explaining why Cocoa needs a special case at all. --- osdep/main-fn-win.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 osdep/main-fn-win.c (limited to 'osdep/main-fn-win.c') diff --git a/osdep/main-fn-win.c b/osdep/main-fn-win.c new file mode 100644 index 0000000000..d8dbcd5a8b --- /dev/null +++ b/osdep/main-fn-win.c @@ -0,0 +1,55 @@ +#include + +#include "config.h" + +#include "common/common.h" +#include "osdep/io.h" +#include "osdep/terminal.h" +#include "osdep/main-fn.h" + +int wmain(int argc, wchar_t *argv[]); + +// mpv does its own wildcard expansion in the option parser +int _dowildcard = 0; + +static bool is_valid_handle(HANDLE h) +{ + return h != INVALID_HANDLE_VALUE && h != NULL && + GetFileType(h) != FILE_TYPE_UNKNOWN; +} + +static bool has_redirected_stdio(void) +{ + return is_valid_handle(GetStdHandle(STD_INPUT_HANDLE)) || + is_valid_handle(GetStdHandle(STD_OUTPUT_HANDLE)) || + is_valid_handle(GetStdHandle(STD_ERROR_HANDLE)); +} + +int wmain(int argc, wchar_t *argv[]) +{ + // If started from the console wrapper (see osdep/win32-console-wrapper.c), + // attach to the console and set up the standard IO handles + bool has_console = terminal_try_attach(); + + // If mpv is started from Explorer, the Run dialog or the Start Menu, it + // will have no console and no standard IO handles. In this case, the user + // is expecting mpv to show some UI, so enable the pseudo-GUI profile. + bool gui = !has_console && !has_redirected_stdio(); + + int argv_len = 0; + char **argv_u8 = NULL; + + // Build mpv's UTF-8 argv, and add the pseudo-GUI profile if necessary + if (argv[0]) + MP_TARRAY_APPEND(NULL, argv_u8, argv_len, mp_to_utf8(argv_u8, argv[0])); + if (gui) + MP_TARRAY_APPEND(NULL, argv_u8, argv_len, "--profile=pseudo-gui"); + for (int i = 1; i < argc; i++) + MP_TARRAY_APPEND(NULL, argv_u8, argv_len, mp_to_utf8(argv_u8, argv[i])); + MP_TARRAY_APPEND(NULL, argv_u8, argv_len, NULL); + + int ret = mpv_main(argv_len - 1, argv_u8); + + talloc_free(argv_u8); + return ret; +} -- cgit v1.2.3