[Windows] Attach to parent console instead of creating new one.

This commit is contained in:
bruvzg 2020-08-10 10:41:06 +03:00
parent f2149fe763
commit 4f7a49db53
No known key found for this signature in database
GPG key ID: FCED35F1CECE0D3A
6 changed files with 27 additions and 18 deletions

View file

@ -2620,7 +2620,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
case SETTINGS_TOGGLE_CONSOLE: {
bool was_visible = DisplayServer::get_singleton()->is_console_visible();
DisplayServer::get_singleton()->console_set_visible(!was_visible);
EditorSettings::get_singleton()->set_setting("interface/editor/hide_console_window", was_visible);
} break;
case EDITOR_SCREENSHOT: {
screenshot_timer->start();

View file

@ -334,7 +334,6 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("interface/editor/automatically_open_screenshots", true);
_initial_set("interface/editor/single_window_mode", false);
hints["interface/editor/single_window_mode"] = PropertyInfo(Variant::BOOL, "interface/editor/single_window_mode", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
_initial_set("interface/editor/hide_console_window", false);
_initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
_initial_set("interface/editor/quit_confirmation", true);

View file

@ -2203,13 +2203,6 @@ bool Main::start() {
}
if (project_manager || editor) {
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CONSOLE_WINDOW)) {
// Hide console window if requested (Windows-only).
bool hide_console = EditorSettings::get_singleton()->get_setting(
"interface/editor/hide_console_window");
DisplayServer::get_singleton()->console_set_visible(!hide_console);
}
// Load SSL Certificates from Editor Settings (or builtin)
Crypto::load_default_certificates(EditorSettings::get_singleton()->get_setting(
"network/ssl/editor_ssl_certificates")

View file

@ -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":

View file

@ -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;

View file

@ -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;