Skip to content

Commit

Permalink
Merge pull request #55966 from bruvzg/wt💩4
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Dec 16, 2021
2 parents 350013f + 1fdb6a9 commit 33e0338
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 5 additions & 2 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,11 @@ void DisplayServerWindows::console_set_visible(bool p_enabled) {
if (console_visible == p_enabled) {
return;
}
ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
console_visible = p_enabled;
if (!((OS_Windows *)OS::get_singleton())->_is_win11_terminal()) {
// GetConsoleWindow is not supported by the Windows Terminal.
ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
console_visible = p_enabled;
}
}

bool DisplayServerWindows::is_console_visible() const {
Expand Down
13 changes: 12 additions & 1 deletion platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,16 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
return OK;
};

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

Error OS_Windows::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id) {
String path = p_path.replace("/", "\\");
String command = _quote_command_line_argument(path);
Expand All @@ -484,7 +494,8 @@ Error OS_Windows::create_process(const String &p_path, const List<String> &p_arg
#ifndef DEBUG_ENABLED
dwCreationFlags |= CREATE_NO_WINDOW;
#endif
if (p_path == get_executable_path() && GetConsoleWindow() != nullptr) {
if (p_path == get_executable_path() && GetConsoleWindow() != nullptr && _is_win11_terminal()) {
// Open a new terminal as a workaround for Windows Terminal bug.
dwCreationFlags |= CREATE_NEW_CONSOLE;
}

Expand Down
1 change: 1 addition & 0 deletions platform/windows/os_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class OS_Windows : public OS {

void run();

bool _is_win11_terminal() const;
virtual bool _check_internal_feature_support(const String &p_feature) override;

virtual void disable_crash_handler() override;
Expand Down

0 comments on commit 33e0338

Please sign in to comment.