mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[FancyZones] Split zones-settings: layout hotkeys (#15514)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <common/SettingsAPI/FileWatcher.h>
|
||||
|
||||
#include <FancyZonesLib/FancyZonesData.h>
|
||||
#include <FancyZonesLib/FancyZonesData/LayoutHotkeys.h>
|
||||
#include <FancyZonesLib/FancyZonesWindowProperties.h>
|
||||
#include <FancyZonesLib/FancyZonesWinHookEventIDs.h>
|
||||
#include <FancyZonesLib/MonitorUtils.h>
|
||||
@@ -68,6 +69,9 @@ public:
|
||||
})
|
||||
{
|
||||
this->disableModuleCallback = std::move(disableModuleCallback);
|
||||
|
||||
FancyZonesDataInstance().ReplaceZoneSettingsFileFromOlderVersions();
|
||||
LayoutHotkeys::instance().LoadData();
|
||||
}
|
||||
|
||||
// IFancyZones
|
||||
@@ -486,8 +490,8 @@ FancyZones::OnKeyDown(PKBDLLHOOKSTRUCT info) noexcept
|
||||
|
||||
if (changeLayoutWhileNotDragging || changeLayoutWhileDragging)
|
||||
{
|
||||
auto quickKeysMap = FancyZonesDataInstance().GetLayoutQuickKeys();
|
||||
if (std::any_of(quickKeysMap.begin(), quickKeysMap.end(), [=](auto item) { return item.second == digitPressed; }))
|
||||
auto layoutId = LayoutHotkeys::instance().GetLayoutId(digitPressed);
|
||||
if (layoutId.has_value())
|
||||
{
|
||||
PostMessageW(m_window, WM_PRIV_QUICK_LAYOUT_KEY, 0, static_cast<LPARAM>(digitPressed));
|
||||
Trace::FancyZones::QuickLayoutSwitched(changeLayoutWhileNotDragging);
|
||||
@@ -767,6 +771,10 @@ LRESULT FancyZones::WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lpa
|
||||
FancyZonesDataInstance().LoadFancyZonesData();
|
||||
UpdateZoneSets();
|
||||
}
|
||||
else if (message == WM_PRIV_LAYOUT_HOTKEYS_FILE_UPDATE)
|
||||
{
|
||||
LayoutHotkeys::instance().LoadData();
|
||||
}
|
||||
else if (message == WM_PRIV_QUICK_LAYOUT_KEY)
|
||||
{
|
||||
ApplyQuickLayout(static_cast<int>(lparam));
|
||||
@@ -1293,13 +1301,16 @@ bool FancyZones::ShouldProcessSnapHotkey(DWORD vkCode) noexcept
|
||||
|
||||
void FancyZones::ApplyQuickLayout(int key) noexcept
|
||||
{
|
||||
std::wstring uuid;
|
||||
for (auto [layoutUuid, hotkey] : FancyZonesDataInstance().GetLayoutQuickKeys())
|
||||
auto layoutId = LayoutHotkeys::instance().GetLayoutId(key);
|
||||
if (!layoutId)
|
||||
{
|
||||
if (hotkey == key)
|
||||
{
|
||||
uuid = layoutUuid;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto uuidStr = FancyZonesUtils::GuidToString(layoutId.value());
|
||||
if (!uuidStr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto workArea = m_workAreaHandler.GetWorkAreaFromCursor(m_currentDesktopId);
|
||||
@@ -1307,12 +1318,12 @@ void FancyZones::ApplyQuickLayout(int key) noexcept
|
||||
// Find a custom zone set with this uuid and apply it
|
||||
auto customZoneSets = FancyZonesDataInstance().GetCustomZoneSetsMap();
|
||||
|
||||
if (!customZoneSets.contains(uuid))
|
||||
if (!customZoneSets.contains(uuidStr.value()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FancyZonesDataTypes::ZoneSetData data{ .uuid = uuid, .type = FancyZonesDataTypes::ZoneSetLayoutType::Custom };
|
||||
FancyZonesDataTypes::ZoneSetData data{ .uuid = uuidStr.value(), .type = FancyZonesDataTypes::ZoneSetLayoutType::Custom };
|
||||
FancyZonesDataInstance().SetActiveZoneSet(workArea->UniqueId(), data);
|
||||
FancyZonesDataInstance().SaveZoneSettings();
|
||||
UpdateZoneSets();
|
||||
|
||||
Reference in New Issue
Block a user