Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev/migrie/b/13211-de…
Browse files Browse the repository at this point in the history
…fterm-focus-foreground
  • Loading branch information
zadjii-msft committed Jun 8, 2022
2 parents a4cd034 + 4e20a86 commit 9295f95
Show file tree
Hide file tree
Showing 26 changed files with 406 additions and 379 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ ICore
IData
IDCANCEL
IDD
IDefault
IDesktop
IDevice
IDictionary
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/CascadiaPackage/Package-Dev.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<com:ProxyStub Id="DEC4804D-56D1-4F73-9FBE-6828E7C85C56" DisplayName="OpenConsoleHandoffProxy" Path="OpenConsoleProxy.dll"/>
<com:Interface Id="E686C757-9A35-4A1C-B3CE-0BCC8B5C69F4" ProxyStubClsid="DEC4804D-56D1-4F73-9FBE-6828E7C85C56"/>
<com:Interface Id="59D55CCE-FC8A-48B4-ACE8-0A9286C6557F" ProxyStubClsid="DEC4804D-56D1-4F73-9FBE-6828E7C85C56"/>
<com:Interface Id="746E6BC0-AB05-4E38-AB14-71E86763141F" ProxyStubClsid="DEC4804D-56D1-4F73-9FBE-6828E7C85C56"/>
</com:ComInterface>
</com:Extension>
<com:Extension Category="windows.comServer">
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/CascadiaPackage/Package-Pre.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<com:ProxyStub Id="1833E661-CC81-4DD0-87C6-C2F74BD39EFA" DisplayName="OpenConsoleHandoffProxy" Path="OpenConsoleProxy.dll"/>
<com:Interface Id="E686C757-9A35-4A1C-B3CE-0BCC8B5C69F4" ProxyStubClsid="1833E661-CC81-4DD0-87C6-C2F74BD39EFA"/>
<com:Interface Id="59D55CCE-FC8A-48B4-ACE8-0A9286C6557F" ProxyStubClsid="1833E661-CC81-4DD0-87C6-C2F74BD39EFA"/>
<com:Interface Id="746E6BC0-AB05-4E38-AB14-71E86763141F" ProxyStubClsid="1833E661-CC81-4DD0-87C6-C2F74BD39EFA"/>
</com:ComInterface>
</com:Extension>
<com:Extension Category="windows.comServer">
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/CascadiaPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<com:ProxyStub Id="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F" DisplayName="OpenConsoleHandoffProxy" Path="OpenConsoleProxy.dll"/>
<com:Interface Id="E686C757-9A35-4A1C-B3CE-0BCC8B5C69F4" ProxyStubClsid="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F"/>
<com:Interface Id="59D55CCE-FC8A-48B4-ACE8-0A9286C6557F" ProxyStubClsid="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F"/>
<com:Interface Id="746E6BC0-AB05-4E38-AB14-71E86763141F" ProxyStubClsid="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F"/>
</com:ComInterface>
</com:Extension>
<com:Extension Category="windows.comServer">
Expand Down
11 changes: 8 additions & 3 deletions src/cascadia/TerminalSettingsEditor/Launch.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

<Grid.RowDefinitions>
<!-- profile name -->
<RowDefinition Height="*" />
<RowDefinition Height="20" />
<!-- author and version -->
<RowDefinition Height="*" />
</Grid.RowDefinitions>
Expand All @@ -109,20 +109,25 @@
<TextBlock Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Height="20"
AutomationProperties.AccessibilityView="Raw"
Text="{x:Bind Name}" />

<TextBlock Grid.Row="1"
Grid.Column="1"
Height="20"
AutomationProperties.AccessibilityView="Raw"
Style="{ThemeResource SecondaryTextBlockStyle}"
Text="{x:Bind Author}" />
Text="{x:Bind Author}"
Visibility="{x:Bind local:Converters.StringNotEmptyToVisibility(Author)}" />

<TextBlock Grid.Row="1"
Grid.Column="2"
Height="20"
AutomationProperties.AccessibilityView="Raw"
Style="{ThemeResource SecondaryTextBlockStyle}"
Text="{x:Bind Version}" />
Text="{x:Bind Version}"
Visibility="{x:Bind local:Converters.StringNotEmptyToVisibility(Version)}" />

