Skip to content

Commit

Permalink
background image works now
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Dec 1, 2020
1 parent f4dd69a commit 235bbd7
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/AppAppearanceConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppAppearanceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace winrt::TerminalApp::implementation
struct AppAppearanceConfig : AppAppearanceConfigT<AppAppearanceConfig>
{
AppAppearanceConfig() = default;
void ApplyColorScheme(const Microsoft::Terminal::Settings::Model::ColorScheme& scheme);

GETSET_PROPERTY(hstring, ColorSchemeName);
GETSET_PROPERTY(uint32_t, DefaultForeground, DEFAULT_FOREGROUND_WITH_ALPHA);
Expand Down
10 changes: 8 additions & 2 deletions src/cascadia/TerminalApp/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,14 @@ namespace winrt::TerminalApp::implementation
{
auto unfocusedConfig = winrt::make_self<implementation::AppAppearanceConfig>();

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() });
Expand All @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::wstring>(path.c_str()) };
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/AppearanceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/AppearanceConfig.idl
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ namespace Microsoft.Terminal.Settings.Model
Boolean HasBackgroundImagePath();
void ClearBackgroundImagePath();
String BackgroundImagePath;
String ExpandedBackgroundImagePath { get; };
}
}

1 comment on commit 235bbd7

@github-actions

This comment was marked as outdated.

Please sign in to comment.