From 476c8c1ee8e8453877e921e1efd4fe124866b793 Mon Sep 17 00:00:00 2001 From: Michael Niksa Date: Thu, 17 Oct 2019 00:48:52 +0000 Subject: [PATCH] Merged PR 3896217: [Git2Git] Changes from vb_release_dep_dev1 https://microsoft.visualstudio.com os OS official/vb_release_dep_dev1 e4969135c0b6cc004a192e707f538cb1cedb274b --- src/host/srvinit.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index e1f8001187b..7e1718cd57c 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -502,6 +502,18 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand, return STATUS_SUCCESS; } +[[nodiscard]] bool ConsoleConnectionDeservesVisibleWindow(PCONSOLE_API_CONNECTINFO p) +{ + Globals& g = ServiceLocator::LocateGlobals(); + // processes that are created ... + // ... with CREATE_NO_WINDOW never get a window. + // ... on Desktop, with a visible window always get one (even a fake one) + // ... not on Desktop, with a visible window only get one if we are headful (not ConPTY). + // This prevents pseudoconsole-hosted applications from taking over the screen, + // even if they really beg us for a window. + return p->WindowVisible && (s_IsOnDesktop() || !g.IsHeadless()); +} + [[nodiscard]] NTSTATUS ConsoleAllocateConsole(PCONSOLE_API_CONNECTINFO p) { // AllocConsole is outside our codebase, but we should be able to mostly track the call here. @@ -546,7 +558,7 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand, Status = NTSTATUS_FROM_HRESULT(wil::ResultFromCaughtException()); } - if (NT_SUCCESS(Status) && p->WindowVisible) + if (NT_SUCCESS(Status) && ConsoleConnectionDeservesVisibleWindow(p)) { HANDLE Thread = nullptr; @@ -576,9 +588,6 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand, CloseHandle(Thread); // This doesn't stop the thread from running. - g.consoleInputInitializedEvent.release(); - g.consoleInputSetupEvent.release(); - if (!NT_SUCCESS(g.ntstatusConsoleInputInitStatus)) { Status = g.ntstatusConsoleInputInitStatus;