PowerToys/src/modules/fancyzones/FancyZonesLib/FancyZonesData.h

161 lines
5.3 KiB
C
Raw Normal View History

#pragma once
#include "JsonHelpers.h"
#include <common/SettingsAPI/settings_helpers.h>
#include <common/utils/json.h>
#include <mutex>
#include <string>
#include <unordered_map>
#include <optional>
#include <vector>
#include <winnt.h>
#include <FancyZonesLib/JsonHelpers.h>
// Non-localizable strings
namespace NonLocalizable
{
const wchar_t FancyZonesStr[] = L"FancyZones";
}
namespace FancyZonesDataTypes
{
struct ZoneSetData;
struct DeviceIdData;
struct DeviceInfoData;
struct CustomZoneSetData;
struct AppZoneHistoryData;
}
#if defined(UNIT_TESTS)
namespace FancyZonesUnitTests
{
class FancyZonesDataUnitTests;
class FancyZonesIFancyZonesCallbackUnitTests;
class ZoneSetCalculateZonesUnitTests;
class ZoneWindowUnitTests;
class ZoneWindowCreationUnitTests;
}
#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;
const JSONHelpers::TDeviceInfoMap& GetDeviceInfoMap() const;
const JSONHelpers::TCustomZoneSetsMap& GetCustomZoneSetsMap() const;
const std::unordered_map<std::wstring, std::vector<FancyZonesDataTypes::AppZoneHistoryData>>& GetAppZoneHistoryMap() const;
inline const JSONHelpers::TLayoutQuickKeysMap& GetLayoutQuickKeys() const
{
std::scoped_lock lock{ dataLock };
return quickKeysMap;
}
inline const std::wstring& GetZonesSettingsFileName() const
{
return zonesSettingsFileName;
}
inline const std::wstring& GetSettingsFileName() const
{
return settingsFileName;
}
bool AddDevice(const std::wstring& deviceId);
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);
std::vector<size_t> GetAppLastZoneIndexSet(HWND window, const std::wstring_view& deviceId, const std::wstring_view& zoneSetId) const;
bool RemoveAppLastZone(HWND window, const std::wstring_view& deviceId, const std::wstring_view& zoneSetId);
bool SetAppLastZones(HWND window, const std::wstring& deviceId, const std::wstring& zoneSetId, const std::vector<size_t>& zoneIndexSet);
void SetActiveZoneSet(const std::wstring& deviceId, const FancyZonesDataTypes::ZoneSetData& zoneSet);
json::JsonObject GetPersistFancyZonesJSON();
void LoadFancyZonesData();
void SaveAppZoneHistoryAndZoneSettings() const;
void SaveZoneSettings() const;
void SaveAppZoneHistory() const;
void SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors, const std::wstring& virtualDesktopId, const HMONITOR& targetMonitor, const std::vector<std::pair<HMONITOR, MONITORINFOEX>>& allMonitors) const;
[FancyZones Editor] New UX for the FZ editor. (#9325) * Removed MetroWindow, added theming support and modernWPF * Rmoved MahApps refs * Removed MahApps * Updated canvas zones * Updated GridEditor * Fixes * UI updates * New layout type selection dialog * New editor UI * Updates * Fix * UI enhancements * Updated UI * Added styles to layoutpreview * Accesibility improvements * Accesibility and styling improvements * Fix * Cleaned up brushes * Updated UX * Updated UI * Added no layouts description * Fix * UI fixes * [FZ Editor] Serialize/deserialize settings (#8615) * conflicts fix * [FZ Editor] Parse json file instead of command line args (#8649) * [FZ Editor] Serialize/deserialize settings fix (#8707) * [FZ Editor] Hide unsupported settings in custom layouts flyouts (#8716) * [FZ Editor] Duplicate custom layouts (#8718) * [FZ Editor] Duplicate layout behavior (#8720) * New UX proposal * Updated spacing * Switching to toggleswitches * Revert toggleswitch * Updated colorbrush * Updated string for saving label * Updated UI * Dark theme color fixes * Removed space * [FZ Editor] Bind dialog properties (#9199) * Resize editor window to fit the content in single-monitor mode (#9203) * Editor opening fix (#9207) * Disable "Create" button if the Name textbox is empty (#9212) * [FZ Editor] Changed edit dialog for template layouts. (#9233) * [FZ Editor] Small fixes and refactoring. (#9236) * new layout creation refactoring * "Save and apply" applies the layout * number of zones header hide * [FZ Editor] Empty layout template. (#9237) * [FZ Editor] Move "Duplicate" and "Delete" buttons to the Edit dialog. (#9272) * [FZ Editor] Preview the applied layout after editing another layout. (#9278) * Fixed "Save and apply" button behavior (#9286) * [FZ Editor] Save template layouts in the settings. (#9283) * Added default custom layout name (#9291) * close dialog before opening zones editor (#9302) * Pressing Esc closes dialogs (#9301) * [FZ Editor] Reset applied layout to "No layout" if it was deleted. (#9315) * [FZ Editor] Dark theme colors (#9317) * "Number of zones" buttons colors. (#9321) * rebase fix * added ModernWpf.dll * address PR comments: updated colors * added comments, replaced magic numbers * refactoring * merge zones crash fix * removed redundant using directive Co-authored-by: Niels Laute <niels9001@hotmail.com> Co-authored-by: Niels Laute <niels.laute@live.nl>
2021-01-28 02:33:52 +08:00
private:
#if defined(UNIT_TESTS)
friend class FancyZonesUnitTests::FancyZonesDataUnitTests;
friend class FancyZonesUnitTests::FancyZonesIFancyZonesCallbackUnitTests;
friend class FancyZonesUnitTests::ZoneWindowUnitTests;
friend class FancyZonesUnitTests::ZoneWindowCreationUnitTests;
friend class FancyZonesUnitTests::ZoneSetCalculateZonesUnitTests;
inline void SetDeviceInfo(const std::wstring& deviceId, FancyZonesDataTypes::DeviceInfoData data)
{
deviceInfoMap[deviceId] = data;
}
[FancyZones Editor] New UX for the FZ editor. (#9325) * Removed MetroWindow, added theming support and modernWPF * Rmoved MahApps refs * Removed MahApps * Updated canvas zones * Updated GridEditor * Fixes * UI updates * New layout type selection dialog * New editor UI * Updates * Fix * UI enhancements * Updated UI * Added styles to layoutpreview * Accesibility improvements * Accesibility and styling improvements * Fix * Cleaned up brushes * Updated UX * Updated UI * Added no layouts description * Fix * UI fixes * [FZ Editor] Serialize/deserialize settings (#8615) * conflicts fix * [FZ Editor] Parse json file instead of command line args (#8649) * [FZ Editor] Serialize/deserialize settings fix (#8707) * [FZ Editor] Hide unsupported settings in custom layouts flyouts (#8716) * [FZ Editor] Duplicate custom layouts (#8718) * [FZ Editor] Duplicate layout behavior (#8720) * New UX proposal * Updated spacing * Switching to toggleswitches * Revert toggleswitch * Updated colorbrush * Updated string for saving label * Updated UI * Dark theme color fixes * Removed space * [FZ Editor] Bind dialog properties (#9199) * Resize editor window to fit the content in single-monitor mode (#9203) * Editor opening fix (#9207) * Disable "Create" button if the Name textbox is empty (#9212) * [FZ Editor] Changed edit dialog for template layouts. (#9233) * [FZ Editor] Small fixes and refactoring. (#9236) * new layout creation refactoring * "Save and apply" applies the layout * number of zones header hide * [FZ Editor] Empty layout template. (#9237) * [FZ Editor] Move "Duplicate" and "Delete" buttons to the Edit dialog. (#9272) * [FZ Editor] Preview the applied layout after editing another layout. (#9278) * Fixed "Save and apply" button behavior (#9286) * [FZ Editor] Save template layouts in the settings. (#9283) * Added default custom layout name (#9291) * close dialog before opening zones editor (#9302) * Pressing Esc closes dialogs (#9301) * [FZ Editor] Reset applied layout to "No layout" if it was deleted. (#9315) * [FZ Editor] Dark theme colors (#9317) * "Number of zones" buttons colors. (#9321) * rebase fix * added ModernWpf.dll * address PR comments: updated colors * added comments, replaced magic numbers * refactoring * merge zones crash fix * removed redundant using directive Co-authored-by: Niels Laute <niels9001@hotmail.com> Co-authored-by: Niels Laute <niels.laute@live.nl>
2021-01-28 02:33:52 +08:00
inline void SetCustomZonesets(const std::wstring& uuid, FancyZonesDataTypes::CustomZoneSetData data)
{
customZoneSetsMap[uuid] = data;
}
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{};
// Maps custom zoneset UUID to it's data
2020-12-29 00:54:23 +08:00
JSONHelpers::TCustomZoneSetsMap customZoneSetsMap{};
// Maps zoneset UUID with quick access keys
JSONHelpers::TLayoutQuickKeysMap quickKeysMap{};
std::wstring settingsFileName;
std::wstring zonesSettingsFileName;
std::wstring appZoneHistoryFileName;
[FancyZones Editor] New UX for the FZ editor. (#9325) * Removed MetroWindow, added theming support and modernWPF * Rmoved MahApps refs * Removed MahApps * Updated canvas zones * Updated GridEditor * Fixes * UI updates * New layout type selection dialog * New editor UI * Updates * Fix * UI enhancements * Updated UI * Added styles to layoutpreview * Accesibility improvements * Accesibility and styling improvements * Fix * Cleaned up brushes * Updated UX * Updated UI * Added no layouts description * Fix * UI fixes * [FZ Editor] Serialize/deserialize settings (#8615) * conflicts fix * [FZ Editor] Parse json file instead of command line args (#8649) * [FZ Editor] Serialize/deserialize settings fix (#8707) * [FZ Editor] Hide unsupported settings in custom layouts flyouts (#8716) * [FZ Editor] Duplicate custom layouts (#8718) * [FZ Editor] Duplicate layout behavior (#8720) * New UX proposal * Updated spacing * Switching to toggleswitches * Revert toggleswitch * Updated colorbrush * Updated string for saving label * Updated UI * Dark theme color fixes * Removed space * [FZ Editor] Bind dialog properties (#9199) * Resize editor window to fit the content in single-monitor mode (#9203) * Editor opening fix (#9207) * Disable "Create" button if the Name textbox is empty (#9212) * [FZ Editor] Changed edit dialog for template layouts. (#9233) * [FZ Editor] Small fixes and refactoring. (#9236) * new layout creation refactoring * "Save and apply" applies the layout * number of zones header hide * [FZ Editor] Empty layout template. (#9237) * [FZ Editor] Move "Duplicate" and "Delete" buttons to the Edit dialog. (#9272) * [FZ Editor] Preview the applied layout after editing another layout. (#9278) * Fixed "Save and apply" button behavior (#9286) * [FZ Editor] Save template layouts in the settings. (#9283) * Added default custom layout name (#9291) * close dialog before opening zones editor (#9302) * Pressing Esc closes dialogs (#9301) * [FZ Editor] Reset applied layout to "No layout" if it was deleted. (#9315) * [FZ Editor] Dark theme colors (#9317) * "Number of zones" buttons colors. (#9321) * rebase fix * added ModernWpf.dll * address PR comments: updated colors * added comments, replaced magic numbers * refactoring * merge zones crash fix * removed redundant using directive Co-authored-by: Niels Laute <niels9001@hotmail.com> Co-authored-by: Niels Laute <niels.laute@live.nl>
2021-01-28 02:33:52 +08:00
std::wstring editorParametersFileName;
mutable std::recursive_mutex dataLock;
};
FancyZonesData& FancyZonesDataInstance();
namespace DefaultValues
{
const int ZoneCount = 3;
const bool ShowSpacing = true;
const int Spacing = 16;
const int SensitivityRadius = 20;
}