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

[FancyZones] Set 3-zones PriorityGrid as default layout #6248

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 19 additions & 6 deletions src/modules/fancyzones/lib/FancyZonesData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,28 @@ std::optional<FancyZonesDataTypes::CustomZoneSetData> FancyZonesData::FindCustom

void FancyZonesData::AddDevice(const std::wstring& deviceId)
{
using namespace FancyZonesDataTypes;

std::scoped_lock lock{ dataLock };
if (!deviceInfoMap.contains(deviceId))
{
// Creates default entry in map when ZoneWindow is created
deviceInfoMap[deviceId] = FancyZonesDataTypes::DeviceInfoData{ FancyZonesDataTypes::ZoneSetData{ NonLocalizable::NullStr, FancyZonesDataTypes::ZoneSetLayoutType::Blank } };
GUID guid;
auto result{ CoCreateGuid(&guid) };
wil::unique_cotaskmem_string guidString;
if (result == S_OK && SUCCEEDED(StringFromCLSID(guid, &guidString)))
{
constexpr bool defaultShowSpacing{ true };
constexpr int defaultSpacing{ 16 };
constexpr int defaultZoneCount{ 3 };
const ZoneSetData zoneSetData{ guidString.get(), ZoneSetLayoutType::PriorityGrid };
DeviceInfoData defaultDeviceInfoData{ zoneSetData, defaultShowSpacing, defaultSpacing, defaultZoneCount };
deviceInfoMap[deviceId] = std::move(defaultDeviceInfoData);
}
else
{
deviceInfoMap[deviceId] = DeviceInfoData{ ZoneSetData{ NonLocalizable::NullStr, ZoneSetLayoutType::Blank } };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add anything into deviceInfoMap in this case? I remember that ZoneSetLayoutType::Blank has been added for some purpose, but I can't recall why exactly.
Everywhere there are checks if zone set UUID is valid and ZoneSetLayoutType is not Blank. It won't be saved in the settings file and just takes a place in the memory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double check whether Blank type and checks are still needed at all

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that we will add functionality to the editor to set no zoneset on a desktop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔼 That's why it is still needed :)

}
}
}

Expand All @@ -118,11 +135,7 @@ void FancyZonesData::CloneDeviceInfo(const std::wstring& source, const std::wstr
}

// Clone information from source device if destination device is uninitialized (Blank).
auto& destInfo = deviceInfoMap[destination];
if (destInfo.activeZoneSet.type == FancyZonesDataTypes::ZoneSetLayoutType::Blank)
{
destInfo = deviceInfoMap[source];
}
deviceInfoMap[destination] = deviceInfoMap[source];
}

void FancyZonesData::UpdatePrimaryDesktopData(const std::wstring& desktopId)
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/tests/UnitTests/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ DWORD WINAPI ThreadProc(LPVOID lpParam)
if (RegisterDLLWindowClass((LPCWSTR)creator->getWindowClassName().c_str(), creator) != 0)
{
auto hWnd = CreateWindowEx(0, (LPCWSTR)creator->getWindowClassName().c_str(), (LPCWSTR)creator->getTitle().c_str(), WS_EX_APPWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 10, 10, nullptr, nullptr, creator->getHInstance(), NULL);
SetWindowPos(hWnd, HWND_TOPMOST, 10, 10, 100, 100, SWP_SHOWWINDOW);
creator->setHwnd(hWnd);
creator->setCondition(true);

Expand Down
96 changes: 30 additions & 66 deletions src/modules/fancyzones/tests/UnitTests/ZoneWindow.Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,33 @@ namespace FancyZonesUnitTests
{
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
testZoneWindow(zoneWindow);
Assert::IsNull(zoneWindow->ActiveZoneSet());

auto* activeZoneSet{ zoneWindow->ActiveZoneSet() };
Assert::IsNotNull(activeZoneSet);
Assert::AreEqual(static_cast<int>(activeZoneSet->LayoutType()), static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid));
Assert::AreEqual(activeZoneSet->GetZones().size(), static_cast<size_t>(3));
}

TEST_METHOD(CreateZoneWindowNoHinst)
{
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), {}, m_monitor, m_uniqueId.str(), {}, false);
testZoneWindow(zoneWindow);
Assert::IsNull(zoneWindow->ActiveZoneSet());

