2020-07-22 16:39:13 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "JsonHelpers.h"
|
|
|
|
|
2020-12-15 20:16:09 +08:00
|
|
|
#include <common/SettingsAPI/settings_helpers.h>
|
|
|
|
#include <common/utils/json.h>
|
2020-07-22 16:39:13 +08:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <optional>
|
|
|
|
#include <vector>
|
|
|
|
#include <winnt.h>
|
2021-06-23 20:48:54 +08:00
|
|
|
#include <FancyZonesLib/JsonHelpers.h>
|
|
|
|
|
|
|
|
// Non-localizable strings
|
|
|
|
namespace NonLocalizable
|
|
|
|
{
|
|
|
|
const wchar_t FancyZonesStr[] = L"FancyZones";
|
|
|
|
}
|
2020-07-22 16:39:13 +08:00
|
|
|
|
|
|
|
namespace FancyZonesDataTypes
|
|
|
|
{
|
|
|
|
struct ZoneSetData;
|
2020-11-17 16:38:19 +08:00
|
|
|
struct DeviceIdData;
|
2020-07-22 16:39:13 +08:00
|
|
|
struct DeviceInfoData;
|
|
|
|
struct CustomZoneSetData;
|
|
|
|
struct AppZoneHistoryData;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(UNIT_TESTS)
|
|
|
|
namespace FancyZonesUnitTests
|
|
|
|
{
|
|
|
|
class FancyZonesDataUnitTests;
|
|
|
|
class FancyZonesIFancyZonesCallbackUnitTests;
|
|
|
|
class ZoneSetCalculateZonesUnitTests;
|
|
|
|
class ZoneWindowUnitTests;
|
2020-08-21 13:56:25 +08:00
|
|
|
class ZoneWindowCreationUnitTests;
|
2020-07-22 16:39:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class FancyZonesData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FancyZonesData();
|
|
|
|
|
|
|
|
std::optional<FancyZonesDataTypes::DeviceInfoData> FindDeviceInfo(const std::wstring& zoneWindowId) const;
|
|
|
|
|
|
|
|
std::optional<FancyZonesDataTypes::CustomZoneSetData> FindCustomZoneSet(const std::wstring& guid) const;
|
|
|
|
|
2021-03-15 20:58:25 +08:00
|
|
|
const JSONHelpers::TDeviceInfoMap& GetDeviceInfoMap() const;
|
2020-07-22 16:39:13 +08:00
|
|
|
|
2021-03-15 20:58:25 +08:00
|
|
|
const JSONHelpers::TCustomZoneSetsMap& GetCustomZoneSetsMap() const;
|
2020-07-22 16:39:13 +08:00
|
|
|
|
2021-03-15 20:58:25 +08:00
|
|
|
const std::unordered_map<std::wstring, std::vector<FancyZonesDataTypes::AppZoneHistoryData>>& GetAppZoneHistoryMap() const;
|
2020-07-22 16:39:13 +08:00
|
|
|
|
2021-03-25 20:44:55 +08:00
|
|
|
inline const JSONHelpers::TLayoutQuickKeysMap& GetLayoutQuickKeys() const
|
|
|
|
{
|
|
|
|
std::scoped_lock lock{ dataLock };
|
|
|
|
return quickKeysMap;
|
|
|
|
}
|
|
|
|
|
2020-12-16 21:53:48 +08:00
|
|
|
inline const std::wstring& GetZonesSettingsFileName() const
|
|
|
|
{
|
|
|
|
return zonesSettingsFileName;
|
|
|
|
}
|
|
|
|
|
2021-06-23 20:48:54 +08:00
|
|
|
inline const std::wstring& GetSettingsFileName() const
|
|
|
|
{
|
|
|
|
return settingsFileName;
|
|
|
|
}
|
|
|
|
|
2020-10-08 22:02:51 +08:00
|
|
|
bool AddDevice(const std::wstring& deviceId);
|
2020-07-22 16:39:13 +08:00
|
|
|
void CloneDeviceInfo(const std::wstring& source, const std::wstring& destination);
|
|
|
|
void UpdatePrimaryDesktopData(const std::wstring& desktopId);
|
|
|
|
void RemoveDeletedDesktops(const std::vector<std::wstring>& activeDesktops);
|
|
|
|
|
|
|
|
bool IsAnotherWindowOfApplicationInstanceZoned(HWND window, const std::wstring_view& deviceId) const;
|
|
|
|
void UpdateProcessIdToHandleMap(HWND window, const std::wstring_view& deviceId);
|
2020-08-24 20:39:34 +08:00
|
|
|
std::vector<size_t> GetAppLastZoneIndexSet(HWND window, const std::wstring_view& deviceId, const std::wstring_view& zoneSetId) const;
|
2020-07-22 16:39:13 +08:00
|
|
|
bool RemoveAppLastZone(HWND window, const std::wstring_view& deviceId, const std::wstring_view& zoneSetId);
|
2020-08-24 20:39:34 +08:00
|
|
|
bool SetAppLastZones(HWND window, const std::wstring& deviceId, const std::wstring& zoneSetId, const std::vector<size_t>& zoneIndexSet);
|
2020-07-22 16:39:13 +08:00
|
|
|
|
|
|
|
void SetActiveZoneSet(const std::wstring& deviceId, const FancyZonesDataTypes::ZoneSetData& zoneSet);
|
|
|
|
|
|
|
|
json::JsonObject GetPersistFancyZonesJSON();
|
|
|
|
|
|
|
|
void LoadFancyZonesData();
|
2021-02-05 04:02:24 +08:00
|
|
|
void SaveAppZoneHistoryAndZoneSettings() const;
|
2021-01-05 21:00:39 +08:00
|
|
|
void SaveZoneSettings() const;
|
|
|
|
void SaveAppZoneHistory() const;
|
2020-07-22 16:39:13 +08:00
|
|
|
|
2021-06-23 23:28:23 +08:00
|
|
|
void SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors, const std::wstring& virtualDesktopId, const HMONITOR& targetMonitor, const std::vector<std::pair<HMONITOR, MONITORINFOEX>>& allMonitors) const;
|
2021-01-28 02:33:52 +08:00
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
private:
|
|
|
|
#if defined(UNIT_TESTS)
|
|
|
|
friend class FancyZonesUnitTests::FancyZonesDataUnitTests;
|
|
|
|
friend class FancyZonesUnitTests::FancyZonesIFancyZonesCallbackUnitTests;
|
|
|
|
friend class FancyZonesUnitTests::ZoneWindowUnitTests;
|
2020-08-21 13:56:25 +08:00
|
|
|
friend class FancyZonesUnitTests::ZoneWindowCreationUnitTests;
|
2020-07-22 16:39:13 +08:00
|
|
|
friend class FancyZonesUnitTests::ZoneSetCalculateZonesUnitTests;
|
|
|
|
|
|
|
|
inline void SetDeviceInfo(const std::wstring& deviceId, FancyZonesDataTypes::DeviceInfoData data)
|
|
|
|
{
|
|
|
|
deviceInfoMap[deviceId] = data;
|
|
|
|
}
|
|
|
|
|
2021-01-28 02:33:52 +08:00
|
|
|
inline void SetCustomZonesets(const std::wstring& uuid, FancyZonesDataTypes::CustomZoneSetData data)
|
|
|
|
{
|
|
|
|
customZoneSetsMap[uuid] = data;
|
|
|
|
}
|
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
inline bool ParseDeviceInfos(const json::JsonObject& fancyZonesDataJSON)
|
|
|
|
{
|
|
|
|
deviceInfoMap = JSONHelpers::ParseDeviceInfos(fancyZonesDataJSON);
|
|
|
|
return !deviceInfoMap.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void clear_data()
|
|
|
|
{
|
|
|
|
appZoneHistoryMap.clear();
|
|
|
|
deviceInfoMap.clear();
|
|
|
|
customZoneSetsMap.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetSettingsModulePath(std::wstring_view moduleName)
|
|
|
|
{
|
|
|
|
std::wstring result = PTSettingsHelper::get_module_save_folder_location(moduleName);
|
|
|
|
zonesSettingsFileName = result + L"\\" + std::wstring(L"zones-settings.json");
|
|
|
|
appZoneHistoryFileName = result + L"\\" + std::wstring(L"app-zone-history.json");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
void RemoveDesktopAppZoneHistory(const std::wstring& desktopId);
|
|
|
|
|
|
|
|
// Maps app path to app's zone history data
|
|
|
|
std::unordered_map<std::wstring, std::vector<FancyZonesDataTypes::AppZoneHistoryData>> appZoneHistoryMap{};
|
|
|
|
// Maps device unique ID to device data
|
2020-12-29 00:54:23 +08:00
|
|
|
JSONHelpers::TDeviceInfoMap deviceInfoMap{};
|
2020-07-22 16:39:13 +08:00
|
|
|
// Maps custom zoneset UUID to it's data
|
2020-12-29 00:54:23 +08:00
|
|
|
JSONHelpers::TCustomZoneSetsMap customZoneSetsMap{};
|
2021-03-25 20:44:55 +08:00
|
|
|
// Maps zoneset UUID with quick access keys
|
|
|
|
JSONHelpers::TLayoutQuickKeysMap quickKeysMap{};
|
2020-07-22 16:39:13 +08:00
|
|
|
|
2021-06-23 20:48:54 +08:00
|
|
|
std::wstring settingsFileName;
|
2020-07-22 16:39:13 +08:00
|
|
|
std::wstring zonesSettingsFileName;
|
|
|
|
std::wstring appZoneHistoryFileName;
|
2021-01-28 02:33:52 +08:00
|
|
|
std::wstring editorParametersFileName;
|
2020-07-22 16:39:13 +08:00
|
|
|
|
|
|
|
mutable std::recursive_mutex dataLock;
|
|
|
|
};
|
|
|
|
|
|
|
|
FancyZonesData& FancyZonesDataInstance();
|
2020-09-18 15:16:06 +08:00
|
|
|
|
|
|
|
namespace DefaultValues
|
|
|
|
{
|
|
|
|
const int ZoneCount = 3;
|
|
|
|
const bool ShowSpacing = true;
|
|
|
|
const int Spacing = 16;
|
|
|
|
const int SensitivityRadius = 20;
|
|
|
|
}
|