</Grid>
</DataTemplate>
Expand Down
10 changes: 9 additions & 1 deletion src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// navigate to the profile next to this one
const auto newSelectedItem{ menuItems.GetAt(index < menuItems.Size() - 1 ? index : index - 1) };
SettingsNav().SelectedItem(newSelectedItem);
_Navigate(newSelectedItem.try_as<MUX::Controls::NavigationViewItem>().Tag().try_as<Editor::ProfileViewModel>(), BreadcrumbSubPage::None, true);
const auto newTag = newSelectedItem.as<MUX::Controls::NavigationViewItem>().Tag();
if (const auto profileViewModel = newTag.try_as<ProfileViewModel>())
{
_Navigate(*profileViewModel, BreadcrumbSubPage::None);
}
else
{
_Navigate(newTag.as<hstring>(), BreadcrumbSubPage::None);
}
}

IObservableVector<IInspectable> MainPage::Breadcrumbs() noexcept
Expand Down
24 changes: 20 additions & 4 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <shellapi.h>
#include <shlwapi.h>
#include <til/latch.h>

using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::Settings;
Expand Down Expand Up @@ -1120,12 +1121,27 @@ void CascadiaSettings::CurrentDefaultTerminal(const Model::DefaultTerminal& term
// but in the future it might be worthwhile to change the code to use list indices instead.
void CascadiaSettings::_refreshDefaultTerminals()
{
if (!_defaultTerminals)
if (_defaultTerminals)
{
auto [defaultTerminals, defaultTerminal] = DefaultTerminal::Available();
_defaultTerminals = winrt::single_threaded_observable_vector(std::move(defaultTerminals));
_currentDefaultTerminal = std::move(defaultTerminal);
return;
}

// This is an extract of extractValueFromTaskWithoutMainThreadAwait
// as DefaultTerminal::Available creates the exact same issue.
std::pair<std::vector<Model::DefaultTerminal>, Model::DefaultTerminal> result{ {}, nullptr };
til::latch latch{ 1 };

std::ignore = [&]() -> winrt::fire_and_forget {
const auto cleanup = wil::scope_exit([&]() {
latch.count_down();
});
co_await winrt::resume_background();
result = DefaultTerminal::Available();
}();

latch.wait();
_defaultTerminals = winrt::single_threaded_observable_vector(std::move(result.first));
_currentDefaultTerminal = std::move(result.second);
}

void CascadiaSettings::ExportFile(winrt::hstring path, winrt::hstring content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ static auto extractValueFromTaskWithoutMainThreadAwait(TTask&& task) -> decltype
til::latch latch{ 1 };

const auto _ = [&]() -> winrt::fire_and_forget {
const auto cleanup = wil::scope_exit([&]() {
latch.count_down();
});
co_await winrt::resume_background();
finalVal.emplace(co_await task);
latch.count_down();
}();

latch.wait();
Expand Down
30 changes: 22 additions & 8 deletions src/cascadia/TerminalSettingsModel/DefaultTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ DefaultTerminal::DefaultTerminal(DelegationConfig::DelegationPackage&& pkg) :

winrt::hstring DefaultTerminal::Name() const
{
return _pkg.terminal.name.empty() ? winrt::hstring{ RS_(L"InboxWindowsConsoleName") } : winrt::hstring{ _pkg.terminal.name };
switch (_pkg.pair.kind)
{
case DelegationConfig::DelegationPairKind::Default:
return RS_(L"DefaultWindowsConsoleName");
case DelegationConfig::DelegationPairKind::Conhost:
return RS_(L"InboxWindowsConsoleName");
default:
return winrt::hstring{ _pkg.info.name };
}
}

winrt::hstring DefaultTerminal::Version() const
{
// If there's no version information... return empty string instead.
const auto& version = _pkg.terminal.version;
const auto& version = _pkg.info.version;
if (DelegationConfig::PkgVersion{} == version)
{
return winrt::hstring{};
Expand All @@ -36,12 +44,20 @@ winrt::hstring DefaultTerminal::Version() const

winrt::hstring DefaultTerminal::Author() const
{
return _pkg.terminal.author.empty() ? winrt::hstring{ RS_(L"InboxWindowsConsoleAuthor") } : winrt::hstring{ _pkg.terminal.author };
switch (_pkg.pair.kind)
{
case DelegationConfig::DelegationPairKind::Default:
return {}; // The "Let Windows decide" option has no author.
case DelegationConfig::DelegationPairKind::Conhost:
return RS_(L"InboxWindowsConsoleAuthor");
default:
return winrt::hstring{ _pkg.info.author };
}
}

winrt::hstring DefaultTerminal::Icon() const
{
return _pkg.terminal.logo.empty() ? winrt::hstring{ L"\uE756" } : winrt::hstring{ _pkg.terminal.logo };
return _pkg.info.logo.empty() ? winrt::hstring{ L"\uE756" } : winrt::hstring{ _pkg.info.logo };
}

std::pair<std::vector<Model::DefaultTerminal>, Model::DefaultTerminal> DefaultTerminal::Available()
Expand Down Expand Up @@ -76,11 +92,9 @@ std::pair<std::vector<Model::DefaultTerminal>, Model::DefaultTerminal> DefaultTe
bool DefaultTerminal::HasCurrent()
{
std::vector<DelegationConfig::DelegationPackage> allPackages;
DelegationConfig::DelegationPackage currentPackage;
DelegationConfig::DelegationPackage currentPackage{ DelegationConfig::DefaultDelegationPair };
LOG_IF_FAILED(DelegationConfig::s_GetAvailablePackages(allPackages, currentPackage));

// Good old conhost has a hardcoded GUID of {00000000-0000-0000-0000-000000000000}.
return currentPackage.terminal.clsid != CLSID{};
return !currentPackage.pair.IsDefault();
}

void DefaultTerminal::Current(const Model::DefaultTerminal& term)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@
<value>Clear scrollback</value>
<comment>A command to clear the part of the buffer above the viewport</comment>
</data>
<data name="DefaultWindowsConsoleName" xml:space="preserve">
<value>Let Windows decide</value>
<comment>This is the default option if a user doesn't choose to override Microsoft's choice of a Terminal.</comment>
</data>
<data name="InboxWindowsConsoleAuthor" xml:space="preserve">
<value>Microsoft Corporation</value>
<comment>Paired with `InboxWindowsConsoleName`, this is the application author... which is us: Microsoft.</comment>
Expand Down
2 changes: 1 addition & 1 deletion src/host/exe/CConsoleHandoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Author(s):
using namespace Microsoft::WRL;

struct __declspec(uuid(__CLSID_CConsoleHandoff))
CConsoleHandoff : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IConsoleHandoff>
CConsoleHandoff : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IConsoleHandoff, IDefaultTerminalMarker>
{
#pragma region IConsoleHandoff
STDMETHODIMP EstablishHandoff(HANDLE server,
Expand Down
3 changes: 1 addition & 2 deletions src/host/exe/exemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ int CALLBACK wWinMain(
{
// Only try to register as a handoff target if we are NOT a part of Windows.
#if TIL_FEATURE_RECEIVEINCOMINGHANDOFF_ENABLED
auto defAppEnabled = false;
if (args.ShouldRunAsComServer() && SUCCEEDED(Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy(defAppEnabled)) && defAppEnabled)
if (args.ShouldRunAsComServer() && Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy())
{
try
{
Expand Down
6 changes: 3 additions & 3 deletions src/host/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Revision History:
#include "ConsoleArguments.hpp"
#include "ApiRoutines.h"

#include "../propslib/DelegationConfig.hpp"
#include "../renderer/base/Renderer.hpp"

#include "../server/DeviceComm.h"
#include "../server/ConDrvDeviceComm.h"

Expand Down Expand Up @@ -71,10 +71,10 @@ class Globals

bool handoffTarget = false;

std::optional<CLSID> handoffConsoleClsid;
std::optional<CLSID> handoffTerminalClsid;
DelegationConfig::DelegationPair delegationPair;
wil::unique_hfile handoffInboxConsoleHandle;
wil::unique_threadpool_wait handoffInboxConsoleExitWait;
bool defaultTerminalMarkerCheckRequired = false;

#ifdef UNIT_TESTING
void EnableConptyModeForTests(std::unique_ptr<Microsoft::Console::Render::VtEngine> vtRenderEngine);
Expand Down
6 changes: 6 additions & 0 deletions src/host/proxy/IConsoleHandoff.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ typedef const CONSOLE_PORTABLE_ATTACH_MSG* PCCONSOLE_PORTABLE_ATTACH_MSG;
[out, system_handle(sh_process)] HANDLE* process);
};

[
object,
uuid(746E6BC0-AB05-4E38-AB14-71E86763141F)
] interface IDefaultTerminalMarker : IUnknown
{
};
73 changes: 31 additions & 42 deletions src/host/srvinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "../renderer/base/renderer.hpp"

#include "../inc/conint.h"
#include "../propslib/DelegationConfig.hpp"

#include "tracing.hpp"

Expand Down Expand Up @@ -64,28 +63,28 @@ try

// Check if this conhost is allowed to delegate its activities to another.
// If so, look up the registered default console handler.
auto isEnabled = false;
if (SUCCEEDED(Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy(isEnabled)) && isEnabled)
if (Globals.delegationPair.IsUndecided() && Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy())
{
IID delegationClsid;
if (SUCCEEDED(DelegationConfig::s_GetDefaultConsoleId(delegationClsid)))
{
Globals.handoffConsoleClsid = delegationClsid;
TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_FoundDelegationConsole",
TraceLoggingGuid(Globals.handoffConsoleClsid.value(), "ConsoleClsid"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}
if (SUCCEEDED(DelegationConfig::s_GetDefaultTerminalId(delegationClsid)))
{
Globals.handoffTerminalClsid = delegationClsid;
TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_FoundDelegationTerminal",
TraceLoggingGuid(Globals.handoffTerminalClsid.value(), "TerminalClsid"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}
Globals.delegationPair = DelegationConfig::s_GetDelegationPair();

TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_FoundDelegationConsole",
TraceLoggingGuid(Globals.delegationPair.console, "ConsoleClsid"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_FoundDelegationTerminal",
TraceLoggingGuid(Globals.delegationPair.terminal, "TerminalClsid"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}
// If we looked up the registered defterm pair, and it was left as the default (missing or {0}),
// AND velocity is enabled for DxD, then we switch the delegation pair to Terminal and
// mark that we should check that class for the marker interface later.
if (Globals.delegationPair.IsDefault() && Microsoft::Console::Internal::DefaultApp::CheckShouldTerminalBeDefault())
{
Globals.delegationPair = DelegationConfig::TerminalDelegationPair;
Globals.defaultTerminalMarkerCheckRequired = true;
}

// Create the accessibility notifier early in the startup process.
Expand Down Expand Up @@ -427,28 +426,18 @@ try
auto& g = ServiceLocator::LocateGlobals();
g.handoffTarget = true;

IID delegationClsid;
if (SUCCEEDED(DelegationConfig::s_GetDefaultConsoleId(delegationClsid)))
{
g.handoffConsoleClsid = delegationClsid;
}
if (SUCCEEDED(DelegationConfig::s_GetDefaultTerminalId(delegationClsid)))
{
g.handoffTerminalClsid = delegationClsid;
}

if (!g.handoffTerminalClsid)
g.delegationPair = DelegationConfig::s_GetDelegationPair();
// We've been handed off to (we're OpenConsole, not conhost).
// If we get here and there's not a custom defterm set, then it must be because
// conhost defaulted to us for DxD. Set up Terminal as the thing to handoff too.
if (!g.delegationPair.IsCustom())
{
TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_ReceiveHandoff_NoTerminal",
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
return E_NOT_SET;
g.delegationPair = DelegationConfig::TerminalDelegationPair;
}

TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_ReceiveHandoff",
TraceLoggingGuid(g.handoffTerminalClsid.value(), "TerminalClsid"),
TraceLoggingGuid(g.delegationPair.terminal, "TerminalClsid"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));

Expand Down Expand Up @@ -509,14 +498,14 @@ try

TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_PrepareToCreateDelegationTerminal",
TraceLoggingGuid(g.handoffTerminalClsid.value(), "TerminalClsid"),
TraceLoggingGuid(g.delegationPair.terminal, "TerminalClsid"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));

RETURN_IF_FAILED(CoCreateInstance(g.handoffTerminalClsid.value(), nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&handoff)));
RETURN_IF_FAILED(CoCreateInstance(g.delegationPair.terminal, nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&handoff)));
TraceLoggingWrite(g_hConhostV2EventTraceProvider,
"SrvInit_CreatedDelegationTerminal",
TraceLoggingGuid(g.handoffTerminalClsid.value(), "TerminalClsid"),
TraceLoggingGuid(g.delegationPair.terminal, "TerminalClsid"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));

Expand Down
4 changes: 2 additions & 2 deletions src/inc/conint.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Microsoft::Console::Internal

namespace DefaultApp
{
[[nodiscard]] HRESULT CheckDefaultAppPolicy(bool& isEnabled) noexcept;
[[nodiscard]] HRESULT CheckShouldTerminalBeDefault(bool& isEnabled) noexcept;
[[nodiscard]] bool CheckDefaultAppPolicy() noexcept;
[[nodiscard]] bool CheckShouldTerminalBeDefault() noexcept;
}
}
Loading

0 comments on commit 9295f95

Please sign in to comment.