mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
[FancyZones] Configurable sensitivity radius (#6554)
* Add the setting for the Sensitivity Radius to JSON and the Editor Use the setting when determining Zones to highligh * Fix FanzyZones unit tests Add test for Json upgrade * Updated texts in FancyZone Editor More Text to Resources / Use Resources * Added constant for default of Sensitivity Radius * When installing from scratch of when a new device is added set the sensitivity radius to the default. Move all the constant values to a single namespace * restore correct formatting Co-authored-by: Remy Blok <remy.blok@prodware.nl>
This commit is contained in:
@@ -183,11 +183,8 @@ void FancyZonesData::AddDevice(const std::wstring& deviceId)
|
||||
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 };
|
||||
DeviceInfoData defaultDeviceInfoData{ zoneSetData, DefaultValues::ShowSpacing, DefaultValues::Spacing, DefaultValues::ZoneCount, DefaultValues::SensitivityRadius };
|
||||
deviceInfoMap[deviceId] = std::move(defaultDeviceInfoData);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -136,3 +136,11 @@ private:
|
||||
};
|
||||
|
||||
FancyZonesData& FancyZonesDataInstance();
|
||||
|
||||
namespace DefaultValues
|
||||
{
|
||||
const int ZoneCount = 3;
|
||||
const bool ShowSpacing = true;
|
||||
const int Spacing = 16;
|
||||
const int SensitivityRadius = 20;
|
||||
}
|
||||
|
||||
@@ -114,5 +114,6 @@ namespace FancyZonesDataTypes
|
||||
bool showSpacing;
|
||||
int spacing;
|
||||
int zoneCount;
|
||||
int sensitivityRadius;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "JsonHelpers.h"
|
||||
#include "FancyZonesData.h"
|
||||
#include "FancyZonesDataTypes.h"
|
||||
#include "trace.h"
|
||||
#include "util.h"
|
||||
@@ -27,6 +28,7 @@ namespace NonLocalizable
|
||||
const wchar_t EditorShowSpacingStr[] = L"editor-show-spacing";
|
||||
const wchar_t EditorSpacingStr[] = L"editor-spacing";
|
||||
const wchar_t EditorZoneCountStr[] = L"editor-zone-count";
|
||||
const wchar_t EditorSensitivityRadiusStr[] = L"editor-sensitivity-radius";
|
||||
const wchar_t GridStr[] = L"grid";
|
||||
const wchar_t HeightStr[] = L"height";
|
||||
const wchar_t HistoryStr[] = L"history";
|
||||
@@ -404,6 +406,7 @@ namespace JSONHelpers
|
||||
result.SetNamedValue(NonLocalizable::EditorShowSpacingStr, json::value(device.data.showSpacing));
|
||||
result.SetNamedValue(NonLocalizable::EditorSpacingStr, json::value(device.data.spacing));
|
||||
result.SetNamedValue(NonLocalizable::EditorZoneCountStr, json::value(device.data.zoneCount));
|
||||
result.SetNamedValue(NonLocalizable::EditorSensitivityRadiusStr, json::value(device.data.sensitivityRadius));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -431,8 +434,8 @@ namespace JSONHelpers
|
||||
|
||||
result.data.showSpacing = device.GetNamedBoolean(NonLocalizable::EditorShowSpacingStr);
|
||||
result.data.spacing = static_cast<int>(device.GetNamedNumber(NonLocalizable::EditorSpacingStr));
|
||||
result.data.zoneCount = static_cast<int>(
|
||||
device.GetNamedNumber(NonLocalizable::EditorZoneCountStr));
|
||||
result.data.zoneCount = static_cast<int>(device.GetNamedNumber(NonLocalizable::EditorZoneCountStr));
|
||||
result.data.sensitivityRadius = static_cast<int>(device.GetNamedNumber(NonLocalizable::EditorSensitivityRadiusStr, DefaultValues::SensitivityRadius));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace JSONHelpers
|
||||
static std::optional<CustomZoneSetJSON> FromJson(const json::JsonObject& customZoneSet);
|
||||
};
|
||||
|
||||
namespace ZoneSetDataJSON
|
||||
namespace ZoneSetDataJSON
|
||||
{
|
||||
json::JsonObject ToJson(const FancyZonesDataTypes::ZoneSetData& zoneSet);
|
||||
std::optional<FancyZonesDataTypes::ZoneSetData> FromJson(const json::JsonObject& zoneSet);
|
||||
@@ -62,10 +62,10 @@ namespace JSONHelpers
|
||||
|
||||
json::JsonObject GetPersistFancyZonesJSON(const std::wstring& zonesSettingsFileName, const std::wstring& appZoneHistoryFileName);
|
||||
void SaveFancyZonesData(const std::wstring& zonesSettingsFileName,
|
||||
const std::wstring& appZoneHistoryFileName,
|
||||
const TDeviceInfoMap& deviceInfoMap,
|
||||
const TCustomZoneSetsMap& customZoneSetsMap,
|
||||
const TAppZoneHistoryMap& appZoneHistoryMap);
|
||||
const std::wstring& appZoneHistoryFileName,
|
||||
const TDeviceInfoMap& deviceInfoMap,
|
||||
const TCustomZoneSetsMap& customZoneSetsMap,
|
||||
const TAppZoneHistoryMap& appZoneHistoryMap);
|
||||
|
||||
TAppZoneHistoryMap ParseAppZoneHistory(const json::JsonObject& fancyZonesDataJSON);
|
||||
json::JsonArray SerializeAppZoneHistory(const TAppZoneHistoryMap& appZoneHistoryMap);
|
||||
|
||||
@@ -187,7 +187,7 @@ IFACEMETHODIMP ZoneSet::AddZone(winrt::com_ptr<IZone> zone) noexcept
|
||||
IFACEMETHODIMP_(std::vector<size_t>)
|
||||
ZoneSet::ZonesFromPoint(POINT pt) noexcept
|
||||
{
|
||||
const int SENSITIVITY_RADIUS = 20;
|
||||
int sensitivityRadius = m_config.SensitivityRadius;
|
||||
std::vector<size_t> capturedZones;
|
||||
std::vector<size_t> strictlyCapturedZones;
|
||||
for (size_t i = 0; i < m_zones.size(); i++)
|
||||
@@ -196,8 +196,8 @@ ZoneSet::ZonesFromPoint(POINT pt) noexcept
|
||||
RECT newZoneRect = zone->GetZoneRect();
|
||||
if (newZoneRect.left < newZoneRect.right && newZoneRect.top < newZoneRect.bottom) // proper zone
|
||||
{
|
||||
if (newZoneRect.left - SENSITIVITY_RADIUS <= pt.x && pt.x <= newZoneRect.right + SENSITIVITY_RADIUS &&
|
||||
newZoneRect.top - SENSITIVITY_RADIUS <= pt.y && pt.y <= newZoneRect.bottom + SENSITIVITY_RADIUS)
|
||||
if (newZoneRect.left - sensitivityRadius <= pt.x && pt.x <= newZoneRect.right + sensitivityRadius &&
|
||||
newZoneRect.top - sensitivityRadius <= pt.y && pt.y <= newZoneRect.bottom + sensitivityRadius)
|
||||
{
|
||||
capturedZones.emplace_back(i);
|
||||
}
|
||||
@@ -227,8 +227,8 @@ ZoneSet::ZonesFromPoint(POINT pt) noexcept
|
||||
{
|
||||
auto rectI = m_zones[capturedZones[i]]->GetZoneRect();
|
||||
auto rectJ = m_zones[capturedZones[j]]->GetZoneRect();
|
||||
if (max(rectI.top, rectJ.top) + SENSITIVITY_RADIUS < min(rectI.bottom, rectJ.bottom) &&
|
||||
max(rectI.left, rectJ.left) + SENSITIVITY_RADIUS < min(rectI.right, rectJ.right))
|
||||
if (max(rectI.top, rectJ.top) + sensitivityRadius < min(rectI.bottom, rectJ.bottom) &&
|
||||
max(rectI.left, rectJ.left) + sensitivityRadius < min(rectI.right, rectJ.right))
|
||||
{
|
||||
overlap = true;
|
||||
i = capturedZones.size() - 1;
|
||||
|
||||
@@ -148,16 +148,19 @@ struct ZoneSetConfig
|
||||
ZoneSetConfig(
|
||||
GUID id,
|
||||
FancyZonesDataTypes::ZoneSetLayoutType layoutType,
|
||||
HMONITOR monitor) noexcept :
|
||||
HMONITOR monitor,
|
||||
int sensitivityRadius) noexcept :
|
||||
Id(id),
|
||||
LayoutType(layoutType),
|
||||
Monitor(monitor)
|
||||
Monitor(monitor),
|
||||
SensitivityRadius(sensitivityRadius)
|
||||
{
|
||||
}
|
||||
|
||||
GUID Id{};
|
||||
FancyZonesDataTypes::ZoneSetLayoutType LayoutType{};
|
||||
HMONITOR Monitor{};
|
||||
int SensitivityRadius;
|
||||
};
|
||||
|
||||
winrt::com_ptr<IZoneSet> MakeZoneSet(ZoneSetConfig const& config) noexcept;
|
||||
@@ -472,10 +472,13 @@ void ZoneWindow::CalculateZoneSet() noexcept
|
||||
GUID zoneSetId;
|
||||
if (SUCCEEDED_LOG(CLSIDFromString(activeZoneSet.uuid.c_str(), &zoneSetId)))
|
||||
{
|
||||
int sensitivityRadius = deviceInfoData->sensitivityRadius;
|
||||
|
||||
auto zoneSet = MakeZoneSet(ZoneSetConfig(
|
||||
zoneSetId,
|
||||
activeZoneSet.type,
|
||||
m_monitor));
|
||||
m_monitor,
|
||||
sensitivityRadius));
|
||||
|
||||
RECT workArea;
|
||||
if (m_monitor)
|
||||
@@ -499,6 +502,7 @@ void ZoneWindow::CalculateZoneSet() noexcept
|
||||
bool showSpacing = deviceInfoData->showSpacing;
|
||||
int spacing = showSpacing ? deviceInfoData->spacing : 0;
|
||||
int zoneCount = deviceInfoData->zoneCount;
|
||||
|
||||
zoneSet->CalculateZones(workArea, zoneCount, spacing);
|
||||
UpdateActiveZoneSet(zoneSet.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user