Skip to content

Commit

Permalink
Force the use of v2 (non-legacy) conhost when in ConPTY mode
Browse files Browse the repository at this point in the history
Fixes #1838.
  • Loading branch information
DHowett committed Jul 12, 2019
1 parent 6d3001f commit f24920e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/host/exemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TRACELOGGING_DEFINE_PROVIDER(
(0x770aa552, 0x671a, 0x5e97, 0x57, 0x9b, 0x15, 0x17, 0x09, 0xec, 0x0d, 0xbd),
TraceLoggingOptionMicrosoftTelemetry());

static bool ShouldUseConhostV2()
static bool ConhostV2ForcedInRegistry()
{
// If the registry value doesn't exist, or exists and is non-zero, we should default to using the v2 console.
// Otherwise, in the case of an explicit value of 0, we should use the legacy console.
Expand Down Expand Up @@ -83,9 +83,21 @@ static bool ShouldUseConhostV2()
}
}

static bool ShouldUseLegacyConhost(const bool fForceV1)
static bool ShouldUseLegacyConhost(const ConsoleArguments& args)
{
return fForceV1 || !ShouldUseConhostV2();
if (args.InConptyMode())
{
return false;
}

if (args.GetForceV1())
{
return true;
}

// Per the documentation in ConhostV2ForcedInRegistry, it checks the value
// of HKCU\Console:ForceV2. If it's *not found* or nonzero, "v2" is forced.
return !ConhostV2ForcedInRegistry();
}

[[nodiscard]] static HRESULT ActivateLegacyConhost(const HANDLE handle)
Expand Down Expand Up @@ -163,7 +175,7 @@ int CALLBACK wWinMain(
HRESULT hr = args.ParseCommandline();
if (SUCCEEDED(hr))
{
if (ShouldUseLegacyConhost(args.GetForceV1()))
if (ShouldUseLegacyConhost(args))
{
if (args.ShouldCreateServerHandle())
{
Expand Down

0 comments on commit f24920e

Please sign in to comment.