From 25527789c0733d9ac5fdbc94c17d513438998dd2 Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Mon, 29 Mar 2021 15:24:43 -0500 Subject: [PATCH 01/11] Reflect testlist change from OS --- src/testlist/sources | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testlist/sources b/src/testlist/sources index de0493fa9de..eaa0a1270a7 100644 --- a/src/testlist/sources +++ b/src/testlist/sources @@ -19,4 +19,4 @@ TESTLIST_REFERENCE_DIRS=\ $(OBJ_PATH)\..\terminal\adapter\ut_adapter\$O \ $(OBJ_PATH)\..\terminal\parser\ut_parser\$O \ $(OBJ_PATH)\..\types\ut_types\$O \ - $(ONECORE_PRIVATE_PATH)\minkernel\lib\$(TARGET_DIRECTORY)\testmetadata\console \ + $(MINKERNEL_PRIVATE_TESTMETADATA_PATH_L)\console \ From b67f40f4c4a11b479547951f32d4695f8899cc6e Mon Sep 17 00:00:00 2001 From: Michael Niksa Date: Mon, 29 Mar 2021 15:28:09 -0500 Subject: [PATCH 02/11] Switch to create function as it will open if exists and create if not. --- src/propslib/DelegationConfig.cpp | 3 ++- src/propslib/RegistrySerialization.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/propslib/DelegationConfig.cpp b/src/propslib/DelegationConfig.cpp index 6a6f8ae9221..cbd0727bb7c 100644 --- a/src/propslib/DelegationConfig.cpp +++ b/src/propslib/DelegationConfig.cpp @@ -302,8 +302,9 @@ try RETURN_IF_NTSTATUS_FAILED(RegistrySerialization::s_OpenConsoleKey(¤tUserKey, &consoleKey)); + // Create method for registry is a "create if not exists, otherwise open" function. wil::unique_hkey startupKey; - RETURN_IF_NTSTATUS_FAILED(RegistrySerialization::s_OpenKey(consoleKey.get(), L"%%Startup", &startupKey)); + RETURN_IF_NTSTATUS_FAILED(RegistrySerialization::s_CreateKey(consoleKey.get(), L"%%Startup", &startupKey)); wil::unique_cotaskmem_string str; RETURN_IF_FAILED(StringFromCLSID(clsid, &str)); diff --git a/src/propslib/RegistrySerialization.cpp b/src/propslib/RegistrySerialization.cpp index 627fbcb5e21..09995d680a1 100644 --- a/src/propslib/RegistrySerialization.cpp +++ b/src/propslib/RegistrySerialization.cpp @@ -227,7 +227,8 @@ NTSTATUS RegistrySerialization::s_OpenConsoleKey(_Out_ HKEY* phCurrentUserKey, _ } // Routine Description: -// - Opens a subkey of the given key +// - Opens a subkey of the given key. Fails if it doesn't exist. +// - NOTE: To create if it doesn't exist and open otherwise, try `s_CreateKey`. // Arguments: // - hKey - Handle to a registry key // - pwszSubKey - String name of sub key @@ -256,6 +257,7 @@ NTSTATUS RegistrySerialization::s_DeleteValue(const HKEY hKey, _In_ PCWSTR const // Routine Description: // - Creates a subkey of the given key // This function creates keys with read/write access. +// - If key already exists, opens existing. // Arguments: // - hKey - Handle to a registry key // - pwszSubKey - String name of sub key From 477c4d9986de0a9157a7a25c60374746ccb935ba Mon Sep 17 00:00:00 2001 From: Dragos Sambotin Date: Mon, 29 Mar 2021 20:39:47 +0000 Subject: [PATCH 03/11] Merged PR 5854784: [Git2Git] When V1 console fails to load, fail upwards to V2 This change introduces a fallback from v1 to v2 for SKUs of Windows that do not compose v1. Related work items: MSFT-29352720 --- src/host/exemain.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/host/exemain.cpp b/src/host/exemain.cpp index 8d338ff48ec..33c5306e89c 100644 --- a/src/host/exemain.cpp +++ b/src/host/exemain.cpp @@ -16,6 +16,7 @@ TRACELOGGING_DEFINE_PROVIDER( (0x770aa552, 0x671a, 0x5e97, 0x57, 0x9b, 0x15, 0x17, 0x09, 0xec, 0x0d, 0xbd), TraceLoggingOptionMicrosoftTelemetry()); +static bool useV2 = true; static bool ConhostV2ForcedInRegistry() { // If the registry value doesn't exist, or exists and is non-zero, we should default to using the v2 console. @@ -23,6 +24,9 @@ static bool ConhostV2ForcedInRegistry() bool fShouldUseConhostV2 = true; PCSTR pszErrorDescription = nullptr; bool fIgnoreError = false; + DWORD dwValue; + DWORD dwType; + DWORD cbValue = sizeof(dwValue); // open HKCU\Console wil::unique_hkey hConsoleSubKey; @@ -30,9 +34,7 @@ static bool ConhostV2ForcedInRegistry() if (ERROR_SUCCESS == lStatus) { // now get the value of the ForceV2 reg value, if it exists - DWORD dwValue; - DWORD dwType; - DWORD cbValue = sizeof(dwValue); + cbValue = sizeof(dwValue); lStatus = RegQueryValueExW(hConsoleSubKey.get(), L"ForceV2", nullptr, @@ -132,6 +134,8 @@ static bool ShouldUseLegacyConhost(const ConsoleArguments& args) { // setup status error hr = HRESULT_FROM_WIN32(GetLastError()); + // fallback to V2 if conhostv1.dll cannot be loaded. + useV2 = true; } if (SUCCEEDED(hr)) @@ -177,6 +181,7 @@ int CALLBACK wWinMain( { if (ShouldUseLegacyConhost(args)) { + useV2 = false; if (args.ShouldCreateServerHandle()) { hr = E_INVALIDARG; @@ -191,7 +196,7 @@ int CALLBACK wWinMain( } } } - else + if(useV2) { if (args.ShouldCreateServerHandle()) { From 295fa382950327724641a7526090cbfb230c5720 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Tue, 30 Mar 2021 13:15:49 -0700 Subject: [PATCH 04/11] Introduce MS.Term.Core.Color to replace W.U.Color for Core/Control/TSM (#9658) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pull request introduces Microsoft.Terminal.Core.Color as an alternative to both Windows.UI.Color and uint32_t/COLORREF in the TerminalCore, ...Control, ...SettingsModel and ...SettingsEditor layers. M.T.C.Color is trivially convertible to/from til::color and therefore to/from COLORREF, W.U.Color, and any other color representation we might need². I've replaced almost every use of W.U.Color and uint32_t-as-color in the above layers, with minor exception¹. The need for this work is twofold. First: We cannot bear a dependency from TerminalCore (which should, on paper, be Windows 7 compatible) on Windows.UI or any other WinRT namespace. This work removes one big dependency on Windows.UI, but it does not go all the way. Second: TerminalCore chose to communicate mostly in packed uint32s (COLORREF), which was inherently lossy and dangerous. ¹ The UI layers (TerminalControl, TerminalApp) still use Windows.UI.Color as they are intimately connected to the UWP XAML UI. ² In the future, we might even be able to *use* the alpha channel... ## PR Checklist * [x] I ran into the need for this when I introduced cursor inversion * [X] Fixes a longstanding itch ## Validation Steps Performed Built and ran all tests for the impacted layers, even the local ones! --- src/cascadia/LocalTests_SettingsModel/pch.h | 2 ++ .../TerminalControl/IControlSettings.idl | 2 +- src/cascadia/TerminalControl/TermControl.cpp | 23 +++++------- src/cascadia/TerminalControl/TermControl.h | 2 +- src/cascadia/TerminalCore/ICoreSettings.idl | 30 ++++++++++++---- src/cascadia/TerminalCore/Terminal.cpp | 14 ++++---- src/cascadia/TerminalCore/Terminal.hpp | 9 ++--- src/cascadia/TerminalCore/pch.h | 6 ++++ .../TerminalSettingsEditor/ColorSchemes.cpp | 36 ++++++++++--------- .../TerminalSettingsEditor/Profiles.idl | 10 +++--- src/cascadia/TerminalSettingsEditor/pch.h | 1 + .../TerminalSettingsModel/ColorScheme.cpp | 14 ++++---- .../TerminalSettingsModel/ColorScheme.h | 26 ++++++++++---- .../TerminalSettingsModel/ColorScheme.idl | 12 +++---- .../TerminalSettingsModel/JsonUtils.h | 26 ++++++++++++++ src/cascadia/TerminalSettingsModel/Profile.h | 10 +++--- .../TerminalSettingsModel/Profile.idl | 10 +++--- .../TerminalSettings.cpp | 26 ++++++-------- .../TerminalSettingsModel/TerminalSettings.h | 22 ++++++------ src/cascadia/TerminalSettingsModel/pch.h | 1 + .../UnitTests_TerminalCore/MockTermSettings.h | 25 ++++++------- src/cascadia/UnitTests_TerminalCore/pch.h | 2 ++ src/cascadia/inc/cppwinrt_utils.h | 12 ------- src/cascadia/ut_app/precomp.h | 2 ++ src/inc/DefaultSettings.h | 12 +++---- src/inc/til/color.h | 17 +++++++++ 26 files changed, 210 insertions(+), 142 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/pch.h b/src/cascadia/LocalTests_SettingsModel/pch.h index 67251267611..53f6145d27e 100644 --- a/src/cascadia/LocalTests_SettingsModel/pch.h +++ b/src/cascadia/LocalTests_SettingsModel/pch.h @@ -56,6 +56,8 @@ Author(s): #include +#include + // Manually include til after we include Windows.Foundation to give it winrt superpowers #include "til.h" diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl index e9063280455..baf63841127 100644 --- a/src/cascadia/TerminalControl/IControlSettings.idl +++ b/src/cascadia/TerminalControl/IControlSettings.idl @@ -51,7 +51,7 @@ namespace Microsoft.Terminal.Control Windows.UI.Xaml.HorizontalAlignment BackgroundImageHorizontalAlignment; Windows.UI.Xaml.VerticalAlignment BackgroundImageVerticalAlignment; - UInt32 SelectionBackground; + Microsoft.Terminal.Core.Color SelectionBackground; TextAntialiasingMode AntialiasingMode; diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 2f7fa3ad1f4..6a743ae2035 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -327,7 +327,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation } // Update DxEngine settings under the lock - _renderEngine->SetSelectionBackground(_settings.SelectionBackground()); + _renderEngine->SetSelectionBackground(til::color{ _settings.SelectionBackground() }); _renderEngine->SetRetroTerminalEffect(_settings.RetroTerminalEffect()); _renderEngine->SetPixelShaderPath(_settings.PixelShaderPath()); @@ -427,7 +427,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation { _InitializeBackgroundBrush(); - COLORREF bg = newSettings.DefaultBackground(); + const auto bg = newSettings.DefaultBackground(); _BackgroundColorChanged(bg); // Apply padding as swapChainPanel's margin @@ -503,12 +503,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // see GH#1082: Initialize background color so we don't get a // fade/flash when _BackgroundColorChanged is called - uint32_t color = _settings.DefaultBackground(); - winrt::Windows::UI::Color bgColor{}; - bgColor.R = GetRValue(color); - bgColor.G = GetGValue(color); - bgColor.B = GetBValue(color); - bgColor.A = 255; + auto bgColor = til::color{ _settings.DefaultBackground() }.with_alpha(0xff); acrylic.FallbackColor(bgColor); acrylic.TintColor(bgColor); @@ -579,7 +574,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - color: The background color to use as a uint32 (aka DWORD COLORREF) // Return Value: // - - winrt::fire_and_forget TermControl::_BackgroundColorChanged(const COLORREF color) + winrt::fire_and_forget TermControl::_BackgroundColorChanged(const til::color color) { til::color newBgColor{ color }; @@ -774,7 +769,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation LOG_IF_FAILED(dxEngine->SetWindowSize({ viewInPixels.Width(), viewInPixels.Height() })); // Update DxEngine's SelectionBackground - dxEngine->SetSelectionBackground(_settings.SelectionBackground()); + dxEngine->SetSelectionBackground(til::color{ _settings.SelectionBackground() }); const auto vp = dxEngine->GetViewportInCharacters(viewInPixels); const auto width = vp.Width(); @@ -1710,7 +1705,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation { _settings.UseAcrylic(false); _InitializeBackgroundBrush(); - COLORREF bg = _settings.DefaultBackground(); + const auto bg = _settings.DefaultBackground(); _BackgroundColorChanged(bg); } else @@ -2528,7 +2523,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation TextBuffer::GenHTML(bufferData, _actualFont.GetUnscaledSize().Y, _actualFont.GetFaceName(), - _settings.DefaultBackground()) : + til::color{ _settings.DefaultBackground() }) : ""; // convert to RTF format @@ -2536,7 +2531,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation TextBuffer::GenRTF(bufferData, _actualFont.GetUnscaledSize().Y, _actualFont.GetFaceName(), - _settings.DefaultBackground()) : + til::color{ _settings.DefaultBackground() }) : ""; if (!_settings.CopyOnSelect()) @@ -3272,7 +3267,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation Windows::Foundation::IReference TermControl::TabColor() noexcept { auto coreColor = _terminal->GetTabColor(); - return coreColor.has_value() ? Windows::Foundation::IReference(coreColor.value()) : nullptr; + return coreColor.has_value() ? Windows::Foundation::IReference(til::color{ coreColor.value() }) : nullptr; } // Method Description: diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index f4391f1f01d..72abee5b5fe 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -200,7 +200,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void _UpdateSettingsOnUIThread(); void _UpdateSystemParameterSettings() noexcept; void _InitializeBackgroundBrush(); - winrt::fire_and_forget _BackgroundColorChanged(const COLORREF color); + winrt::fire_and_forget _BackgroundColorChanged(const til::color color); bool _InitializeTerminal(); void _UpdateFont(const bool initialUpdate = false); void _SetFontSize(int fontSize); diff --git a/src/cascadia/TerminalCore/ICoreSettings.idl b/src/cascadia/TerminalCore/ICoreSettings.idl index b3caf8c9170..a3955fb6e24 100644 --- a/src/cascadia/TerminalCore/ICoreSettings.idl +++ b/src/cascadia/TerminalCore/ICoreSettings.idl @@ -3,6 +3,24 @@ namespace Microsoft.Terminal.Core { + // TerminalCore declares its own Color struct to avoid depending + // on Windows.UI.Color and to avoid passing around unclothed uint32s. + // It is supported by til::color for conversions in and out of WinRT land. + struct Color + { + UInt8 R; + UInt8 G; + UInt8 B; + UInt8 A; + }; + + declare + { + // Forward declare this parameterized specialization so that it lives + // in TerminalCore instead of being flung to the winds of all IDL dependents. + interface Windows.Foundation.IReference; + } + enum CursorStyle { Vintage, @@ -15,9 +33,9 @@ namespace Microsoft.Terminal.Core interface ICoreSettings { - UInt32 DefaultForeground; - UInt32 DefaultBackground; - UInt32 GetColorTableEntry(Int32 index); + Microsoft.Terminal.Core.Color DefaultForeground; + Microsoft.Terminal.Core.Color DefaultBackground; + Microsoft.Terminal.Core.Color GetColorTableEntry(Int32 index); // TODO:MSFT:20642297 - define a sentinel for Infinite Scrollback Int32 HistorySize; Int32 InitialRows; @@ -26,7 +44,7 @@ namespace Microsoft.Terminal.Core Boolean SnapOnInput; Boolean AltGrAliasing; - UInt32 CursorColor; + Microsoft.Terminal.Core.Color CursorColor; CursorStyle CursorShape; UInt32 CursorHeight; String StartingTitle; @@ -35,8 +53,8 @@ namespace Microsoft.Terminal.Core Boolean ForceVTInput; - Windows.Foundation.IReference TabColor; - Windows.Foundation.IReference StartingTabColor; + Windows.Foundation.IReference TabColor; + Windows.Foundation.IReference StartingTabColor; }; } diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 3d0a0b81098..ae64d38a00c 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -114,7 +114,7 @@ void Terminal::UpdateSettings(ICoreSettings settings) { // Set the default background as transparent to prevent the // DX layer from overwriting the background image or acrylic effect - til::color newBackgroundColor{ static_cast(settings.DefaultBackground()) }; + til::color newBackgroundColor{ settings.DefaultBackground() }; _defaultBg = newBackgroundColor.with_alpha(0); _defaultFg = settings.DefaultForeground(); @@ -145,7 +145,7 @@ void Terminal::UpdateSettings(ICoreSettings settings) if (_buffer) { _buffer->GetCursor().SetStyle(settings.CursorHeight(), - settings.CursorColor(), + til::color{ settings.CursorColor() }, cursorShape); } @@ -153,7 +153,7 @@ void Terminal::UpdateSettings(ICoreSettings settings) for (int i = 0; i < 16; i++) { - _colorTable.at(i) = settings.GetColorTableEntry(i); + _colorTable.at(i) = til::color{ settings.GetColorTableEntry(i) }; } _snapOnInput = settings.SnapOnInput(); @@ -170,12 +170,12 @@ void Terminal::UpdateSettings(ICoreSettings settings) } else { - _tabColor = til::color(settings.TabColor().Value() | 0xff000000); + _tabColor = til::color{ settings.TabColor().Value() }.with_alpha(0xff); } if (!_startingTabColor && settings.StartingTabColor()) { - _startingTabColor = til::color(settings.StartingTabColor().Value() | 0xff000000); + _startingTabColor = til::color{ settings.StartingTabColor().Value() }.with_alpha(0xff); } if (_pfnTabColorChanged) @@ -1128,8 +1128,8 @@ void Terminal::SetCursorPositionChangedCallback(std::function pfn) noexc // Method Description: // - Allows setting a callback for when the background color is changed // Arguments: -// - pfn: a function callback that takes a uint32 (DWORD COLORREF) color in the format 0x00BBGGRR -void Terminal::SetBackgroundCallback(std::function pfn) noexcept +// - pfn: a function callback that takes a color +void Terminal::SetBackgroundCallback(std::function pfn) noexcept { _pfnBackgroundColorChanged.swap(pfn); } diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 732e545e55e..231c35a826c 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -198,7 +198,7 @@ class Microsoft::Terminal::Core::Terminal final : void SetCopyToClipboardCallback(std::function pfn) noexcept; void SetScrollPositionChangedCallback(std::function pfn) noexcept; void SetCursorPositionChangedCallback(std::function pfn) noexcept; - void SetBackgroundCallback(std::function pfn) noexcept; + void SetBackgroundCallback(std::function pfn) noexcept; void TaskbarProgressChangedCallback(std::function pfn) noexcept; void SetCursorOn(const bool isOn); @@ -236,7 +236,7 @@ class Microsoft::Terminal::Core::Terminal final : std::function _pfnTitleChanged; std::function _pfnCopyToClipboard; std::function _pfnScrollPositionChanged; - std::function _pfnBackgroundColorChanged; + std::function _pfnBackgroundColorChanged; std::function _pfnCursorPositionChanged; std::function)> _pfnTabColorChanged; std::function _pfnTaskbarProgressChanged; @@ -249,9 +249,10 @@ class Microsoft::Terminal::Core::Terminal final : std::optional _tabColor; std::optional _startingTabColor; + // This is still stored as a COLORREF because it interacts with some code in ConTypes std::array _colorTable; - COLORREF _defaultFg; - COLORREF _defaultBg; + til::color _defaultFg; + til::color _defaultBg; CursorType _defaultCursorShape; bool _screenReversed; mutable Microsoft::Console::Render::BlinkingState _blinkingState; diff --git a/src/cascadia/TerminalCore/pch.h b/src/cascadia/TerminalCore/pch.h index 58fe68df1da..f345f5e680c 100644 --- a/src/cascadia/TerminalCore/pch.h +++ b/src/cascadia/TerminalCore/pch.h @@ -3,5 +3,11 @@ #pragma once +// We're suspending the inclusion of til here so that we can include +// it after some of our C++/WinRT headers. +#define BLOCK_TIL #include #include "winrt/Windows.Foundation.h" + +#include "winrt/Microsoft.Terminal.Core.h" +#include diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 01325767f02..b4c7dcea310 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -219,43 +219,44 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::ColorPickerChanged(IInspectable const& sender, ColorChangedEventArgs const& args) { + const til::color newColor{ args.NewColor() }; if (const auto& picker{ sender.try_as() }) { if (const auto& tag{ picker.Tag() }) { if (const auto index{ tag.try_as() }) { - CurrentColorScheme().SetColorTableEntry(*index, args.NewColor()); + CurrentColorScheme().SetColorTableEntry(*index, newColor); if (index < ColorTableDivider) { - _CurrentNonBrightColorTable.GetAt(*index).Color(args.NewColor()); + _CurrentNonBrightColorTable.GetAt(*index).Color(newColor); } else { - _CurrentBrightColorTable.GetAt(*index - ColorTableDivider).Color(args.NewColor()); + _CurrentBrightColorTable.GetAt(*index - ColorTableDivider).Color(newColor); } } else if (const auto stringTag{ tag.try_as() }) { if (stringTag == ForegroundColorTag) { - CurrentColorScheme().Foreground(args.NewColor()); - _CurrentForegroundColor.Color(args.NewColor()); + CurrentColorScheme().Foreground(newColor); + _CurrentForegroundColor.Color(newColor); } else if (stringTag == BackgroundColorTag) { - CurrentColorScheme().Background(args.NewColor()); - _CurrentBackgroundColor.Color(args.NewColor()); + CurrentColorScheme().Background(newColor); + _CurrentBackgroundColor.Color(newColor); } else if (stringTag == CursorColorTag) { - CurrentColorScheme().CursorColor(args.NewColor()); - _CurrentCursorColor.Color(args.NewColor()); + CurrentColorScheme().CursorColor(newColor); + _CurrentCursorColor.Color(newColor); } else if (stringTag == SelectionBackgroundColorTag) { - CurrentColorScheme().SelectionBackground(args.NewColor()); - _CurrentSelectionBackgroundColor.Color(args.NewColor()); + CurrentColorScheme().SelectionBackground(newColor); + _CurrentSelectionBackgroundColor.Color(newColor); } } } @@ -397,19 +398,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { for (uint8_t i = 0; i < TableColorNames.size(); ++i) { + til::color currentColor{ colorScheme.Table()[i] }; if (i < ColorTableDivider) { - _CurrentNonBrightColorTable.GetAt(i).Color(colorScheme.Table()[i]); + _CurrentNonBrightColorTable.GetAt(i).Color(currentColor); } else { - _CurrentBrightColorTable.GetAt(i - ColorTableDivider).Color(colorScheme.Table()[i]); + _CurrentBrightColorTable.GetAt(i - ColorTableDivider).Color(currentColor); } } - _CurrentForegroundColor.Color(colorScheme.Foreground()); - _CurrentBackgroundColor.Color(colorScheme.Background()); - _CurrentCursorColor.Color(colorScheme.CursorColor()); - _CurrentSelectionBackgroundColor.Color(colorScheme.SelectionBackground()); + _CurrentForegroundColor.Color(til::color{ colorScheme.Foreground() }); + _CurrentBackgroundColor.Color(til::color{ colorScheme.Background() }); + _CurrentCursorColor.Color(til::color{ colorScheme.CursorColor() }); + _CurrentSelectionBackgroundColor.Color(til::color{ colorScheme.SelectionBackground() }); } ColorTableEntry::ColorTableEntry(uint8_t index, Windows::UI::Color color) diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.idl b/src/cascadia/TerminalSettingsEditor/Profiles.idl index a3c94ef2f1d..eca17a75fe4 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.idl +++ b/src/cascadia/TerminalSettingsEditor/Profiles.idl @@ -40,7 +40,7 @@ namespace Microsoft.Terminal.Settings.Editor OBSERVABLE_PROJECTED_PROFILE_SETTING(String, Icon); OBSERVABLE_PROJECTED_PROFILE_SETTING(Microsoft.Terminal.Settings.Model.CloseOnExitMode, CloseOnExit); OBSERVABLE_PROJECTED_PROFILE_SETTING(String, TabTitle); - OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, TabColor); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, TabColor); OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, SuppressApplicationTitle); OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, UseAcrylic); OBSERVABLE_PROJECTED_PROFILE_SETTING(Double, AcrylicOpacity); @@ -60,10 +60,10 @@ namespace Microsoft.Terminal.Settings.Editor OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, ForceFullRepaintRendering); OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, SoftwareRendering); OBSERVABLE_PROJECTED_PROFILE_SETTING(String, ColorSchemeName); - OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, Foreground); - OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, Background); - OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, SelectionBackground); - OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, CursorColor); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, Foreground); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, Background); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, SelectionBackground); + OBSERVABLE_PROJECTED_PROFILE_SETTING(Windows.Foundation.IReference, CursorColor); OBSERVABLE_PROJECTED_PROFILE_SETTING(Int32, HistorySize); OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, SnapOnInput); OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AltGrAliasing); diff --git a/src/cascadia/TerminalSettingsEditor/pch.h b/src/cascadia/TerminalSettingsEditor/pch.h index c75842a182c..dc42b8bf6f4 100644 --- a/src/cascadia/TerminalSettingsEditor/pch.h +++ b/src/cascadia/TerminalSettingsEditor/pch.h @@ -50,6 +50,7 @@ #include #include +#include #include #include diff --git a/src/cascadia/TerminalSettingsModel/ColorScheme.cpp b/src/cascadia/TerminalSettingsModel/ColorScheme.cpp index 8f86297e0d8..ddbe2269e31 100644 --- a/src/cascadia/TerminalSettingsModel/ColorScheme.cpp +++ b/src/cascadia/TerminalSettingsModel/ColorScheme.cpp @@ -42,18 +42,18 @@ static constexpr std::array TableColors = { }; ColorScheme::ColorScheme() : - ColorScheme(L"", DEFAULT_FOREGROUND_WITH_ALPHA, DEFAULT_BACKGROUND_WITH_ALPHA, DEFAULT_CURSOR_COLOR) + ColorScheme(L"", DEFAULT_FOREGROUND, DEFAULT_BACKGROUND, DEFAULT_CURSOR_COLOR) { Utils::InitializeCampbellColorTable(_table); } ColorScheme::ColorScheme(winrt::hstring name) : - ColorScheme(name, DEFAULT_FOREGROUND_WITH_ALPHA, DEFAULT_BACKGROUND_WITH_ALPHA, DEFAULT_CURSOR_COLOR) + ColorScheme(name, DEFAULT_FOREGROUND, DEFAULT_BACKGROUND, DEFAULT_CURSOR_COLOR) { Utils::InitializeCampbellColorTable(_table); } -ColorScheme::ColorScheme(winrt::hstring name, COLORREF defaultFg, COLORREF defaultBg, COLORREF cursorColor) : +ColorScheme::ColorScheme(winrt::hstring name, til::color defaultFg, til::color defaultBg, til::color cursorColor) : _Name{ name }, _Foreground{ defaultFg }, _Background{ defaultBg }, @@ -153,10 +153,10 @@ Json::Value ColorScheme::ToJson() const return json; } -winrt::com_array ColorScheme::Table() const noexcept +winrt::com_array ColorScheme::Table() const noexcept { - winrt::com_array result{ base::checked_cast(_table.size()) }; - std::transform(_table.begin(), _table.end(), result.begin(), [](til::color c) -> Color { return c; }); + winrt::com_array result{ base::checked_cast(_table.size()) }; + std::transform(_table.begin(), _table.end(), result.begin(), [](til::color c) -> winrt::Microsoft::Terminal::Core::Color { return c; }); return result; } @@ -167,7 +167,7 @@ winrt::com_array ColorScheme::Table() const noexcept // - value: the color value we are setting the color table color to // Return Value: // - none -void ColorScheme::SetColorTableEntry(uint8_t index, const winrt::Windows::UI::Color& value) noexcept +void ColorScheme::SetColorTableEntry(uint8_t index, const winrt::Microsoft::Terminal::Core::Color& value) noexcept { THROW_HR_IF(E_INVALIDARG, index > _table.size() - 1); _table[index] = value; diff --git a/src/cascadia/TerminalSettingsModel/ColorScheme.h b/src/cascadia/TerminalSettingsModel/ColorScheme.h index 4bf4d5fb681..a7eed8ce7f5 100644 --- a/src/cascadia/TerminalSettingsModel/ColorScheme.h +++ b/src/cascadia/TerminalSettingsModel/ColorScheme.h @@ -27,6 +27,18 @@ namespace SettingsModelLocalTests class ColorSchemeTests; }; +// Use this macro to quick implement both the getter and setter for a color property. +// This should only be used for color types where there's no logic in the +// getter/setter beyond just accessing/updating the value. +// This takes advantage of til::color +#define WINRT_TERMINAL_COLOR_PROPERTY(name, ...) \ +public: \ + winrt::Microsoft::Terminal::Core::Color name() const noexcept { return _##name; } \ + void name(const winrt::Microsoft::Terminal::Core::Color& value) noexcept { _##name = value; } \ + \ +private: \ + til::color _##name{ __VA_ARGS__ }; + namespace winrt::Microsoft::Terminal::Settings::Model::implementation { struct ColorScheme : ColorSchemeT @@ -34,7 +46,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation public: ColorScheme(); ColorScheme(hstring name); - ColorScheme(hstring name, COLORREF defaultFg, COLORREF defaultBg, COLORREF cursorColor); + ColorScheme(hstring name, til::color defaultFg, til::color defaultBg, til::color cursorColor); com_ptr Copy() const; hstring ToString() @@ -50,16 +62,16 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static std::optional GetNameFromJson(const Json::Value& json); - com_array Table() const noexcept; - void SetColorTableEntry(uint8_t index, const winrt::Windows::UI::Color& value) noexcept; + com_array Table() const noexcept; + void SetColorTableEntry(uint8_t index, const winrt::Microsoft::Terminal::Core::Color& value) noexcept; static bool ValidateColorScheme(const Json::Value& scheme); WINRT_PROPERTY(winrt::hstring, Name); - GETSET_COLORPROPERTY(Foreground); // defined in constructor - GETSET_COLORPROPERTY(Background); // defined in constructor - GETSET_COLORPROPERTY(SelectionBackground); // defined in constructor - GETSET_COLORPROPERTY(CursorColor); // defined in constructor + WINRT_TERMINAL_COLOR_PROPERTY(Foreground); // defined in constructor + WINRT_TERMINAL_COLOR_PROPERTY(Background); // defined in constructor + WINRT_TERMINAL_COLOR_PROPERTY(SelectionBackground); // defined in constructor + WINRT_TERMINAL_COLOR_PROPERTY(CursorColor); // defined in constructor private: std::array _table; diff --git a/src/cascadia/TerminalSettingsModel/ColorScheme.idl b/src/cascadia/TerminalSettingsModel/ColorScheme.idl index f2f5615c3ec..bb812aaac0f 100644 --- a/src/cascadia/TerminalSettingsModel/ColorScheme.idl +++ b/src/cascadia/TerminalSettingsModel/ColorScheme.idl @@ -8,15 +8,15 @@ namespace Microsoft.Terminal.Settings.Model String Name; - Windows.UI.Color Foreground; - Windows.UI.Color Background; - Windows.UI.Color SelectionBackground; - Windows.UI.Color CursorColor; + Microsoft.Terminal.Core.Color Foreground; + Microsoft.Terminal.Core.Color Background; + Microsoft.Terminal.Core.Color SelectionBackground; + Microsoft.Terminal.Core.Color CursorColor; // winrt::com_arrays prevent data binding. // Instead of representing Table as a property, // we expose the getter as a function. - Windows.UI.Color[] Table(); - void SetColorTableEntry(UInt8 index, Windows.UI.Color value); + Microsoft.Terminal.Core.Color[] Table(); + void SetColorTableEntry(UInt8 index, Microsoft.Terminal.Core.Color value); } } diff --git a/src/cascadia/TerminalSettingsModel/JsonUtils.h b/src/cascadia/TerminalSettingsModel/JsonUtils.h index 3721afc8339..1e2f5193bb2 100644 --- a/src/cascadia/TerminalSettingsModel/JsonUtils.h +++ b/src/cascadia/TerminalSettingsModel/JsonUtils.h @@ -438,6 +438,32 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils }; #endif +#ifdef WINRT_Microsoft_Terminal_Core_H + template<> + struct ConversionTrait + { + winrt::Microsoft::Terminal::Core::Color FromJson(const Json::Value& json) const + { + return static_cast(ConversionTrait{}.FromJson(json)); + } + + bool CanConvert(const Json::Value& json) const + { + return ConversionTrait{}.CanConvert(json); + } + + Json::Value ToJson(const winrt::Microsoft::Terminal::Core::Color& val) + { + return ConversionTrait{}.ToJson(val); + } + + std::string TypeDescription() const + { + return ConversionTrait{}.TypeDescription(); + } + }; +#endif + template::type>, typename TOpt = std::optional::type>> struct OptionalConverter { diff --git a/src/cascadia/TerminalSettingsModel/Profile.h b/src/cascadia/TerminalSettingsModel/Profile.h index 3b7efbc67cd..7112ab3cfe4 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.h +++ b/src/cascadia/TerminalSettingsModel/Profile.h @@ -80,7 +80,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::Profile, CloseOnExitMode, CloseOnExit, CloseOnExitMode::Graceful); INHERITABLE_SETTING(Model::Profile, hstring, TabTitle); - INHERITABLE_NULLABLE_SETTING(Model::Profile, Windows::UI::Color, TabColor, nullptr); + INHERITABLE_NULLABLE_SETTING(Model::Profile, Microsoft::Terminal::Core::Color, TabColor, nullptr); INHERITABLE_SETTING(Model::Profile, bool, SuppressApplicationTitle, false); INHERITABLE_SETTING(Model::Profile, bool, UseAcrylic, false); @@ -108,10 +108,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::Profile, hstring, ColorSchemeName, L"Campbell"); - INHERITABLE_NULLABLE_SETTING(Model::Profile, Windows::UI::Color, Foreground, nullptr); - INHERITABLE_NULLABLE_SETTING(Model::Profile, Windows::UI::Color, Background, nullptr); - INHERITABLE_NULLABLE_SETTING(Model::Profile, Windows::UI::Color, SelectionBackground, nullptr); - INHERITABLE_NULLABLE_SETTING(Model::Profile, Windows::UI::Color, CursorColor, nullptr); + INHERITABLE_NULLABLE_SETTING(Model::Profile, Microsoft::Terminal::Core::Color, Foreground, nullptr); + INHERITABLE_NULLABLE_SETTING(Model::Profile, Microsoft::Terminal::Core::Color, Background, nullptr); + INHERITABLE_NULLABLE_SETTING(Model::Profile, Microsoft::Terminal::Core::Color, SelectionBackground, nullptr); + INHERITABLE_NULLABLE_SETTING(Model::Profile, Microsoft::Terminal::Core::Color, CursorColor, nullptr); INHERITABLE_SETTING(Model::Profile, int32_t, HistorySize, DEFAULT_HISTORY_SIZE); INHERITABLE_SETTING(Model::Profile, bool, SnapOnInput, true); diff --git a/src/cascadia/TerminalSettingsModel/Profile.idl b/src/cascadia/TerminalSettingsModel/Profile.idl index a122dcb4a07..9e29da0cb60 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.idl +++ b/src/cascadia/TerminalSettingsModel/Profile.idl @@ -66,7 +66,7 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_PROFILE_SETTING(String, Icon); INHERITABLE_PROFILE_SETTING(CloseOnExitMode, CloseOnExit); INHERITABLE_PROFILE_SETTING(String, TabTitle); - INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, TabColor); + INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, TabColor); INHERITABLE_PROFILE_SETTING(Boolean, SuppressApplicationTitle); INHERITABLE_PROFILE_SETTING(Boolean, UseAcrylic); INHERITABLE_PROFILE_SETTING(Double, AcrylicOpacity); @@ -92,10 +92,10 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_PROFILE_SETTING(Boolean, ForceFullRepaintRendering); INHERITABLE_PROFILE_SETTING(Boolean, SoftwareRendering); INHERITABLE_PROFILE_SETTING(String, ColorSchemeName); - INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, Foreground); - INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, Background); - INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, SelectionBackground); - INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, CursorColor); + INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, Foreground); + INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, Background); + INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, SelectionBackground); + INHERITABLE_PROFILE_SETTING(Windows.Foundation.IReference, CursorColor); INHERITABLE_PROFILE_SETTING(Int32, HistorySize); INHERITABLE_PROFILE_SETTING(Boolean, SnapOnInput); INHERITABLE_PROFILE_SETTING(Boolean, AltGrAliasing); diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 77e52c2a200..73b26cbf349 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -112,7 +112,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation } if (newTerminalArgs.TabColor()) { - settings.StartingTabColor(static_cast(til::color(newTerminalArgs.TabColor().Value()))); + settings.StartingTabColor(winrt::Windows::Foundation::IReference{ til::color{ newTerminalArgs.TabColor().Value() } }); } if (newTerminalArgs.SuppressApplicationTitle()) { @@ -239,7 +239,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation if (profile.TabColor()) { const til::color colorRef{ profile.TabColor().Value() }; - _TabColor = static_cast(colorRef); + _TabColor = static_cast(colorRef); } } @@ -277,44 +277,40 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation _CursorColor = til::color{ scheme.CursorColor() }; const auto table = scheme.Table(); - std::array colorTable{}; - std::transform(table.cbegin(), table.cend(), colorTable.begin(), [](auto&& color) { - return static_cast(til::color{ color }); - }); + std::array colorTable{}; + std::copy(table.cbegin(), table.cend(), colorTable.begin()); ColorTable(colorTable); } - uint32_t TerminalSettings::GetColorTableEntry(int32_t index) noexcept + winrt::Microsoft::Terminal::Core::Color TerminalSettings::GetColorTableEntry(int32_t index) noexcept { return ColorTable().at(index); } - void TerminalSettings::ColorTable(std::array colors) + void TerminalSettings::ColorTable(std::array colors) { _ColorTable = colors; } - std::array TerminalSettings::ColorTable() + std::array TerminalSettings::ColorTable() { auto span = _getColorTableImpl(); - std::array colorTable{}; + std::array colorTable{}; if (span.size() > 0) { - std::transform(span.begin(), span.end(), colorTable.begin(), [](auto&& color) { - return static_cast(til::color{ color }); - }); + std::copy(span.begin(), span.end(), colorTable.begin()); } else { const auto campbellSpan = CampbellColorTable(); std::transform(campbellSpan.begin(), campbellSpan.end(), colorTable.begin(), [](auto&& color) { - return static_cast(til::color{ color }); + return static_cast(til::color{ color }); }); } return colorTable; } - gsl::span TerminalSettings::_getColorTableImpl() + gsl::span TerminalSettings::_getColorTableImpl() { if (_ColorTable.has_value()) { diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index 1f8f44714eb..8346b2afad1 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -50,20 +50,20 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // GetColorTableEntry needs to be implemented manually, to get a // particular value from the array. - uint32_t GetColorTableEntry(int32_t index) noexcept; - void ColorTable(std::array colors); - std::array ColorTable(); + Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept; + void ColorTable(std::array colors); + std::array ColorTable(); - INHERITABLE_SETTING(Model::TerminalSettings, uint32_t, DefaultForeground, DEFAULT_FOREGROUND_WITH_ALPHA); - INHERITABLE_SETTING(Model::TerminalSettings, uint32_t, DefaultBackground, DEFAULT_BACKGROUND_WITH_ALPHA); - INHERITABLE_SETTING(Model::TerminalSettings, uint32_t, SelectionBackground, DEFAULT_FOREGROUND); + INHERITABLE_SETTING(Model::TerminalSettings, til::color, DefaultForeground, DEFAULT_FOREGROUND); + INHERITABLE_SETTING(Model::TerminalSettings, til::color, DefaultBackground, DEFAULT_BACKGROUND); + INHERITABLE_SETTING(Model::TerminalSettings, til::color, SelectionBackground, DEFAULT_FOREGROUND); INHERITABLE_SETTING(Model::TerminalSettings, int32_t, HistorySize, DEFAULT_HISTORY_SIZE); INHERITABLE_SETTING(Model::TerminalSettings, int32_t, InitialRows, 30); INHERITABLE_SETTING(Model::TerminalSettings, int32_t, InitialCols, 80); INHERITABLE_SETTING(Model::TerminalSettings, bool, SnapOnInput, true); INHERITABLE_SETTING(Model::TerminalSettings, bool, AltGrAliasing, true); - INHERITABLE_SETTING(Model::TerminalSettings, uint32_t, CursorColor, DEFAULT_CURSOR_COLOR); + INHERITABLE_SETTING(Model::TerminalSettings, til::color, CursorColor, DEFAULT_CURSOR_COLOR); INHERITABLE_SETTING(Model::TerminalSettings, Microsoft::Terminal::Core::CursorStyle, CursorShape, Core::CursorStyle::Vintage); INHERITABLE_SETTING(Model::TerminalSettings, uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT); INHERITABLE_SETTING(Model::TerminalSettings, hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS); @@ -71,7 +71,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::TerminalSettings, bool, InputServiceWarning, true); INHERITABLE_SETTING(Model::TerminalSettings, bool, FocusFollowMouse, false); - INHERITABLE_SETTING(Model::TerminalSettings, Windows::Foundation::IReference, TabColor, nullptr); + INHERITABLE_SETTING(Model::TerminalSettings, Windows::Foundation::IReference, TabColor, nullptr); // When set, StartingTabColor allows to create a terminal with a "sticky" tab color. // This color is prioritized above the TabColor (that is usually initialized based on profile settings). @@ -81,7 +81,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // TODO: to ensure that this property is not populated during settings reload, // we should consider moving this property to a separate interface, // passed to the terminal only upon creation. - INHERITABLE_SETTING(Model::TerminalSettings, Windows::Foundation::IReference, StartingTabColor, nullptr); + INHERITABLE_SETTING(Model::TerminalSettings, Windows::Foundation::IReference, StartingTabColor, nullptr); // ------------------------ End of Core Settings ----------------------- @@ -121,8 +121,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::TerminalSettings, hstring, PixelShaderPath); private: - std::optional> _ColorTable; - gsl::span _getColorTableImpl(); + std::optional> _ColorTable; + gsl::span _getColorTableImpl(); void _ApplyProfileSettings(const Model::Profile& profile, const Windows::Foundation::Collections::IMapView& schemes); void _ApplyGlobalSettings(const Model::GlobalAppSettings& globalSettings) noexcept; diff --git a/src/cascadia/TerminalSettingsModel/pch.h b/src/cascadia/TerminalSettingsModel/pch.h index 8bedb61ba67..688719cd7f3 100644 --- a/src/cascadia/TerminalSettingsModel/pch.h +++ b/src/cascadia/TerminalSettingsModel/pch.h @@ -54,6 +54,7 @@ TRACELOGGING_DECLARE_PROVIDER(g_hSettingsModelProvider); #include +#include #include #include diff --git a/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h b/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h index 8f93cfa050a..face736ea45 100644 --- a/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h +++ b/src/cascadia/UnitTests_TerminalCore/MockTermSettings.h @@ -26,11 +26,11 @@ namespace TerminalCoreUnitTests int32_t HistorySize() { return _historySize; } int32_t InitialRows() { return _initialRows; } int32_t InitialCols() { return _initialCols; } - uint32_t DefaultForeground() { return COLOR_WHITE; } - uint32_t DefaultBackground() { return COLOR_BLACK; } + til::color DefaultForeground() { return COLOR_WHITE; } + til::color DefaultBackground() { return COLOR_BLACK; } bool SnapOnInput() { return false; } bool AltGrAliasing() { return true; } - uint32_t CursorColor() { return COLOR_WHITE; } + til::color CursorColor() { return COLOR_WHITE; } CursorStyle CursorShape() const noexcept { return CursorStyle::Vintage; } uint32_t CursorHeight() { return 42UL; } winrt::hstring WordDelimiters() { return winrt::hstring(DEFAULT_WORD_DELIMITERS); } @@ -38,21 +38,23 @@ namespace TerminalCoreUnitTests bool FocusFollowMouse() { return _focusFollowMouse; } winrt::hstring StartingTitle() { return _startingTitle; } bool SuppressApplicationTitle() { return _suppressApplicationTitle; } - uint32_t SelectionBackground() { return COLOR_WHITE; } + til::color SelectionBackground() { return COLOR_WHITE; } bool ForceVTInput() { return false; } + winrt::Windows::Foundation::IReference TabColor() { return nullptr; } + winrt::Windows::Foundation::IReference StartingTabColor() { return nullptr; } // other implemented methods - uint32_t GetColorTableEntry(int32_t) const { return 123; } + til::color GetColorTableEntry(int32_t) const { return 123; } // property setters - all unimplemented void HistorySize(int32_t) {} void InitialRows(int32_t) {} void InitialCols(int32_t) {} - void DefaultForeground(uint32_t) {} - void DefaultBackground(uint32_t) {} + void DefaultForeground(til::color) {} + void DefaultBackground(til::color) {} void SnapOnInput(bool) {} void AltGrAliasing(bool) {} - void CursorColor(uint32_t) {} + void CursorColor(til::color) {} void CursorShape(CursorStyle const&) noexcept {} void CursorHeight(uint32_t) {} void WordDelimiters(winrt::hstring) {} @@ -60,11 +62,10 @@ namespace TerminalCoreUnitTests void FocusFollowMouse(bool focusFollowMouse) { _focusFollowMouse = focusFollowMouse; } void StartingTitle(winrt::hstring const& value) { _startingTitle = value; } void SuppressApplicationTitle(bool suppressApplicationTitle) { _suppressApplicationTitle = suppressApplicationTitle; } - void SelectionBackground(uint32_t) {} + void SelectionBackground(til::color) {} void ForceVTInput(bool) {} - - WINRT_PROPERTY(winrt::Windows::Foundation::IReference, TabColor, nullptr); - WINRT_PROPERTY(winrt::Windows::Foundation::IReference, StartingTabColor, nullptr); + void TabColor(const IInspectable&) {} + void StartingTabColor(const IInspectable&) {} private: int32_t _historySize; diff --git a/src/cascadia/UnitTests_TerminalCore/pch.h b/src/cascadia/UnitTests_TerminalCore/pch.h index 799e3c89b3b..68c53c874a4 100644 --- a/src/cascadia/UnitTests_TerminalCore/pch.h +++ b/src/cascadia/UnitTests_TerminalCore/pch.h @@ -40,6 +40,8 @@ Author(s): #include #include +#include + // Manually include til after we include Windows.Foundation to give it winrt superpowers #include "til.h" diff --git a/src/cascadia/inc/cppwinrt_utils.h b/src/cascadia/inc/cppwinrt_utils.h index ee8d6add2ee..d73ad493411 100644 --- a/src/cascadia/inc/cppwinrt_utils.h +++ b/src/cascadia/inc/cppwinrt_utils.h @@ -107,18 +107,6 @@ public: \ private: \ type _##name{ __VA_ARGS__ }; -// Use this macro to quick implement both the getter and setter for a color property. -// This should only be used for color types where there's no logic in the -// getter/setter beyond just accessing/updating the value. -// This takes advantage of til::color -#define GETSET_COLORPROPERTY(name, ...) \ -public: \ - winrt::Windows::UI::Color name() const noexcept { return _##name; } \ - void name(const winrt::Windows::UI::Color& value) noexcept { _##name = value; } \ - \ -private: \ - til::color _##name{ __VA_ARGS__ }; - // Use this macro to quickly implement both the getter and setter for an // observable property. This is similar to the WINRT_PROPERTY macro above, // except this will also raise a PropertyChanged event with the name of the diff --git a/src/cascadia/ut_app/precomp.h b/src/cascadia/ut_app/precomp.h index bb5f4eaa2b6..1dfe0cb53c2 100644 --- a/src/cascadia/ut_app/precomp.h +++ b/src/cascadia/ut_app/precomp.h @@ -45,6 +45,8 @@ Author(s): #include #include +#include + #include "winrtTaefTemplates.hpp" // Manually include til after we include Windows.Foundation to give it winrt superpowers diff --git a/src/inc/DefaultSettings.h b/src/inc/DefaultSettings.h index 6d86a51be7c..a3ef99f6854 100644 --- a/src/inc/DefaultSettings.h +++ b/src/inc/DefaultSettings.h @@ -14,14 +14,12 @@ Author(s): --*/ #pragma once -constexpr COLORREF COLOR_WHITE = 0x00ffffff; -constexpr COLORREF COLOR_BLACK = 0x00000000; +constexpr til::color COLOR_WHITE{ 0xff, 0xff, 0xff }; +constexpr til::color COLOR_BLACK{ 0, 0, 0 }; constexpr COLORREF OPACITY_OPAQUE = 0xff000000; -constexpr COLORREF DEFAULT_FOREGROUND = COLOR_WHITE; -constexpr COLORREF DEFAULT_FOREGROUND_WITH_ALPHA = OPACITY_OPAQUE | DEFAULT_FOREGROUND; -constexpr COLORREF DEFAULT_BACKGROUND = COLOR_BLACK; -constexpr COLORREF DEFAULT_BACKGROUND_WITH_ALPHA = OPACITY_OPAQUE | DEFAULT_BACKGROUND; +constexpr auto DEFAULT_FOREGROUND = COLOR_WHITE; +constexpr auto DEFAULT_BACKGROUND = COLOR_BLACK; constexpr short DEFAULT_HISTORY_SIZE = 9001; @@ -38,7 +36,7 @@ constexpr int DEFAULT_COLS = 120; const std::wstring DEFAULT_PADDING{ L"8, 8, 8, 8" }; const std::wstring DEFAULT_STARTING_DIRECTORY{ L"%USERPROFILE%" }; -constexpr COLORREF DEFAULT_CURSOR_COLOR = COLOR_WHITE; +constexpr auto DEFAULT_CURSOR_COLOR = COLOR_WHITE; constexpr COLORREF DEFAULT_CURSOR_HEIGHT = 25; const std::wstring DEFAULT_WORD_DELIMITERS{ L" ./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?\u2502" }; diff --git a/src/inc/til/color.h b/src/inc/til/color.h index b39682b7f11..76b45802519 100644 --- a/src/inc/til/color.h +++ b/src/inc/til/color.h @@ -158,6 +158,23 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" } #endif +#ifdef WINRT_Microsoft_Terminal_Core_H + constexpr color(const winrt::Microsoft::Terminal::Core::Color& coreColor) : + color(coreColor.R, coreColor.G, coreColor.B, coreColor.A) + { + } + + operator winrt::Microsoft::Terminal::Core::Color() const noexcept + { + winrt::Microsoft::Terminal::Core::Color ret; + ret.R = r; + ret.G = g; + ret.B = b; + ret.A = a; + return ret; + } +#endif + constexpr bool operator==(const til::color& other) const { return abgr == other.abgr; From 69df0de6bf0681f86dce195ba4e75ddd7a55ef59 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 30 Mar 2021 15:37:53 -0500 Subject: [PATCH 05/11] Add a sample outline shader (#9646) I accidentally the whole thing ## References * Heavily inspired by the original rasterbars shader. ## PR Checklist * [x] Closes #9010 --- samples/PixelShaders/Outlines.hlsl | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 samples/PixelShaders/Outlines.hlsl diff --git a/samples/PixelShaders/Outlines.hlsl b/samples/PixelShaders/Outlines.hlsl new file mode 100644 index 00000000000..789f5dc2d22 --- /dev/null +++ b/samples/PixelShaders/Outlines.hlsl @@ -0,0 +1,66 @@ +// A minimal pixel shader that outlines text + +// The terminal graphics as a texture +Texture2D shaderTexture; +SamplerState samplerState; + +// Terminal settings such as the resolution of the texture +cbuffer PixelShaderSettings { + // The number of seconds since the pixel shader was enabled + float Time; + // UI Scale + float Scale; + // Resolution of the shaderTexture + float2 Resolution; + // Background color as rgba + float4 Background; +}; + +// A pixel shader is a program that given a texture coordinate (tex) produces a color. +// tex is an x,y tuple that ranges from 0,0 (top left) to 1,1 (bottom right). +// Just ignore the pos parameter. +float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET +{ + // Read the color value at the current texture coordinate (tex) + // float4 is tuple of 4 floats, rgba + float4 color = shaderTexture.Sample(samplerState, tex); + + // Read the color value at some offset, will be used as shadow. For the best + // effect, read the colors offset on the left, right, top, bottom of this + // fragment, as well as on the corners of this fragment. + // + // You could get away with fewer samples, but the resulting outlines will be + // blurrier. + + //left, right, top, bottom: + float4 leftColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2( 1.0, 0.0)/Resolution.y); + float4 rightColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2(-1.0, 0.0)/Resolution.y); + float4 topColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2( 0.0, 1.0)/Resolution.y); + float4 bottomColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2( 0.0, -1.0)/Resolution.y); + + // Corners + float4 topLeftColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2( 1.0, 1.0)/Resolution.y); + float4 topRightColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2(-1.0, 1.0)/Resolution.y); + float4 bottomLeftColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2( 1.0, -1.0)/Resolution.y); + float4 bottomRightColor = shaderTexture.Sample(samplerState, tex+1.0*Scale*float2(-1.0, -1.0)/Resolution.y); + + + // Now, if any of those adjacent cells has text in it, then the *color vec4 + // will have a non-zero .w (which is used for alpha). Use that alpha value + // to add some black to the current fragment. + // + // This will result in only coloring fragments adjacent to text, but leaving + // background images (for example) untouched. + float3 outlineColor = float3(0, 0, 0); + float4 result = color; + result = result + float4(outlineColor, leftColor.w); + result = result + float4(outlineColor, rightColor.w); + result = result + float4(outlineColor, topColor.w); + result = result + float4(outlineColor, bottomColor.w); + + result = result + float4(outlineColor, topLeftColor.w); + result = result + float4(outlineColor, topRightColor.w); + result = result + float4(outlineColor, bottomLeftColor.w); + result = result + float4(outlineColor, bottomRightColor.w); + return result; +} From 5ab78fcafbe8902544b828f3be0945ea08c68ed4 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 30 Mar 2021 15:38:43 -0500 Subject: [PATCH 06/11] Another fix for the localtests, March 2021 edition (#9660) Broadly, the tests were broken by #7489 because there were no `_startupActions`. They relied on the removed codepath that assumed `wt.exe` always set actions, or `AppCommandlineArgs::ValidateStartupCommands` created one by default. * [x] fixes #9659 * [x] I work here * [x] the tests pass again --- src/cascadia/LocalTests_TerminalApp/TabTests.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp index e2b3ab6b73a..921c7630b7d 100644 --- a/src/cascadia/LocalTests_TerminalApp/TabTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/TabTests.cpp @@ -260,6 +260,15 @@ namespace TerminalAppLocalTests page->Create(); Log::Comment(L"Create()'d the page successfully"); + // Build a NewTab action, to make sure we start with one. The real + // Terminal will always get one from AppCommandlineArgs. + NewTerminalArgs newTerminalArgs{}; + NewTabArgs args{ newTerminalArgs }; + ActionAndArgs newTabAction{ ShortcutAction::NewTab, args }; + // push the arg onto the front + page->_startupActions.Append(newTabAction); + Log::Comment(L"Added a single newTab action"); + auto app = ::winrt::Windows::UI::Xaml::Application::Current(); winrt::TerminalApp::TerminalPage pp = *page; @@ -276,8 +285,9 @@ namespace TerminalAppLocalTests // In the real app, this isn't a problem, but doesn't happen // reliably in the unit tests. Log::Comment(L"Ensure we set the first tab as the selected one."); - auto tab = page->_GetTerminalTabImpl(page->_tabs.GetAt(0)); - page->_tabView.SelectedItem(tab->TabViewItem()); + auto tab = page->_tabs.GetAt(0); + auto tabImpl = page->_GetTerminalTabImpl(tab); + page->_tabView.SelectedItem(tabImpl->TabViewItem()); page->_UpdatedSelectedTab(0); }); VERIFY_SUCCEEDED(result); @@ -601,7 +611,6 @@ namespace TerminalAppLocalTests auto result = RunOnUIThread([&page]() { SplitPaneArgs args{ SplitType::Duplicate }; ActionEventArgs eventArgs{ args }; - // eventArgs.Args(args); page->_HandleSplitPane(nullptr, eventArgs); auto firstTab = page->_GetTerminalTabImpl(page->_tabs.GetAt(0)); From 8f16fdd817b178b9e50825900c3dd5819fec09ec Mon Sep 17 00:00:00 2001 From: Gabriel C <78622729+gabrielconl@users.noreply.github.com> Date: Wed, 31 Mar 2021 00:03:33 +0300 Subject: [PATCH 07/11] Fix rightmost tab corner (#9575) Before and after: ![image](https://user-images.githubusercontent.com/78622729/111928492-710b9000-8abc-11eb-9760-0ecd3eb038fb.png) The bottom right corner appeared without a radius because of the custom padding. --- src/cascadia/TerminalApp/App.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/App.xaml b/src/cascadia/TerminalApp/App.xaml index 77bfe5cec19..88630a11c07 100644 --- a/src/cascadia/TerminalApp/App.xaml +++ b/src/cascadia/TerminalApp/App.xaml @@ -44,8 +44,8 @@ - - 8,0,0,0 + + 8,0,8,0 From 940254dd57c7bb792da2aba96741105b10b53270 Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Tue, 30 Mar 2021 17:43:48 -0500 Subject: [PATCH 08/11] Fix variable shadowing in exemain from bad merge Signed-off-by: Michael Niksa --- src/host/exe/exemain.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/host/exe/exemain.cpp b/src/host/exe/exemain.cpp index 53b21574a13..68057c62a11 100644 --- a/src/host/exe/exemain.cpp +++ b/src/host/exe/exemain.cpp @@ -67,8 +67,6 @@ static bool ConhostV2ForcedInRegistry() if (ERROR_SUCCESS == lStatus) { // now get the value of the ForceV2 reg value, if it exists - DWORD dwValue; - DWORD dwType; cbValue = sizeof(dwValue); lStatus = RegQueryValueExW(hConsoleSubKey.get(), L"ForceV2", From 07c57354710a78ff574e8a9d91b690664d228d80 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Tue, 30 Mar 2021 16:08:53 -0700 Subject: [PATCH 09/11] Move Branding into common props (#9668) --- src/cascadia/ShellExtension/WindowsTerminalShellExt.vcxproj | 1 - src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj | 1 - src/common.build.pre.props | 2 ++ 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/ShellExtension/WindowsTerminalShellExt.vcxproj b/src/cascadia/ShellExtension/WindowsTerminalShellExt.vcxproj index b97bb1e6062..ad10da07a77 100644 --- a/src/cascadia/ShellExtension/WindowsTerminalShellExt.vcxproj +++ b/src/cascadia/ShellExtension/WindowsTerminalShellExt.vcxproj @@ -49,7 +49,6 @@ - - diff --git a/src/common.build.pre.props b/src/common.build.pre.props index 3df286774ed..bbb553640a4 100644 --- a/src/common.build.pre.props +++ b/src/common.build.pre.props @@ -203,4 +203,6 @@ + + From c09472347c5f92317d0d907f87421fd14066537f Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 31 Mar 2021 11:38:25 -0500 Subject: [PATCH 10/11] Add X Macro for fun and for profit (#9667) **Summary of the Pull Request** This PR adds an X Macro for defining our ShortcutActions. This means that you can add the action in one place, and have the macro synthesize all sorts of boilerplate for you! From the `AllShortcutActions.h` file: > For a clearer explanation of how this file should be used, see: > https://en.wikipedia.org/wiki/X_Macro > > Include this file to be able to quickly define some code in the exact same > way for _every single shortcut action_. To use: > > 1. Include this file > 2. Define the ON_ALL_ACTIONS macro with what you want each action to show up > as. Ex: > > #define ON_ALL_ACTIONS(action) void action##Handler(); > > 3. Then, use the ALL_SHORTCUT_ACTIONS macro to get the ON_ALL_ACTIONS marcro > repeated once for every ShortcutAction > > This is used in KeyMapping.idl, ShortcutAction.*, TerminalPage.*, etc. to > reduce the number of places where we must copy-paste boiler-plate code for > each action. This is _NOT_ something that should be used when any individual > case should be customized. **PR Checklist** * [x] Scratches an itch * [x] I work here * [x] Tests passed * [n/a] Requires documentation to be updated **Detailed Description of the Pull Request / Additional comments** Originally I had this blocked as a follow up to #9662. However, I've grown tired after a month of merging main into this branch, and I'm just shipping it separately. It will inevitably conflict with anyone who has actions in flight currently. **Validation Steps Performed** The code still builds exactly as before! --- .../TerminalApp/ShortcutActionDispatch.cpp | 58 +-------------- .../TerminalApp/ShortcutActionDispatch.h | 53 +------------- .../TerminalApp/ShortcutActionDispatch.idl | 52 ++----------- src/cascadia/TerminalApp/TerminalPage.cpp | 50 +------------ src/cascadia/TerminalApp/TerminalPage.h | 51 +------------ .../AllShortcutActions.h | 73 +++++++++++++++++++ .../TerminalSettingsModel/KeyMapping.idl | 56 ++------------ 7 files changed, 98 insertions(+), 295 deletions(-) create mode 100644 src/cascadia/TerminalSettingsModel/AllShortcutActions.h diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp index 3bb2d75bc4c..8b7a15cd312 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp @@ -41,61 +41,9 @@ namespace winrt::TerminalApp::implementation switch (action) { - ACTION_CASE(CopyText); - ACTION_CASE(PasteText); - ACTION_CASE(OpenNewTabDropdown); - ACTION_CASE(DuplicateTab); - ACTION_CASE(OpenSettings); - ACTION_CASE(NewTab); - ACTION_CASE(CloseWindow); - ACTION_CASE(CloseTab); - ACTION_CASE(ClosePane); - ACTION_CASE(ScrollUp); - ACTION_CASE(ScrollDown); - ACTION_CASE(ScrollUpPage); - ACTION_CASE(ScrollDownPage); - ACTION_CASE(ScrollToTop); - ACTION_CASE(ScrollToBottom); - ACTION_CASE(NextTab); - ACTION_CASE(PrevTab); - ACTION_CASE(SendInput); - - case ShortcutAction::SplitVertical: - case ShortcutAction::SplitHorizontal: - case ShortcutAction::SplitPane: - { - _SplitPaneHandlers(*this, eventArgs); - break; - } - - ACTION_CASE(TogglePaneZoom); - ACTION_CASE(SwitchToTab); - ACTION_CASE(ResizePane); - ACTION_CASE(MoveFocus); - ACTION_CASE(AdjustFontSize); - ACTION_CASE(Find); - ACTION_CASE(ResetFontSize); - ACTION_CASE(ToggleShaderEffects); - ACTION_CASE(ToggleFocusMode); - ACTION_CASE(ToggleFullscreen); - ACTION_CASE(ToggleAlwaysOnTop); - ACTION_CASE(ToggleCommandPalette); - ACTION_CASE(SetColorScheme); - ACTION_CASE(SetTabColor); - ACTION_CASE(OpenTabColorPicker); - ACTION_CASE(RenameTab); - ACTION_CASE(OpenTabRenamer); - ACTION_CASE(ExecuteCommandline); - ACTION_CASE(CloseOtherTabs); - ACTION_CASE(CloseTabsAfter); - ACTION_CASE(MoveTab); - ACTION_CASE(TabSearch); - ACTION_CASE(BreakIntoDebugger); - ACTION_CASE(FindMatch); - ACTION_CASE(TogglePaneReadOnly); - ACTION_CASE(NewWindow); - ACTION_CASE(IdentifyWindow); - ACTION_CASE(IdentifyWindows); +#define ON_ALL_ACTIONS(id) ACTION_CASE(id); + ALL_SHORTCUT_ACTIONS +#undef ON_ALL_ACTIONS default: return false; } diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.h b/src/cascadia/TerminalApp/ShortcutActionDispatch.h index f4494e2c3c4..54c59d11ca0 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.h +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.h @@ -5,6 +5,7 @@ #include "ShortcutActionDispatch.g.h" #include "../inc/cppwinrt_utils.h" +#include "../TerminalSettingsModel/AllShortcutActions.h" // fwdecl unittest classes namespace TerminalAppLocalTests @@ -23,55 +24,9 @@ namespace winrt::TerminalApp::implementation bool DoAction(const Microsoft::Terminal::Settings::Model::ActionAndArgs& actionAndArgs); - // clang-format off - DECLARE_ACTION(CopyText); - DECLARE_ACTION(PasteText); - DECLARE_ACTION(OpenNewTabDropdown); - DECLARE_ACTION(DuplicateTab); - DECLARE_ACTION(NewTab); - DECLARE_ACTION(CloseWindow); - DECLARE_ACTION(CloseTab); - DECLARE_ACTION(ClosePane); - DECLARE_ACTION(SwitchToTab); - DECLARE_ACTION(NextTab); - DECLARE_ACTION(PrevTab); - DECLARE_ACTION(SendInput); - DECLARE_ACTION(SplitPane); - DECLARE_ACTION(TogglePaneZoom); - DECLARE_ACTION(AdjustFontSize); - DECLARE_ACTION(ResetFontSize); - DECLARE_ACTION(ScrollUp); - DECLARE_ACTION(ScrollDown); - DECLARE_ACTION(ScrollUpPage); - DECLARE_ACTION(ScrollDownPage); - DECLARE_ACTION(ScrollToTop); - DECLARE_ACTION(ScrollToBottom); - DECLARE_ACTION(OpenSettings); - DECLARE_ACTION(ResizePane); - DECLARE_ACTION(Find); - DECLARE_ACTION(MoveFocus); - DECLARE_ACTION(ToggleShaderEffects); - DECLARE_ACTION(ToggleFocusMode); - DECLARE_ACTION(ToggleFullscreen); - DECLARE_ACTION(ToggleAlwaysOnTop); - DECLARE_ACTION(ToggleCommandPalette); - DECLARE_ACTION(SetColorScheme); - DECLARE_ACTION(SetTabColor); - DECLARE_ACTION(OpenTabColorPicker); - DECLARE_ACTION(RenameTab); - DECLARE_ACTION(OpenTabRenamer); - DECLARE_ACTION(ExecuteCommandline); - DECLARE_ACTION(CloseOtherTabs); - DECLARE_ACTION(CloseTabsAfter); - DECLARE_ACTION(TabSearch); - DECLARE_ACTION(MoveTab); - DECLARE_ACTION(BreakIntoDebugger); - DECLARE_ACTION(FindMatch); - DECLARE_ACTION(TogglePaneReadOnly); - DECLARE_ACTION(NewWindow); - DECLARE_ACTION(IdentifyWindow); - DECLARE_ACTION(IdentifyWindows); - // clang-format on +#define ON_ALL_ACTIONS(action) DECLARE_ACTION(action); + ALL_SHORTCUT_ACTIONS +#undef ON_ALL_ACTIONS private: friend class TerminalAppLocalTests::SettingsTests; diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.idl b/src/cascadia/TerminalApp/ShortcutActionDispatch.idl index 577c7097efc..74d4bed4e42 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.idl +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.idl @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +#include "../TerminalSettingsModel/AllShortcutActions.h" #define ACTION_EVENT(name) event Windows.Foundation.TypedEventHandler name @@ -10,53 +11,10 @@ namespace TerminalApp Boolean DoAction(Microsoft.Terminal.Settings.Model.ActionAndArgs actionAndArgs); - ACTION_EVENT(CopyText); - ACTION_EVENT(PasteText); - ACTION_EVENT(NewTab); - ACTION_EVENT(OpenNewTabDropdown); - ACTION_EVENT(DuplicateTab); - ACTION_EVENT(CloseWindow); - ACTION_EVENT(CloseTab); - ACTION_EVENT(ClosePane); - ACTION_EVENT(SwitchToTab); - ACTION_EVENT(NextTab); - ACTION_EVENT(PrevTab); - ACTION_EVENT(SendInput); - ACTION_EVENT(SplitPane); - ACTION_EVENT(TogglePaneZoom); - ACTION_EVENT(AdjustFontSize); - ACTION_EVENT(ResetFontSize); - ACTION_EVENT(ScrollUp); - ACTION_EVENT(ScrollDown); - ACTION_EVENT(ScrollUpPage); - ACTION_EVENT(ScrollDownPage); - ACTION_EVENT(ScrollToTop); - ACTION_EVENT(ScrollToBottom); - ACTION_EVENT(OpenSettings); - ACTION_EVENT(ResizePane); - ACTION_EVENT(Find); - ACTION_EVENT(MoveFocus); - ACTION_EVENT(ToggleShaderEffects); - ACTION_EVENT(ToggleFocusMode); - ACTION_EVENT(ToggleFullscreen); - ACTION_EVENT(ToggleAlwaysOnTop); - ACTION_EVENT(ToggleCommandPalette); - ACTION_EVENT(SetColorScheme); - ACTION_EVENT(SetTabColor); - ACTION_EVENT(OpenTabColorPicker); - ACTION_EVENT(RenameTab); - ACTION_EVENT(OpenTabRenamer); - ACTION_EVENT(ExecuteCommandline); - ACTION_EVENT(CloseOtherTabs); - ACTION_EVENT(CloseTabsAfter); - ACTION_EVENT(TabSearch); - ACTION_EVENT(MoveTab); - ACTION_EVENT(BreakIntoDebugger); - ACTION_EVENT(FindMatch); - ACTION_EVENT(TogglePaneReadOnly); - ACTION_EVENT(NewWindow); - ACTION_EVENT(IdentifyWindow); - ACTION_EVENT(IdentifyWindows); + // When adding a new action, add them to AllShortcutActions.h! + #define ON_ALL_ACTIONS(action) ACTION_EVENT(action); + ALL_SHORTCUT_ACTIONS + #undef ON_ALL_ACTIONS } } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 7afd30ce9aa..05b7d6c0745 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -949,53 +949,9 @@ namespace winrt::TerminalApp::implementation // Hook up the ShortcutActionDispatch object's events to our handlers. // They should all be hooked up here, regardless of whether or not // there's an actual keychord for them. - HOOKUP_ACTION(OpenNewTabDropdown); - HOOKUP_ACTION(DuplicateTab); - HOOKUP_ACTION(CloseTab); - HOOKUP_ACTION(ClosePane); - HOOKUP_ACTION(CloseWindow); - HOOKUP_ACTION(ScrollUp); - HOOKUP_ACTION(ScrollDown); - HOOKUP_ACTION(NextTab); - HOOKUP_ACTION(PrevTab); - HOOKUP_ACTION(SendInput); - HOOKUP_ACTION(SplitPane); - HOOKUP_ACTION(TogglePaneZoom); - HOOKUP_ACTION(ScrollUpPage); - HOOKUP_ACTION(ScrollDownPage); - HOOKUP_ACTION(ScrollToTop); - HOOKUP_ACTION(ScrollToBottom); - HOOKUP_ACTION(OpenSettings); - HOOKUP_ACTION(PasteText); - HOOKUP_ACTION(NewTab); - HOOKUP_ACTION(SwitchToTab); - HOOKUP_ACTION(ResizePane); - HOOKUP_ACTION(MoveFocus); - HOOKUP_ACTION(CopyText); - HOOKUP_ACTION(AdjustFontSize); - HOOKUP_ACTION(Find); - HOOKUP_ACTION(ResetFontSize); - HOOKUP_ACTION(ToggleShaderEffects); - HOOKUP_ACTION(ToggleFocusMode); - HOOKUP_ACTION(ToggleFullscreen); - HOOKUP_ACTION(ToggleAlwaysOnTop); - HOOKUP_ACTION(ToggleCommandPalette); - HOOKUP_ACTION(SetColorScheme); - HOOKUP_ACTION(SetTabColor); - HOOKUP_ACTION(OpenTabColorPicker); - HOOKUP_ACTION(RenameTab); - HOOKUP_ACTION(OpenTabRenamer); - HOOKUP_ACTION(ExecuteCommandline); - HOOKUP_ACTION(CloseOtherTabs); - HOOKUP_ACTION(CloseTabsAfter); - HOOKUP_ACTION(TabSearch); - HOOKUP_ACTION(MoveTab); - HOOKUP_ACTION(BreakIntoDebugger); - HOOKUP_ACTION(FindMatch); - HOOKUP_ACTION(TogglePaneReadOnly); - HOOKUP_ACTION(NewWindow); - HOOKUP_ACTION(IdentifyWindow); - HOOKUP_ACTION(IdentifyWindows); +#define ON_ALL_ACTIONS(action) HOOKUP_ACTION(action); + ALL_SHORTCUT_ACTIONS +#undef ON_ALL_ACTIONS } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 70814088b99..1a6f4278a97 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -313,54 +313,9 @@ namespace winrt::TerminalApp::implementation #pragma region ActionHandlers // These are all defined in AppActionHandlers.cpp - DECLARE_ACTION_HANDLER(OpenNewTabDropdown); - DECLARE_ACTION_HANDLER(DuplicateTab); - DECLARE_ACTION_HANDLER(CloseTab); - DECLARE_ACTION_HANDLER(ClosePane); - DECLARE_ACTION_HANDLER(ScrollUp); - DECLARE_ACTION_HANDLER(ScrollDown); - DECLARE_ACTION_HANDLER(NextTab); - DECLARE_ACTION_HANDLER(PrevTab); - DECLARE_ACTION_HANDLER(SendInput); - DECLARE_ACTION_HANDLER(SplitPane); - DECLARE_ACTION_HANDLER(TogglePaneZoom); - DECLARE_ACTION_HANDLER(ScrollUpPage); - DECLARE_ACTION_HANDLER(ScrollDownPage); - DECLARE_ACTION_HANDLER(ScrollToTop); - DECLARE_ACTION_HANDLER(ScrollToBottom); - DECLARE_ACTION_HANDLER(OpenSettings); - DECLARE_ACTION_HANDLER(PasteText); - DECLARE_ACTION_HANDLER(NewTab); - DECLARE_ACTION_HANDLER(SwitchToTab); - DECLARE_ACTION_HANDLER(ResizePane); - DECLARE_ACTION_HANDLER(MoveFocus); - DECLARE_ACTION_HANDLER(CopyText); - DECLARE_ACTION_HANDLER(CloseWindow); - DECLARE_ACTION_HANDLER(AdjustFontSize); - DECLARE_ACTION_HANDLER(Find); - DECLARE_ACTION_HANDLER(ResetFontSize); - DECLARE_ACTION_HANDLER(ToggleShaderEffects); - DECLARE_ACTION_HANDLER(ToggleFocusMode); - DECLARE_ACTION_HANDLER(ToggleFullscreen); - DECLARE_ACTION_HANDLER(ToggleAlwaysOnTop); - DECLARE_ACTION_HANDLER(SetColorScheme); - DECLARE_ACTION_HANDLER(SetTabColor); - DECLARE_ACTION_HANDLER(OpenTabColorPicker); - DECLARE_ACTION_HANDLER(RenameTab); - DECLARE_ACTION_HANDLER(OpenTabRenamer); - DECLARE_ACTION_HANDLER(ExecuteCommandline); - DECLARE_ACTION_HANDLER(ToggleCommandPalette); - DECLARE_ACTION_HANDLER(CloseOtherTabs); - DECLARE_ACTION_HANDLER(CloseTabsAfter); - DECLARE_ACTION_HANDLER(TabSearch); - DECLARE_ACTION_HANDLER(MoveTab); - DECLARE_ACTION_HANDLER(BreakIntoDebugger); - DECLARE_ACTION_HANDLER(FindMatch); - DECLARE_ACTION_HANDLER(TogglePaneReadOnly); - DECLARE_ACTION_HANDLER(NewWindow); - DECLARE_ACTION_HANDLER(IdentifyWindow); - DECLARE_ACTION_HANDLER(IdentifyWindows); - // Make sure to hook new actions up in _RegisterActionCallbacks! +#define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action); + ALL_SHORTCUT_ACTIONS +#undef ON_ALL_ACTIONS #pragma endregion friend class TerminalAppLocalTests::TabTests; diff --git a/src/cascadia/TerminalSettingsModel/AllShortcutActions.h b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h new file mode 100644 index 00000000000..b5b40252efd --- /dev/null +++ b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +// For a clearer explanation of how this file should be used, see: +// https://en.wikipedia.org/wiki/X_Macro +// +// Include this file to be able to quickly define some code in the exact same +// way for _every single shortcut action_. To use: +// +// 1. Include this file +// 2. Define the ON_ALL_ACTIONS macro with what you want each action to show up +// as. Ex: +// +// #define ON_ALL_ACTIONS(action) void action##Handler(); +// +// 3. Then, use the ALL_SHORTCUT_ACTIONS macro to get the ON_ALL_ACTIONS macro +// repeated once for every ShortcutAction +// +// This is used in KeyMapping.idl, ShortcutAction.*, TerminalPage.*, etc. to +// reduce the number of places where we must copy-paste boiler-plate code for +// each action. This is _NOT_ something that should be used when any individual +// case should be customized. + +#define ALL_SHORTCUT_ACTIONS \ + ON_ALL_ACTIONS(CopyText) \ + ON_ALL_ACTIONS(PasteText) \ + ON_ALL_ACTIONS(OpenNewTabDropdown) \ + ON_ALL_ACTIONS(DuplicateTab) \ + ON_ALL_ACTIONS(NewTab) \ + ON_ALL_ACTIONS(CloseWindow) \ + ON_ALL_ACTIONS(CloseTab) \ + ON_ALL_ACTIONS(ClosePane) \ + ON_ALL_ACTIONS(NextTab) \ + ON_ALL_ACTIONS(PrevTab) \ + ON_ALL_ACTIONS(SendInput) \ + ON_ALL_ACTIONS(SplitPane) \ + ON_ALL_ACTIONS(TogglePaneZoom) \ + ON_ALL_ACTIONS(SwitchToTab) \ + ON_ALL_ACTIONS(AdjustFontSize) \ + ON_ALL_ACTIONS(ResetFontSize) \ + ON_ALL_ACTIONS(ScrollUp) \ + ON_ALL_ACTIONS(ScrollDown) \ + ON_ALL_ACTIONS(ScrollUpPage) \ + ON_ALL_ACTIONS(ScrollDownPage) \ + ON_ALL_ACTIONS(ScrollToTop) \ + ON_ALL_ACTIONS(ScrollToBottom) \ + ON_ALL_ACTIONS(ResizePane) \ + ON_ALL_ACTIONS(MoveFocus) \ + ON_ALL_ACTIONS(Find) \ + ON_ALL_ACTIONS(ToggleShaderEffects) \ + ON_ALL_ACTIONS(ToggleFocusMode) \ + ON_ALL_ACTIONS(ToggleFullscreen) \ + ON_ALL_ACTIONS(ToggleAlwaysOnTop) \ + ON_ALL_ACTIONS(OpenSettings) \ + ON_ALL_ACTIONS(SetColorScheme) \ + ON_ALL_ACTIONS(SetTabColor) \ + ON_ALL_ACTIONS(OpenTabColorPicker) \ + ON_ALL_ACTIONS(RenameTab) \ + ON_ALL_ACTIONS(OpenTabRenamer) \ + ON_ALL_ACTIONS(ExecuteCommandline) \ + ON_ALL_ACTIONS(ToggleCommandPalette) \ + ON_ALL_ACTIONS(CloseOtherTabs) \ + ON_ALL_ACTIONS(CloseTabsAfter) \ + ON_ALL_ACTIONS(TabSearch) \ + ON_ALL_ACTIONS(MoveTab) \ + ON_ALL_ACTIONS(BreakIntoDebugger) \ + ON_ALL_ACTIONS(TogglePaneReadOnly) \ + ON_ALL_ACTIONS(FindMatch) \ + ON_ALL_ACTIONS(NewWindow) \ + ON_ALL_ACTIONS(IdentifyWindow) \ + ON_ALL_ACTIONS(IdentifyWindows) diff --git a/src/cascadia/TerminalSettingsModel/KeyMapping.idl b/src/cascadia/TerminalSettingsModel/KeyMapping.idl index a6669c6b515..540c74dea50 100644 --- a/src/cascadia/TerminalSettingsModel/KeyMapping.idl +++ b/src/cascadia/TerminalSettingsModel/KeyMapping.idl @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +#include "AllShortcutActions.h" + import "ActionArgs.idl"; namespace Microsoft.Terminal.Settings.Model @@ -8,55 +10,11 @@ namespace Microsoft.Terminal.Settings.Model enum ShortcutAction { Invalid = 0, - CopyText, - PasteText, - OpenNewTabDropdown, - DuplicateTab, - NewTab, - CloseWindow, - CloseTab, - ClosePane, - NextTab, - PrevTab, - SplitVertical, - SplitHorizontal, - SendInput, - SplitPane, - TogglePaneZoom, - SwitchToTab, - AdjustFontSize, - ResetFontSize, - ScrollUp, - ScrollDown, - ScrollUpPage, - ScrollDownPage, - ScrollToTop, - ScrollToBottom, - ResizePane, - MoveFocus, - Find, - ToggleShaderEffects, - ToggleFocusMode, - ToggleFullscreen, - ToggleAlwaysOnTop, - OpenSettings, - SetColorScheme, - SetTabColor, - OpenTabColorPicker, - RenameTab, - OpenTabRenamer, - ExecuteCommandline, - ToggleCommandPalette, - CloseOtherTabs, - CloseTabsAfter, - TabSearch, - MoveTab, - BreakIntoDebugger, - TogglePaneReadOnly, - FindMatch, - NewWindow, - IdentifyWindow, - IdentifyWindows + + // When adding a new action, add them to AllShortcutActions.h! + #define ON_ALL_ACTIONS(action) action, + ALL_SHORTCUT_ACTIONS + #undef ON_ALL_ACTIONS }; [default_interface] runtimeclass ActionAndArgs { From fd99b012f55e677d18955be7324eeb25c95bf173 Mon Sep 17 00:00:00 2001 From: Kayla Cinnamon Date: Wed, 31 Mar 2021 11:50:40 -0700 Subject: [PATCH 11/11] Remove default terminal item from SUI (#9671) Looks like we forgot to comment out the Default terminal setting from the UI. Commented it out here. --- src/cascadia/TerminalSettingsEditor/Launch.xaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cascadia/TerminalSettingsEditor/Launch.xaml b/src/cascadia/TerminalSettingsEditor/Launch.xaml index c75f4d78812..465895b89a7 100644 --- a/src/cascadia/TerminalSettingsEditor/Launch.xaml +++ b/src/cascadia/TerminalSettingsEditor/Launch.xaml @@ -70,6 +70,8 @@ + +