summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/windows/detect.py9
-rw-r--r--platform/windows/display_server_windows.cpp26
-rw-r--r--platform/windows/display_server_windows.h1
3 files changed, 27 insertions, 9 deletions
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 271ffc8871..a9f25fa078 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -183,7 +183,6 @@ def configure_msvc(env, manual_msvc_config):
env.Append(CCFLAGS=["/O2"])
else: # optimize for size
env.Append(CCFLAGS=["/O1"])
- env.Append(LINKFLAGS=["/SUBSYSTEM:WINDOWS"])
env.Append(LINKFLAGS=["/ENTRY:mainCRTStartup"])
env.Append(LINKFLAGS=["/OPT:REF"])
@@ -193,15 +192,15 @@ def configure_msvc(env, manual_msvc_config):
else: # optimize for size
env.Append(CCFLAGS=["/O1"])
env.AppendUnique(CPPDEFINES=["DEBUG_ENABLED"])
- env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
env.Append(LINKFLAGS=["/OPT:REF"])
elif env["target"] == "debug":
env.AppendUnique(CCFLAGS=["/Z7", "/Od", "/EHsc"])
env.AppendUnique(CPPDEFINES=["DEBUG_ENABLED"])
- env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
env.Append(LINKFLAGS=["/DEBUG"])
+ env.Append(LINKFLAGS=["/SUBSYSTEM:WINDOWS"])
+
if env["debug_symbols"] == "full" or env["debug_symbols"] == "yes":
env.AppendUnique(CCFLAGS=["/Z7"])
env.AppendUnique(LINKFLAGS=["/DEBUG"])
@@ -314,8 +313,6 @@ def configure_mingw(env):
else: # optimize for size
env.Prepend(CCFLAGS=["-Os"])
- env.Append(LINKFLAGS=["-Wl,--subsystem,windows"])
-
if env["debug_symbols"] == "yes":
env.Prepend(CCFLAGS=["-g1"])
if env["debug_symbols"] == "full":
@@ -337,6 +334,8 @@ def configure_mingw(env):
env.Append(CCFLAGS=["-g3"])
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
+ env.Append(LINKFLAGS=["-Wl,--subsystem,windows"])
+
## Compiler configuration
if os.name != "nt":
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;
diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h
index 7bd93a7086..52f5b0f4a9 100644
--- a/platform/windows/display_server_windows.h
+++ b/platform/windows/display_server_windows.h
@@ -405,6 +405,7 @@ private:
bool drop_events = false;
bool in_dispatch_input_event = false;
bool console_visible = false;
+ bool own_console = false;
WNDCLASSEXW wc;