mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Move window to last known zone. Support movement in multi-monitor scenario (#1511)
This commit is contained in:
@@ -114,7 +114,8 @@ public:
|
|||||||
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
|
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
|
||||||
void OnDisplayChange(DisplayChangeType changeType) noexcept;
|
void OnDisplayChange(DisplayChangeType changeType) noexcept;
|
||||||
void AddZoneWindow(HMONITOR monitor, PCWSTR deviceId) noexcept;
|
void AddZoneWindow(HMONITOR monitor, PCWSTR deviceId) noexcept;
|
||||||
void MoveWindowIntoZoneByIndex(HWND window, int index) noexcept;
|
|
||||||
|
void MoveWindowIntoZoneByIndex(HWND window, HMONITOR monitor, int index) noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static LRESULT CALLBACK s_WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
|
static LRESULT CALLBACK s_WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
|
||||||
@@ -310,26 +311,21 @@ FancyZones::WindowCreated(HWND window) noexcept
|
|||||||
{
|
{
|
||||||
if (m_settings->GetSettings().appLastZone_moveWindows && IsInterestingWindow(window))
|
if (m_settings->GetSettings().appLastZone_moveWindows && IsInterestingWindow(window))
|
||||||
{
|
{
|
||||||
auto monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
|
for (const auto& [monitor, zoneWindow] : m_zoneWindowMap)
|
||||||
if (monitor)
|
|
||||||
{
|
{
|
||||||
auto zoneWindow = m_zoneWindowMap.find(monitor);
|
const auto activeZoneSet = zoneWindow->ActiveZoneSet();
|
||||||
if (zoneWindow != m_zoneWindowMap.end())
|
if (activeZoneSet)
|
||||||
{
|
{
|
||||||
const auto& zoneWindowPtr = zoneWindow->second;
|
const auto& fancyZonesData = JSONHelpers::FancyZonesDataInstance();
|
||||||
const auto activeZoneSet = zoneWindowPtr->ActiveZoneSet();
|
|
||||||
if (activeZoneSet)
|
|
||||||
{
|
|
||||||
const auto& fancyZonesData = JSONHelpers::FancyZonesDataInstance();
|
|
||||||
|
|
||||||
wil::unique_cotaskmem_string guidString;
|
wil::unique_cotaskmem_string guidString;
|
||||||
if (SUCCEEDED_LOG(StringFromCLSID(activeZoneSet->Id(), &guidString)))
|
if (SUCCEEDED_LOG(StringFromCLSID(activeZoneSet->Id(), &guidString)))
|
||||||
|
{
|
||||||
|
int zoneIndex = fancyZonesData.GetAppLastZoneIndex(window, zoneWindow->UniqueId(), guidString.get());
|
||||||
|
if (zoneIndex != -1)
|
||||||
{
|
{
|
||||||
int zoneIndex = fancyZonesData.GetAppLastZoneIndex(window, zoneWindowPtr->UniqueId(), guidString.get());
|
MoveWindowIntoZoneByIndex(window, monitor, zoneIndex);
|
||||||
if (zoneIndex != -1)
|
break;
|
||||||
{
|
|
||||||
MoveWindowIntoZoneByIndex(window, zoneIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -667,18 +663,18 @@ void FancyZones::AddZoneWindow(HMONITOR monitor, PCWSTR deviceId) noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZones::MoveWindowIntoZoneByIndex(HWND window, int index) noexcept
|
void FancyZones::MoveWindowIntoZoneByIndex(HWND window, HMONITOR monitor, int index) noexcept
|
||||||
{
|
{
|
||||||
std::shared_lock readLock(m_lock);
|
std::shared_lock readLock(m_lock);
|
||||||
if (window != m_windowMoveSize)
|
if (window != m_windowMoveSize)
|
||||||
{
|
{
|
||||||
const HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
|
const HMONITOR hm = (monitor != nullptr) ? monitor : MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
|
||||||
if (monitor)
|
if (hm)
|
||||||
{
|
{
|
||||||
auto iter = m_zoneWindowMap.find(monitor);
|
auto zoneWindow = m_zoneWindowMap.find(hm);
|
||||||
if (iter != m_zoneWindowMap.end())
|
if (zoneWindow != m_zoneWindowMap.end())
|
||||||
{
|
{
|
||||||
const auto& zoneWindowPtr = iter->second;
|
const auto& zoneWindowPtr = zoneWindow->second;
|
||||||
zoneWindowPtr->MoveWindowIntoZoneByIndex(window, index);
|
zoneWindowPtr->MoveWindowIntoZoneByIndex(window, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -771,7 +767,7 @@ void FancyZones::MoveWindowsOnDisplayChange() noexcept
|
|||||||
{
|
{
|
||||||
// i is off by 1 since 0 is special.
|
// i is off by 1 since 0 is special.
|
||||||
auto strongThis = reinterpret_cast<FancyZones*>(data);
|
auto strongThis = reinterpret_cast<FancyZones*>(data);
|
||||||
strongThis->MoveWindowIntoZoneByIndex(window, i - 1);
|
strongThis->MoveWindowIntoZoneByIndex(window, nullptr, i - 1);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user