summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ross-Gowan <rossymiles@gmail.com>2015-03-30 02:34:58 +1100
committerJames Ross-Gowan <rossymiles@gmail.com>2015-04-11 14:35:09 +1000
commit1e3aad5f876b8e01dd3100e1bc6ecd6572f2f9bf (patch)
treeeb81fbe5e386c7f26d6a4d1cf26dc0227667cf6e
parent527911d2a2047796acd59bae03b075e4425cf73b (diff)
downloadmpv-1e3aad5f876b8e01dd3100e1bc6ecd6572f2f9bf.tar.bz2
mpv-1e3aad5f876b8e01dd3100e1bc6ecd6572f2f9bf.tar.xz
win32: use pseudo-gui profile when started without stdio
If mpv is started from Explorer or the Start Menu, it will have no console and no standard IO handles. In this case, it's fairly safe to enable the pseudo-gui profile.
-rw-r--r--player/main-fn-win.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/player/main-fn-win.c b/player/main-fn-win.c
index 9e46e4af5f..ad883dcba9 100644
--- a/player/main-fn-win.c
+++ b/player/main-fn-win.c
@@ -1,24 +1,53 @@
+#include <windows.h>
+
#include "config.h"
-#include "core.h"
+
#include "osdep/io.h"
#include "osdep/terminal.h"
+#include "core.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;
+}
+
+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
- terminal_try_attach();
+ 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;
- char **argv_u8 = talloc_zero_array(NULL, char*, argc + 1);
- for (int i = 0; i < argc; i++)
- argv_u8[i] = mp_to_utf8(argv_u8, argv[i]);
+ // 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(argc, argv_u8);
+ int ret = mpv_main(argv_len - 1, argv_u8);
talloc_free(argv_u8);
return ret;