auto* activeZoneSet{ zoneWindow->ActiveZoneSet() };
Assert::IsNotNull(activeZoneSet);
Assert::AreEqual(static_cast<int>(activeZoneSet->LayoutType()), static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid));
Assert::AreEqual(activeZoneSet->GetZones().size(), static_cast<size_t>(3));
}

TEST_METHOD(CreateZoneWindowNoHinstFlashZones)
{
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), {}, m_monitor, m_uniqueId.str(), {}, false);
testZoneWindow(zoneWindow);
Assert::IsNull(zoneWindow->ActiveZoneSet());

auto* activeZoneSet{ zoneWindow->ActiveZoneSet() };
Assert::IsNotNull(activeZoneSet);
Assert::AreEqual(static_cast<int>(activeZoneSet->LayoutType()), static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid));
Assert::AreEqual(activeZoneSet->GetZones().size(), static_cast<size_t>(3));
}

TEST_METHOD(CreateZoneWindowNoMonitor)
Expand All @@ -156,7 +168,11 @@ namespace FancyZonesUnitTests

Assert::IsNotNull(zoneWindow.get());
Assert::AreEqual(expectedUniqueId.c_str(), zoneWindow->UniqueId().c_str());
Assert::IsNull(zoneWindow->ActiveZoneSet());

auto* activeZoneSet{ zoneWindow->ActiveZoneSet() };
Assert::IsNotNull(activeZoneSet);
Assert::AreEqual(static_cast<int>(activeZoneSet->LayoutType()), static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid));
Assert::AreEqual(activeZoneSet->GetZones().size(), static_cast<size_t>(3));
}

TEST_METHOD(CreateZoneWindowNoDesktopId)
Expand All @@ -168,8 +184,11 @@ namespace FancyZonesUnitTests
const std::wstring expectedWorkArea = std::to_wstring(m_monitorInfo.rcMonitor.right) + L"_" + std::to_wstring(m_monitorInfo.rcMonitor.bottom);
Assert::IsNotNull(zoneWindow.get());
Assert::IsTrue(zoneWindow->UniqueId().empty());
Assert::IsNull(zoneWindow->ActiveZoneSet());
Assert::IsNull(zoneWindow->ActiveZoneSet());

auto* activeZoneSet{ zoneWindow->ActiveZoneSet() };
Assert::IsNotNull(activeZoneSet);
Assert::AreEqual(static_cast<int>(activeZoneSet->LayoutType()), static_cast<int>(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid));
Assert::AreEqual(activeZoneSet->GetZones().size(), static_cast<size_t>(3));
}

TEST_METHOD(CreateZoneWindowWithActiveZoneTmpFile)
Expand Down Expand Up @@ -401,16 +420,15 @@ namespace FancyZonesUnitTests
// newWorkArea = false - zoneWindow won't be cloned from parent
auto actualZoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);

Assert::IsNull(actualZoneWindow->ActiveZoneSet());
Assert::IsNotNull(actualZoneWindow->ActiveZoneSet());

Assert::IsTrue(m_fancyZonesData.GetDeviceInfoMap().contains(m_uniqueId.str()));
auto currentDeviceInfo = m_fancyZonesData.GetDeviceInfoMap().at(m_uniqueId.str());
// default values
Assert::AreEqual(false, currentDeviceInfo.showSpacing);
Assert::AreEqual(0, currentDeviceInfo.zoneCount);
Assert::AreEqual(0, currentDeviceInfo.spacing);
Assert::AreEqual(std::wstring{ L"null" }, currentDeviceInfo.activeZoneSet.uuid);
Assert::AreEqual(static_cast<int>(ZoneSetLayoutType::Blank), static_cast<int>(currentDeviceInfo.activeZoneSet.type));
Assert::AreEqual(true, currentDeviceInfo.showSpacing);
Assert::AreEqual(3, currentDeviceInfo.zoneCount);
Assert::AreEqual(16, currentDeviceInfo.spacing);
Assert::AreEqual(static_cast<int>(ZoneSetLayoutType::PriorityGrid), static_cast<int>(currentDeviceInfo.activeZoneSet.type));
}
};

