[Windows] Detect new Windows Terminal and disable unsupported set_console_visible code.

(cherry picked from commit 9aef3a93dd)
This commit is contained in:
bruvzg 2021-12-15 20:00:35 +02:00 committed by Rémi Verschelde
parent 3c752893c5
commit 5f7b91136f
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 20 additions and 3 deletions

View File

@ -2229,11 +2229,25 @@ bool OS_Windows::is_window_focused() const {
return window_focused;
}
bool OS_Windows::_is_win11_terminal() const {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = 0;
if (GetConsoleMode(hStdOut, &dwMode)) {
return ((dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == ENABLE_VIRTUAL_TERMINAL_PROCESSING);
} else {
return false;
}
}
void OS_Windows::set_console_visible(bool p_enabled) {
if (console_visible == p_enabled)
return;
ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
console_visible = p_enabled;
if (!_is_win11_terminal()) {
// GetConsoleWindow is not supported by the Windows Terminal.
ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
console_visible = p_enabled;
}
}
bool OS_Windows::is_console_visible() const {
@ -2840,7 +2854,8 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
}
DWORD creation_flags = NORMAL_PRIORITY_CLASS & CREATE_NO_WINDOW;
if (p_path == get_executable_path() && GetConsoleWindow() != NULL) {
if (p_path == get_executable_path() && GetConsoleWindow() != NULL && _is_win11_terminal()) {
// Open a new terminal as a workaround for Windows Terminal bug.
creation_flags |= CREATE_NEW_CONSOLE;
}

View File

@ -371,6 +371,8 @@ class OS_Windows : public OS {
CrashHandler crash_handler;
bool _is_win11_terminal() const;
void _drag_event(float p_x, float p_y, int idx);
void _touch_event(bool p_pressed, float p_x, float p_y, int idx);