mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Introduce handling of new/old work areas (#1296)
* Introduce handling of new/old work areas (defined by virtual desktop id and monitor) * Save data to JSON storage only once after we register all deleted virtual desktops * Update saving mechanism * Remove resolution from unique identifier * Update comments related to new unique identifier * Don't handle NULL GUID as it is default one * Revert "Remove resolution from unique identifier" This reverts commit5a36651217. * Revert "Update comments related to new unique identifier" This reverts commit8e89802549. * removed MigrateDeviceInfoFromRegistry Co-authored-by: Seraphima Zykova <zykovas91@gmail.com>
This commit is contained in:
@@ -22,6 +22,13 @@ namespace
|
||||
constexpr int c_blankCustomModelId = 0xFFFA;
|
||||
|
||||
const wchar_t* FANCY_ZONES_DATA_FILE = L"zones-settings.json";
|
||||
const wchar_t* DEFAULT_GUID = L"{00000000-0000-0000-0000-000000000000}";
|
||||
|
||||
std::wstring ExtractVirtualDesktopId(const std::wstring& deviceId)
|
||||
{
|
||||
// Format: <device-id>_<resolution>_<virtual-desktop-id>
|
||||
return deviceId.substr(deviceId.rfind('_') + 1);
|
||||
}
|
||||
}
|
||||
|
||||
namespace JSONHelpers
|
||||
@@ -174,11 +181,31 @@ namespace JSONHelpers
|
||||
{
|
||||
// Creates default entry in map when ZoneWindow is created
|
||||
deviceInfoMap[deviceId] = DeviceInfoData{ ZoneSetData{ L"null", ZoneSetLayoutType::Blank } };
|
||||
|
||||
MigrateDeviceInfoFromRegistry(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
bool FancyZonesData::RemoveDevicesByVirtualDesktopId(const std::wstring& virtualDesktopId)
|
||||
{
|
||||
if (virtualDesktopId == DEFAULT_GUID)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool modified{ false };
|
||||
for (auto it = deviceInfoMap.begin(); it != deviceInfoMap.end();)
|
||||
{
|
||||
if (ExtractVirtualDesktopId(it->first) == virtualDesktopId)
|
||||
{
|
||||
it = deviceInfoMap.erase(it);
|
||||
modified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
void FancyZonesData::CloneDeviceInfo(const std::wstring& source, const std::wstring& destination)
|
||||
{
|
||||
std::scoped_lock lock{ dataLock };
|
||||
@@ -558,32 +585,6 @@ namespace JSONHelpers
|
||||
}
|
||||
}
|
||||
|
||||
void FancyZonesData::MigrateDeviceInfoFromRegistry(const std::wstring& deviceId)
|
||||
{
|
||||
std::scoped_lock lock{ dataLock };
|
||||
wchar_t key[256];
|
||||
StringCchPrintf(key, ARRAYSIZE(key), L"%s\\%s", RegistryHelpers::REG_SETTINGS, deviceId.c_str());
|
||||
|
||||
wchar_t activeZoneSetId[256];
|
||||
activeZoneSetId[0] = '\0';
|
||||
DWORD bufferSize = sizeof(activeZoneSetId);
|
||||
DWORD showSpacing = 1;
|
||||
DWORD spacing = 16;
|
||||
DWORD zoneCount = 3;
|
||||
DWORD size = sizeof(DWORD);
|
||||
|
||||
SHRegGetUSValueW(key, L"ActiveZoneSetId", nullptr, &activeZoneSetId, &bufferSize, FALSE, nullptr, 0);
|
||||
SHRegGetUSValueW(key, L"ShowSpacing", nullptr, &showSpacing, &size, FALSE, nullptr, 0);
|
||||
SHRegGetUSValueW(key, L"Spacing", nullptr, &spacing, &size, FALSE, nullptr, 0);
|
||||
SHRegGetUSValueW(key, L"ZoneCount", nullptr, &zoneCount, &size, FALSE, nullptr, 0);
|
||||
|
||||
if (appliedZoneSetsMap.contains(std::wstring{ activeZoneSetId }))
|
||||
{
|
||||
deviceInfoMap[deviceId] = DeviceInfoData{ appliedZoneSetsMap.at(std::wstring{ activeZoneSetId }), static_cast<bool>(showSpacing), static_cast<int>(spacing), static_cast<int>(zoneCount) };
|
||||
SaveFancyZonesData();
|
||||
}
|
||||
}
|
||||
|
||||
void FancyZonesData::MigrateCustomZoneSetsFromRegistry()
|
||||
{
|
||||
std::scoped_lock lock{ dataLock };
|
||||
|
||||
Reference in New Issue
Block a user