mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 23:19:13 +08:00
Use same zone set initially for new virtual desktops of same monitor (#815)
This commit is contained in:
parent
add63d2dde
commit
014c2c5249
@ -36,7 +36,7 @@ namespace FancyZonesEditor
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Settings()
|
||||
{
|
||||
ParseCommandLineArgs();
|
||||
@ -64,9 +64,9 @@ namespace FancyZonesEditor
|
||||
|
||||
_blankCustomModel = new CanvasLayoutModel("Create new custom", c_blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);
|
||||
|
||||
_zoneCount = (int)Registry.GetValue(_uniqueRegistryPath, "ZoneCount", 3);
|
||||
_spacing = (int)Registry.GetValue(_uniqueRegistryPath, "Spacing", 16);
|
||||
_showSpacing = (int)Registry.GetValue(_uniqueRegistryPath, "ShowSpacing", 1) == 1;
|
||||
_zoneCount = ReadRegistryInt("ZoneCount", 3);
|
||||
_spacing = ReadRegistryInt("Spacing", 16);
|
||||
_showSpacing = ReadRegistryInt("ShowSpacing", 1) == 1;
|
||||
|
||||
UpdateLayoutModels();
|
||||
}
|
||||
@ -181,6 +181,12 @@ namespace FancyZonesEditor
|
||||
}
|
||||
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
|
||||
// Update the five default layouts based on the new ZoneCount
|
||||
private void UpdateLayoutModels()
|
||||
|
@ -39,6 +39,13 @@ public:
|
||||
const auto nB = (tmp & 0xFF);
|
||||
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;
|
||||
void OnDisplayChange(DisplayChangeType changeType) noexcept;
|
||||
@ -308,9 +315,12 @@ void FancyZones::ToggleEditor() noexcept
|
||||
std::to_wstring(width) + L"_" +
|
||||
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 =
|
||||
iter->second->UniqueId() + L" " +
|
||||
std::to_wstring(iter->second->ActiveZoneSet()->LayoutId()) + L" " +
|
||||
layoutID + L" " +
|
||||
std::to_wstring(reinterpret_cast<UINT_PTR>(monitor)) + L" " +
|
||||
editorLocation + L" " +
|
||||
iter->second->WorkAreaKey() + L" " +
|
||||
@ -553,10 +563,6 @@ void FancyZones::UpdateZoneWindows() noexcept
|
||||
return TRUE;
|
||||
};
|
||||
|
||||
{
|
||||
std::unique_lock writeLock(m_lock);
|
||||
m_zoneWindowMap.clear();
|
||||
}
|
||||
EnumDisplayMonitors(nullptr, nullptr, callback, reinterpret_cast<LPARAM>(this));
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindow
|
||||
{
|
||||
IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0;
|
||||
IFACEMETHOD_(COLORREF, GetZoneHighlightColor)() = 0;
|
||||
IFACEMETHOD_(GUID, GetCurrentMonitorZoneSetId)(HMONITOR monitor) = 0;
|
||||
};
|
||||
|
||||
winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, IFancyZonesSettings* settings) noexcept;
|
||||
|
@ -41,7 +41,6 @@ private:
|
||||
void LoadSettings() noexcept;
|
||||
void InitializeZoneSets(MONITORINFO const& mi) noexcept;
|
||||
void LoadZoneSetsFromRegistry() noexcept;
|
||||
void AddDefaultZoneSet(MONITORINFO const& mi) noexcept;
|
||||
void UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept;
|
||||
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||
void DrawBackdrop(wil::unique_hdc& hdc, RECT const& clientRect) noexcept;
|
||||
@ -250,7 +249,7 @@ IFACEMETHODIMP_(void) ZoneWindow::SaveWindowProcessToZoneIndex(HWND window) noex
|
||||
RegistryHelpers::SaveAppLastZone(window, processPath.data(), zoneIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma region private
|
||||
void ZoneWindow::ShowZoneWindow() noexcept
|
||||
@ -314,12 +313,6 @@ void ZoneWindow::InitializeZoneSets(MONITORINFO const& mi) noexcept
|
||||
{
|
||||
LoadZoneSetsFromRegistry();
|
||||
|
||||
if (m_zoneSets.empty())
|
||||
{
|
||||
// Add a "maximize" zone as the only default layout.
|
||||
AddDefaultZoneSet(mi);
|
||||
}
|
||||
|
||||
if (!m_activeZoneSet)
|
||||
{
|
||||
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
|
||||
{
|
||||
m_activeZoneSet.copy_from(zoneSet);
|
||||
@ -644,10 +623,15 @@ winrt::com_ptr<IZone> ZoneWindow::ZoneFromPoint(POINT pt) noexcept
|
||||
|
||||
void ZoneWindow::ChooseDefaultActiveZoneSet() noexcept
|
||||
{
|
||||
if (!m_activeZoneSet)
|
||||
{
|
||||
auto zoneSet = m_zoneSets.at(0);
|
||||
UpdateActiveZoneSet(zoneSet.get());
|
||||
// Default zone set can be empty (no fancyzones layout), or it can be layout from virtual
|
||||
// desktop from which this virtual desktop is created.
|
||||
if (GUID id{ m_host->GetCurrentMonitorZoneSetId(m_monitor) }; id != GUID_NULL) {
|
||||
for (const auto& zoneSet : m_zoneSets) {
|
||||
if (id == zoneSet->Id()) {
|
||||
UpdateActiveZoneSet(zoneSet.get());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user