mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-11 20:23:07 +08:00
[FancyZones] Only process windows located on currently active work area when moving them (#2691)
* Only process windows located on currently active work area when moving them. * Move all editor exit handling into dedicated method.
This commit is contained in:
parent
8b988409e2
commit
56c0a78c64
@ -22,7 +22,6 @@ enum class DisplayChangeType
|
|||||||
WorkArea,
|
WorkArea,
|
||||||
DisplayChange,
|
DisplayChange,
|
||||||
VirtualDesktop,
|
VirtualDesktop,
|
||||||
Editor,
|
|
||||||
Initialization
|
Initialization
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -219,7 +218,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void UpdateZoneWindows() noexcept;
|
void UpdateZoneWindows() noexcept;
|
||||||
void MoveWindowsOnDisplayChange() noexcept;
|
void UpdateWindowsPositions() noexcept;
|
||||||
void CycleActiveZoneSet(DWORD vkCode) noexcept;
|
void CycleActiveZoneSet(DWORD vkCode) noexcept;
|
||||||
bool OnSnapHotkey(DWORD vkCode) noexcept;
|
bool OnSnapHotkey(DWORD vkCode) noexcept;
|
||||||
|
|
||||||
@ -559,7 +558,7 @@ FancyZones::MoveWindowsOnActiveZoneSetChange() noexcept
|
|||||||
{
|
{
|
||||||
if (m_settings->GetSettings()->zoneSetChange_moveWindows)
|
if (m_settings->GetSettings()->zoneSetChange_moveWindows)
|
||||||
{
|
{
|
||||||
MoveWindowsOnDisplayChange();
|
UpdateWindowsPositions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,7 +620,6 @@ LRESULT FancyZones::WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lpa
|
|||||||
if (lparam == static_cast<LPARAM>(EditorExitKind::Exit))
|
if (lparam == static_cast<LPARAM>(EditorExitKind::Exit))
|
||||||
{
|
{
|
||||||
OnEditorExitEvent();
|
OnEditorExitEvent();
|
||||||
OnDisplayChange(DisplayChangeType::Editor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -693,21 +691,14 @@ void FancyZones::OnDisplayChange(DisplayChangeType changeType) noexcept
|
|||||||
{
|
{
|
||||||
if (m_settings->GetSettings()->displayChange_moveWindows)
|
if (m_settings->GetSettings()->displayChange_moveWindows)
|
||||||
{
|
{
|
||||||
MoveWindowsOnDisplayChange();
|
UpdateWindowsPositions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (changeType == DisplayChangeType::VirtualDesktop)
|
else if (changeType == DisplayChangeType::VirtualDesktop)
|
||||||
{
|
{
|
||||||
if (m_settings->GetSettings()->virtualDesktopChange_moveWindows)
|
if (m_settings->GetSettings()->virtualDesktopChange_moveWindows)
|
||||||
{
|
{
|
||||||
MoveWindowsOnDisplayChange();
|
UpdateWindowsPositions();
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (changeType == DisplayChangeType::Editor)
|
|
||||||
{
|
|
||||||
if (m_settings->GetSettings()->zoneSetChange_moveWindows)
|
|
||||||
{
|
|
||||||
MoveWindowsOnDisplayChange();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -796,7 +787,7 @@ void FancyZones::UpdateZoneWindows() noexcept
|
|||||||
EnumDisplayMonitors(nullptr, nullptr, callback, reinterpret_cast<LPARAM>(this));
|
EnumDisplayMonitors(nullptr, nullptr, callback, reinterpret_cast<LPARAM>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZones::MoveWindowsOnDisplayChange() noexcept
|
void FancyZones::UpdateWindowsPositions() noexcept
|
||||||
{
|
{
|
||||||
auto callback = [](HWND window, LPARAM data) -> BOOL {
|
auto callback = [](HWND window, LPARAM data) -> BOOL {
|
||||||
int i = static_cast<int>(reinterpret_cast<UINT_PTR>(::GetProp(window, ZONE_STAMP)));
|
int i = static_cast<int>(reinterpret_cast<UINT_PTR>(::GetProp(window, ZONE_STAMP)));
|
||||||
@ -947,6 +938,15 @@ void FancyZones::OnEditorExitEvent() noexcept
|
|||||||
JSONHelpers::FancyZonesDataInstance().ParseDeletedCustomZoneSetsFromTmpFile(ZoneWindowUtils::GetCustomZoneSetsTmpPath());
|
JSONHelpers::FancyZonesDataInstance().ParseDeletedCustomZoneSetsFromTmpFile(ZoneWindowUtils::GetCustomZoneSetsTmpPath());
|
||||||
JSONHelpers::FancyZonesDataInstance().ParseCustomZoneSetFromTmpFile(ZoneWindowUtils::GetAppliedZoneSetTmpPath());
|
JSONHelpers::FancyZonesDataInstance().ParseCustomZoneSetFromTmpFile(ZoneWindowUtils::GetAppliedZoneSetTmpPath());
|
||||||
JSONHelpers::FancyZonesDataInstance().SaveFancyZonesData();
|
JSONHelpers::FancyZonesDataInstance().SaveFancyZonesData();
|
||||||
|
// Update zone sets for currently active work areas.
|
||||||
|
for (auto& [monitor, zoneWindow] : m_zoneWindowMap)
|
||||||
|
{
|
||||||
|
zoneWindow->UpdateActiveZoneSet();
|
||||||
|
}
|
||||||
|
if (m_settings->GetSettings()->zoneSetChange_moveWindows)
|
||||||
|
{
|
||||||
|
UpdateWindowsPositions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<HMONITOR> FancyZones::GetMonitorsSorted() noexcept
|
std::vector<HMONITOR> FancyZones::GetMonitorsSorted() noexcept
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "lib/Settings.h"
|
#include "lib/Settings.h"
|
||||||
#include "lib/ZoneWindow.h"
|
#include "lib/ZoneWindow.h"
|
||||||
#include "lib/util.h"
|
#include "lib/util.h"
|
||||||
|
#include "VirtualDesktopUtils.h"
|
||||||
|
|
||||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||||
|
|
||||||
@ -298,6 +299,15 @@ void WindowMoveHandlerPrivate::MoveWindowIntoZoneByIndexSet(HWND window, HMONITO
|
|||||||
if (zoneWindow != zoneWindowMap.end())
|
if (zoneWindow != zoneWindowMap.end())
|
||||||
{
|
{
|
||||||
const auto& zoneWindowPtr = zoneWindow->second;
|
const auto& zoneWindowPtr = zoneWindow->second;
|
||||||
|
// Only process windows located on currently active work area.
|
||||||
|
GUID windowDesktopId{};
|
||||||
|
GUID zoneWindowDesktopId{};
|
||||||
|
if (VirtualDesktopUtils::GetWindowDesktopId(window, &windowDesktopId) &&
|
||||||
|
VirtualDesktopUtils::GetZoneWindowDesktopId(zoneWindowPtr.get(), &zoneWindowDesktopId) &&
|
||||||
|
(windowDesktopId != zoneWindowDesktopId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
zoneWindowPtr->MoveWindowIntoZoneByIndexSet(window, indexSet);
|
zoneWindowPtr->MoveWindowIntoZoneByIndexSet(window, indexSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,6 +233,8 @@ public:
|
|||||||
ShowZoneWindow() noexcept;
|
ShowZoneWindow() noexcept;
|
||||||
IFACEMETHODIMP_(void)
|
IFACEMETHODIMP_(void)
|
||||||
HideZoneWindow() noexcept;
|
HideZoneWindow() noexcept;
|
||||||
|
IFACEMETHODIMP_(void)
|
||||||
|
UpdateActiveZoneSet() noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||||
@ -536,6 +538,12 @@ ZoneWindow::HideZoneWindow() noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IFACEMETHODIMP_(void)
|
||||||
|
ZoneWindow::UpdateActiveZoneSet() noexcept
|
||||||
|
{
|
||||||
|
CalculateZoneSet();
|
||||||
|
}
|
||||||
|
|
||||||
#pragma region private
|
#pragma region private
|
||||||
|
|
||||||
void ZoneWindow::LoadSettings() noexcept
|
void ZoneWindow::LoadSettings() noexcept
|
||||||
|
@ -103,6 +103,10 @@ interface __declspec(uuid("{7F017528-8110-4FB3-BE41-F472969C2560}")) IZoneWindow
|
|||||||
IFACEMETHOD_(IZoneSet*, ActiveZoneSet)() = 0;
|
IFACEMETHOD_(IZoneSet*, ActiveZoneSet)() = 0;
|
||||||
IFACEMETHOD_(void, ShowZoneWindow)() = 0;
|
IFACEMETHOD_(void, ShowZoneWindow)() = 0;
|
||||||
IFACEMETHOD_(void, HideZoneWindow)() = 0;
|
IFACEMETHOD_(void, HideZoneWindow)() = 0;
|
||||||
|
/**
|
||||||
|
* Update currently active zone layout for this work area.
|
||||||
|
*/
|
||||||
|
IFACEMETHOD_(void, UpdateActiveZoneSet)() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
winrt::com_ptr<IZoneWindow> MakeZoneWindow(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor,
|
winrt::com_ptr<IZoneWindow> MakeZoneWindow(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor,
|
||||||
|
Loading…
Reference in New Issue
Block a user