Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto detect background image #7849

Merged
22 commits merged into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ RSHIFT
rx
serializer
SIZENS
GETDESKWALLPAPER
UPDATEINIFILE
spsc
STDCPP
syscall
Expand Down
23 changes: 23 additions & 0 deletions src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace SettingsModelLocalTests
TEST_METHOD(TestHelperFunctions);

TEST_METHOD(TestProfileBackgroundImageWithEnvVar);
TEST_METHOD(TestProfileBackgroundImageWithDesktopWallpaper);

TEST_METHOD(TestCloseOnExitParsing);
TEST_METHOD(TestCloseOnExitCompatibilityShim);
Expand Down Expand Up @@ -1400,6 +1401,28 @@ namespace SettingsModelLocalTests
VERIFY_ARE_NOT_EQUAL(0u, settings->_profiles.Size());
VERIFY_ARE_EQUAL(expectedPath, settings->_profiles.GetAt(0).ExpandedBackgroundImagePath());
}
void DeserializationTests::TestProfileBackgroundImageWithDesktopWallpaper()
bennettnicholas marked this conversation as resolved.
Show resolved Hide resolved
{
const winrt::hstring expectedBackgroundImagePath{ winrt::to_hstring("DesktopWallpaper") };

const std::string settingsJson{ R"(
{
"profiles": [
{
"name": "profile0",
"backgroundImage": "DesktopWallpaper"
}
]
})" };

VerifyParseSucceeded(settingsJson);

auto settings = winrt::make_self<implementation::CascadiaSettings>();
settings->_ParseJsonString(settingsJson, false);
settings->LayerJson(settings->_userSettings);
VERIFY_ARE_EQUAL(expectedBackgroundImagePath, settings->_profiles.GetAt(0).BackgroundImagePath());
VERIFY_ARE_NOT_EQUAL(expectedBackgroundImagePath, settings->_profiles.GetAt(0).ExpandedBackgroundImagePath());
}
void DeserializationTests::TestCloseOnExitParsing()
{
const std::string settingsJson{ R"(
Expand Down
27 changes: 25 additions & 2 deletions src/cascadia/TerminalSettingsModel/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static constexpr std::string_view RetroTerminalEffectKey{ "experimental.retroTer
static constexpr std::string_view AntialiasingModeKey{ "antialiasingMode" };
static constexpr std::string_view TabColorKey{ "tabColor" };

static const winrt::hstring DesktopWallpaperEnum{ L"DesktopWallpaper" };

Profile::Profile()
{
}
Expand Down Expand Up @@ -244,17 +246,38 @@ void Profile::LayerJson(const Json::Value& json)
}

// Method Description:
// - Either Returns this profile's background image path, if one is set, expanding
// - Returns this profile's background image path, if one is set, expanding
// any environment variables in the path, if there are any.
// - Or if "DesktopWallpaper" is set, then gets the path to the desktops wallpaper.
// Return Value:
// - This profile's expanded background image path / the empty string.
// - This profile's expanded background image path / desktops's wallpaper path /the empty string.
winrt::hstring Profile::ExpandedBackgroundImagePath() const
bennettnicholas marked this conversation as resolved.
Show resolved Hide resolved
{
if (_BackgroundImagePath.empty())
{
return _BackgroundImagePath;
}
return winrt::hstring{ wil::ExpandEnvironmentStringsW<std::wstring>(_BackgroundImagePath.c_str()) };
// checks if the user would like to copy their desktop wallpaper
// if so, replaces the path with the desktop wallpaper's path
else if (_BackgroundImagePath == to_hstring(DesktopWallpaperEnum))
bennettnicholas marked this conversation as resolved.
Show resolved Hide resolved
{
WCHAR desktopWallpaper[MAX_PATH];
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

// "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>(_BackgroundImagePath.c_str()) };
}
}

winrt::hstring Profile::EvaluatedStartingDirectory() const
Expand Down