summaryrefslogtreecommitdiffstats
path: root/platform/windows/display_server_windows.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-08-11 12:58:12 +0200
committerGitHub <noreply@github.com>2020-08-11 12:58:12 +0200
commit0e751ea7c3b4997cb15e3ae00dfe097f690a1f3a (patch)
treebca439fa7b626cc2aaf899174052b4f5f59bdbb1 /platform/windows/display_server_windows.cpp
parentb3707aeff2243871b853ea0e08f3a485093d687b (diff)
parent4f7a49db53c6aaabeca70fe8901144af708fb6b2 (diff)
downloadredot-engine-0e751ea7c3b4997cb15e3ae00dfe097f690a1f3a.tar.gz
Merge pull request #41164 from bruvzg/win_attach_console
[Windows] Attach to parent console instead of creating new one.
Diffstat (limited to 'platform/windows/display_server_windows.cpp')
-rw-r--r--platform/windows/display_server_windows.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index da2fc1c2c1..e4a7814cc1 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -1135,10 +1135,17 @@ void DisplayServerWindows::window_set_ime_position(const Point2i &p_pos, WindowI
void DisplayServerWindows::console_set_visible(bool p_enabled) {
_THREAD_SAFE_METHOD_
- if (console_visible == p_enabled)
+ if (console_visible == p_enabled) {
return;
- ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
- console_visible = p_enabled;
+ }
+ if (p_enabled && GetConsoleWindow() == nullptr) { // Open new console if not attached.
+ own_console = true;
+ AllocConsole();
+ }
+ if (own_console) { // Note: Do not hide parent console.
+ ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
+ console_visible = p_enabled;
+ }
}
bool DisplayServerWindows::is_console_visible() const {
@@ -3019,7 +3026,18 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
shift_mem = false;
control_mem = false;
meta_mem = false;
- console_visible = IsWindowVisible(GetConsoleWindow());
+
+ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
+ FILE *_file = nullptr;
+ freopen_s(&_file, "CONOUT$", "w", stdout);
+ freopen_s(&_file, "CONOUT$", "w", stderr);
+ freopen_s(&_file, "CONIN$", "r", stdin);
+
+ printf("\n");
+ console_visible = true;
+ } else {
+ console_visible = false;
+ }
hInstance = ((OS_Windows *)OS::get_singleton())->get_hinstance();
pressrc = 0;