diff --git a/src/cascadia/TerminalApp/AppAppearanceConfig.cpp b/src/cascadia/TerminalApp/AppAppearanceConfig.cpp index 29845d8eb5b..df2aaf5fcff 100644 --- a/src/cascadia/TerminalApp/AppAppearanceConfig.cpp +++ b/src/cascadia/TerminalApp/AppAppearanceConfig.cpp @@ -12,4 +12,11 @@ using namespace winrt::Microsoft::Terminal::TerminalControl; namespace winrt::TerminalApp::implementation { + void AppAppearanceConfig::ApplyColorScheme(const Microsoft::Terminal::Settings::Model::ColorScheme& scheme) + { + _DefaultForeground = til::color{ scheme.Foreground() }; + _DefaultBackground = til::color{ scheme.Background() }; + _SelectionBackground = til::color{ scheme.SelectionBackground() }; + _CursorColor = til::color{ scheme.CursorColor() }; + } } diff --git a/src/cascadia/TerminalApp/AppAppearanceConfig.h b/src/cascadia/TerminalApp/AppAppearanceConfig.h index 9900d28fec7..a26a81e53cc 100644 --- a/src/cascadia/TerminalApp/AppAppearanceConfig.h +++ b/src/cascadia/TerminalApp/AppAppearanceConfig.h @@ -12,6 +12,7 @@ namespace winrt::TerminalApp::implementation struct AppAppearanceConfig : AppAppearanceConfigT { AppAppearanceConfig() = default; + void ApplyColorScheme(const Microsoft::Terminal::Settings::Model::ColorScheme& scheme); GETSET_PROPERTY(hstring, ColorSchemeName); GETSET_PROPERTY(uint32_t, DefaultForeground, DEFAULT_FOREGROUND_WITH_ALPHA); diff --git a/src/cascadia/TerminalApp/TerminalSettings.cpp b/src/cascadia/TerminalApp/TerminalSettings.cpp index 83d07ce47d3..48c6cd30c7d 100644 --- a/src/cascadia/TerminalApp/TerminalSettings.cpp +++ b/src/cascadia/TerminalApp/TerminalSettings.cpp @@ -161,8 +161,14 @@ namespace winrt::TerminalApp::implementation { auto unfocusedConfig = winrt::make_self(); - unfocusedConfig->ColorSchemeName(profile.UnfocusedConfig().ColorSchemeName()); unfocusedConfig->CursorShape(profile.UnfocusedConfig().CursorShape()); + if (!profile.UnfocusedConfig().ColorSchemeName().empty()) + { + if (const auto scheme = schemes.TryLookup(profile.UnfocusedConfig().ColorSchemeName())) + { + unfocusedConfig->ApplyColorScheme(scheme); + } + } if (profile.UnfocusedConfig().Background()) { unfocusedConfig->DefaultBackground(til::color{ profile.UnfocusedConfig().Background().Value() }); @@ -181,7 +187,7 @@ namespace winrt::TerminalApp::implementation } if (!profile.UnfocusedConfig().BackgroundImagePath().empty()) { - unfocusedConfig->BackgroundImage(profile.UnfocusedConfig().BackgroundImagePath()); + unfocusedConfig->BackgroundImage(profile.UnfocusedConfig().ExpandedBackgroundImagePath()); } _UnfocusedConfig = *unfocusedConfig; } diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 9612eadf9bb..b4efc67bec4 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -337,6 +337,28 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation co_return; } + if (!newAppearance.BackgroundImage().empty()) + { + Windows::Foundation::Uri imageUri{ newAppearance.BackgroundImage() }; + + // Note that BitmapImage handles the image load asynchronously, + // which is especially important since the image + // may well be both large and somewhere out on the + // internet. + Media::Imaging::BitmapImage image(imageUri); + BackgroundImage().Source(image); + + // Apply stretch, opacity and alignment settings + BackgroundImage().Stretch(_settings.BackgroundImageStretchMode()); + BackgroundImage().Opacity(_settings.BackgroundImageOpacity()); + BackgroundImage().HorizontalAlignment(_settings.BackgroundImageHorizontalAlignment()); + BackgroundImage().VerticalAlignment(_settings.BackgroundImageVerticalAlignment()); + } + else + { + BackgroundImage().Source(nullptr); + } + // Update our control settings COLORREF bg = newAppearance.DefaultBackground(); _BackgroundColorChanged(bg); diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index 244b6c6756f..44b24ed0033 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -188,6 +188,36 @@ void Terminal::UpdateAppearance(IAppearance appearance) { _defaultFg = appearance.DefaultForeground(); _defaultBg = appearance.DefaultBackground(); + + CursorType cursorShape = CursorType::VerticalBar; + switch (appearance.CursorShape()) + { + case CursorStyle::Underscore: + cursorShape = CursorType::Underscore; + break; + case CursorStyle::FilledBox: + cursorShape = CursorType::FullBox; + break; + case CursorStyle::EmptyBox: + cursorShape = CursorType::EmptyBox; + break; + case CursorStyle::Vintage: + cursorShape = CursorType::Legacy; + break; + default: + case CursorStyle::Bar: + cursorShape = CursorType::VerticalBar; + break; + } + + if (_buffer) + { + _buffer->GetCursor().SetStyle(GetCursorHeight(), + GetCursorColor(), + cursorShape); + } + + _defaultCursorShape = cursorShape; } // Method Description: diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index 031cb5a44d4..6c20e74e893 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -33,3 +33,33 @@ void AppearanceConfig::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, CursorShapeKey, _CursorShape); JsonUtils::GetValueForKey(json, BackgroundImageKey, _BackgroundImagePath); } + +// NOTE: This is just placeholder for now, eventually the path will no longer be expanded in the settings model +winrt::hstring AppearanceConfig::ExpandedBackgroundImagePath() +{ + const auto path{ BackgroundImagePath() }; + if (path.empty()) + { + return path; + } + // checks if the user would like to copy their desktop wallpaper + // if so, replaces the path with the desktop wallpaper's path + else if (path == L"desktopWallpaper") + { + WCHAR desktopWallpaper[MAX_PATH]; + + // "The returned string will not exceed MAX_PATH characters" as of 2020 + if (SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, desktopWallpaper, SPIF_UPDATEINIFILE)) + { + return winrt::hstring{ (desktopWallpaper) }; + } + else + { + return winrt::hstring{ L"" }; + } + } + else + { + return winrt::hstring{ wil::ExpandEnvironmentStringsW(path.c_str()) }; + } +} diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.h b/src/cascadia/TerminalSettingsModel/AppearanceConfig.h index ee18f223c40..bb06f636c9a 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.h +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.h @@ -17,6 +17,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation AppearanceConfig(); void LayerJson(const Json::Value& json); + winrt::hstring ExpandedBackgroundImagePath(); GETSET_SETTING(hstring, ColorSchemeName, L"Campbell"); GETSET_NULLABLE_SETTING(Windows::UI::Color, Foreground, nullptr); diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.idl b/src/cascadia/TerminalSettingsModel/AppearanceConfig.idl index 1cea97606cb..84d21b14da1 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.idl +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.idl @@ -33,5 +33,6 @@ namespace Microsoft.Terminal.Settings.Model Boolean HasBackgroundImagePath(); void ClearBackgroundImagePath(); String BackgroundImagePath; + String ExpandedBackgroundImagePath { get; }; } }