Expand Down Expand Up @@ -454,22 +472,6 @@ namespace FancyZonesUnitTests
std::filesystem::remove(m_fancyZonesData.deletedCustomZoneSetsTmpFileName);
}

void PrepareFZData()
{
const auto activeZoneSetTempPath = m_fancyZonesData.activeZoneSetTmpFileName;
Assert::IsFalse(std::filesystem::exists(activeZoneSetTempPath));

const auto type = FancyZonesDataTypes::ZoneSetLayoutType::Columns;
const auto expectedZoneSet = FancyZonesDataTypes::ZoneSetData{ Helpers::CreateGuidString(), type };
const auto data = FancyZonesDataTypes::DeviceInfoData{ expectedZoneSet, true, 16, 3 };
const auto deviceInfo = JSONHelpers::DeviceInfoJSON{ m_uniqueId.str(), data };
const auto json = JSONHelpers::DeviceInfoJSON::ToJson(deviceInfo);
json::to_file(activeZoneSetTempPath, json);
Assert::IsTrue(std::filesystem::exists(activeZoneSetTempPath));

m_fancyZonesData.ParseDeviceInfoFromTmpFile(activeZoneSetTempPath);
}

public:
TEST_METHOD(MoveSizeEnter)
{
Expand Down Expand Up @@ -525,7 +527,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(MoveSizeEnd)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);

const auto window = Mocks::Window();
Expand All @@ -543,7 +544,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(MoveSizeEndWindowNotAdded)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);

const auto window = Mocks::Window();
Expand Down Expand Up @@ -583,7 +583,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(MoveSizeEndInvalidPoint)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);

const auto window = Mocks::Window();
Expand All @@ -599,17 +598,8 @@ namespace FancyZonesUnitTests
Assert::IsFalse(std::vector<size_t>{} == actualZoneIndex); // with invalid point zone remains the same
}

TEST_METHOD(MoveWindowIntoZoneByIndexNoActiveZoneSet)
{
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNull(zoneWindow->ActiveZoneSet());

zoneWindow->MoveWindowIntoZoneByIndex(Mocks::Window(), 0);
}

TEST_METHOD(MoveWindowIntoZoneByIndex)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand All @@ -618,17 +608,8 @@ namespace FancyZonesUnitTests
const auto actual = zoneWindow->ActiveZoneSet();
}

TEST_METHOD(MoveWindowIntoZoneByDirectionNoActiveZoneSet)
{
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNull(zoneWindow->ActiveZoneSet());

zoneWindow->MoveWindowIntoZoneByIndex(Mocks::Window(), 0);
}

TEST_METHOD(MoveWindowIntoZoneByDirectionAndIndex)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand All @@ -644,7 +625,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(MoveWindowIntoZoneByDirectionManyTimes)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand All @@ -660,20 +640,8 @@ namespace FancyZonesUnitTests
Assert::IsTrue(std::vector<size_t>{ 2 } == appHistoryArray[0].zoneIndexSet);
}

TEST_METHOD(SaveWindowProcessToZoneIndexNoActiveZoneSet)
{
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNull(zoneWindow->ActiveZoneSet());

zoneWindow->SaveWindowProcessToZoneIndex(Mocks::Window());

const auto actualAppZoneHistory = m_fancyZonesData.GetAppZoneHistoryMap();
Assert::IsTrue(actualAppZoneHistory.empty());
}

TEST_METHOD(SaveWindowProcessToZoneIndexNullptrWindow)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand All @@ -685,7 +653,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(SaveWindowProcessToZoneIndexNoWindowAdded)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand All @@ -701,7 +668,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(SaveWindowProcessToZoneIndexNoWindowAddedWithFilledAppZoneHistory)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand Down Expand Up @@ -730,7 +696,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(SaveWindowProcessToZoneIndexWindowAdded)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand Down Expand Up @@ -761,7 +726,6 @@ namespace FancyZonesUnitTests

TEST_METHOD(WhenWindowIsNotResizablePlacingItIntoTheZoneShouldNotResizeIt)
{
PrepareFZData();
auto zoneWindow = MakeZoneWindow(winrt::make_self<MockZoneWindowHost>().get(), m_hInst, m_monitor, m_uniqueId.str(), {}, false);
Assert::IsNotNull(zoneWindow->ActiveZoneSet());

Expand Down