Use same zone set initially for new virtual desktops of same monitor (#815)

This commit is contained in:
vldmr11080
2019-12-06 15:09:27 +01:00
committed by Enrico Giordani
parent add63d2dde
commit 014c2c5249
4 changed files with 32 additions and 35 deletions

View File

@@ -64,9 +64,9 @@ namespace FancyZonesEditor
_blankCustomModel = new CanvasLayoutModel("Create new custom", c_blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height); _blankCustomModel = new CanvasLayoutModel("Create new custom", c_blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);
_zoneCount = (int)Registry.GetValue(_uniqueRegistryPath, "ZoneCount", 3); _zoneCount = ReadRegistryInt("ZoneCount", 3);
_spacing = (int)Registry.GetValue(_uniqueRegistryPath, "Spacing", 16); _spacing = ReadRegistryInt("Spacing", 16);
_showSpacing = (int)Registry.GetValue(_uniqueRegistryPath, "ShowSpacing", 1) == 1; _showSpacing = ReadRegistryInt("ShowSpacing", 1) == 1;
UpdateLayoutModels(); UpdateLayoutModels();
} }
@@ -181,6 +181,12 @@ namespace FancyZonesEditor
} }
private static float _dpi; private static float _dpi;
private int ReadRegistryInt(string valueName, int defaultValue)
{
object obj = Registry.GetValue(_uniqueRegistryPath, valueName, defaultValue);
return (obj != null) ? (int)obj : defaultValue;
}
// UpdateLayoutModels // UpdateLayoutModels
// Update the five default layouts based on the new ZoneCount // Update the five default layouts based on the new ZoneCount
private void UpdateLayoutModels() private void UpdateLayoutModels()

View File

@@ -39,6 +39,13 @@ public:
const auto nB = (tmp & 0xFF); const auto nB = (tmp & 0xFF);
return RGB(nR, nG, nB); return RGB(nR, nG, nB);
} }
IFACEMETHODIMP_(GUID) GetCurrentMonitorZoneSetId(HMONITOR monitor) noexcept
{
if (auto it = m_zoneWindowMap.find(monitor); it != m_zoneWindowMap.end() && it->second->ActiveZoneSet()) {
return it->second->ActiveZoneSet()->Id();
}
return GUID_NULL;
}
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept; LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
void OnDisplayChange(DisplayChangeType changeType) noexcept; void OnDisplayChange(DisplayChangeType changeType) noexcept;
@@ -308,9 +315,12 @@ void FancyZones::ToggleEditor() noexcept
std::to_wstring(width) + L"_" + std::to_wstring(width) + L"_" +
std::to_wstring(height); std::to_wstring(height);
const auto activeZoneSet = iter->second->ActiveZoneSet();
const std::wstring layoutID = activeZoneSet ? std::to_wstring(activeZoneSet->LayoutId()) : L"0";
const std::wstring params = const std::wstring params =
iter->second->UniqueId() + L" " + iter->second->UniqueId() + L" " +
std::to_wstring(iter->second->ActiveZoneSet()->LayoutId()) + L" " + layoutID + L" " +
std::to_wstring(reinterpret_cast<UINT_PTR>(monitor)) + L" " + std::to_wstring(reinterpret_cast<UINT_PTR>(monitor)) + L" " +
editorLocation + L" " + editorLocation + L" " +
iter->second->WorkAreaKey() + L" " + iter->second->WorkAreaKey() + L" " +
@@ -553,10 +563,6 @@ void FancyZones::UpdateZoneWindows() noexcept
return TRUE; return TRUE;
}; };
{
std::unique_lock writeLock(m_lock);
m_zoneWindowMap.clear();
}
EnumDisplayMonitors(nullptr, nullptr, callback, reinterpret_cast<LPARAM>(this)); EnumDisplayMonitors(nullptr, nullptr, callback, reinterpret_cast<LPARAM>(this));
} }

View File

@@ -34,6 +34,7 @@ interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindow
{ {
IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0; IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0;
IFACEMETHOD_(COLORREF, GetZoneHighlightColor)() = 0; IFACEMETHOD_(COLORREF, GetZoneHighlightColor)() = 0;
IFACEMETHOD_(GUID, GetCurrentMonitorZoneSetId)(HMONITOR monitor) = 0;
}; };
winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, IFancyZonesSettings* settings) noexcept; winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, IFancyZonesSettings* settings) noexcept;

View File

@@ -41,7 +41,6 @@ private:
void LoadSettings() noexcept; void LoadSettings() noexcept;
void InitializeZoneSets(MONITORINFO const& mi) noexcept; void InitializeZoneSets(MONITORINFO const& mi) noexcept;
void LoadZoneSetsFromRegistry() noexcept; void LoadZoneSetsFromRegistry() noexcept;
void AddDefaultZoneSet(MONITORINFO const& mi) noexcept;
void UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept; void UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept;
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept; LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
void DrawBackdrop(wil::unique_hdc& hdc, RECT const& clientRect) noexcept; void DrawBackdrop(wil::unique_hdc& hdc, RECT const& clientRect) noexcept;
@@ -314,12 +313,6 @@ void ZoneWindow::InitializeZoneSets(MONITORINFO const& mi) noexcept
{ {
LoadZoneSetsFromRegistry(); LoadZoneSetsFromRegistry();
if (m_zoneSets.empty())
{
// Add a "maximize" zone as the only default layout.
AddDefaultZoneSet(mi);
}
if (!m_activeZoneSet) if (!m_activeZoneSet)
{ {
ChooseDefaultActiveZoneSet(); ChooseDefaultActiveZoneSet();
@@ -378,20 +371,6 @@ void ZoneWindow::LoadZoneSetsFromRegistry() noexcept
} }
} }
void ZoneWindow::AddDefaultZoneSet(MONITORINFO const& mi) noexcept
{
GUID zoneSetId;
if (SUCCEEDED_LOG(CoCreateGuid(&zoneSetId)))
{
if (auto zoneSet = MakeZoneSet(ZoneSetConfig(zoneSetId, 0, m_monitor, m_workArea)))
{
zoneSet->AddZone(MakeZone(mi.rcWork));
m_zoneSets.emplace_back(zoneSet);
}
}
}
void ZoneWindow::UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept void ZoneWindow::UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept
{ {
m_activeZoneSet.copy_from(zoneSet); m_activeZoneSet.copy_from(zoneSet);
@@ -644,10 +623,15 @@ winrt::com_ptr<IZone> ZoneWindow::ZoneFromPoint(POINT pt) noexcept
void ZoneWindow::ChooseDefaultActiveZoneSet() noexcept void ZoneWindow::ChooseDefaultActiveZoneSet() noexcept
{ {
if (!m_activeZoneSet) // Default zone set can be empty (no fancyzones layout), or it can be layout from virtual
{ // desktop from which this virtual desktop is created.
auto zoneSet = m_zoneSets.at(0); if (GUID id{ m_host->GetCurrentMonitorZoneSetId(m_monitor) }; id != GUID_NULL) {
UpdateActiveZoneSet(zoneSet.get()); for (const auto& zoneSet : m_zoneSets) {
if (id == zoneSet->Id()) {
UpdateActiveZoneSet(zoneSet.get());
return;
}
}
} }
} }