summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorMartin Herkt <lachs0r@srsfckn.biz>2013-12-28 04:45:52 +0100
committerMartin Herkt <lachs0r@srsfckn.biz>2014-01-02 05:30:49 +0100
commite9f577eb9a81cea09209bbf4eb910f89caa63b02 (patch)
tree9e097866d594edcb7ea975d64eed09d66445bdac /osdep
parentfd89a7598820f5b5a7a4b7029e31dd100cefbb96 (diff)
downloadmpv-e9f577eb9a81cea09209bbf4eb910f89caa63b02.tar.bz2
mpv-e9f577eb9a81cea09209bbf4eb910f89caa63b02.tar.xz
Windows: use the GUI subsystem, attach to console
This is necessary to start mpv without forcing a console window, but also breaks console usability. A workaround is to call mpv from a wrapper process that uses the console subsystem and helps redirecting the standard streams and WriteConsole output to where they belong.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/io.c22
-rw-r--r--osdep/io.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/osdep/io.c b/osdep/io.c
index 2e2603eb7f..b348890533 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -327,4 +327,26 @@ char *mp_getenv(const char *name)
return NULL;
}
+void mp_attach_console(void)
+{
+ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
+ // We have been started by something with a console window.
+ // Redirect output streams to that console's low-level handles,
+ // so we can actually use WriteConsole later on.
+
+ int hConHandle;
+ intptr_t hStdio;
+
+ hStdio = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
+ hConHandle = _open_osfhandle(hStdio, _O_TEXT);
+ *stdout = *_fdopen(hConHandle, "w");
+ setvbuf(stdout, NULL, _IONBF, 0);
+
+ hStdio = (intptr_t)GetStdHandle(STD_ERROR_HANDLE);
+ hConHandle = _open_osfhandle(hStdio, _O_TEXT);
+ *stderr = *_fdopen(hConHandle, "w");
+ setvbuf(stderr, NULL, _IONBF, 0);
+ }
+}
+
#endif // __MINGW32__
diff --git a/osdep/io.h b/osdep/io.h
index 9f715d904e..7c20d262b0 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -77,6 +77,7 @@ struct dirent *mp_readdir(DIR *dir);
int mp_closedir(DIR *dir);
int mp_mkdir(const char *path, int mode);
char *mp_getenv(const char *name);
+void mp_attach_console(void);
// NOTE: stat is not overridden with mp_stat, because MinGW-w64 defines it as
// macro.